KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > transport > TransportFilter


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.transport;
19
20 import java.io.IOException JavaDoc;
21 /**
22  * @version $Revision: 1.5 $
23  */

24 public class TransportFilter implements TransportListener,Transport{
25     final protected Transport next;
26     protected TransportListener transportListener;
27
28     public TransportFilter(Transport next){
29         this.next=next;
30     }
31
32     public TransportListener getTransportListener(){
33         return transportListener;
34     }
35
36     public void setTransportListener(TransportListener channelListener){
37         this.transportListener=channelListener;
38         if(channelListener==null)
39             next.setTransportListener(null);
40         else
41             next.setTransportListener(this);
42     }
43
44     /**
45      * @see org.apache.activemq.Service#start()
46      * @throws IOException
47      * if the next channel has not been set.
48      */

49     public void start() throws Exception JavaDoc{
50         if(next==null)
51             throw new IOException JavaDoc("The next channel has not been set.");
52         if(transportListener==null)
53             throw new IOException JavaDoc("The command listener has not been set.");
54         next.start();
55     }
56
57     /**
58      * @see org.apache.activemq.Service#stop()
59      */

60     public void stop() throws Exception JavaDoc{
61         next.stop();
62     }
63
64     public void onCommand(Object JavaDoc command){
65         transportListener.onCommand(command);
66     }
67
68     /**
69      * @return Returns the next.
70      */

71     public Transport getNext(){
72         return next;
73     }
74
75     public String JavaDoc toString(){
76         return next.toString();
77     }
78
79     public void oneway(Object JavaDoc command) throws IOException JavaDoc{
80         next.oneway(command);
81     }
82
83     public FutureResponse asyncRequest(Object JavaDoc command,ResponseCallback responseCallback) throws IOException JavaDoc{
84         return next.asyncRequest(command,null);
85     }
86
87     public Object JavaDoc request(Object JavaDoc command) throws IOException JavaDoc{
88         return next.request(command);
89     }
90
91     public Object JavaDoc request(Object JavaDoc command,int timeout) throws IOException JavaDoc{
92         return next.request(command,timeout);
93     }
94
95     public void onException(IOException JavaDoc error){
96         transportListener.onException(error);
97     }
98
99     public void transportInterupted(){
100         transportListener.transportInterupted();
101     }
102
103     public void transportResumed(){
104         transportListener.transportResumed();
105     }
106
107     public Object JavaDoc narrow(Class JavaDoc target){
108         if(target.isAssignableFrom(getClass())){
109             return this;
110         }
111         return next.narrow(target);
112     }
113
114     public String JavaDoc getRemoteAddress() {
115         return next.getRemoteAddress();
116     }
117 }
118
Popular Tags