libbmq  a5f8a06ba1d16cb5a65643e1fa7f1a1d6aadef40
bmqa_session.h
Go to the documentation of this file.
1 // Copyright 2014-2023 Bloomberg Finance L.P.
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 // bmqa_session.h -*-C++-*-
17 #ifndef INCLUDED_BMQA_SESSION
18 #define INCLUDED_BMQA_SESSION
19 
553 
554 // BMQ
555 
556 #include <bmqa_abstractsession.h>
557 #include <bmqa_closequeuestatus.h>
561 #include <bmqa_openqueuestatus.h>
562 #include <bmqt_queueoptions.h>
563 #include <bmqt_sessionoptions.h>
564 #include <bmqt_uri.h>
565 
566 // BDE
567 #include <ball_log.h>
568 #include <bsl_memory.h>
569 #include <bsl_string.h>
570 #include <bslma_allocator.h>
571 #include <bslma_managedptr.h>
572 #include <bslma_usesbslmaallocator.h>
573 #include <bslmf_nestedtraitdeclaration.h>
574 #include <bsls_keyword.h>
575 #include <bsls_timeinterval.h>
576 #include <bsls_types.h>
577 
578 namespace BloombergLP {
579 
580 // FORWARD DECLARATION
581 namespace bmqimp {
582 class Application;
583 }
584 namespace bmqimp {
585 class Event;
586 }
587 namespace bmqp {
588 class MessageGUIDGenerator;
589 }
590 namespace bslmt {
591 class Semaphore;
592 }
593 
594 namespace bmqa {
595 
596 // FORWARD DECLARATION
597 class Event;
598 class Message;
599 class MessageEvent;
600 class MessageProperties;
601 class QueueId;
602 class SessionEvent;
603 
604 // =========================
605 // class SessionEventHandler
606 // =========================
607 
612  public:
613  // CREATORS
614 
617 
618  // MANIPULATORS
619 
622  virtual void onSessionEvent(const SessionEvent& event) = 0;
623 
626  virtual void onMessageEvent(const MessageEvent& event) = 0;
627 };
628 
629 // ==================
630 // struct SessionImpl
631 // ==================
632 
637 struct SessionImpl {
638  // PUBLIC DATA
639 
641  bslma::Allocator* d_allocator_p;
642 
644  bmqt::SessionOptions d_sessionOptions;
645 
647  bslma::ManagedPtr<SessionEventHandler> d_eventHandler_mp;
648 
650  bsl::shared_ptr<bmqp::MessageGUIDGenerator> d_guidGenerator_sp;
651 
653  bslma::ManagedPtr<bmqimp::Application> d_application_mp;
654 
655  private:
656  // NOT IMPLEMENTED
657  SessionImpl(const SessionImpl&) BSLS_KEYWORD_DELETED;
658  SessionImpl& operator=(const SessionImpl&) BSLS_KEYWORD_DELETED;
659 
660  public:
661  // TRAITS
662  BSLMF_NESTED_TRAIT_DECLARATION(SessionImpl, bslma::UsesBslmaAllocator)
663 
664  // CREATORS
665 
666 
668  SessionImpl(const bmqt::SessionOptions& options,
669  bslma::ManagedPtr<SessionEventHandler> eventHandler,
670  bslma::Allocator* allocator = 0);
671 };
672 
673 // =============
674 // class Session
675 // =============
676 
678 class Session : public AbstractSession {
679  public:
680  // TYPES
681 
687 
693 
699 
700  private:
701  // CLASS-SCOPE CATEGORY
702  BALL_LOG_SET_CLASS_CATEGORY("BMQA.SESSION");
703 
704  private:
705  // DATA
706  SessionImpl d_impl; // Sole data member of this object.
707 
708  private:
709  // NOT IMPLEMENTED
710  Session(const Session&) BSLS_KEYWORD_DELETED;
711 
713  Session& operator=(const Session&) BSLS_KEYWORD_DELETED;
714 
715  public:
716  // TRAITS
717  BSLMF_NESTED_TRAIT_DECLARATION(Session, bslma::UsesBslmaAllocator)
718 
719  // CREATORS
720 
721 
726  explicit Session(
727  const bmqt::SessionOptions& options = bmqt::SessionOptions(),
728  bslma::Allocator* allocator = 0);
729 
735  explicit Session(
736  bslma::ManagedPtr<SessionEventHandler> eventHandler,
737  const bmqt::SessionOptions& options = bmqt::SessionOptions(),
738  bslma::Allocator* allocator = 0);
739 
741  ~Session() BSLS_KEYWORD_OVERRIDE;
742 
743  // MANIPULATORS
744  // (virtual bmqa::AbstractSession)
745 
748 
757  int start(const bsls::TimeInterval& timeout = bsls::TimeInterval())
758  BSLS_KEYWORD_OVERRIDE;
759 
768  int startAsync(const bsls::TimeInterval& timeout = bsls::TimeInterval())
769  BSLS_KEYWORD_OVERRIDE;
770 
778  void stop() BSLS_KEYWORD_OVERRIDE;
779 
784  void stopAsync() BSLS_KEYWORD_OVERRIDE;
785 
791  void finalizeStop() BSLS_KEYWORD_OVERRIDE;
792 
806 
817  BSLS_KEYWORD_OVERRIDE;
818 
827  BSLS_KEYWORD_OVERRIDE;
828 
836  void
837  loadMessageProperties(MessageProperties* buffer) BSLS_KEYWORD_OVERRIDE;
838 
841 
846  int getQueueId(QueueId* queueId,
847  const bmqt::Uri& uri) BSLS_KEYWORD_OVERRIDE;
848 
853  int getQueueId(QueueId* queueId, const bmqt::CorrelationId& correlationId)
854  BSLS_KEYWORD_OVERRIDE;
855 
860  int openQueue(QueueId* queueId,
861  const bmqt::Uri& uri,
862  bsls::Types::Uint64 flags,
863  const bmqt::QueueOptions& options = bmqt::QueueOptions(),
864  const bsls::TimeInterval& timeout = bsls::TimeInterval())
865  BSLS_KEYWORD_OVERRIDE;
866 
884  const bmqt::Uri& uri,
885  bsls::Types::Uint64 flags,
886  const bmqt::QueueOptions& options = bmqt::QueueOptions(),
887  const bsls::TimeInterval& timeout = bsls::TimeInterval())
888  BSLS_KEYWORD_OVERRIDE;
889 
893  virtual int
894  openQueue(const QueueId& queueId,
895  const bmqt::Uri& uri,
896  bsls::Types::Uint64 flags,
897  const bmqt::QueueOptions& options = bmqt::QueueOptions(),
898  const bsls::TimeInterval& timeout = bsls::TimeInterval());
899 
904  int
906  const bmqt::Uri& uri,
907  bsls::Types::Uint64 flags,
908  const bmqt::QueueOptions& options = bmqt::QueueOptions(),
909  const bsls::TimeInterval& timeout = bsls::TimeInterval())
910  BSLS_KEYWORD_OVERRIDE;
911 
928  void
930  const bmqt::Uri& uri,
931  bsls::Types::Uint64 flags,
932  const OpenQueueCallback& callback,
933  const bmqt::QueueOptions& options = bmqt::QueueOptions(),
934  const bsls::TimeInterval& timeout = bsls::TimeInterval())
935  BSLS_KEYWORD_OVERRIDE;
936 
941  int configureQueue(QueueId* queueId,
942  const bmqt::QueueOptions& options,
943  const bsls::TimeInterval& timeout =
944  bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE;
945 
965  const bmqt::QueueOptions& options,
966  const bsls::TimeInterval& timeout =
967  bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE;
968 
974  const bmqt::QueueOptions& options,
975  const bsls::TimeInterval& timeout =
976  bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE;
977 
996  const bmqt::QueueOptions& options,
997  const ConfigureQueueCallback& callback,
998  const bsls::TimeInterval& timeout =
999  bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE;
1000 
1005  int closeQueue(QueueId* queueId,
1006  const bsls::TimeInterval& timeout = bsls::TimeInterval())
1007  BSLS_KEYWORD_OVERRIDE;
1008 
1027  const bsls::TimeInterval& timeout = bsls::TimeInterval())
1028  BSLS_KEYWORD_OVERRIDE;
1029 
1033  virtual int
1034  closeQueue(const QueueId& queueId,
1035  const bsls::TimeInterval& timeout = bsls::TimeInterval());
1036 
1041  int closeQueueAsync(QueueId* queueId,
1042  const bsls::TimeInterval& timeout =
1043  bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE;
1044 
1062  void closeQueueAsync(QueueId* queueId,
1063  const CloseQueueCallback& callback,
1064  const bsls::TimeInterval& timeout =
1065  bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE;
1066 
1071  virtual int
1072  closeQueueAsync(const QueueId& queueId,
1073  const bsls::TimeInterval& timeout = bsls::TimeInterval());
1074 
1077 
1089  Event nextEvent(const bsls::TimeInterval& timeout = bsls::TimeInterval())
1090  BSLS_KEYWORD_OVERRIDE;
1091 
1098  int post(const MessageEvent& event) BSLS_KEYWORD_OVERRIDE;
1099 
1107  int confirmMessage(const Message& message) BSLS_KEYWORD_OVERRIDE;
1108 
1118  BSLS_KEYWORD_OVERRIDE;
1119 
1132  int confirmMessages(ConfirmEventBuilder* builder) BSLS_KEYWORD_OVERRIDE;
1133 
1136 
1160  int configureMessageDumping(const bslstl::StringRef& command)
1161  BSLS_KEYWORD_OVERRIDE;
1162 };
1163 
1164 // ============================================================================
1165 // INLINE DEFINITIONS
1166 // ============================================================================
1167 
1168 // -------------
1169 // class Session
1170 // -------------
1171 
1172 inline int Session::confirmMessage(const Message& message)
1173 {
1174  return confirmMessage(message.confirmationCookie());
1175 }
1176 
1177 } // close package namespace
1178 } // close enterprise namespace
1179 
1180 #endif
Provide a pure protocol for a BlazingMQ session.
Provide Value-Semantic Type for a close queue operation status.
Provide Value-Semantic Type for a configure queue operation status.
Provide a builder for batching confirmation messages.
Provide a builder for bmqa::MessageEvent objects.
Provide Value-Semantic Type for an open queue operation status.
Provide a value-semantic type for options related to a queue.
Provide a value-semantic type to configure session with the broker.
Provide value-semantic type and utilities for a BlazingMQ queue URI.
A pure protocol for a session.
Definition: bmqa_abstractsession.h:50
bsl::function< void(const bmqa::CloseQueueStatus &result)> CloseQueueCallback
Definition: bmqa_abstractsession.h:73
bsl::function< void(const bmqa::ConfigureQueueStatus &result)> ConfigureQueueCallback
Definition: bmqa_abstractsession.h:66
bsl::function< void(const bmqa::OpenQueueStatus &result)> OpenQueueCallback
Definition: bmqa_abstractsession.h:59
Definition: bmqa_closequeuestatus.h:62
Definition: bmqa_configurequeuestatus.h:61
Mechanism to build a batch of CONFIRM messages.
Definition: bmqa_confirmeventbuilder.h:157
A variant type encompassing all types of events.
Definition: bmqa_event.h:69
Cookie for async message confirmation.
Definition: bmqa_message.h:131
A builder for MessageEvent objects.
Definition: bmqa_messageeventbuilder.h:319
Definition: bmqa_messageevent.h:64
Provide a VST representing message properties.
Definition: bmqa_messageproperties.h:92
A message sent/received to/from the BlazingMQ broker.
Definition: bmqa_message.h:170
Definition: bmqa_openqueuestatus.h:62
Value-semantic efficient identifier for a queue.
Definition: bmqa_queueid.h:59
Definition: bmqa_session.h:611
virtual ~SessionEventHandler()
Destroy this object.
virtual void onSessionEvent(const SessionEvent &event)=0
virtual void onMessageEvent(const MessageEvent &event)=0
An event related to the operation of a Session.
Definition: bmqa_sessionevent.h:75
A session with a BlazingMQ broker.
Definition: bmqa_session.h:678
int closeQueue(QueueId *queueId, const bsls::TimeInterval &timeout=bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE
int start(const bsls::TimeInterval &timeout=bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE
OpenQueueStatus openQueueSync(QueueId *queueId, const bmqt::Uri &uri, bsls::Types::Uint64 flags, const bmqt::QueueOptions &options=bmqt::QueueOptions(), const bsls::TimeInterval &timeout=bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE
void stopAsync() BSLS_KEYWORD_OVERRIDE
int confirmMessage(const Message &message) BSLS_KEYWORD_OVERRIDE
Definition: bmqa_session.h:1172
ConfigureQueueStatus configureQueueSync(QueueId *queueId, const bmqt::QueueOptions &options, const bsls::TimeInterval &timeout=bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE
int confirmMessages(ConfirmEventBuilder *builder) BSLS_KEYWORD_OVERRIDE
int configureMessageDumping(const bslstl::StringRef &command) BSLS_KEYWORD_OVERRIDE
AbstractSession::CloseQueueCallback CloseQueueCallback
Definition: bmqa_session.h:698
void finalizeStop() BSLS_KEYWORD_OVERRIDE
int getQueueId(QueueId *queueId, const bmqt::Uri &uri) BSLS_KEYWORD_OVERRIDE
void stop() BSLS_KEYWORD_OVERRIDE
int openQueueAsync(QueueId *queueId, const bmqt::Uri &uri, bsls::Types::Uint64 flags, const bmqt::QueueOptions &options=bmqt::QueueOptions(), const bsls::TimeInterval &timeout=bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE
CloseQueueStatus closeQueueSync(QueueId *queueId, const bsls::TimeInterval &timeout=bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE
AbstractSession::OpenQueueCallback OpenQueueCallback
Definition: bmqa_session.h:686
Event nextEvent(const bsls::TimeInterval &timeout=bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE
int startAsync(const bsls::TimeInterval &timeout=bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE
int configureQueue(QueueId *queueId, const bmqt::QueueOptions &options, const bsls::TimeInterval &timeout=bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE
int post(const MessageEvent &event) BSLS_KEYWORD_OVERRIDE
void loadConfirmEventBuilder(ConfirmEventBuilder *builder) BSLS_KEYWORD_OVERRIDE
void loadMessageProperties(MessageProperties *buffer) BSLS_KEYWORD_OVERRIDE
int openQueue(QueueId *queueId, const bmqt::Uri &uri, bsls::Types::Uint64 flags, const bmqt::QueueOptions &options=bmqt::QueueOptions(), const bsls::TimeInterval &timeout=bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE
virtual MessageEventBuilder createMessageEventBuilder()
void loadMessageEventBuilder(MessageEventBuilder *builder) BSLS_KEYWORD_OVERRIDE
int closeQueueAsync(QueueId *queueId, const bsls::TimeInterval &timeout=bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE
AbstractSession::ConfigureQueueCallback ConfigureQueueCallback
Definition: bmqa_session.h:692
int configureQueueAsync(QueueId *queueId, const bmqt::QueueOptions &options, const bsls::TimeInterval &timeout=bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE
Definition: bmqt_sessionoptions.h:161
Definition: bmqa_abstractsession.h:42