|
activemq-cpp-3.4.0
|
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_FAILOVER_BACKUPTRANSPORTPOOL_H_ 00019 #define _ACTIVEMQ_TRANSPORT_FAILOVER_BACKUPTRANSPORTPOOL_H_ 00020 00021 #include <activemq/util/Config.h> 00022 #include <activemq/threads/CompositeTask.h> 00023 #include <activemq/threads/CompositeTaskRunner.h> 00024 #include <activemq/transport/failover/CloseTransportsTask.h> 00025 #include <activemq/transport/failover/BackupTransport.h> 00026 #include <activemq/transport/failover/URIPool.h> 00027 00028 #include <decaf/lang/Pointer.h> 00029 #include <decaf/io/IOException.h> 00030 #include <decaf/util/LinkedList.h> 00031 00032 namespace activemq { 00033 namespace transport { 00034 namespace failover { 00035 00036 using decaf::lang::Pointer; 00037 using decaf::util::LinkedList; 00038 using activemq::threads::CompositeTaskRunner; 00039 00040 class AMQCPP_API BackupTransportPool : public activemq::threads::CompositeTask { 00041 private: 00042 00043 friend class BackupTransport; 00044 00045 mutable LinkedList< Pointer<BackupTransport> > backups; 00046 Pointer<CompositeTaskRunner> taskRunner; 00047 Pointer<CloseTransportsTask> closeTask; 00048 Pointer<URIPool> uriPool; 00049 volatile int backupPoolSize; 00050 volatile bool enabled; 00051 volatile bool pending; 00052 00053 public: 00054 00055 BackupTransportPool( const Pointer<CompositeTaskRunner>& taskRunner, 00056 const Pointer<CloseTransportsTask>& closeTask, 00057 const Pointer<URIPool>& uriPool ); 00058 00059 BackupTransportPool( int backupPoolSize, 00060 const Pointer<CompositeTaskRunner>& taskRunner, 00061 const Pointer<CloseTransportsTask>& closeTask, 00062 const Pointer<URIPool>& uriPool ); 00063 00064 virtual ~BackupTransportPool(); 00065 00069 virtual bool isPending() const; 00070 00077 Pointer<BackupTransport> getBackup(); 00078 00083 virtual bool iterate(); 00084 00089 int getBackupPoolSize() const { 00090 return this->backupPoolSize; 00091 } 00092 00097 void setBackupPoolSize( int size ) { 00098 this->backupPoolSize = size; 00099 } 00100 00107 bool isEnabled() const { 00108 return this->enabled; 00109 } 00110 00117 void setEnabled( bool value ); 00118 00119 private: 00120 00121 // The backups report their failure to the pool, the pool removes them 00122 // from the list and returns their URIs to the URIPool, and then adds 00123 // the internal transport to the close transport's task for cleanup. 00124 void onBackupTransportFailure( BackupTransport* failedTransport ); 00125 00126 Pointer<Transport> createTransport( const URI& location ) const; 00127 00128 }; 00129 00130 }}} 00131 00132 #endif /*_ACTIVEMQ_TRANSPORT_FAILOVER_BACKUPTRANSPORTPOOL_H_*/