activemq-cpp-3.9.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/EnhancedConnection.h>
22 #include <activemq/util/Config.h>
34 #include <decaf/util/Properties.h>
35 #include <decaf/util/ArrayList.h>
41 
42 #include <string>
43 #include <memory>
44 
45 namespace activemq {
46 namespace core {
47 
49 
50  class ActiveMQSession;
51  class ConnectionConfig;
52  class PrefetchPolicy;
53  class RedeliveryPolicy;
54 
63  private:
64 
65  ConnectionConfig* config;
66 
70  std::auto_ptr<cms::ConnectionMetaData> connectionMetaData;
71 
76 
82 
88 
93 
94  private:
95 
97  ActiveMQConnection& operator=(const ActiveMQConnection&);
98 
99  public:
100 
110  const Pointer<decaf::util::Properties> properties);
111 
112  virtual ~ActiveMQConnection();
113 
122  virtual void addSession(Pointer<activemq::core::kernels::ActiveMQSessionKernel> session);
123 
132  virtual void removeSession(Pointer<activemq::core::kernels::ActiveMQSessionKernel> session);
133 
142  virtual void addProducer(Pointer<kernels::ActiveMQProducerKernel> producer);
143 
149  virtual void removeProducer(const Pointer<commands::ProducerId>& producerId);
150 
157  virtual void addDispatcher(const Pointer<commands::ConsumerId>& consumer, Dispatcher* dispatcher);
158 
164  virtual void removeDispatcher(const Pointer<commands::ConsumerId>& consumer);
165 
176  virtual void sendPullRequest(const commands::ConsumerInfo* consumer, long long timeout);
177 
182  bool isClosed() const {
183  return this->closed.get();
184  }
185 
190  bool isStarted() const {
191  return this->started.get();
192  }
193 
198  bool isTransportFailed() const {
199  return this->transportFailed.get();
200  }
201 
220  virtual void destroyDestination(const commands::ActiveMQDestination* destination);
221 
240  virtual void destroyDestination(const cms::Destination* destination);
241 
252  bool isDuplicate(Dispatcher* dispatcher, Pointer<commands::Message> message);
253 
262  void rollbackDuplicate(Dispatcher* dispatcher, Pointer<commands::Message> message);
263 
270  void removeAuditedDispatcher(Dispatcher* dispatcher);
271 
272  public: // Connection Interface Methods
273 
277  virtual const cms::ConnectionMetaData* getMetaData() const {
278  return connectionMetaData.get();
279  }
280 
284  virtual cms::Session* createSession();
285 
289  virtual std::string getClientID() const;
290 
294  virtual void setClientID(const std::string& clientID);
295 
299  virtual cms::Session* createSession(cms::Session::AcknowledgeMode ackMode);
300 
304  virtual void close();
305 
309  virtual void start();
310 
314  virtual void stop();
315 
319  virtual cms::ExceptionListener* getExceptionListener() const;
320 
324  virtual void setExceptionListener(cms::ExceptionListener* listener);
325 
329  virtual void setMessageTransformer(cms::MessageTransformer* transformer);
330 
334  virtual cms::MessageTransformer* getMessageTransformer() const;
335 
339  virtual cms::DestinationSource* getDestinationSource();
340 
341  public: // Configuration Options
342 
347  void setUsername(const std::string& username);
348 
354  const std::string& getUsername() const;
355 
360  void setPassword(const std::string& password);
361 
367  const std::string& getPassword() const;
368 
373  void setDefaultClientId(const std::string& clientId);
374 
380  void setBrokerURL(const std::string& brokerURL);
381 
387  const std::string& getBrokerURL() const;
388 
397  void setPrefetchPolicy(PrefetchPolicy* policy);
398 
404  PrefetchPolicy* getPrefetchPolicy() const;
405 
414  void setRedeliveryPolicy(RedeliveryPolicy* policy);
415 
421  RedeliveryPolicy* getRedeliveryPolicy() const;
422 
426  bool isDispatchAsync() const;
427 
436  void setDispatchAsync(bool value);
437 
443  bool isAlwaysSyncSend() const;
444 
450  void setAlwaysSyncSend(bool value);
451 
456  bool isUseAsyncSend() const;
457 
462  void setUseAsyncSend(bool value);
463 
468  bool isUseCompression() const;
469 
476  void setUseCompression(bool value);
477 
487  void setCompressionLevel(int value);
488 
494  int getCompressionLevel() const;
495 
500  unsigned int getSendTimeout() const;
501 
507  void setSendTimeout(unsigned int timeout);
508 
513  unsigned int getCloseTimeout() const;
514 
519  void setCloseTimeout(unsigned int timeout);
520 
528  unsigned int getProducerWindowSize() const;
529 
536  void setProducerWindowSize(unsigned int windowSize);
537 
542  bool isMessagePrioritySupported() const;
543 
551  void setMessagePrioritySupported(bool value);
552 
557  long long getNextTempDestinationId();
558 
563  long long getNextLocalTransactionId();
564 
571  bool isWatchTopicAdvisories() const;
572 
580  void setWatchTopicAdvisories(bool value);
581 
590  int getAuditDepth() const;
591 
601  void setAuditDepth(int auditDepth);
602 
608  int getAuditMaximumProducerNumber() const;
609 
616  void setAuditMaximumProducerNumber(int auditMaximumProducerNumber);
617 
630  bool isCheckForDuplicates() const;
631 
645  void setCheckForDuplicates(bool checkForDuplicates);
646 
654  bool isTransactedIndividualAck() const;
655 
664  void setTransactedIndividualAck(bool transactedIndividualAck);
665 
672  bool isNonBlockingRedelivery() const;
673 
682  void setNonBlockingRedelivery(bool nonBlockingRedelivery);
683 
689  long long getConsumerFailoverRedeliveryWaitPeriod() const;
690 
697  void setConsumerFailoverRedeliveryWaitPeriod(long long value);
698 
702  bool isOptimizeAcknowledge() const;
703 
710  void setOptimizeAcknowledge(bool optimizeAcknowledge);
711 
717  long long getOptimizeAcknowledgeTimeOut() const;
718 
725  void setOptimizeAcknowledgeTimeOut(long long optimizeAcknowledgeTimeOut);
726 
735  long long getOptimizedAckScheduledAckInterval() const;
736 
746  void setOptimizedAckScheduledAckInterval(long long optimizedAckScheduledAckInterval);
747 
753  bool isUseRetroactiveConsumer() const;
754 
763  void setUseRetroactiveConsumer(bool useRetroactiveConsumer);
764 
770  bool isExclusiveConsumer() const;
771 
779  void setExclusiveConsumer(bool exclusiveConsumer);
780 
787  bool isSendAcksAsync() const;
788 
796  void setSendAcksAsync(bool sendAcksAsync);
797 
801  bool isAlwaysSessionAsync() const;
802 
809  void setAlwaysSessionAsync(bool alwaysSessionAsync);
810 
814  bool isConsumerExpiryCheckEnabled();
815 
823  void setConsumerExpiryCheckEnabled(bool consumerExpiryCheckEnabled);
824 
828  int getProtocolVersion() const;
829 
830  public: // TransportListener
831 
843  void addTransportListener(transport::TransportListener* transportListener);
844 
853  void removeTransportListener(transport::TransportListener* transportListener);
854 
860  virtual void onCommand(const Pointer<commands::Command> command);
861 
866  virtual void onException(const decaf::lang::Exception& ex);
867 
871  virtual void transportInterrupted();
872 
876  virtual void transportResumed();
877 
878  public:
879 
886  const commands::ConnectionInfo& getConnectionInfo() const;
887 
894  const commands::ConnectionId& getConnectionId() const;
895 
901  transport::Transport& getTransport() const;
902 
908  Pointer<threads::Scheduler> getScheduler() const;
909 
916  std::string getResourceManagerId() const;
917 
922  void cleanup();
923 
934  void oneway(Pointer<commands::Command> command);
935 
950  Pointer<commands::Response> syncRequest(Pointer<commands::Command> command, unsigned int timeout = 0);
951 
964  void asyncRequest(Pointer<commands::Command> command, cms::AsyncCallback* onComplete);
965 
970  virtual void fire(const exceptions::ActiveMQException& ex);
971 
976  void setTransportInterruptionProcessingComplete();
977 
985  void setFirstFailureError(decaf::lang::Exception* error);
986 
992  decaf::lang::Exception* getFirstFailureError() const;
993 
1000  void onAsyncException(const decaf::lang::Exception& ex);
1001 
1008  void onClientInternalException(const decaf::lang::Exception& ex);
1009 
1015  void checkClosed() const;
1016 
1022  void checkClosedOrFailed() const;
1023 
1027  void ensureConnectionInfoSent();
1028 
1032  decaf::util::concurrent::ExecutorService* getExecutor() const;
1033 
1041  void addTempDestination(Pointer<commands::ActiveMQTempDestination> destination);
1042 
1050  void removeTempDestination(Pointer<commands::ActiveMQTempDestination> destination);
1051 
1061  void deleteTempDestination(Pointer<commands::ActiveMQTempDestination> destination);
1062 
1069  void cleanUpTempDestinations();
1070 
1077  bool isDeleted(Pointer<commands::ActiveMQTempDestination> destination) const;
1078 
1086 
1087  protected:
1088 
1092  virtual Pointer<commands::SessionId> getNextSessionId();
1093 
1094  // Sends a oneway disconnect message to the broker.
1095  void disconnect(long long lastDeliveredSequenceId);
1096 
1097  // Waits for all Consumers to handle the Transport Interrupted event.
1098  void waitForTransportInterruptionProcessingToComplete();
1099 
1100  // Marks processing complete for a single caller when interruption processing completes.
1101  void signalInterruptionProcessingComplete();
1102 
1103  // Allow subclasses to access the original Properties object for this connection.
1104  const decaf::util::Properties& getProperties() const;
1105 
1106  // Process the WireFormatInfo command
1107  void onWireFormatInfo(Pointer<commands::Command> command);
1108 
1109  // Process the ControlCommand command
1110  void onControlCommand(Pointer<commands::Command> command);
1111 
1112  // Process the ConnectionControl command
1113  void onConnectionControl(Pointer<commands::Command> command);
1114 
1115  // Process the ConsumerControl command
1116  void onConsumerControl(Pointer<commands::Command> command);
1117 
1118  };
1119 
1120 }}
1121 
1122 #endif /*_ACTIVEMQ_CORE_ACTIVEMQCONNECTION_H_*/
Provides an interface for clients to transform cms::Message objects inside the CMS MessageProducer an...
Definition: MessageTransformer.h:37
Interface for a RedeliveryPolicy object that controls how message Redelivery is handled in ActiveMQ-C...
Definition: RedeliveryPolicy.h:34
Definition: ConnectionInfo.h:49
A Destination object encapsulates a provider-specific address.
Definition: Destination.h:39
#define AMQCPP_API
Definition: Config.h:30
AcknowledgeMode
Definition: Session.h:108
Asynchronous event interface for CMS asynchronous operations.
Definition: AsyncCallback.h:37
bool isStarted() const
Check if this connection has been started.
Definition: ActiveMQConnection.h:190
Definition: ConnectionId.h:51
An Executor that provides methods to manage termination and methods that can produce a Future for tra...
Definition: ExecutorService.h:56
If a CMS provider detects a serious problem, it notifies the client application through an ExceptionL...
Definition: ExceptionListener.h:37
bool isClosed() const
Checks if this connection has been closed.
Definition: ActiveMQConnection.h:182
bool isTransportFailed() const
Checks if the Connection's Transport has failed.
Definition: ActiveMQConnection.h:198
A ConnectionMetaData object provides information describing the Connection object.
Definition: ConnectionMetaData.h:31
Interface for a transport layer for command objects.
Definition: Transport.h:60
A Session object is a single-threaded context for producing and consuming messages.
Definition: Session.h:105
Definition: ConsumerInfo.h:51
A boolean value that may be updated atomically.
Definition: AtomicBoolean.h:34
Interface for a Policy object that controls message Prefetching on various destination types in Activ...
Definition: PrefetchPolicy.h:34
Definition: ActiveMQException.h:35
virtual const cms::ConnectionMetaData * getMetaData() const
Gets the metadata for this connection.the connection MetaData pointer ( caller does not own it )...
Definition: ActiveMQConnection.h:277
Definition: ArrayList.h:39
Definition: Exception.h:38
Java-like properties class for mapping string names to string values.
Definition: Properties.h:53
An enhanced CMS Connection instance that provides additional features above the default required feat...
Definition: EnhancedConnection.h:33
Interface for an object responsible for dispatching messages to consumers.
Definition: Dispatcher.h:32
Decaf's implementation of a Smart Pointer that is a template on a Type and is Thread Safe if the defa...
Definition: Pointer.h:53
Provides an object that will provide a snapshot view of Destinations that exist on the Message provid...
Definition: DestinationSource.h:38
Concrete connection used for all connectors to the ActiveMQ broker.
Definition: ActiveMQConnection.h:61
A listener of asynchronous exceptions from a command transport object.
Definition: TransportListener.h:38
Definition: ActiveMQDestination.h:38