/* Copyright 1999-2011 (c) My-Channels Copyright (c) 2012-2014 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 2 nirvana channels */ namespace com.pcbsys.nirvana.apps { public class makechanneljoin : nSampleApp { private bool ALLOWPURGE = true; private int jhc = -2; private string SELECTOR; private static string RNAME; private string chanName; private string rchanName; private static makechanneljoin mySelf; /** * This method demonstrates the Nirvana API calls necessary to create * a channel 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 channel 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(rchanName); //Obtain a reference to the source channel nChannel mySrcChannel = mySession.findChannel(nca); //Obtain a reference to the destination channel nChannel myDstChannel = mySession.findChannel(dest); //has a value for JHOPS been specified? //if no if (jhc == -2) { mySrcChannel.joinChannel(myDstChannel, SELECTOR); } //if yes else if (jhc > 1) { mySrcChannel.joinChannel(myDstChannel, true, jhc, SELECTOR, ALLOWPURGE); } } //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]; rchanName = args[2]; break; case 4: RNAME = args[0]; chanName = args[1]; rchanName = args[2]; jhc = Convert.ToInt32(args[3]); break; case 5: RNAME = args[0]; chanName = args[1]; rchanName = args[2]; jhc = Convert.ToInt32(args[3]); SELECTOR = args[4]; break; case 6: RNAME = args[0]; chanName = args[1]; rchanName = args[2]; jhc = Convert.ToInt32(args[3]); SELECTOR = args[4]; ALLOWPURGE = Convert.ToBoolean(args[5]); break; } } public static void Main(String[] args) { //Create an instance for this class mySelf = new makechanneljoin(); //Process command line arguments mySelf.processArgs(args); //Process the local REALM RNAME details String[] rproperties = new String[4]; rproperties = parseRealmProperties(RNAME); //create the channel join specified mySelf.doit(rproperties); } /** * Prints the usage message for this class */ private static void Usage() { Console.WriteLine("Usage ...\n"); Console.WriteLine("makechanneljoin [max hops] [selector] [allow purge] \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( " - Channel name parameter of the remote channel 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"); Console.WriteLine( "[allow purge] - boolean to specify whether purging is allowed (default : true)"); } } // End of makechanneljoin Class }