/* * * 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 nirvana channel */ public class makeChannelWithDeadStore extends nSampleApp { private static makeChannelWithDeadStore mySelf = null; /** * This method demonstrates the Nirvana API calls necessary to create a * channel. It is called after all command line arguments have been received * and validated * * @param achannelName the name of the channel to create * @param deadStore the dead store that optionally may have been created */ private void doit(String achannelName, nAbstractChannel deadStore) { long initialEid = 0; // Check if the optional starteid is specified if (System.getProperty("STARTEID") != null) { try { Integer i = new Integer(System.getProperty("STARTEID")); initialEid = i.intValue(); } catch (Exception num) { initialEid = 0; } } // Creates the specified channel try { // Create a channel attributes object, with optional deadStore nChannelAttributes nca = createChannelAttributes(achannelName, deadStore); // Create the channel nChannel myChannel = mySession.createChannel(nca, initialEid); } // 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 (nChannelAlreadyExistsException caee) { System.out.println("The channel specified already exists on the REALM."); caee.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(); } /** * This method demonstrates the Nirvana API calls necessary to create a * channel. It is called after all command line arguments have been received * and validated * * @param realmDetails a String[] containing the possible RNAME values * @param achannelName the channel name to create * @param deadStoreName the optional name of a dead event store to create */ private void doit(String[] realmDetails, String achannelName, String deadStoreName) { mySelf.constructSession(realmDetails); if (deadStoreName == null) { mySelf.doit(achannelName, null); } else { // Check if the dead store type has been specified String deadStoreType = System.getProperty("DEADEVENTCHANORQUEUE", "C"); // Creates the specified channel try { // Create a channel attributes object for the dead event store nChannelAttributes nca = createDeadStoreAttributes(deadStoreName); if (deadStoreType.equalsIgnoreCase("C")) { // Create the channel dead event store nChannel myChannel; try { myChannel = mySession.createChannel(nca); } catch (nChannelAlreadyExistsException nce) { myChannel = mySession.findChannel(nca); } mySelf.doit(achannelName, myChannel); } else { // Create the channel dead event store nQueue myQueue; try { myQueue = mySession.createQueue(nca); } catch (nChannelAlreadyExistsException nce) { myQueue = mySession.findQueue(nca); } mySelf.doit(achannelName, myQueue); } } // 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 (nChannelAlreadyExistsException caee) { System.out.println("The channel specified already exists on the REALM."); caee.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 10: System.getProperties().put("DEADEVENTCAP", args[9]); case 9: System.getProperties().put("DEADEVENTTTL", args[8]); case 8: System.getProperties().put("DEADEVENTTYPE", args[7]); case 7: System.getProperties().put("DEADEVENTCHANORQUEUE", args[6]); case 6: System.getProperties().put("DEADEVENTNAME", args[5]); case 5: System.getProperties().put("STARTEID", args[4]); case 4: System.getProperties().put("TYPE", args[3]); case 3: System.getProperties().put("CAPACITY", args[2]); case 2: System.getProperties().put("TTL", args[1]); case 1: if (args[0].equals("-?")) { Usage(); UsageEnv(); } System.getProperties().put("CHANNAME", args[0]); break; } } public static void main(String[] args) { // Create an instance for this class mySelf = new makeChannelWithDeadStore(); // Process command line arguments mySelf.processArgs(args); // Process Environment Variables nSampleApp.processEnvironmentVariables(); // Check the channel name specified String channelName = null; if (System.getProperty("CHANNAME") != null) { channelName = System.getProperty("CHANNAME"); } else { Usage(); System.exit(1); } // Check if dead event store is specified String deadStoreName = null; if (System.getProperty("DEADEVENTNAME") != null) { deadStoreName = System.getProperty("DEADEVENTNAME", null); } // 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); // create the channel specified mySelf.doit(rproperties, channelName, deadStoreName); } private nChannelAttributes createChannelAttributes(String achannelName, nAbstractChannel deadStore) throws nBaseClientException { // Create a channel attributes object nChannelAttributes nca = new nChannelAttributes(); // Set the channel name nca.setName(achannelName); if (deadStore != null) { nca.setDeadEventHandler(deadStore); } // Set the channel type parameter (reliable or guaranteed) if (System.getProperty("TYPE") != null) { if (System.getProperty("TYPE").equalsIgnoreCase("R")) { nca.setType(nChannelAttributes.RELIABLE_TYPE); } else if (System.getProperty("TYPE").equalsIgnoreCase("P")) { nca.setType(nChannelAttributes.PERSISTENT_TYPE); } else if (System.getProperty("TYPE").equalsIgnoreCase("M")) { nca.setType(nChannelAttributes.MIXED_TYPE); } else if (System.getProperty("TYPE").equalsIgnoreCase("S")) { nca.setType(nChannelAttributes.SIMPLE_TYPE); } else if (System.getProperty("TYPE").equalsIgnoreCase("T")) { nca.setType(nChannelAttributes.TRANSIENT_TYPE); } else if (System.getProperty("TYPE").equalsIgnoreCase("O")) { nca.setType(nChannelAttributes.OFF_HEAP_TYPE); } else if (System.getProperty("TYPE").equalsIgnoreCase("G")) { nca.setType(nChannelAttributes.PAGED_TYPE); } } else { nca.setType(nChannelAttributes.SIMPLE_TYPE); } // Set the channel capacity parameter if (System.getProperty("CAPACITY") != null) { Integer i = new Integer(System.getProperty("CAPACITY")); nca.setMaxEvents(i.intValue()); } // Set the channel Time to Live parameter if (System.getProperty("TTL") != null) { Integer i = new Integer(System.getProperty("TTL")); nca.setTTL(i.intValue()); } return nca; } private nChannelAttributes createDeadStoreAttributes(String storeName) throws nBaseClientException { // Create a channel attributes object nChannelAttributes nca = new nChannelAttributes(); // Set the channel name nca.setName(storeName); // Set the channel type parameter (reliable or guaranteed) if (System.getProperty("DEADEVENTTYPE") != null) { if (System.getProperty("DEADEVENTTYPE").equalsIgnoreCase("R")) { nca.setType(nChannelAttributes.RELIABLE_TYPE); } else if (System.getProperty("DEADEVENTTYPE").equalsIgnoreCase("P")) { nca.setType(nChannelAttributes.PERSISTENT_TYPE); } else if (System.getProperty("DEADEVENTTYPE").equalsIgnoreCase("M")) { nca.setType(nChannelAttributes.MIXED_TYPE); } else if (System.getProperty("DEADEVENTTYPE").equalsIgnoreCase("S")) { nca.setType(nChannelAttributes.SIMPLE_TYPE); } else if (System.getProperty("DEADEVENTTYPE").equalsIgnoreCase("T")) { nca.setType(nChannelAttributes.TRANSIENT_TYPE); } else if (System.getProperty("DEADEVENTTYPE").equalsIgnoreCase("O")) { nca.setType(nChannelAttributes.OFF_HEAP_TYPE); } else if (System.getProperty("DEADEVENTTYPE").equalsIgnoreCase("G")) { nca.setType(nChannelAttributes.PAGED_TYPE); } } else { nca.setType(nChannelAttributes.PERSISTENT_TYPE); } // Set the channel capacity parameter if (System.getProperty("DEADEVENTCAP") != null) { Integer i = new Integer(System.getProperty("DEADEVENTCAP", "0")); nca.setMaxEvents(i.intValue()); } // Set the channel Time to Live parameter if (System.getProperty("DEADEVENTTTL") != null) { Integer i = new Integer(System.getProperty("DEADEVENTTTL", "0")); nca.setTTL(i.intValue()); } return nca; } /** * Prints the usage message for this class */ private static void Usage() { System.out.println("Usage ...\n"); System.out.println( "nmakechan [time to live] [capacity] [type] [start eid] [dead store name] [C | Q - channel or queue] [dead store type] [dead store ttl] [dead store capacity]\n"); System.out.println(" \n"); System.out.println(" - Channel name parameter for the channel to be created"); System.out.println("\n[Optional Arguments] \n"); System.out.println("[time to live] - The Time To Live parameter for the new channel (default: 0)"); System.out.println("[capacity] - The Capacity parameter for the new channel (default: 0)"); System.out.println("[type] - The type parameter for the new channel (default: S)"); System.out.println(" R - For a reliable (stored in memory) channel with persistent eids"); System.out.println(" P - For a persistent (stored on disk) channel"); System.out.println(" S - For a simple (stored in memory) channel with non-persistent eids"); System.out.println(" O - For a off-heap (stored off-heap) channel with persistent eids"); System.out.println(" G - For a paged (stored off-heap and on disk) channel"); System.out.println(" M - For a Mixed (allows both memory and persistent events) channel\n"); System.out.println("[start eid] - The initial start event id for the new channel (default: 0)"); System.out.println("[dead store name] - Name parameter for the dead store to be created"); System.out.println("[C or Q] The type of store, i.e. C for channel, Q for a queue"); System.out.println("[time to live] - The Time To Live parameter for the dead store (default: 0)"); System.out.println("[capacity] - The Capacity parameter for the dead store (default: 0)"); System.out.println("[type] - The type parameter for the dead store (default: S)"); System.out.println(" R - For a reliable (stored in memory) dead event store with persistent eids"); System.out.println(" P - For a persistent (stored on disk) dead event store"); System.out.println(" S - For a simple (stored in memory) dead event store with non-persistent eids"); System.out.println(" T - For a transient (no server based storage)"); System.out.println(" O - For a off-heap (stored off-heap) dead event store with persistent eids"); System.out.println(" G - For a paged (stored off-heap and on disk) dead event store"); System.out.println(" M - For a Mixed (allows both memory and persistent events) dead event store\n"); System.out.println("\n\nNote: -? provides help on environment variables \n"); } } // End of makeChannel Class