fintp_base
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BatchManager.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 
21 #ifndef BATCHMANAGER_H
22 #define BATCHMANAGER_H
23 
24 //#include "../XmlUtil.h"
25 //#include "../XPathHelper.h"
26 #include "../XSLT/XSLTFilter.h"
27 #include "../Transactions/MemoryStatePersist.h"
28 
29 //#include "DllMain.h"
30 
31 #include "BatchConfig.h"
32 #include "BatchItem.h"
33 #include "BatchResolution.h"
34 
35 // // usage scenario :
36 // // 1. get messages from flatfile ( CEC - input flatfile use case, ACH[FPM] )
37 //
38 // BatchManager<BatchFlatfileStorage> batchManager( BatchResolution::SYNCHRONOUS );
39 // batchManager.open( flatFilename, ios_base::in );
40 //
41 // BatchManager<BatchFlatfileStorage>::iterator enumerator = batchManager.first();
42 //
43 // while( enumerator != batchManager.end() )
44 // {
45 // ProcessMessage( enumerator.str() );
46 // enumerator++;
47 // }
48 
49 // // 2. get messages from XML file ( ACH[FTM] - input XML use case )
50 //
51 // BatchManager<BatchXMLStorage> batchManager( BatchResolution::SYNCHRONOUS );
52 // batchManager.open( xmlFilename, ios_base::in );
53 //
54 // BatchManager<BatchXMLStorage>::iterator enumerator = batchManager.first();
55 //
56 // while( enumerator != batchManager.end() )
57 // {
58 // ProcessMessage( enumerator.str() );
59 // enumerator++;
60 // }
61 
62 // // 3. get messages from WMQ ( BCR - output MT950 use case )
63 // // the BatchManager will get only the complete message ( all in group ). the app will process
64 // // all messages in group one by one. It is the reponsability of the BatchManager to serve them in order
65 //
66 // BatchManager<BatchMQStorage> batchManager( BatchResolution::SYNCHRONOUS );
67 // batchManager.storage().setQueue( batchQueue );
68 // batchManager.storage().setQueueManager( batchQueueManager );
69 // batchManager.storage().setTransportURI( batchChannelDefinition );
70 // batchManager.open( messageGroupId, ios_base::in );
71 //
72 // BatchManager<BatchMQStorage>::iterator enumerator = batchManager.first();
73 //
74 // while( enumerator != batchManager.end() )
75 // {
76 // ProcessMessage( enumerator.str() );
77 // enumerator++;
78 // }
79 
80 // // 4. synchronously write messages to flatfile ( CEC - output flatfile use case ?, ACH[FMP] )
81 //
82 // BatchManager<BatchFlatfileStorage> batchManager( BatchResolution::SYNCHRONOUS );
83 // batchManager.open( flatFilename, ios_base::out );
84 //
85 // while( messagesLeft )
86 // {
87 // batchManager << messageAsString;
88 // }
89 
90 // // 5. synchronously write messages to XML file ( ACH[FTM] - output use case )
91 //
92 // BatchManager<BatchXMLStorage> batchManager( BatchResolution::SYNCHRONOUS );
93 // batchManager.open( xmlFilename, ios_base::out );
94 //
95 // while( messagesLeft )
96 // {
97 // batchManager << messageAsString;
98 // }
99 
100 // // 6. synchronously write messages to message queue
101 //
102 // BatchManager<BatchMQStorage> batchManager( BatchResolution::SYNCHRONOUS );
103 // batchManager.storage().setQueue( batchQueue );
104 // batchManager.storage().setQueueManager( batchQueueManager );
105 // batchManager.storage().setTransportURI( batchChannelDefinition );
106 // batchManager.open( messageGroupId, ios_base::in );
107 //
108 // while( messagesLeft )
109 // {
110 // batchManager << messageAsString;
111 // }
112 
113 // RoutingEngine use case
114 
115 // // 7. ACH connector[ FPM ] use case
116 // ... in fetcher Process ...
117 // see use case 1.
118 //
119 // ... in publisher Process ...
120 // see use case 4.
121 
122 // // 8. CEC connector use case
123 // ... see use case 7.
124 
125 // // asynchronously write messages to
126 //
127 // void ReleaseBatch( string batchId )
128 //
129 // BatchManager<BatchFlatfileStorage> batchManager( BatchResolution::ASYNCHRONOUS );
130 // batchManager.open( flatFilename, ios_base::out );
131 //
132 // batchManager.setReleaseCallback( &releaseCallback ); // check race conditions
133 //
134 // while( messagesLeft )
135 // {
136 // BatchResolution resolution = batchManager << messageAsString;
137 // if
138 // }
139 
140 // ::setReleaseCallback( &releaseFunction );
141 namespace BatchManip
142 {
144  {
145  public :
146  explicit BufferSize( const int size ){ m_Size = size; };
147  int getSize() const { return m_Size; }
148 
149  private :
150  int m_Size;
151  };
152 
154  {
155  public :
156  explicit BatchMetadata( const XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* const document, const string eyecatcher = "", const string batchId = "", const string batchtransform = "" ) :
157  m_Transform( batchtransform ), m_EyeCatcher( eyecatcher ), m_BatchId( batchId )
158  {
159  m_Document = document;
160  }
161 
162  const XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* getDocument() const { return m_Document; }
163  string getEyeCatcher() const { return m_EyeCatcher; }
164  string getTransform() const { return m_Transform; }
165  string getBatchId() const { return m_BatchId; }
166 
167  private :
168 
169  const XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* m_Document;
170  string m_Transform;
171  string m_EyeCatcher;
172  string m_BatchId;
173  };
174 
175  // stream modifiers
177  ExportedObject BatchManip::BatchMetadata setmeta( XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* const document );
178 }
179 
180 namespace FinTP
181 {
183  {
184  public :
185 
186  typedef enum
187  {
188  BATCH_NEW = 0,
189  BATCH_INPROGRESS = 10,
190  BATCH_READY = 15,
191  BATCH_FAILED = 20,
192  BATCH_COMPLETED = 30
193  } BATCH_STATUS;
194 
196  {
199  MQ,
200  ZIP
201  };
202 
203  static BatchManagerBase* CreateBatchManager( const BatchManagerBase::StorageCategory storageCategory );
204 
205  virtual ~BatchManagerBase(){};
206 
207  // open storage
208  virtual void open( const string& storageId, ios_base::openmode openMode ) = 0;
209 
210  //close storage
211  virtual void close( const string& storageId ) = 0;
212 
213  //transaction support
214  virtual void commit() = 0;
215  virtual void rollback() = 0;
216 
217  // add to storage
218  const BatchManagerBase& operator << ( const string& document );
219 
220  // manip inserts
221  const BatchManagerBase& operator << ( BatchManip::BatchMetadata metadata );
222  const BatchManagerBase& operator << ( const BatchManip::BufferSize size );
223  const BatchManagerBase& operator << ( const BatchItem& item );
224 
225  // get from storage
226  void operator >> ( BatchItem &item );
227 
228  // returns true if more messages can be got/put from/in the storage
229  bool moreMessages() const { return m_MoreMessages; }
230 
231  // item discrimination
232  void setXPath( const string& xpath ) { m_XPath = xpath; };
233  string getXPath() const { return m_XPath; };
234 
235  BatchManagerBase::StorageCategory getStorageCategory() const { return m_StorageCategory; }
236 
237  static string ToString( const BatchManagerBase::BATCH_STATUS status );
238 
239  protected :
240 
241  virtual void internalEnqueue( const string& document ) = 0;
242  virtual void internalEnqueue( XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* const document ) = 0;
243  virtual void internalEnqueue( BatchManip::BatchMetadata metadata ) = 0;
244  virtual void internalEnqueue( const BatchManip::BufferSize size ) = 0;
245  virtual void internalEnqueue( const BatchItem &item ) = 0;
246 
247  virtual void internalDequeue( BatchItem &item ) = 0;
248 
249  string m_XPath;
253  const XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* m_MetaDoc;
254 
255  explicit BatchManagerBase( const BatchManagerBase::StorageCategory storageCategory );
256  };
257 
258  template < class T >
260  {
261  public:
262 
263  BatchManager( const BatchManagerBase::StorageCategory storageCategory, const BatchResolution::BatchThreadModel threadModel );
264  ~BatchManager();
265 
266  // open/close storage
267  void open( const string& storageId, ios_base::openmode openMode );
268  void close( const string& storageId );
269 
270  void commit() { m_Storage.commit(); }
271  void rollback() { m_Storage.rollback(); }
272 
273  // accessors
274  T& storage() { return m_Storage; }
275 
276  // iterators
277  BatchItem begin() const { return T::begin(); }
278  BatchItem end() const { return T::end(); }
279 
280  // utils
281  long size() const { return m_Storage.size(); }
282 
283  void setConfig( const string& configFile );
284  const BatchResolution& getResolution() { return m_CrtResolution; }
285  void setResolution( const BatchResolution& resolution ) { m_CrtResolution = resolution; }
286 
287  protected :
288 
289  void internalEnqueue( const string& document );
290  void internalEnqueue( XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* const document );
291  void internalEnqueue( BatchManip::BatchMetadata metadata );
292  void internalEnqueue( const BatchManip::BufferSize size );
293  void internalEnqueue( const BatchItem& item );
294 
295  void internalDequeue( BatchItem &item );
296 
297  private :
298 
300  ios_base::openmode m_OpenMode;
302 
304  string m_StorageId;
305 
307  //MemoryStatePersist m_MetaStorage;
308  };
309 }
310 
311 #endif // BATCHMANAGER_H