fintp_routingengine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RoutingSchema.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 ROUTINGSCHEMA_H
22 #define ROUTINGSCHEMA_H
23 
24 #ifdef WIN32
25  /*#ifdef _DEBUG
26  //#define _CRTDBG_MAP_ALLOC
27  #include <stdlib.h>
28  #include <crtdbg.h>
29  #endif*/
30 #endif
31 
32 #include "RoutingEngineMain.h"
33 #include "RoutingJob.h"
34 #include "RoutingRule.h"
35 #include "RoutingPlan.h"
36 #include "RoutingStructures.h"
37 
39 {
40  private :
41 
42  bool m_Dirty;
43  bool m_Copy;
44 
45  string m_SchemaName;
46  string m_Description;
47 
48  // the vector is ordered by sequence
49  map< long, vector< RoutingRule > > m_RulesByQueue;
50  map< long, vector< RoutingRule > > m_InitRulesByQueue;
51  map< long, vector< RoutingRule > > m_TearRulesByQueue;
52 
53  map< string, RoutingPlan* > m_Plans;
54  map< long, RoutingPlan* > m_UsablePlans;
55 
56  vector< RoutingMessage > m_RBatchMessages;
57 
58 #if defined( WIN32 ) && defined( _DEBUG )
59  _CrtMemState m_NextMemoryState, m_OldMemoryState;
60  bool m_OldStateAvailable;
61 #endif // WIN32 && _DEBUG
62 
63  map< long, int > m_InnerSchemas;
64 
65  public:
66 
67  //default .ctor
68  RoutingSchema();
69 
70  void Load();
71  void LoadSchema( const string& schemaName, long schemaId, const string& sessionCode );
72 
73  RoutingSchema* Duplicate( bool createPlans = false );
74 
75  // destructor
76  ~RoutingSchema();
77 
78  string getName() const { return m_SchemaName; }
79 
80  //methods
81  void Explain( void );
82  void DisplayPlan( RoutingPlan* plan, unsigned int level );
83 
84  bool ApplyPlanRouting( RoutingJob* job, RoutingMessage* theMessage, const RoutingPlan* plan, const int userId, const bool isBulk, const bool fastpath = false ) const;
85  bool ApplyQueueRouting( RoutingJob* job, RoutingMessage* theMessage, const long queueId, const int userId, const bool isBulk, const bool fastpath = false );
86 
87  void ApplyRouting( RoutingJob* job, RoutingMessage* theMessage, RoutingMessage ( *messageProviderCallback )() = NULL, bool fastpath = false );
88  void ApplyRouting( RoutingJob* job, RoutingMessage( *messageProviderCallback )() = NULL, bool fastpath = false );
89  /*
90  * Process batch messages
91  * 1. Batch acks with/no transaction
92  * 2. Batch nacks with/no transactions
93  * 3. Batch not acks/ not nacks
94  * Constraint every ack/nack batch with no transactions should have a not NULL SequenceResponse
95  */
96  bool RouteBatchReply( RoutingJob* job, RoutingMessage* theMessage, bool fastpath = false );
97  bool RouteBatch( RoutingJob* job, RoutingMessage* theMessage, bool fastpath = false );
98 
99  void PerformInitRoutine( long schemaId );
100  void PerformTearRoutine( long schemaId );
101 
102  // plans
103  void DeletePlans();
104  void CreatePlans();
105  RoutingPlan* CreatePlan( RoutingPlan* plan, const long queue, const long sequence, const unsigned char depth );
106  void InsertPlan( RoutingPlan* plan );
107 
108  const map< string, RoutingPlan* >& Plans() const { return m_Plans; }
109  RoutingPlan* Plan( const string& name );
110  void UsePlan( const string& name );
111  RoutingPlan* getPlan( long queue, RoutingMessage* theMessage );
112 
113  const vector< RoutingMessage >& GetRBatchItems() const { return m_RBatchMessages; }
114 
115  bool isDirty() const { return m_Dirty; }
116  void setDirty( const bool value ) { m_Dirty = value; }
117 
118  bool RouteDelayedReply( RoutingJob* job, RoutingMessage* theMessage, bool fastpath = false );
119 };
120 
121 #endif