activemq-cpp-3.6.0
ActiveMQConnection.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_ACTIVEMQCONNECTION_H_
19 #define _ACTIVEMQ_CORE_ACTIVEMQCONNECTION_H_
20 
21 #include <cms/Connection.h>
22 #include <activemq/util/Config.h>
34 #include <decaf/util/Properties.h>
40 
41 #include <string>
42 #include <memory>
43 
44 namespace activemq{
45 namespace core{
46 
48 
49  class ActiveMQSession;
50  class ConnectionConfig;
51  class PrefetchPolicy;
52  class RedeliveryPolicy;
53 
62  private:
63 
64  ConnectionConfig* config;
65 
69  std::auto_ptr<cms::ConnectionMetaData> connectionMetaData;
70 
75 
81 
87 
92 
93  private:
94 
96  ActiveMQConnection& operator=(const ActiveMQConnection&);
97 
98  public:
99 
109  const Pointer<decaf::util::Properties> properties);
110 
111  virtual ~ActiveMQConnection();
112 
121  virtual void addSession(Pointer<activemq::core::kernels::ActiveMQSessionKernel> session);
122 
131  virtual void removeSession(Pointer<activemq::core::kernels::ActiveMQSessionKernel> session);
132 
141  virtual void addProducer(Pointer<kernels::ActiveMQProducerKernel> producer);
142 
148  virtual void removeProducer(const Pointer<commands::ProducerId>& producerId);
149 
156  virtual void addDispatcher(const Pointer<commands::ConsumerId>& consumer, Dispatcher* dispatcher);
157 
163  virtual void removeDispatcher(const Pointer<commands::ConsumerId>& consumer);
164 
175  virtual void sendPullRequest(const commands::ConsumerInfo* consumer, long long timeout);
176 
181  bool isClosed() const {
182  return this->closed.get();
183  }
184 
189  bool isStarted() const {
190  return this->started.get();
191  }
192 
197  bool isTransportFailed() const {
198  return this->transportFailed.get();
199  }
200 
219  virtual void destroyDestination(const commands::ActiveMQDestination* destination);
220 
239  virtual void destroyDestination(const cms::Destination* destination);
240 
241  public: // Connection Interface Methods
242 
246  virtual const cms::ConnectionMetaData* getMetaData() const {
247  return connectionMetaData.get();
248  }
249 
253  virtual cms::Session* createSession();
254 
258  virtual std::string getClientID() const;
259 
263  virtual void setClientID(const std::string& clientID);
264 
268  virtual cms::Session* createSession(cms::Session::AcknowledgeMode ackMode);
269 
273  virtual void close();
274 
278  virtual void start();
279 
283  virtual void stop();
284 
288  virtual cms::ExceptionListener* getExceptionListener() const;
289 
293  virtual void setExceptionListener(cms::ExceptionListener* listener);
294 
298  virtual void setMessageTransformer(cms::MessageTransformer* transformer);
299 
303  virtual cms::MessageTransformer* getMessageTransformer() const;
304 
305  public: // Configuration Options
306 
311  void setUsername(const std::string& username);
312 
318  const std::string& getUsername() const;
319 
324  void setPassword(const std::string& password);
325 
331  const std::string& getPassword() const;
332 
337  void setDefaultClientId(const std::string& clientId);
338 
344  void setBrokerURL(const std::string& brokerURL);
345 
351  const std::string& getBrokerURL() const;
352 
361  void setPrefetchPolicy(PrefetchPolicy* policy);
362 
368  PrefetchPolicy* getPrefetchPolicy() const;
369 
378  void setRedeliveryPolicy(RedeliveryPolicy* policy);
379 
385  RedeliveryPolicy* getRedeliveryPolicy() const;
386 
390  bool isDispatchAsync() const;
391 
400  void setDispatchAsync(bool value);
401 
407  bool isAlwaysSyncSend() const;
408 
414  void setAlwaysSyncSend(bool value);
415 
420  bool isUseAsyncSend() const;
421 
426  void setUseAsyncSend(bool value);
427 
432  bool isUseCompression() const;
433 
440  void setUseCompression(bool value);
441 
451  void setCompressionLevel(int value);
452 
458  int getCompressionLevel() const;
459 
464  unsigned int getSendTimeout() const;
465 
471  void setSendTimeout(unsigned int timeout);
472 
477  unsigned int getCloseTimeout() const;
478 
483  void setCloseTimeout(unsigned int timeout);
484 
492  unsigned int getProducerWindowSize() const;
493 
500  void setProducerWindowSize(unsigned int windowSize);
501 
506  bool isMessagePrioritySupported() const;
507 
515  void setMessagePrioritySupported(bool value);
516 
521  long long getNextTempDestinationId();
522 
527  long long getNextLocalTransactionId();
528 
535  bool isWatchTopicAdvisories() const;
536 
544  void setWatchTopicAdvisories(bool value);
545 
546  public: // TransportListener
547 
559  void addTransportListener(transport::TransportListener* transportListener);
560 
569  void removeTransportListener(transport::TransportListener* transportListener);
570 
576  virtual void onCommand(const Pointer<commands::Command> command);
577 
582  virtual void onException(const decaf::lang::Exception& ex);
583 
587  virtual void transportInterrupted();
588 
592  virtual void transportResumed();
593 
594  public:
595 
602  const commands::ConnectionInfo& getConnectionInfo() const;
603 
610  const commands::ConnectionId& getConnectionId() const;
611 
617  transport::Transport& getTransport() const;
618 
624  Pointer<threads::Scheduler> getScheduler() const;
625 
632  std::string getResourceManagerId() const;
633 
638  void cleanup();
639 
650  void oneway(Pointer<commands::Command> command);
651 
666  Pointer<commands::Response> syncRequest(Pointer<commands::Command> command, unsigned int timeout = 0);
667 
680  void asyncRequest(Pointer<commands::Command> command, cms::AsyncCallback* onComplete);
681 
686  virtual void fire(const exceptions::ActiveMQException& ex);
687 
692  void setTransportInterruptionProcessingComplete();
693 
700  void setFirstFailureError(decaf::lang::Exception* error);
701 
707  decaf::lang::Exception* getFirstFailureError() const;
708 
715  void onAsyncException(const decaf::lang::Exception& ex);
716 
723  void onClientInternalException(const decaf::lang::Exception& ex);
724 
730  void checkClosed() const;
731 
737  void checkClosedOrFailed() const;
738 
742  void ensureConnectionInfoSent();
743 
747  decaf::util::concurrent::ExecutorService* getExecutor() const;
748 
756  void addTempDestination(Pointer<commands::ActiveMQTempDestination> destination);
757 
765  void removeTempDestination(Pointer<commands::ActiveMQTempDestination> destination);
766 
776  void deleteTempDestination(Pointer<commands::ActiveMQTempDestination> destination);
777 
784  void cleanUpTempDestinations();
785 
792  bool isDeleted(Pointer<commands::ActiveMQTempDestination> destination) const;
793 
794  protected:
795 
799  virtual Pointer<commands::SessionId> getNextSessionId();
800 
801  // Sends a oneway disconnect message to the broker.
802  void disconnect(long long lastDeliveredSequenceId);
803 
804  // Waits for all Consumers to handle the Transport Interrupted event.
805  void waitForTransportInterruptionProcessingToComplete();
806 
807  // Marks processing complete for a single caller when interruption processing completes.
808  void signalInterruptionProcessingComplete();
809 
810  // Allow subclasses to access the original Properties object for this connection.
811  const decaf::util::Properties& getProperties() const;
812 
813  // Process the ControlCommand command
814  void onControlCommand(Pointer<commands::Command> command);
815 
816  // Process the ConnectionControl command
817  void onConnectionControl(Pointer<commands::Command> command);
818 
819  // Process the ConsumerControl command
820  void onConsumerControl(Pointer<commands::Command> command);
821 
822  };
823 
824 }}
825 
826 #endif /*_ACTIVEMQ_CORE_ACTIVEMQCONNECTION_H_*/