/* * * Copyright (c) 1999 - 2011 my-Channels Ltd * Copyright (c) 2012 - 2017 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors. * * Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG. * */ #include "nSampleApp.h" #include "nChannel.h" #include "nSession.h" #include "nChannelAttributes.h" #include "nSessionFactory.h" #include "nSessionPausedException.h" #include "nSecurityException.h" #include "nSessionNotConnectedException.h" #include "nUnexpectedResponseException.h" #include "nRequestTimedOutException.h" #include "nChannelNotFoundException.h" #include "nUnknownRemoteRealmException.h" using namespace com::pcbsys::nirvana::client; using namespace com::pcbsys::nirvana::apps; /** * Creates a join between a nirvana channel and a nirvana queue */ class makequeuejoin : public nSampleApp { private: int jhc; std::string SELECTOR; static std::string RNAME; std::string chanName; std::string queueName; static makequeuejoin* mySelf; /** * This method demonstrates the Nirvana API calls necessary to create * a queue join. * It is called after all command line arguments have been received and * validated * * @param realmDetails a string* containing the possible RNAME values * @param nRproperty the length of the realmDetails array */ void doit(std::string* realmDetails, int nRproperty) { mySelf->constructSession(realmDetails, nRproperty); //Creates the specified queue join try { //Create the channel attributes object to locate the source channel first nChannelAttributes* nca = new nChannelAttributes(); nca->setName( chanName ); //Create the channel attributes for the destination queue nChannelAttributes* dest = new nChannelAttributes(); dest->setName( queueName ); //Obtain a reference to the source channel nChannel* mySrcChannel = m_pSession->findChannel( nca ); //Obtain a reference to the destination queue nQueue* myDstQueue = m_pSession->findQueue( dest ); //has a value for JHOPS been specified? //if no if ( jhc == -2 ) { mySrcChannel->joinChannel( myDstQueue, SELECTOR ); } //if yes else if ( jhc > 1 ) { mySrcChannel->joinChannel( myDstQueue, true, jhc, SELECTOR ); } } //Handle errors catch(nChannelNotFoundException cnfe) { printf("The channel specified could not be found."); printf("Please ensure that the channel exists in the REALM you connect to."); exit(1); } catch (nSecurityException se) { printf("Unsufficient permissions for the requested operation."); printf("Please check the ACL settings on the server."); exit(1); } catch (nSessionNotConnectedException snce) { printf("The session object used is not physically connected to the Nirvana realm."); printf("Please ensure the realm is up and check your RNAME value."); exit(1); } catch (nUnexpectedResponseException ure) { printf("The Nirvana REALM has returned an unexpected response."); printf("Please ensure the Nirvana REALM and client API used are compatible."); exit(1); } catch (nUnknownRemoteRealmException urre) { printf("The channel specified resided in a remote realm which could not be found."); printf("Please ensure the channel name specified is correct."); exit(1); } catch (nRequestTimedOutException rtoe) { printf("The requested operation has timed out waiting for a response from the REALM."); printf("If this is a very busy REALM ask your administrator to increase the client timeout values."); exit(1); } catch (nBaseClientException nbce) { printf("An error occured while creating the Channel Attributes object."); exit(1); } //Close the session we opened try { nSessionFactory::close ( m_pSession ); } catch(Exception) {} //Close any other sessions so that we can exit nSessionFactory::shutdown ( ); } void processArgs(int argc, char** argv) { jhc = -2; if(argc < 4) { Usage(); exit(1); } if(argc > 3) { RNAME = argv[1]; chanName = argv[2]; queueName = argv[3]; } if(argc > 4) { jhc = atoi(argv[4]); } if(argc > 5) { SELECTOR = argv[5]; } } /** * Prints the usage message for this class */ static void Usage() { printf( "Usage ...\n\n" ); printf("makequeuejoin [max hops] [selector]\n\n"); printf( " \n\n"); printf( " - the rname of the server to connect to\n"); printf( " - Channel name parameter of the local channel name to join\n" ); printf( " - Queue name parameter of the remote queue name to join\n" ); printf( "\n[Optional Arguments] \n\n"); printf( "[max hops] - The maximum number of join hops a message can travel through\n" ); printf( "[selector] - The event filter std::string to use on messages travelling through this join\n" ); } public: static int Main(int argc, char** argv) { //Create an instance for this class mySelf = new makequeuejoin(); //Process command line arguments mySelf->processArgs(argc,argv); //Process the local REALM RNAME details int nRproperty; std::string* rproperties = parseRealmProperties(RNAME,nRproperty); //sets nRproperty to the number of realms in RNAME //create the queue join specified mySelf->doit(rproperties,nRproperty); return 0; } }; // End of makequeuejoin Class makequeuejoin* makequeuejoin::mySelf = NULL; std::string makequeuejoin::RNAME = ""; int main (int argc, char** argv) { return makequeuejoin::Main (argc, argv); }