001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.activemq.transport; 018 019 import java.io.IOException; 020 import java.net.URI; 021 022 /** 023 * @version $Revision: 1.5 $ 024 */ 025 public class TransportFilter implements TransportListener, Transport { 026 protected final Transport next; 027 protected TransportListener transportListener; 028 029 public TransportFilter(Transport next) { 030 this.next = next; 031 } 032 033 public TransportListener getTransportListener() { 034 return transportListener; 035 } 036 037 public void setTransportListener(TransportListener channelListener) { 038 this.transportListener = channelListener; 039 if (channelListener == null) { 040 next.setTransportListener(null); 041 } else { 042 next.setTransportListener(this); 043 } 044 } 045 046 /** 047 * @see org.apache.activemq.Service#start() 048 * @throws IOException if the next channel has not been set. 049 */ 050 public void start() throws Exception { 051 if (next == null) { 052 throw new IOException("The next channel has not been set."); 053 } 054 if (transportListener == null) { 055 throw new IOException("The command listener has not been set."); 056 } 057 next.start(); 058 } 059 060 /** 061 * @see org.apache.activemq.Service#stop() 062 */ 063 public void stop() throws Exception { 064 next.stop(); 065 } 066 067 public void onCommand(Object command) { 068 transportListener.onCommand(command); 069 } 070 071 /** 072 * @return Returns the next. 073 */ 074 public Transport getNext() { 075 return next; 076 } 077 078 public String toString() { 079 return next.toString(); 080 } 081 082 public void oneway(Object command) throws IOException { 083 next.oneway(command); 084 } 085 086 public FutureResponse asyncRequest(Object command, ResponseCallback responseCallback) throws IOException { 087 return next.asyncRequest(command, null); 088 } 089 090 public Object request(Object command) throws IOException { 091 return next.request(command); 092 } 093 094 public Object request(Object command, int timeout) throws IOException { 095 return next.request(command, timeout); 096 } 097 098 public void onException(IOException error) { 099 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 141 public int getReceiveCounter() { 142 return next.getReceiveCounter(); 143 } 144 }