fintp_connectors
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
Endpoint.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 QPIENDPOINT_H
22 #define QPIENDPOINT_H
23 
24 #ifdef WIN32
25  #ifdef CHECK_MEMLEAKS
26  //#define _CRTDBG_MAP_ALLOC
27  #include <stdlib.h>
28  #include <crtdbg.h>
29  #endif
30 #endif
31 
32 #include "ConnectorMain.h"
33 
34 #include "InstrumentedObject.h"
35 #include "FilterChain.h"
36 #include "Management/Management.h"
37 #include "Transactions/AbstractStatePersistence.h"
38 #include "BatchManager/BatchManager.h"
39 #include "AppSettings.h"
40 #include "TimeUtil.h"
41 #include "AbstractWatcher.h"
42 #include "AppExceptions.h"
43 
45 {
46  private :
48 
49  public :
50 
52  {
57  Common
58  };
59 
64  {
65  // Common settings
106 
107  // DB settings
210 
211  // MQ settings
277 
278  // File settings
329 
335 
341 
347 
354 
360 
366 
372 
389  LAUCERTIFICATE
390  };
391 
392  static string getName( const ConfigDirection prefix, const ConfigSettings setting );
393 };
394 
395 class ExportedTestObject Endpoint : public InstrumentedObject
396 {
397  private :
398 
399  unsigned int m_MessageThrottling;
400 
401  string internalPrepare();
402  void internalCommit( const string& correlationId );
403  void internalAbort( const string& correlationId );
404  void internalRollback( const string& correlationId );
405  void internalProcess( const string& correlationId );
406 
407  void fireManagementEvent( TransactionStatus::TransactionStatusEnum, const void* additionalData );
408 
409 #if defined( WIN32 ) && defined ( CHECK_MEMLEAKS )
410  _CrtMemState m_NextMemoryState, m_OldMemoryState;
411  bool m_OldStateAvailable;
412 #endif
413 
415  static AppSettings *m_GlobalSettings;
416 
417  //performance
418  TimeUtil::TimeMarker m_LastReportTime;
419  //unsigned long m_PerfAborted, m_PerfCommited, m_PerfTotal;
420 
421  protected : //methods
422 
423  // methods for controlling the endpoint
424  virtual void internalStart() = 0;
425  virtual void internalStop() = 0;
426 
427  Endpoint();
428 
429  string getServiceName() const { return m_ServiceName; }
430  void setCorrelationId( const string& correlationId );
431 
432  AppSettings& getGlobalSettings() const;
433  bool haveGlobalSetting( const EndpointConfig::ConfigDirection prefix, const EndpointConfig::ConfigSettings setting ) const;
434  string getGlobalSetting( const EndpointConfig::ConfigDirection prefix, const EndpointConfig::ConfigSettings setting, const string& defaultValue = "__NODEFAULT" ) const;
435 
436  protected : // members
437 
438  static void ( *m_ManagementCallback )( TransactionStatus::TransactionStatusEnum, void* additionalData );
439 
440  BatchManagerBase* m_BatchManager;
441  AbstractStatePersistence* m_PersistenceFacility;
442 
443  unsigned int m_BackoutCount;
444  unsigned int m_CurrentStage;
445  unsigned int m_CrtBatchItem;
446 
449  string m_CorrelationId, m_LastFailureCorrelationId, m_TransactionKey;
450 
451  pthread_t m_SelfThreadId;
452  bool m_Running, m_LastOpSucceeded;
453 
454  AbstractWatcher::NotificationPool m_NotificationPool;
455 
456  NameValueCollection m_TransportHeaders;
457 
458  string m_XmlData;
459  AppException m_TrackingData;
460 
461  //indicate for Batch processing if last message or not
462  bool m_IsLast;
464 
465  FilterChain* m_FilterChain;
466 
467  public:
468 
469  virtual ~Endpoint();
470 
471  // methods for controlling the endpoint
472  static void* StartInNewThread( void* );
473  void Start();
474  void Stop();
475 
476  // called before start. allows the endpoint to prepare environment
477  virtual void Init() = 0;
478 
479  // methods for transactional execution
482  virtual string Prepare() = 0;
483 
485  virtual void Commit() = 0;
486 
488  virtual void Abort() = 0;
489 
491  virtual void Rollback() = 0;
492 
495  virtual void Process( const string& correlationId ) = 0;
496 
497  // workflow methods
498  bool PerformMessageLoop();
499  bool PerformMessageLoop( bool inBatch );
500 
501  virtual bool moreMessages() const { return false; }
502 
503  virtual void trackMessage( const string& payload, const NameValueCollection& transportHeaders );
504 
505  // management methods
506  static void setManagementCallback( void ( *callback )( TransactionStatus::TransactionStatusEnum, void* ) )
507  {
508  m_ManagementCallback = callback;
509  }
510 
511  // state persistence
512  void setPersistenceFacility( AbstractStatePersistence* facility );
513  AbstractStatePersistence* getPersistenceFacility();
514 
515  void setServiceName( const string& value ){ m_ServiceName = value; }
516  void setServiceThreadId( const string& serviceThreadId ) { m_ServiceThreadId = serviceThreadId; }
517 
518  pthread_t getThreadId() { return m_SelfThreadId; }
519  const pthread_t getThreadId() const { return m_SelfThreadId; }
520 
521  virtual pthread_t getWatcherThreadId() = 0;
522 
523  FilterChain* getFilterChain(){ return m_FilterChain; }
524 
525  BatchManagerBase* getBatchManager(){ return m_BatchManager; }
526 
527  static void setGlobalSettings( AppSettings* settings ) { m_GlobalSettings = settings; }
528 };
529 
531 {
532  public :
533  static Endpoint* CreateEndpoint( const string& serviceName, const string& type, bool fetcher );
534 };
535 
536 #endif //QPIENDPOINT_H