00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one or more 00003 * contributor license agreements. See the NOTICE file distributed with 00004 * this work for additional information regarding copyright ownership. 00005 * The ASF licenses this file to You under the Apache License, Version 2.0 00006 * (the "License"); you may not use this file except in compliance with 00007 * the License. You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 #ifndef ACTIVEMQ_TRANSPORT_TRANSPORTFILTER_H_ 00019 #define ACTIVEMQ_TRANSPORT_TRANSPORTFILTER_H_ 00020 00021 #include <activemq/util/Config.h> 00022 #include <activemq/exceptions/ActiveMQException.h> 00023 #include <activemq/transport/Transport.h> 00024 #include <activemq/commands/Command.h> 00025 #include <activemq/transport/TransportListener.h> 00026 #include <decaf/lang/Pointer.h> 00027 #include <typeinfo> 00028 00029 namespace activemq { 00030 namespace transport { 00031 00032 using decaf::lang::Pointer; 00033 using activemq::commands::Command; 00034 using activemq::commands::Response; 00035 00036 class TransportFilterImpl; 00037 00044 class AMQCPP_API TransportFilter: public Transport, public TransportListener { 00045 private: 00046 00047 TransportFilterImpl* impl; 00048 00049 protected: 00050 00054 Pointer<Transport> next; 00055 00059 TransportListener* listener; 00060 00061 private: 00062 00063 TransportFilter(const TransportFilter&); 00064 TransportFilter& operator=(const TransportFilter&); 00065 00066 public: 00067 00072 TransportFilter(const Pointer<Transport> next); 00073 00074 virtual ~TransportFilter(); 00075 00076 void start(); 00077 00078 void stop(); 00079 00080 void close(); 00081 00082 protected: 00083 00087 void checkClosed() const; 00088 00089 public: 00090 00095 virtual void onCommand(const Pointer<Command> command); 00096 00102 virtual void onException(const decaf::lang::Exception& ex); 00103 00107 virtual void transportInterrupted(); 00108 00112 virtual void transportResumed(); 00113 00114 public: 00115 00116 virtual void oneway(const Pointer<Command> command) { 00117 checkClosed(); 00118 next->oneway(command); 00119 } 00120 00121 virtual Pointer<FutureResponse> asyncRequest(const Pointer<Command> command, 00122 const Pointer<ResponseCallback> responseCallback) { 00123 checkClosed(); 00124 return next->asyncRequest(command, responseCallback); 00125 } 00126 00127 virtual Pointer<Response> request(const Pointer<Command> command) { 00128 checkClosed(); 00129 return next->request(command); 00130 } 00131 00132 virtual Pointer<Response> request(const Pointer<Command> command, unsigned int timeout) { 00133 checkClosed(); 00134 return next->request(command, timeout); 00135 } 00136 00137 virtual void setTransportListener(TransportListener* listener) { 00138 this->listener = listener; 00139 } 00140 00141 virtual TransportListener* getTransportListener() const { 00142 return this->listener; 00143 } 00144 00145 virtual Pointer<wireformat::WireFormat> getWireFormat() const; 00146 00147 virtual void setWireFormat(const Pointer<wireformat::WireFormat> wireFormat); 00148 00149 virtual Transport* narrow(const std::type_info& typeId); 00150 00151 virtual bool isFaultTolerant() const { 00152 return !isClosed() && next->isFaultTolerant(); 00153 } 00154 00155 virtual bool isConnected() const { 00156 return !isClosed() && next->isConnected(); 00157 } 00158 00159 virtual bool isReconnectSupported() const { 00160 return !isClosed() && next->isReconnectSupported(); 00161 } 00162 00163 virtual bool isUpdateURIsSupported() const { 00164 return !isClosed() && next->isUpdateURIsSupported(); 00165 } 00166 00167 virtual bool isClosed() const; 00168 00169 virtual std::string getRemoteAddress() const { 00170 00171 if (isClosed()) { 00172 return ""; 00173 } 00174 00175 return next->getRemoteAddress(); 00176 } 00177 00178 virtual void reconnect(const decaf::net::URI& uri); 00179 00180 virtual void updateURIs(bool rebalance, const decaf::util::List<decaf::net::URI>& uris) { 00181 checkClosed(); 00182 next->updateURIs(rebalance, uris); 00183 } 00184 00185 protected: 00186 00192 virtual void beforeNextIsStarted() {} 00193 00199 virtual void afterNextIsStarted() {} 00200 00206 virtual void beforeNextIsStopped() {} 00207 00213 virtual void afterNextIsStopped() {} 00214 00220 virtual void doClose() {} 00221 00222 }; 00223 00224 }} 00225 00226 #endif /*ACTIVEMQ_TRANSPORT_TRANSPORTFILTER_H_*/
1.6.1