activemq-cpp-3.4.0

src/main/activemq/state/SessionState.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_STATE_SESSIONSTATE_H_
00019 #define _ACTIVEMQ_STATE_SESSIONSTATE_H_
00020 
00021 #include <activemq/util/Config.h>
00022 #include <activemq/commands/SessionInfo.h>
00023 #include <activemq/commands/ConsumerId.h>
00024 #include <activemq/commands/ProducerId.h>
00025 #include <activemq/state/ConsumerState.h>
00026 #include <activemq/state/ProducerState.h>
00027 
00028 #include <decaf/util/concurrent/atomic/AtomicBoolean.h>
00029 #include <decaf/util/concurrent/ConcurrentStlMap.h>
00030 
00031 #include <string>
00032 #include <memory>
00033 
00034 namespace activemq {
00035 namespace state {
00036 
00037     using decaf::lang::Pointer;
00038     using decaf::util::concurrent::ConcurrentStlMap;
00039     using decaf::util::concurrent::atomic::AtomicBoolean;
00040     using namespace activemq::commands;
00041 
00042     class AMQCPP_API SessionState {
00043     private:
00044 
00045         Pointer<SessionInfo> info;
00046 
00047         ConcurrentStlMap< Pointer<ProducerId>,
00048                           Pointer<ProducerState>,
00049                           ProducerId::COMPARATOR > producers;
00050 
00051         ConcurrentStlMap< Pointer<ConsumerId>,
00052                           Pointer<ConsumerState>,
00053                           ConsumerId::COMPARATOR > consumers;
00054 
00055         AtomicBoolean disposed;
00056 
00057     public:
00058 
00059         SessionState( const Pointer<SessionInfo>& info );
00060 
00061         virtual ~SessionState();
00062 
00063         std::string toString() const;
00064 
00065         const Pointer<SessionInfo> getInfo() const {
00066             return this->info;
00067         }
00068 
00069         void addProducer( const Pointer<ProducerInfo>& info );
00070 
00071         Pointer<ProducerState> removeProducer( const Pointer<ProducerId>& id );
00072 
00073         void addConsumer( const Pointer<ConsumerInfo>& info ) {
00074             checkShutdown();
00075             consumers.put( info->getConsumerId(),
00076                 Pointer<ConsumerState>( new ConsumerState( info ) ) );
00077         }
00078 
00079         Pointer<ConsumerState> removeConsumer( const Pointer<ConsumerId>& id ) {
00080             return consumers.remove( id );
00081         }
00082 
00083         std::vector< Pointer<ProducerState> > getProducerStates() const {
00084             return producers.values();
00085         }
00086 
00087         Pointer<ProducerState> getProducerState( const Pointer<ProducerId>& id ) {
00088             return producers.get( id );
00089         }
00090 
00091         std::vector< Pointer<ConsumerState> > getConsumerStates() const {
00092             return consumers.values();
00093         }
00094 
00095         Pointer<ConsumerState> getConsumerState( const Pointer<ConsumerId>& id ) {
00096             return consumers.get( id );
00097         }
00098 
00099         void checkShutdown() const;
00100 
00101         void shutdown() {
00102             this->disposed.set( true );
00103         }
00104 
00105     };
00106 
00107 }}
00108 
00109 #endif /*_ACTIVEMQ_STATE_SESSIONSTATE_H_*/