activemq-cpp-3.6.0
ActiveMQSessionKernel.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef _ACTIVEMQ_CORE_KERNELS_ACTIVEMQSESSIONKERNEL_H_
19 #define _ACTIVEMQ_CORE_KERNELS_ACTIVEMQSESSIONKERNEL_H_
20 
21 #include <cms/Session.h>
22 #include <cms/ExceptionListener.h>
23 
24 #include <activemq/util/Config.h>
25 #include <activemq/util/Usage.h>
41 
42 #include <decaf/lang/Pointer.h>
43 #include <decaf/util/Properties.h>
45 
46 #include <string>
47 #include <memory>
48 
49 namespace activemq {
50 namespace core {
51 
52  class ActiveMQConnection;
53  class ActiveMQConsumer;
54  class ActiveMQProducer;
55  class ActiveMQSessionExecutor;
56 
57 namespace kernels {
58 
61 
62  class SessionConfig;
63 
64  class AMQCPP_API ActiveMQSessionKernel : public virtual cms::Session, public Dispatcher {
65  private:
66 
68 
69  protected:
70 
71  SessionConfig* config;
72 
77 
82 
87 
93 
97  std::auto_ptr<ActiveMQSessionExecutor> executor;
98 
103 
108 
113 
118 
123 
124  private:
125 
127  ActiveMQSessionKernel& operator=(const ActiveMQSessionKernel&);
128 
129  public:
130 
134  const decaf::util::Properties& properties);
135 
136  virtual ~ActiveMQSessionKernel();
137 
142  virtual void redispatch(MessageDispatchChannel& unconsumedMessages);
143 
147  virtual void start();
148 
152  virtual void stop();
153 
158  bool isStarted() const;
159 
160  virtual bool isAutoAcknowledge() const {
161  return this->ackMode == cms::Session::AUTO_ACKNOWLEDGE;
162  }
163 
164  virtual bool isDupsOkAcknowledge() const {
165  return this->ackMode == cms::Session::DUPS_OK_ACKNOWLEDGE;
166  }
167 
168  virtual bool isClientAcknowledge() const {
169  return this->ackMode == cms::Session::CLIENT_ACKNOWLEDGE;
170  }
171 
172  virtual bool isIndividualAcknowledge() const {
173  return this->ackMode == cms::Session::INDIVIDUAL_ACKNOWLEDGE;
174  }
175 
179  void fire(const exceptions::ActiveMQException& ex);
180 
181  public: // Methods from ActiveMQMessageDispatcher
182 
187  virtual void dispatch(const Pointer<MessageDispatch>& message);
188 
189  public: // Implements Methods
190 
191  virtual void close();
192 
193  virtual void commit();
194 
195  virtual void rollback();
196 
197  virtual void recover();
198 
199  virtual cms::MessageConsumer* createConsumer(const cms::Destination* destination);
200 
201  virtual cms::MessageConsumer* createConsumer(const cms::Destination* destination,
202  const std::string& selector);
203 
204  virtual cms::MessageConsumer* createConsumer(const cms::Destination* destination,
205  const std::string& selector,
206  bool noLocal);
207 
208  virtual cms::MessageConsumer* createDurableConsumer(const cms::Topic* destination,
209  const std::string& name,
210  const std::string& selector,
211  bool noLocal = false);
212 
213  virtual cms::MessageProducer* createProducer(const cms::Destination* destination);
214 
215  virtual cms::QueueBrowser* createBrowser(const cms::Queue* queue);
216 
217  virtual cms::QueueBrowser* createBrowser(const cms::Queue* queue, const std::string& selector);
218 
219  virtual cms::Queue* createQueue(const std::string& queueName);
220 
221  virtual cms::Topic* createTopic(const std::string& topicName);
222 
223  virtual cms::TemporaryQueue* createTemporaryQueue();
224 
225  virtual cms::TemporaryTopic* createTemporaryTopic();
226 
227  virtual cms::Message* createMessage();
228 
229  virtual cms::BytesMessage* createBytesMessage();
230 
231  virtual cms::BytesMessage* createBytesMessage(const unsigned char* bytes, int bytesSize);
232 
233  virtual cms::StreamMessage* createStreamMessage();
234 
235  virtual cms::TextMessage* createTextMessage();
236 
237  virtual cms::TextMessage* createTextMessage( const std::string& text );
238 
239  virtual cms::MapMessage* createMapMessage();
240 
241  virtual cms::Session::AcknowledgeMode getAcknowledgeMode() const;
242 
243  virtual bool isTransacted() const;
244 
245  virtual void unsubscribe(const std::string& name);
246 
247  public: // ActiveMQSessionKernel specific Methods
248 
277  cms::Message* message, int deliveryMode, int priority, long long timeToLive,
278  util::MemoryUsage* producerWindow, long long sendTimeout, cms::AsyncCallback* onComplete);
279 
288  cms::ExceptionListener* getExceptionListener();
289 
297  virtual void setMessageTransformer(cms::MessageTransformer* transformer);
298 
304  virtual cms::MessageTransformer* getMessageTransformer() const;
305 
312  this->checkClosed();
313  return *( this->sessionInfo );
314  }
315 
322  this->checkClosed();
323  return *( this->sessionInfo->getSessionId() );
324  }
325 
330  return this->connection;
331  }
332 
336  Pointer<threads::Scheduler> getScheduler() const;
337 
343  long long getLastDeliveredSequenceId() const {
344  return this->lastDeliveredSequenceId;
345  }
346 
353  void setLastDeliveredSequenceId(long long value) {
354  this->lastDeliveredSequenceId = value;
355  }
356 
366  void oneway(Pointer<commands::Command> command);
367 
382  Pointer<commands::Response> syncRequest(Pointer<commands::Command> command, unsigned int timeout = 0);
383 
394  void addConsumer(Pointer<ActiveMQConsumerKernel> consumer);
395 
405  void removeConsumer(Pointer<ActiveMQConsumerKernel> consumer);
406 
417  void addProducer(Pointer<ActiveMQProducerKernel> producer);
418 
428  void removeProducer(Pointer<ActiveMQProducerKernel> producer);
429 
437  virtual void doStartTransaction();
438 
445  return this->transaction;
446  }
447 
452  void acknowledge();
453 
458  void deliverAcks();
459 
465 
469  void wakeup();
470 
475  Pointer<commands::ConsumerId> getNextConsumerId();
476 
481  Pointer<commands::ProducerId> getNextProducerId();
482 
489  void doClose();
490 
497  void dispose();
498 
508  void setPrefetchSize(Pointer<commands::ConsumerId> id, int prefetch);
509 
517 
523  bool isInUse(Pointer<commands::ActiveMQDestination> destination);
524 
529 
534 
543  bool iterateConsumers();
544 
545  private:
546 
551  long long getNextProducerSequenceId() {
552  return this->producerSequenceIds.getNextSequenceId();
553  }
554 
555  // Checks for the closed state and throws if so.
556  void checkClosed() const;
557 
558  // Send the Destination Creation Request to the Broker, alerting it
559  // that we've created a new Temporary Destination.
560  // @param tempDestination - The new Temporary Destination
561  void createTemporaryDestination(commands::ActiveMQTempDestination* tempDestination);
562 
563  // Send the Destination Destruction Request to the Broker, alerting
564  // it that we've removed an existing Temporary Destination.
565  // @param tempDestination - The Temporary Destination to remove
566  void destroyTemporaryDestination(commands::ActiveMQTempDestination* tempDestination);
567 
568  // Creates a new Temporary Destination name using the connection id
569  // and a rolling count.
570  // @returns a unique Temporary Destination name
571  std::string createTemporaryDestinationName();
572 
573  };
574 
575 }}}
576 
577 #endif /* _ACTIVEMQ_CORE_KERNELS_ACTIVEMQSESSIONKERNEL_H_ */