/* 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. */ package com.pcbsys.nirvana.apps; import com.pcbsys.nirvana.client.nBaseClientException; import com.pcbsys.nirvana.client.nChannel; import com.pcbsys.nirvana.client.nChannelAttributes; import com.pcbsys.nirvana.client.nChannelNotFoundException; import com.pcbsys.nirvana.client.nIllegalChannelMode; import com.pcbsys.nirvana.client.nQueue; import com.pcbsys.nirvana.client.nRequestTimedOutException; import com.pcbsys.nirvana.client.nSecurityException; import com.pcbsys.nirvana.client.nSessionFactory; import com.pcbsys.nirvana.client.nSessionNotConnectedException; import com.pcbsys.nirvana.client.nUnexpectedResponseException; import com.pcbsys.nirvana.client.nUnknownRemoteRealmException; /** * Deletes a nirvana channel join */ public class deleteChannelJoin extends nSampleApp { private static deleteChannelJoin mySelf=null; /** * This method demonstrates the Nirvana API calls necessary to delete * 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 * @param destChannelName the deatination channel name of the join * @param sourceChannelName the source channel name of the join */ private void doit(String[] realmDetails, String destChannelName, String sourceChannelName ) { mySelf.constructSession(realmDetails); //Removes the specified channel join try{ //Create a channels and attributes objects nChannelAttributes srcattr = new nChannelAttributes(); srcattr.setName( sourceChannelName ); nChannelAttributes dstattr = new nChannelAttributes(); dstattr.setName( destChannelName ); nChannel srcchan = mySession.findChannel(srcattr); try { nChannel dstchan = mySession.findChannel(dstattr); // remove the join srcchan.deleteJoin(dstchan); } catch (nIllegalChannelMode queueerror){ //Its a queue destination nQueue dstqueue = mySession.findQueue(dstattr); srcchan.deleteJoin(dstqueue); } } //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){ switch (args.length){ case 1: if (args[0].equals("-?")) { Usage(); UsageEnv(); } System.getProperties().put("SRCCHANNAME",args[0]); break; case 2: System.getProperties().put("SRCCHANNAME",args[0]); System.getProperties().put("DESTCHANNAME",args[1]); } } public static void main( String[] args ) { //Create an instance for this class mySelf = new deleteChannelJoin(); //Process command line arguments mySelf.processArgs(args); //Process Environment Variables nSampleApp.processEnvironmentVariables(); //Check the channel name specified String destChannelName=null; if ( System.getProperty( "DESTCHANNAME" ) != null ) destChannelName= System.getProperty( "DESTCHANNAME" ) ; else{ Usage(); System.exit( 1 ); } String srcChannelName=null; if ( System.getProperty( "SRCCHANNAME" ) != null ) srcChannelName= System.getProperty( "SRCCHANNAME" ) ; else{ Usage(); System.exit( 1 ); } //Check the local realm details int idx = 0; 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); //delete the channel join specified mySelf.doit(rproperties, destChannelName, srcChannelName); } /** * Prints the usage message for this class */ private static void Usage() { System.out.println( "Usage ...\n" ); System.out.println("ndelchanjoin \n"); System.out.println( " \n"); System.out.println( " - Source Channel name parameter of the join to be deleted" ); System.out.println( " - Destination Channel name parameter of the join to be deleted" ); System.out.println( "\n\nNote: -? provides help on environment variables \n"); } } // End of deleteChannelJoin Class