// ABCOrderProcessor.cpp: implementation of the ABCOrderProcessor class. // ////////////////////////////////////////////////////////////////////// #include "ABCCommon.h" #include "ABCOrderProcessor.h" #include ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// ABCOrderProcessor::ABCOrderProcessor() { } ABCOrderProcessor::~ABCOrderProcessor() { } void ABCOrderProcessor::ProcessIncomingOrders() { /* Register with RTR. This will make sure we are ready to start receiving data. */ Register(); /* Start processing orders */ abc_status sStatus = RTR_STS_OK; RTRData *pOrder = NULL; while (1) { /* Receive an Order */ sStatus = Receive(&pOrder); print_status_on_failure(sStatus); if(ABCSuccess != sStatus) break; // if we can't get an Order then stop processing. /* Dispatch the Order to be processed note: This could be any kind of data, i.e. RTRMessage RTREvent, RTRApplicationMessage or RTRApplicationEvent. The class ABCOrder(derived from RTRApplicationMessage) has redefined the Dispatch() method to call the Process() method of its derived class (ABCBook or ABCMagazine). All other data classes use the default implementation of Dispatch() which will call the appropriate handler. */ sStatus = pOrder->Dispatch(); print_status_on_failure(sStatus); /* Check to see if there were any problems processing the order. If so, let the handler know to reject this txn when asked to vote. note : For the ABC company, orders are processed in the Process() method of all ABCOrder derived classed. */ CheckOrderStatus(sStatus); /* Delete this order that was allocated by the class factory. note: In this sample the class factory returns a separate instance of an order each time it is called. */ delete pOrder; } return; } void ABCOrderProcessor::Register() { rtr_status_t sStatus; // // Create an environment that our server can run in. // CreateRTREnvironment(); // // Register with RTR the following objects // sStatus = RegisterFacility(ABCFacility); print_status_on_failure(sStatus); // ABC Partition sStatus = RegisterPartition(ABCPartition1); print_status_on_failure(sStatus); sStatus = RegisterPartition(ABCPartition2); print_status_on_failure(sStatus); // ABC Class Factory sStatus = RegisterClassFactory(&m_ClassFactory); print_status_on_failure(sStatus); // ABC Server Handlers sStatus = RegisterHandlers(&m_rtrHandlers,&m_rtrHandlers); print_status_on_failure(sStatus); return; } void ABCOrderProcessor::CreateRTREnvironment() { rtr_status_t sStatus; // // If RTR is not already started then start it now. // StartRTR(); // // Create a Facility if not already created. // CreateFacility(); // // Create a partition that processes ISBN numbers in the range 0 - 99 // unsigned int low = 0; unsigned int max = 99; RTRKeySegment KeyZeroTo99( rtr_keyseg_unsigned, sizeof(int), 0, &low, &max ); RTRPartitionManager PartitionManager; sStatus = PartitionManager.CreateBackendPartition( ABCPartition1, ABCFacility, KeyZeroTo99,false,true,false); print_status_on_failure(sStatus); // // Create a partition that processes ISBN numbers in the range 100 - 199 // low = 100; max = 199; RTRKeySegment Key100To199( rtr_keyseg_unsigned, sizeof(int), 0, &low, &max ); sStatus = PartitionManager.CreateBackendPartition( ABCPartition2, ABCFacility, Key100To199,false,true,false); print_status_on_failure(sStatus); } void ABCOrderProcessor::CheckOrderStatus (abc_status sStatus) { /* Check to see if there were any problems processing the order. If so Let the handler know to reject this txn when asked to vote. */ if (sStatus == ABCOrderFailed) { // Let the handler know that the current txn should be rejected GetHandler()->OnABCOrderNotProcessed(); }; }