fintp_transport
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
TransportHelper.h
Go to the documentation of this file.
1 /*
2 * FinTP - Financial Transactions Processing Application
3 * Copyright (C) 2013 Business Information Systems (Allevo) S.R.L.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>
17 * or contact Allevo at : 031281 Bucuresti, 23C Calea Vitan, Romania,
18 * phone +40212554577, office@allevo.ro <mailto:office@allevo.ro>, www.allevo.ro.
19 */
20 
25 #ifndef TRANSPORTHELPER_H
26 #define TRANSPORTHELPER_H
27 
28 #ifdef __GNUC__
29 #define DEPRECATED(func) func __attribute__ ((deprecated))
30 #elif defined(_MSC_VER)
31 #define DEPRECATED(func) __declspec(deprecated) func
32 #else
33 #define DEPRECATED(func) func
34 #endif
35 
36 #include "DllMainTransport.h"
37 
38 #include "WorkItemPool.h"
39 #include "Trace.h"
40 #include "AbstractLogPublisher.h"
41 
42 #include <string>
43 #include <vector>
44 
45 using namespace std;
46 
47 namespace FinTP
48 {
56 #define MAX_REPLY_OPTIONS 7
57 
58 
60  {
61  public :
62 
63  typedef enum
64  {
71  RO_PASS_CORREL_ID
72  } ReplyOption;
73 
74  typedef vector<ReplyOption> ReplyOptions;
75 
76  explicit TransportReplyOptions( const string& options = "NONE" ){ Parse( options ); }
77  //TransportReplyOptions& operator=( const TransportReplyOptions& replyOptions );
78  TransportReplyOptions( const TransportReplyOptions& replyOptions );
79  int getSize()const { return m_Options.size(); }
80  ReplyOption operator[]( int i )const { return m_Options[ i ]; }
81  void addReplyOption( const ReplyOption& option) { m_Options.push_back( option ); }
82  bool isReplyOption( const string& replyValue ) const;
83  bool optionsSet() const;
84  string ToString() const;
85  void Parse( const string& options);
86 
87  private :
88 
90  static const string m_ReplyOptionNames[ MAX_REPLY_OPTIONS ];
91 
92  };
94  {
95  public :
96 
98  {
99  WMQ = 1,
100  AMQ = 2,
101  AQ = 3,
102  NONE = 0
103  };
104 
106  {
107  TMT_DATAGRAM = 0,
108  TMT_REPLY = 1,
109  TMT_REQUEST = 2,
110  TMT_REPORT = 3
111  };
112 
113  protected :
114 
115  const unsigned int m_MessageIdLength;
116 
117  string m_QueueName;
118 
119  string m_MessageId, m_CorrelationId, m_GroupId;
121 
122  bool m_UsePassedMessageId, m_UsePassedCorrelId, m_UsePassedGroupId, m_UsePassedAppName;
123 
124  string m_MessagePutDate, m_MessagePutTime;
125 
126  string m_ReplyQueue;
127 
129 
130  long long m_Feedback;
133 
135  // SSL options
136  string m_SSLKeyRepository, m_SSLCypherSpec, m_SSLPeerName;
137 
138  unsigned int m_MessageLength;
142 
143  //NameValueCollection m_Settings;
144 
151  TransportHelper( unsigned int messageIdLength );
152 
153  public :
154 
155  const static string TMT_STRING;
156  const static string TMT_RF_HEADER_2;
157  const static string TMT_NONE;
158 
165  static TransportHelper* CreateHelper( const TransportHelper::TRANSPORT_HELPER_TYPE& helperType );
166  static TRANSPORT_HELPER_TYPE parseTransportType( const string& transportType );
167  virtual ~TransportHelper() { DEBUG( "TransportHelper dtor." ) };
168 
169  virtual void connect( const string& queueManagerName = "", const string& transportUri = "", bool force = false ) = 0;
170  virtual void connect( const string& queueManagerName, const string& transportUri, const string& keyRepository , const string& sslCypherSpec , const string& sslPeerName , bool force = false ) {} ;
171 
172  virtual void disconnect() = 0;
173  virtual bool commit() = 0;
174  virtual bool rollback() = 0;
175 
176  //get messages methods
177  virtual long getOne( unsigned char* buffer, size_t maxSize, bool syncpoint = true ) = 0;
186  virtual long getOne( ManagedBuffer* buffer, bool syncpoint = true, bool keepJMSHeader = true ) = 0;
187 
191  virtual long getGroupMessage( ManagedBuffer* groupMessageBuffer, const string& groupId, bool& isCleaningUp ) = 0;
192  //put messages methods
193  virtual void putOne( unsigned char* buffer, size_t bufferSize, bool syncpoint = true ) = 0;
194 
195 
196  virtual void putGroupMessage( ManagedBuffer* buffer, const string& batchId, long messageSequence, bool isLast ) = 0;
197 
198  virtual void putSAAmessage( const TransportReplyOptions& replyOptions, const string& replyQueue, ManagedBuffer* buffer, const string& batchId, long messageSequence, bool isLast );
199 
200  // request/reply puts messages
201  virtual void putOneRequest( unsigned char* buffer, size_t bufferSize, const string& rtqName, const string& rtqmName, TransportReplyOptions& replyOptions ) = 0;
202  virtual void putOneReply( unsigned char* buffer, size_t bufferSize = 0, long feedback = 0, TRANSPORT_MESSAGE_TYPE replyType = TMT_REPLY ) = 0;
203 
204  // browse queue
205  virtual long peek( const string& queue = "", bool first = true ) = 0;
206 
207  // helper methods
208  virtual long getQueueDepth( const string& queueName ) = 0;
209  virtual TRANSPORT_MESSAGE_TYPE getLastMessageType() = 0;
210  virtual void clearMessages() = 0;
211 
215  virtual string getApplicationName() const = 0;
216  virtual void setApplicationName( const string& applicationName ) = 0;
220  virtual TransportReplyOptions getLastReplyOptions() const = 0;
221  string getLastReplyQueue() const { return m_ReplyQueue; }
222  virtual string getLastReplyQueueManager() const = 0;
223  virtual void clearSSLOptions() = 0;
224 
228  DEPRECATED(virtual void openQueue( const string& queueName ) ){ m_QueueName = queueName; }
229  DEPRECATED(virtual void closeQueue() ){};
230  virtual long getOne( ManagedBuffer* buffer )
231  {
232  return getOne(buffer, true);
233  }
234  string getLastMessageId() const { return m_MessageId; }
235  virtual void setMessageId( const string& messageId );
236 
237  string getLastCorrelId() const { return m_CorrelationId; }
238  virtual void setCorrelationId( const string& correlId );
239 
240  string getLastGroupId() const { return m_GroupId; }
241  virtual void setGroupId( const string& groupId );
242 
243  int getLastGroupSequence() const { return m_GroupSequence; }
244 
245  virtual void setMessageFormat( const string& format ) = 0;
246  virtual string getLastMessageFormat() const = 0;
247 
248  void setReplyUserData( const string& usrData ){ m_ReplyUsrData = usrData; }
249  string getReplyUserData() const { return m_ReplyUsrData; }
250 
251  time_t getMessagePutTime();
252  unsigned long getLastMessageLength() const { return m_MessageLength; }
253 
254  long long getLastFeedback() const { return m_Feedback; }
255  bool isLastInGroup() const { return m_LastInGroup; }
256 
257  virtual void setAutoAbandon( const int retries );
258 
259  virtual void setBackupQueue( const string& queueName );
260  long getQueueDepth(){ return getQueueDepth( m_QueueName ); }
261 
262  static AbstractLogPublisher* createMqLogPublisher( const NameValueCollection& propSettings, bool& isDefault );
263  };
264 }
265 
266 #endif