/* * * 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. * */ package com.pcbsys.nirvana.apps; import com.pcbsys.nirvana.client.*; /** * Creates a join between 2 nirvana channels */ public class makeChannelJoin extends nSampleApp { private static makeChannelJoin mySelf = null; /** * 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 args a String[] containing the command line arguments */ public static void main(String[] args) { // Create an instance for this class mySelf = new makeChannelJoin(); // Process command line arguments mySelf.processArgs(args); // Process Environment Variables nSampleApp.processEnvironmentVariables(); if (System.getProperty("ARCHIVE") == null) { System.getProperties().put("ARCHIVE", "false"); } // Check the channel name specified String channelName = null; if (System.getProperty("CHANNAME") != null) { channelName = System.getProperty("CHANNAME"); } else { Usage(); System.exit(1); } // Check the local realm details String RNAME = null; if (System.getProperty("RNAME") != null) { RNAME = System.getProperty("RNAME"); } else { Usage(); System.exit(1); } // Process the local REALM RNAME details String[] rproperties = new String[4]; rproperties = parseRealmProperties(RNAME); // Check the remote channel name String rchannelName = null; if (System.getProperty("RCHANNAME") != null) { rchannelName = System.getProperty("RCHANNAME"); } else { Usage(); System.exit(1); } // create the channel join specified mySelf.doit(rproperties, channelName, rchannelName); } private void doit(String[] realmDetails, String chanName, String rchanName) { mySelf.constructSession(realmDetails); // Check for the join max hop count (default is unlimited) String jhopS = null; int jhc = -2; jhopS = System.getProperty("JHOPS"); if (jhopS != null) { Integer jhop = new Integer(jhopS); jhc = jhop.intValue(); } // Check for the selector value to enforce a filter for this join String SELECTOR = ""; if ((System.getProperty("SELECTOR") != null) && (System.getProperty("SELECTOR").length() > 0)) { SELECTOR = System.getProperty("SELECTOR"); } // Check for the boolean to see if allow purge is supported boolean ALLOWPURGE = Boolean.valueOf(System.getProperty("ALLOWPURGE", "true")).booleanValue(); // Creates the specified channel join try { // Create the channel attributes object to locate the source channel // first nChannelAttributes nca = new nChannelAttributes(); nca.setName(chanName); // Obtain a reference to the source channel nChannel mySrcChannel = mySession.findChannel(nca); // If we are performing an archive the if (System.getProperty("ARCHIVE").equals("true")) { nChannelAttributes archiveAtr = new nChannelAttributes(); archiveAtr.setName(rchanName); nQueue archiveQueue = mySession.findQueue(archiveAtr); mySrcChannel.joinChannelToArchive(archiveQueue); } else { // Create the channel attributes for the destination channel nChannelAttributes dest = new nChannelAttributes(); dest.setName(rchanName); // Obtain a reference to the destination channel nChannel myDstChannel = mySession.findChannel(dest); // Obtain a reference to the destination channel's realm nRealm realm = myDstChannel.getChannelAttributes().getRealm(); // 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) { System.out.println("The channel specified could not be found."); System.out.println("Please ensure that the channel exists in the REALM you connect to."); cnfe.printStackTrace(); System.exit(1); } catch (nSecurityException se) { System.out.println("Insufficient permissions for the requested operation."); System.out.println("Please check the ACL settings on the server."); se.printStackTrace(); System.exit(1); } catch (nSessionNotConnectedException snce) { System.out.println("The session object used is not physically connected to the Nirvana realm."); System.out.println("Please ensure the realm is up and check your RNAME value."); snce.printStackTrace(); System.exit(1); } catch (nUnexpectedResponseException ure) { System.out.println("The Nirvana REALM has returned an unexpected response."); System.out.println("Please ensure the Nirvana REALM and client API used are compatible."); ure.printStackTrace(); System.exit(1); } catch (nUnknownRemoteRealmException urre) { System.out.println("The channel specified resided in a remote realm which could not be found."); System.out.println("Please ensure the channel name specified is correct."); urre.printStackTrace(); System.exit(1); } catch (nRequestTimedOutException rtoe) { System.out.println("The requested operation has timed out waiting for a response from the REALM."); System.out.println("If this is a very busy REALM ask your administrator to increase the client timeout values."); rtoe.printStackTrace(); System.exit(1); } catch (nBaseClientException nbce) { System.out.println("An error occured while creating the Channel Attributes object."); nbce.printStackTrace(); System.exit(1); } // Close the session we opened try { nSessionFactory.close(mySession); } catch (Exception ex) { } // Close any other sessions within this JVM so that we can exit nSessionFactory.shutdown(); } protected void processArgs(String[] args) { if (args.length > 6) { Usage(); UsageEnv(); } else { switch (args.length) { case 6: System.getProperties().put("ARCHIVE", args[5]); case 5: System.getProperties().put("ALLOWPURGE", args[4]); case 4: System.getProperties().put("SELECTOR", args[3]); case 3: System.getProperties().put("JHOPS", args[2]); case 2: System.getProperties().put("RCHANNAME", args[1]); case 1: if (args[0].equals("-?")) { Usage(); UsageEnv(); } System.getProperties().put("CHANNAME", args[0]); break; } } } /** * Prints the usage message for this class */ private static void Usage() { System.out.println("Usage ...\n"); System.out.println("nmakechanjoin [max hops] [selector] \n"); System.out.println(" \n"); System.out.println(" - Channel name parameter of the local channel name to join"); System.out.println(" - Channel name parameter of the remote channel name to join"); System.out.println("\n[Optional Arguments] \n"); System.out.println("[max hops] - The maximum number of join hops a message can travel through "); System.out.println("[selector] - The event filter string to use on messages travelling through this join"); System.out.println( "[Allow Purge] - If allow purge is true then when the source channel is purged events will also be purged"); System.out .println("[archive] - true/false, defaults to false, set if you wish to perform an archive join to a queue"); System.out.println("\n\nNote: -? provides help on environment variables \n"); } } // End of makeChannelJoin Class