/* * * 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. * */ using System; using com.pcbsys.nirvana.client; /** * Creates a join between a nirvana channel and a queue */ namespace com.pcbsys.nirvana.apps { public class makequeuejoin : nSampleApp { private int jhc = -2; private string SELECTOR; private static string RNAME; private string chanName; private string queueName; private 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 */ private void doit(String[] realmDetails) { mySelf.constructSession(realmDetails); //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 channel nChannelAttributes dest = new nChannelAttributes(); dest.setName(queueName); //Obtain a reference to the source channel nChannel mySrcChannel = mySession.findChannel(nca); //Obtain a reference to the destination queue nQueue myDstQueue = mySession.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) { Console.WriteLine("The channel specified could not be found."); Console.WriteLine("Please ensure that the channel exists in the REALM you connect to."); Console.WriteLine(cnfe.StackTrace); Environment.Exit(1); } catch (nSecurityException se) { Console.WriteLine("Unsufficient permissions for the requested operation."); Console.WriteLine("Please check the ACL settings on the server."); Console.WriteLine(se.StackTrace); Environment.Exit(1); } catch (nSessionNotConnectedException snce) { Console.WriteLine("The session object used is not physically connected to the Nirvana realm."); Console.WriteLine("Please ensure the realm is up and check your RNAME value."); Console.WriteLine(snce.StackTrace); Environment.Exit(1); } catch (nUnexpectedResponseException ure) { Console.WriteLine("The Nirvana REALM has returned an unexpected response."); Console.WriteLine("Please ensure the Nirvana REALM and client API used are compatible."); Console.WriteLine(ure.StackTrace); Environment.Exit(1); } catch (nUnknownRemoteRealmException urre) { Console.WriteLine("The channel specified resided in a remote realm which could not be found."); Console.WriteLine("Please ensure the channel name specified is correct."); Console.WriteLine(urre.StackTrace); Environment.Exit(1); } catch (nRequestTimedOutException rtoe) { Console.WriteLine("The requested operation has timed out waiting for a response from the REALM."); Console.WriteLine("If this is a very busy REALM ask your administrator to increase the client timeout values."); Console.WriteLine(rtoe.StackTrace); Environment.Exit(1); } catch (nBaseClientException nbce) { Console.WriteLine("An error occured while creating the Channel Attributes object."); Console.WriteLine(nbce.StackTrace); Environment.Exit(1); } //Close the session we opened try { nSessionFactory.close(mySession); } catch (Exception) { } //Close any other sessions so that we can exit nSessionFactory.shutdown(); } protected override void processArgs(String[] args) { if (args.Length < 3) { Usage(); Environment.Exit(1); } switch (args.Length) { case 3: RNAME = args[0]; chanName = args[1]; queueName = args[2]; break; case 4: RNAME = args[0]; chanName = args[1]; queueName = args[2]; jhc = Convert.ToInt32(args[3]); break; case 5: RNAME = args[0]; chanName = args[1]; queueName = args[2]; jhc = Convert.ToInt32(args[3]); SELECTOR = args[4]; break; } } public static void Main(String[] args) { //Create an instance for this class mySelf = new makequeuejoin(); //Process command line arguments mySelf.processArgs(args); //Process the local REALM RNAME details String[] rproperties = new String[4]; rproperties = parseRealmProperties(RNAME); //create the queue join specified mySelf.doit(rproperties); } /** * Prints the usage message for this class */ private static void Usage() { Console.WriteLine("Usage ...\n"); Console.WriteLine("makequeuejoin [max hops] [selector]\n"); Console.WriteLine( " \n"); Console.WriteLine( " - the rname of the server to connect to"); Console.WriteLine( " - Channel name parameter of the local channel name to join"); Console.WriteLine( " - Queue name parameter of the remote queue name to join"); Console.WriteLine( "\n[Optional Arguments] \n"); Console.WriteLine( "[max hops] - The maximum number of join hops a message can travel through "); Console.WriteLine( "[selector] - The event filter string to use on messages travelling through this join"); } } // End of makequeuejoin Class }