fintp_routingengine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RoutingJob.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 ROUTINGJOB_H
22 #define ROUTINGJOB_H
23 
24 #include "StringUtil.h"
25 #include "BatchManager/BatchManager.h"
26 
27 #include "RoutingEngineMain.h"
28 #include "RoutingDbOp.h"
29 
30 #define ROUTINGJOB_MAX_BACKOUT 3
31 
33 {
34  private:
35 
38 
39  string m_JobId, m_RoutingPoint, m_Function, m_BatchId, m_BatchType;
40  int m_UserId;
41 
42  bool m_IsBatch, m_IsParallel;
43  BatchManagerBase::BATCH_STATUS m_BatchStatus;
44 
45  int m_HasUnhold, m_IsMove, m_IsRoute, m_IsComplete;
46 
47  map< std::string, std::string > m_Params;
48  vector< string > m_RoutingActions;
49  string m_Destination;
50 
51  public:
52 
53  static const string PARAM_ROUTINGPOINT;
54  static const string PARAM_ROUTINGKEY;
55  static const string PARAM_FUNCTION;
56  static const string PARAM_USERID ;
57  static const string PARAM_DESTINATION;
58  static const string PARAM_FEEDBACK;
59  static const string PARAM_GROUPORDER;
60  static const string PARAM_GROUPCOUNT;
61  static const string PARAM_BATCHID;
62  static const string PARAM_BATCHREF;
63  static const string PARAM_GROUPAMOUNT;
64 
65  RoutingJob();
66  RoutingJob( const string& table, const string& jobId, const string& function, const int userId );
67  RoutingJob( const string& jobId );
68 
69  ~RoutingJob();
70 
71  string getMessageId() const { return m_JobId; }
72  string getJobId() const { return m_JobId; }
73 
74  string getFunction() const { return m_Function; }
75  void setFunction( const string& function );
76 
77  bool isParallel() const { return m_IsParallel; }
78  void setParallel( const bool value = true ) { m_IsParallel = value; }
79 
80  int getUserId() const { return m_UserId; }
81 
82  bool isBatch() const { return m_IsBatch; }
83  string getBatchId() const { return m_BatchId; }
84  void setBatchId( const string& batchId, const BatchManagerBase::BATCH_STATUS batchStatus )
85  {
86  m_BatchId = batchId;
87  m_IsBatch = true;
88  m_BatchStatus = batchStatus;
89  }
90 
91  string getBatchType() const { return m_BatchType; }
92  void setBatchType( const string& batchType )
93  {
94  m_BatchType = batchType;
95  }
96 
97  BatchManagerBase::BATCH_STATUS getBatchStatus() const { return m_BatchStatus; }
98 
99  string getJobTable() const { return m_RoutingPoint; }
100  void setJobTable( const string& table ) { m_RoutingPoint = table; }
101 
102  long getBackoutCount() const { return m_BackoutCount; }
103 
104  void ReadNextJob( const string& jobId );
105 
106  void Commit() const
107  {
108  try
109  {
110  RoutingDbOp::CommitJob( m_JobId );
111  }
112  catch( const std::exception& ex )
113  {
114  TRACE( "Unable to commit job [" << ex.what() << "]" );
115  }
116  catch( ... )
117  {
118  TRACE( "Unable to commit job." );
119  }
120  }
121 
122  void Rollback() const
123  {
124  try
125  {
126  RoutingDbOp::RollbackJob( m_JobId );
127  }
128  catch( const std::exception& ex )
129  {
130  TRACE( "Unable to rollback job [" << ex.what() << "]" );
131  }
132  catch( ... )
133  {
134  TRACE( "Unable to rollback job." );
135  }
136  }
137 
138  void Abort() const
139  {
140  try
141  {
142  RoutingDbOp::AbortJob( m_JobId );
143  }
144  catch( const std::exception& ex )
145  {
146  TRACE( "Unable to abort job [" << ex.what() << "]" );
147  }
148  catch( ... )
149  {
150  TRACE( "Unable to abort job." );
151  }
152  }
153 
154  BatchManagerBase::BATCH_STATUS Batch( const string& batchId, const string& correlId, const string& feedback, const string& xformItem, const string& amountBDP, const string& amountADP )
155  {
156  BatchManagerBase::BATCH_STATUS batchStatus = BatchManagerBase::BATCH_FAILED;
157  try
158  {
159  m_IsBatch = true;
160  m_BatchId = batchId;
161  batchStatus = RoutingDbOp::BatchJob( m_JobId, getFunctionParam( PARAM_GROUPORDER ), batchId, correlId, feedback, xformItem, amountBDP, amountADP );
162 
163  // HACK - simulate defer
164  //m_DeferedQueue = -2;
165  }
166  catch( const std::exception& ex )
167  {
168  TRACE( "Unable to batch job [" << ex.what() << "]" );
169  }
170  catch( ... )
171  {
172  TRACE( "Unable to batch job." );
173  }
174 
175  return batchStatus;
176  }
177 
178  void Defer( const long queueId, const bool dbCommit = true );
179  static void Resume( const long queueId ) { RoutingDbOp::ResumeJobs( queueId ); }
180 
181  // misc
182  bool isDefered() const { return ( m_DeferedQueue != 0 ); }
183  long getDeferedQueue() const { return m_DeferedQueue; }
184 
185  bool hasUnhold() const;
186  bool isMove();
187  bool isRoute();
188  bool isComplete();
189 
190  bool hasFunctionParam( const string& paramName );
191  string getFunctionParam( const string& paramName );
192 
193  void addAction( const string& action )
194  {
195  m_RoutingActions.push_back( action );
196  }
197 
198  const vector< string >& getActions() const
199  {
200  return m_RoutingActions;
201  }
202 
203  void copyActions( const RoutingJob& job )
204  {
205  // copy actions from the subjob
206  const vector< string >& redirectActions = job.getActions();
207  for( unsigned int i=0; i<redirectActions.size(); i++ )
208  {
209  m_RoutingActions.push_back( redirectActions[ i ] );
210  }
211  m_Destination = job.getDestination();
212  }
213 
214  void populateAddInfo( AppException& ex ) const;
215 
216  string getDestination() const { return m_Destination; }
217  void setDestination( const string& destination ) { m_Destination = destination; }
218 };
219 
220 #endif