activemq-cpp-3.3.0

src/main/activemq/transport/IOTransport.h

Go to the documentation of this file.
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_IOTRANSPORT_H_
00019 #define _ACTIVEMQ_TRANSPORT_IOTRANSPORT_H_
00020 
00021 #include <activemq/util/Config.h>
00022 #include <activemq/transport/Transport.h>
00023 #include <activemq/transport/TransportListener.h>
00024 #include <activemq/commands/Command.h>
00025 #include <activemq/commands/Response.h>
00026 #include <activemq/exceptions/ActiveMQException.h>
00027 #include <activemq/wireformat/WireFormat.h>
00028 
00029 #include <decaf/lang/Runnable.h>
00030 #include <decaf/lang/Thread.h>
00031 #include <decaf/io/DataInputStream.h>
00032 #include <decaf/io/DataOutputStream.h>
00033 #include <decaf/util/logging/LoggerDefines.h>
00034 #include <memory>
00035 
00036 namespace activemq{
00037 namespace transport{
00038 
00039     using decaf::lang::Pointer;
00040     using activemq::commands::Command;
00041     using activemq::commands::Response;
00042 
00055     class AMQCPP_API IOTransport : public Transport,
00056                                    public decaf::lang::Runnable {
00057 
00058         LOGDECAF_DECLARE( logger )
00059 
00060     private:
00061 
00065         Pointer<wireformat::WireFormat> wireFormat;
00066 
00070         TransportListener* listener;
00071 
00075         decaf::io::DataInputStream* inputStream;
00076 
00080         decaf::io::DataOutputStream* outputStream;
00081 
00085         Pointer<decaf::lang::Thread> thread;
00086 
00090         volatile bool closed;
00091 
00092     private:
00093 
00094         IOTransport( const IOTransport& );
00095         IOTransport& operator= ( const IOTransport& );
00096 
00097     private:
00098 
00103         void fire( decaf::lang::Exception& ex );
00104 
00109         void fire( const Pointer<Command>& command );
00110 
00111     public:
00112 
00116         IOTransport();
00117 
00125         IOTransport( const Pointer<wireformat::WireFormat>& wireFormat );
00126 
00127         virtual ~IOTransport();
00128 
00135         virtual void setInputStream( decaf::io::DataInputStream* is ) {
00136             this->inputStream = is;
00137         }
00138 
00145         virtual void setOutputStream( decaf::io::DataOutputStream* os ) {
00146             this->outputStream = os;
00147         }
00148 
00149     public:  //Transport methods
00150 
00151         virtual void oneway( const Pointer<Command>& command );
00152 
00158         virtual Pointer<Response> request( const Pointer<Command>& command );
00159 
00165         virtual Pointer<Response> request( const Pointer<Command>& command, unsigned int timeout );
00166 
00167         virtual void setWireFormat( const Pointer<wireformat::WireFormat>& wireFormat ){
00168             this->wireFormat = wireFormat;
00169         }
00170 
00171         virtual void setTransportListener( TransportListener* listener ){
00172             this->listener = listener;
00173         }
00174 
00175         virtual TransportListener* getTransportListener() const {
00176             return this->listener;
00177         }
00178 
00179         virtual void start();
00180 
00181         virtual void stop();
00182 
00183         virtual void close();
00184 
00185         virtual Transport* narrow( const std::type_info& typeId ) {
00186             if( typeid( *this ) == typeId ) {
00187                 return this;
00188             }
00189 
00190             return NULL;
00191         }
00192 
00193         virtual bool isFaultTolerant() const {
00194             return false;
00195         }
00196 
00197         virtual bool isConnected() const {
00198             return !this->closed;
00199         }
00200 
00201         virtual bool isClosed() const {
00202             return this->closed;
00203         }
00204 
00205         virtual std::string getRemoteAddress() const {
00206             return "";
00207         }
00208 
00209         virtual bool isReconnectSupported() const {
00210             return false;
00211         }
00212 
00213         virtual bool isUpdateURIsSupported() const {
00214             return false;
00215         }
00216 
00217         virtual void updateURIs( bool rebalance AMQCPP_UNUSED,
00218                                  const decaf::util::List<decaf::net::URI>& uris AMQCPP_UNUSED ) {
00219             throw decaf::io::IOException();
00220         }
00221 
00227         virtual void reconnect( const decaf::net::URI& uri AMQCPP_UNUSED ) {}
00228 
00229     public:  // Runnable methods.
00230 
00234         virtual void run();
00235 
00236     };
00237 
00238 }}
00239 
00240 #endif /*_ACTIVEMQ_TRANSPORT_IOTRANSPORT_H_*/