1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.activemq.transport;
18
19 import java.io.IOException;
20 import java.net.URI;
21
22 /**
23 * @version $Revision: 1.5 $
24 */
25 public class TransportFilter implements TransportListener, Transport {
26 protected final Transport next;
27 protected TransportListener transportListener;
28
29 public TransportFilter(Transport next) {
30 this.next = next;
31 }
32
33 public TransportListener getTransportListener() {
34 return transportListener;
35 }
36
37 public void setTransportListener(TransportListener channelListener) {
38 this.transportListener = channelListener;
39 if (channelListener == null) {
40 next.setTransportListener(null);
41 } else {
42 next.setTransportListener(this);
43 }
44 }
45
46 /**
47 * @see org.apache.activemq.Service#start()
48 * @throws IOException if the next channel has not been set.
49 */
50 public void start() throws Exception {
51 if (next == null) {
52 throw new IOException("The next channel has not been set.");
53 }
54 if (transportListener == null) {
55 throw new IOException("The command listener has not been set.");
56 }
57 next.start();
58 }
59
60 /**
61 * @see org.apache.activemq.Service#stop()
62 */
63 public void stop() throws Exception {
64 next.stop();
65 }
66
67 public void onCommand(Object command) {
68 transportListener.onCommand(command);
69 }
70
71 /**
72 * @return Returns the next.
73 */
74 public Transport getNext() {
75 return next;
76 }
77
78 public String toString() {
79 return next.toString();
80 }
81
82 public void oneway(Object command) throws IOException {
83 next.oneway(command);
84 }
85
86 public FutureResponse asyncRequest(Object command, ResponseCallback responseCallback) throws IOException {
87 return next.asyncRequest(command, null);
88 }
89
90 public Object request(Object command) throws IOException {
91 return next.request(command);
92 }
93
94 public Object request(Object command, int timeout) throws IOException {
95 return next.request(command, timeout);
96 }
97
98 public void onException(IOException error) {
99 transportListener.onException(error);
100 }
101
102 public void transportInterupted() {
103 transportListener.transportInterupted();
104 }
105
106 public void transportResumed() {
107 transportListener.transportResumed();
108 }
109
110 public <T> T narrow(Class<T> target) {
111 if (target.isAssignableFrom(getClass())) {
112 return target.cast(this);
113 }
114 return next.narrow(target);
115 }
116
117 public String getRemoteAddress() {
118 return next.getRemoteAddress();
119 }
120
121 /**
122 * @return
123 * @see org.apache.activemq.transport.Transport#isFaultTolerant()
124 */
125 public boolean isFaultTolerant() {
126 return next.isFaultTolerant();
127 }
128
129 public boolean isDisposed() {
130 return next.isDisposed();
131 }
132
133 public boolean isConnected() {
134 return next.isConnected();
135 }
136
137 public void reconnect(URI uri) throws IOException {
138 next.reconnect(uri);
139 }
140 }