Package org.exolab.jms.util

Examples of org.exolab.jms.util.CommandLine


    //////////////////////////////////////////////////////////////////////////////////////
    // Mainline
    public static void main(String[] args)
    throws Exception {
        CommandLine line  = new CommandLine(args);
        if (line.exists("props")) {
            Properties props = new Properties(System.getProperties());
            props.load(new BufferedInputStream(new FileInputStream(line.value("props"))));
            System.setProperties(props);

            Controller controller = new Controller();
            while(true);
        } else {
View Full Code Here


    //////////////////////////////////////////////////////////////////////////////////////
    // Mainline
    public static void main(String[] args)
    throws Exception {
        CommandLine line  = new CommandLine(args);
        if (line.exists("props")) {
            Properties props = new Properties(System.getProperties());
            props.load(new BufferedInputStream(new FileInputStream(line.value("props"))));
            System.setProperties(props);

            Worker worker = new Worker();
            //worker.waitForMessage();
        } else {
View Full Code Here

* specified then an exception is raised.
*/
public class Uploader {
    static public void main(String[] args) {
        try {
            CommandLine cmdline = new CommandLine(args);

            if (cmdline.exists("help")) {
                // the help option has been specified, print the usage
                // information
                usage();
            } else if (cmdline.exists("queue")) {
                // connect to the JNDI server and get a reference to
                // root context
                Hashtable props = new Hashtable();
                String topic_name = cmdline.value("topic");
                String host = "localhost";
                String port = null;
                String jndiname = "JndiServer";

                String mode = null;
                if (cmdline.exists("mode")) {
                    mode = cmdline.value("mode");
                } else {
                    mode = "rmi";
                }

                String modeType =
                    RmiJndiInitialContextFactory.class.getName();

                if (cmdline.exists("jndiport")) {
                    port = cmdline.value("jndiport");
                }

                if (cmdline.exists("jndihost")) {
                    host = cmdline.value("jndihost");
                }

                // override the default server name if specified on the
                // command line.
                if (cmdline.exists("jndiname")) {
                    jndiname = cmdline.value("jndiname");
                }

                if (mode.equals("ipc") || mode.equals("tcp")) {
                    if (port == null) {
                        port = "3035";
                    }

                    props.put(Context.PROVIDER_URL,
                        "tcp://" + host + ":" + port + "/");
                    modeType =
                        "org.exolab.jms.jndi.mipc.IpcJndiInitialContextFactory";
                } else if (mode.equals("http")) {
                    System.out.println("Using HTTP");
                    String type = "http://";
                    if (cmdline.exists("secure")) {
                        if (port == null) {
                            port = "8443";
                        }
                        type = "https://";
                        modeType =
                            "org.exolab.jms.jndi.http.SslHttpJndiInitialContextFactory";
                    } else {
                        if (port == null) {
                            port = "8080";
                        }
                        modeType =
                            "org.exolab.jms.jndi.http.HttpJndiInitialContextFactory";
                    }

                    props.put(Context.PROVIDER_URL,
                        type + host + ":" + port + "/" +
                        "openjms/servlet/OpenJMSJndi");

                    String url = cmdline.value("url");
                    if (url == null) {
                        url = type + "localhost:8080";
                    }

                    // Client URL to allow server to send messages
                    // to registered consumers/receivers
                    System.getProperties().setProperty
                        (JndiConstants.HTTP_CLIENT_URL_PROPERTY, url);

                } else {
                    if (port == null) {
                        port = "1099";
                    }

                    props.put(Context.PROVIDER_URL,
                        "rmi://" + host + ":" + port + "/" + jndiname);
                }

                System.err.println("Using provider url " + props.get(Context.PROVIDER_URL));
                props.put(Context.INITIAL_CONTEXT_FACTORY, modeType);
                Context context = new InitialContext(props);

                String queue_name = cmdline.value("queue");
                if (queue_name != null) {
                    // lookup the connection factory from the context
                    QueueConnectionFactory factory = (QueueConnectionFactory)
                    context.lookup("JmsQueueConnectionFactory");

                    // if we can't find the factory then throw an exception
                    if (factory == null) {
                        throw new RuntimeException(
                            "Failed to locate connection factory");
                    }

                    // determine whether the summary flag has been set. By
                    // default it is false, which means the message details
                    // are displayed as they are browsed
                    boolean summary = false;
                    if (cmdline.exists("summary")) {
                        summary = true;
                    }
                   
                    QueueConnection connection = factory.createQueueConnection();
                    connection.start();

                    QueueSession session = connection.createQueueSession(
                        false, Session.CLIENT_ACKNOWLEDGE);

                    // if the persistent flag is not specified then create the
                    // queue object otherwise look it up
                    Queue queue = null;
                    if (cmdline.exists("persistent")) {
                        queue = (Queue)context.lookup(queue_name);
                    } else {
                        queue = (Queue)session.createQueue(queue_name);
                    }

                    if (queue == null) {
                        getLogger().logError("Failed to create queue " +
                            queue);
                        System.exit(-1);
                    }

                    QueueSender sender = session.createSender(queue);

                    // check the number of iterations that have been
                    // specified on the command line. If it has not been
                    // specified then default to 1.
                    int count = 1;
                    if (cmdline.exists("count")) {
                        try {
                            count = Integer.parseInt(cmdline.value("count"));
                        } catch (Exception exception) {
                            System.err.println("Illegal count value");
                            System.exit(-1);
                        }
                    }

                    // determine if the delivery mode should be persistent or
                    // non persistent
                    int delivery_mode = DeliveryMode.NON_PERSISTENT;
                    if (cmdline.exists("persistent")) {
                        delivery_mode = DeliveryMode.PERSISTENT;
                    }

                    // retrieve the message size
                    int size = 10000;
                    if (cmdline.exists("size")) {
                        try {
                            count = Integer.parseInt(cmdline.value("size"));
                        } catch (Exception exception) {
                            System.err.println("Illegal size value");
                            System.exit(-1);
                        }
                    }
View Full Code Here

                int waitTime = 5000;
                int displayCount = 500;


            // Retreiving the command line arguments with a OpenJMS utility
            CommandLine cmdline = new CommandLine(args);

                // Administered objects accessing
                if (cmdline.exists("jndiport"))
                {
                    jndiPort = Integer.parseInt(cmdline.value("jndiport"));
                    System.out.println("JNDI Port parametered");
                }
                if (cmdline.exists("jndihost"))
                {
                    jndiHost = cmdline.value("jndihost");
                    System.out.println("JNDI Host parametered");
                }

                // Messaging
                if (cmdline.exists("ack"))
                {
                    try
                    {
                        String mode = cmdline.value("ack");
                        if (mode.equals("auto"))
                        {
                            ackType = Session.AUTO_ACKNOWLEDGE;
                            System.out.println("Ack Type parametered");
                        }
                        else if (mode.equals("client"))
                        {
                            ackType = Session.CLIENT_ACKNOWLEDGE;
                            System.out.println("Ack Type parametered");
                        }
                        else if (mode.equals("dups"))
                        {
                            ackType = Session.DUPS_OK_ACKNOWLEDGE;
                            System.out.println("Ack Type parametered");
                        }
                        else
                        {
                            System.err.println("Invalid ackmode specified");
                            System.exit(1);
                        }
                     }
                     catch (Exception exception)
                     {
                        System.err.println("Invalid ackmode specified");
                        System.exit(0);
                     }
                }
                if (cmdline.exists("acknb"))
                {
                    clientAckNb = Integer.parseInt(cmdline.value("acknb"));
                    System.out.println("Client ack size parametered");
                }
                if (cmdline.exists("topic"))
                {
                    topicName = cmdline.value("topic");
                    System.out.println("Topic parametered");
                }
                if (cmdline.exists("transacted"))
                {
                    transacted = true;
                    System.out.println("Transacted mode parametered");
                }

                // Listener parametering
                if (cmdline.exists("count"))
                {
                    // The message listener should show mesurements every <count> messages
                    displayCount = Integer.parseInt(cmdline.value("count"));
                    System.out.println("Message read mode parametered");
                }
                if (cmdline.exists("readmsg"))
                {
                    // The message listener should read the received messages instead of only counting it
                    readMsg = true;
                    System.out.println("Message read mode parametered");
                }
                if (cmdline.exists("wait"))
                {
                    // At the end of a message receipt, wait <time> ms for new messages before terminating
                    waitTime = Integer.parseInt(cmdline.value("wait"));
                    System.out.println("Waiting time parametered");
                }


                // Misc
                if (cmdline.exists("help"))
                {
                    usage();
                }
                if (cmdline.exists("test"))
                {
                    System.out.println("jndiport : " + jndiPort);
                    System.out.println("jndihost : " + jndiHost);
                    System.out.println("ackType : " + ackType);
                    System.out.println("topicName: " + topicName);
View Full Code Here

                  boolean transacted = false;
              // Misc
              long absCount = 0;

              // Retreiving the command line arguments with an Open JMS utility
              CommandLine cmdline = new CommandLine(args);
             
              String connector = null;

                  // Administered objects accessing
                  if (cmdline.exists("jndiport"))
                  {
                      jndiPort = Integer.parseInt(cmdline.value("jndiport"));
                      System.out.println("JNDI Port parametered");
                  }
                  if (cmdline.exists("jndihost"))
                  {
                      jndiHost = cmdline.value("jndihost");
                      System.out.println("JNDI Host parametered");
                  }

                  // Messaging
                  if (cmdline.exists("ack"))
                  {
                      try
                      {
                          String mode = cmdline.value("ack");
                          if (mode.equals("auto"))
                          {
                              ackType = Session.AUTO_ACKNOWLEDGE;
                              System.out.println("Ack Type parametered");
                          }
                          else if (mode.equals("client"))
                          {
                              ackType = Session.CLIENT_ACKNOWLEDGE;
                              System.out.println("Ack Type parametered");
                          }
                          else if (mode.equals("dups"))
                          {
                              ackType = Session.DUPS_OK_ACKNOWLEDGE;
                              System.out.println("Ack Type parametered");
                          }
                          else
                          {
                              System.err.println("Invalid ackmode specified");
                              System.exit(1);
                          }
                       }
                       catch (Exception exception)
                       {
                          System.err.println("Invalid ackmode specified");
                          System.exit(0);
                       }
                  }
                  if (cmdline.exists("count"))
                  {
                      count = Integer.parseInt(cmdline.value("count"));
                      System.out.println("Messages count parametered");
                  }
                  if (cmdline.exists("infinite"))
                  {
                      infiniteCount = true;
                      System.out.println("Infinite messages count parametered");
                  }
                  if (cmdline.exists("heavyweight"))
                  {
                      heavyweight = true;
                      weight = Integer.parseInt(cmdline.value("heavyweight"));
                      System.out.println("Heavyweight messages parametered");
                  }
                  if (cmdline.exists("persistent"))
                  {
                      persistency = DeliveryMode.PERSISTENT;
                      System.out.println("Persistent messages delivery parametered");
                  }
                  if (cmdline.exists("sleep"))
                  {
                      sleepTime = Integer.parseInt(cmdline.value("sleep"));
                      System.out.println("Sleep parametered");
                  }
                  if (cmdline.exists("text"))
                  {
                      textMessages = true;
                      System.out.println("Text messages parametered");
                  }
                  if (cmdline.exists("topic"))
                  {
                      topicName = cmdline.value("topic");
                      System.out.println("Topic parametered");
                  }
                  if (cmdline.exists("transacted"))
                  {
                      transacted = true;
                      System.out.println("Transacted mode parametered");
                  }
                  if (cmdline.exists("mode")) {
                        connector = cmdline.value("mode");
                  }
                  // Misc
                  if (cmdline.exists("help"))
                  {
                      usage();
                  }
                  if (cmdline.exists("test"))
                  {
                    System.out.println("jndiPort : " + jndiPort);
                    System.out.println("jndiHost : " + jndiHost);
                    System.out.println("ackType : " + ackType);
                    System.out.println("count : " + count);
View Full Code Here

* specified then an exception is raised.
*/
public class SimplePublisher {
    static public void main(String[] args) {
        try {
            CommandLine cmdline = new CommandLine(args);

            if (cmdline.exists("help")) {
                // the help option has been specified, print the usage
                // information
                usage();
            } else if (cmdline.exists("topic")) {
                // enable debugging - unbdocumented option
                if (cmdline.exists("debug")) {
                    LoggerIfc logger = LoggerFactory.getLogger();
                    logger.setLogLevel(LogEventType.Debug);
                }

                // connect to the JNDI server and get a reference to
                // root context
                Hashtable props = new Hashtable();
                String topic_name = cmdline.value("topic");
                String host = "localhost";
                String port = null;
                String jndiname = "JndiServer";

                String mode = null;
                if (cmdline.exists("mode")) {
                    mode = cmdline.value("mode");
                } else {
                    mode = "rmi";
                }

                String modeType =
                    RmiJndiInitialContextFactory.class.getName();

                if (cmdline.exists("jndiport")) {
                    port = cmdline.value("jndiport");
                }

                if (cmdline.exists("jndihost")) {
                    host = cmdline.value("jndihost");
                }

                // override the default server name if specified on the
                // command line.
                if (cmdline.exists("jndiname")) {
                    jndiname = cmdline.value("jndiname");
                }

                if (mode.equals("ipc") || mode.equals("tcp")) {
                    if (port == null) {
                        port = "3035";
                    }

                    props.put(Context.PROVIDER_URL,
                        "tcp://" + host + ":" + port + "/");
                    modeType =
                        "org.exolab.jms.jndi.mipc.IpcJndiInitialContextFactory";
                } else if (mode.equals("http")) {
                    System.out.println("Using HTTP");

                    /* CONNECTING BY WAY OF PROXY 
                       Client needs to set these system properties if
                       it requires to go through a proxy for HTTP.
                       System.setProperty("http.proxyHost", host);
                       System.setProperty("http.proxyPort", port);
                    */

                    /* CONNECTING FOR SSL TRANSACTIONS.
                       Client needs to set these system properties
                       if it requires to go through a proxy for HTTPS.

                       System.setProperty("https.proxyHost", "host");
                       System.setProperty("https.proxyPort", "port");


                       Client needs to pass in "-mode http -secure"
                       to use https
                       Client needs -Djavax.net.ssl.trustStore=cacerts
                       passed in. JSSE is required to make this work.
                    */

                    String type = "http://";
                    if (cmdline.exists("secure")) {
                        if (port == null) {
                            port = "8443";
                        }
                        type = "https://";
                        modeType =
                            "org.exolab.jms.jndi.http.SslHttpJndiInitialContextFactory";
                    } else {
                        if (port == null) {
                            port = "8080";
                        }
                        modeType =
                            "org.exolab.jms.jndi.http.HttpJndiInitialContextFactory";
                    }

                    props.put(Context.PROVIDER_URL,
                        type + host + ":" + port + "/" +
                        "openjms/servlet/OpenJMSJndi");

                    String url = cmdline.value("url");
                    if (url == null) {
                        url = type + "localhost:8080";
                    }

                    // Client URL to allow server to send messages
                    // to registered consumers/receivers
                    System.getProperties().setProperty
                        (JndiConstants.HTTP_CLIENT_URL_PROPERTY, url);

                } else {
                    if (port == null) {
                        port = "1099";
                    }

                    props.put(Context.PROVIDER_URL,
                        "rmi://" + host + ":" + port + "/" + jndiname);
                }

                System.err.println("Using provider url " + props.get(Context.PROVIDER_URL));
                props.put(Context.INITIAL_CONTEXT_FACTORY, modeType);
                Context context = new InitialContext(props);

                // lookup the connection factory from the context
                TopicConnectionFactory factory = (TopicConnectionFactory)
                context.lookup("JmsTopicConnectionFactory");

                // if we can't find the factory then throw an exception
                if (factory == null) {
                    throw new RuntimeException(
                        "Failed to locate connection factory");
                }

                TopicConnection connection =
                    factory.createTopicConnection();
                connection.start();

                TopicSession session = connection.createTopicSession(
                    false, Session.CLIENT_ACKNOWLEDGE);
                Topic topic = null;
                topic = session.createTopic(topic_name);

                if (topic == null) {
                    System.err.println("Failed to get administered object"
                        + " exiting.....");
                    System.exit(-1);
                }

                TopicPublisher publisher = session.createPublisher(topic);

                // check the number of iterations that have been specified
                // on the command line. If it has not yet been specified
                // then default to 10.
                int count = 10;
                if (cmdline.exists("count")) {
                    try {
                        count = Integer.parseInt(cmdline.value("count"));
                    } catch (Exception exception) {
                        System.err.println("Illegal count value");
                        System.exit(-1);
                    }
                }

                // check if a sleep has been specified
                int sleep = 0;
                if (cmdline.exists("sleep")) {
                    try {
                        sleep = Integer.parseInt(cmdline.value("sleep"));
                    } catch (Exception exception) {
                        System.err.println("Illegal sleep value");
                        System.exit(-1);
                    }
                }

                // determine if the delivery mode should be persistent or
                // non persistent
                int delivery_mode = DeliveryMode.NON_PERSISTENT;
                if (cmdline.exists("persistent")) {
                    delivery_mode = DeliveryMode.PERSISTENT;
                }

                // create a text message
                Random rand = new Random((new Date()).getTime());
View Full Code Here

    static public void main(String[] args)
    {
        try
        {
            CommandLine cmdline = new CommandLine(args);
            Thread server_thread = null;

            if (cmdline.exists("help")) {
                // the help option has been specified, print the usage
                // information
                usage();
            } else if (cmdline.exists("topic")) {
                // connect to the JNDI server and get a reference to
                // root context
                Hashtable props = new Hashtable();
                String topic_name = cmdline.value("topic");
                String host = "localhost";
                String port = null;
                String jndiname = "JndiServer";

                String mode = null;
                if (cmdline.exists("mode")) {
                    mode = cmdline.value("mode");
                } else {
                    mode = "rmi";
                }

                String modeType =
                    RmiJndiInitialContextFactory.class.getName();

                if (cmdline.exists("jndiport")) {
                    port = cmdline.value("jndiport");
                }

                if (cmdline.exists("jndihost")) {
                    host = cmdline.value("jndihost");
                }

                // override the default server name if specified on the
                // command line.
                if (cmdline.exists("jndiname")) {
                    jndiname = cmdline.value("jndiname");
                }

                if (mode.equals("ipc") || mode.equals("tcp")) {
                    if (port == null) {
                        port = "3035";
                    }

                    props.put(Context.PROVIDER_URL,
                        "tcp://" + host + ":" + port + "/");
                    modeType =
                        "org.exolab.jms.jndi.mipc.IpcJndiInitialContextFactory";
                } else if (mode.equals("http")) {
                    System.out.println("Using HTTP");
                    String type = "http://";
                    if (cmdline.exists("secure")) {
                        if (port == null) {
                            port = "8443";
                        }
                        type = "https://";
                        modeType =
                            "org.exolab.jms.jndi.http.SslHttpJndiInitialContextFactory";
                    } else {
                        if (port == null) {
                            port = "8080";
                        }
                        modeType =
                            "org.exolab.jms.jndi.http.HttpJndiInitialContextFactory";
                    }

                    props.put(Context.PROVIDER_URL,
                        type + host + ":" + port + "/" +
                        "openjms/servlet/OpenJMSJndi");

                    String url = cmdline.value("url");
                    if (url == null) {
                        url = type + "localhost:8080";
                    }

                    // Client URL to allow server to send messages
                    // to registered consumers/receivers
                    System.getProperties().setProperty
                        (JndiConstants.HTTP_CLIENT_URL_PROPERTY, url);

                } else {
                    if (port == null) {
                        port = "1099";
                    }

                    props.put(Context.PROVIDER_URL,
                        "rmi://" + host + ":" + port + "/" + jndiname);
                }

                System.err.println("Using provider url " + props.get(Context.PROVIDER_URL));
                props.put(Context.INITIAL_CONTEXT_FACTORY, modeType);
                Context context = new InitialContext(props);

                // lookup the connection factory from the context
                TopicConnectionFactory factory = (TopicConnectionFactory)
                context.lookup("JmsTopicConnectionFactory");

                // if we can't find the factory then throw an exception
                if (factory == null) {
                    throw new RuntimeException(
                        "Failed to locate connection factory");
                }

                TopicConnection connection = factory.createTopicConnection();
                connection.start();

                TopicSession session =
                    connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

                // this is not the preferred way to get a topic
                Topic topic = session.createTopic(topic_name);

                if (topic == null)
                {
                    System.err.println("Failed to create topic");
                }
                else
                {
                    // create a receiver of the request in a separate thread and
                    // start it running
                    if (cmdline.exists("standalone")) {
                        if (cmdline.value("standalone").equals("A")) {
                            RequestReply server = new RequestReply(props, topic);
                            server_thread = new Thread(server);
                            server_thread.start();
                        }
                    } else {
View Full Code Here

        received_ = 0;
    }

    static public void main(String[] args) {
        try {
            CommandLine cmdline = new CommandLine(args);

            if (cmdline.exists("help")) {
                // the help option has been specified, print the usage
                // information
                usage();
            } else if (cmdline.exists("topic")) {
                // see if an ack mode has been specified. If it hasn't
                // then assume CLIENT_ACKNOWLEDGE mode.
                int ackMode = Session.CLIENT_ACKNOWLEDGE;
                if (cmdline.exists("ackmode")) {
                    String amode = cmdline.value("ackmode");
                    if (amode.equals("auto")) {
                        ackMode = Session.AUTO_ACKNOWLEDGE;
                    } else if (amode.equals("dups")) {
                        ackMode = Session.DUPS_OK_ACKNOWLEDGE;
                    } else if (!amode.equals("client")) {
                        // ignore all ack modes, to test no acking
                        ackMode = -1;
                    }
                }

                // enable debugging - undocumented option
                if (cmdline.exists("debug")) {
                    LoggerIfc logger = LoggerFactory.getLogger();
                    logger.setLogLevel(LogEventType.Debug);
                }

                String topic_name = cmdline.value("topic");
                if (topic_name != null) {
                    // connect to the JNDI server and get a reference to
                    // root context
                    Hashtable props = new Hashtable();
                    String host = "localhost";
                    String port = null;
                    String jndiname = "JndiServer";

                    String mode = "rmi";
                    if (cmdline.exists("mode")) {
                        mode = cmdline.value("mode");
                    }

                    String modeType =
                        RmiJndiInitialContextFactory.class.getName();

                    if (cmdline.exists("jndiport")) {
                        port = cmdline.value("jndiport");
                    }

                    if (cmdline.exists("jndihost")) {
                        host = cmdline.value("jndihost");
                    }

                    // override the default server name if specified on the
                    // command line.
                    if (cmdline.exists("jndiname")) {
                        jndiname = cmdline.value("jndiname");
                    }

                    if (mode.equals("ipc") || mode.equals("tcp")) {
                        if (port == null) {
                            port = "3035";
                        }

                        props.put(Context.PROVIDER_URL,
                            "tcp://" + host + ":" + port + "/");
                        modeType =
                            "org.exolab.jms.jndi.mipc.IpcJndiInitialContextFactory";
                    } else if (mode.equals("http")) {
                        System.out.println("Using HTTP");

                        /* CONNECTING BY WAY OF PROXY 
                           Client needs to set these system properties if
                           it requires to go through a proxy for HTTP.
                           System.setProperty("http.proxyHost", host);
                           System.setProperty("http.proxyPort", port);
                        */

                        /* CONNECTING FOR SSL TRANSACTIONS.
                           Client needs to set these system properties
                           if it requires to go through a proxy for
                           HTTPS.

                           System.setProperty("https.proxyHost", "host");
                           System.setProperty("https.proxyPort", "port");
                          

                           Client needs to pass in "-mode http -secure"
                           to use https,
                           Client needs -Djavax.net.ssl.trustStore=cacerts
                           passed in. JSSE is required to make this work.
                        */
                        String type = "http://";

                        if (cmdline.exists("secure")) {
                            if (port == null) {
                                port = "8443";
                            }
                            type = "https://";
                            modeType =
                                "org.exolab.jms.jndi.http.SslHttpJndiInitialContextFactory";
                        } else {
                            if (port == null) {
                                port = "8080";
                            }
                            modeType =
                                "org.exolab.jms.jndi.http.HttpJndiInitialContextFactory";
                        }

                        props.put(Context.PROVIDER_URL,
                            type + host + ":" + port + "/" +
                            "openjms/servlet/OpenJMSJndi");
                        String url = cmdline.value("url");
                        if (url == null) {
                            if (cmdline.exists("secure")) {
                                url = type + "localhost:8443";
                            } else {
                                url = type + "localhost:8080";
                            }
                        }

                        // Client URL to allow server to send messages
                        // to registered consumers/receivers
                        System.getProperties().setProperty
                            (JndiConstants.HTTP_CLIENT_URL_PROPERTY, url);

                    } else {
                        if (port == null) {
                            port = "1099";
                        }

                        props.put(Context.PROVIDER_URL,
                            "rmi://" + host + ":" + port + "/" + jndiname);
                    }

                    System.err.println("Using provider url " + props.get(Context.PROVIDER_URL));
                    props.put(Context.INITIAL_CONTEXT_FACTORY, modeType);
                    Context context = new InitialContext(props);

                    // lookup the connection factory from the context
                    TopicConnectionFactory factory = (TopicConnectionFactory)
                    context.lookup("JmsTopicConnectionFactory");

                    // if we can't find the factory then throw an exception
                    if (factory == null) {
                        throw new RuntimeException(
                            "Failed to locate connection factory");
                    }

                    LoggerFactory.getLogger().logDebug("Have the connection factory " + factory);
                    TopicConnection connection =
                        factory.createTopicConnection();

                    TopicSession session =
                        connection.createTopicSession(false, ackMode);

                    Topic topic = null;
                    if (cmdline.exists("persistent")) {
                        topic = (Topic)context.lookup(topic_name);
                    } else {
                        topic = session.createTopic(topic_name);
                    }

                    if (topic == null) {
                        System.err.println("Failed to get administered object"
                            + " exiting.....");
                        System.exit(-1);
                    }

                    String selector = null;
                    if (cmdline.exists("selector")) {
                        selector = "JMSPriority=1";
                    }

                    // determine if the summary flag has been specified. By
                    // default the message details are printed out. If the
                    // summary flag is specified then the count of the messages
                    // received is displayed.
                    boolean summary = false;
                    if (cmdline.exists("summary")) {
                        summary = true;
                    }

                    // if the 'name' option has been specified then assume a
                    // durable subscriber otherwise transient
                    TopicSubscriber subscriber = null;
                    String name = cmdline.value("name");
                    if (name != null) {

                        subscriber = session.createDurableSubscriber
                            (topic, name, selector, false);
                    } else {
                        subscriber = session.createSubscriber(topic, selector, false);
                    }

                    int secs = 60;
                    boolean counted = false;
                    int count = 1;

                    if (cmdline.exists("count")) {
                        counted = true;
                        try {
                            String value = cmdline.value("count");
                            count = Integer.parseInt(value);
                        } catch (Exception exception) {
                            System.err.println("Illegal count value");
                            System.exit(-1);
                        }
                    }

                    // the timeout is used to terminate the consumer if not
                    // messags are received within the specified timeframe.
                    // The default value is 5 minutes.
                    secs = 5 * 60;
                    if (cmdline.exists("timeout")) {
                        secs = Integer.parseInt(cmdline.value("timeout"));
                    }

                    SimpleConsumer consumer = (counted)
                    ? new SimpleConsumer(name, connection, subscriber, ackMode, count, secs,summary)
                    : new SimpleConsumer(name, connection, subscriber, ackMode, secs, summary);
                    subscriber.setMessageListener(consumer);
                    connection.setExceptionListener(consumer);

                    // start the connection unless the noStart option is specified
                    if (!cmdline.exists("noStart")) {
                        connection.start();
                    }

                } else {
                    System.err.println("Cannot subscribe to messages under "
View Full Code Here

*/
public class TemporaryQueue {

    static public void main(String[] args) {
        try {
            CommandLine cmdline = new CommandLine(args);
            Thread server_thread = null;

            if (cmdline.exists("help")) {
                // the help option has been speifie, print the usage
                // information
                usage();
            } else if (cmdline.exists("queue")) {
                String queue_name = cmdline.value("queue");
                // connect to the JNDI server and get a reference to
                // root context
                Hashtable props = new Hashtable();
                String topic_name = cmdline.value("topic");
                String host = "localhost";
                String port = null;
                String jndiname = "JndiServer";

                String mode = null;
                if (cmdline.exists("mode")) {
                    mode = cmdline.value("mode");
                } else {
                    mode = "rmi";
                }

                String modeType =
                    RmiJndiInitialContextFactory.class.getName();

                if (cmdline.exists("jndiport")) {
                    port = cmdline.value("jndiport");
                }

                if (cmdline.exists("jndihost")) {
                    host = cmdline.value("jndihost");
                }

                // override the default server name if specified on the
                // command line.
                if (cmdline.exists("jndiname")) {
                    jndiname = cmdline.value("jndiname");
                }

                if (mode.equals("ipc") || mode.equals("tcp")) {
                    if (port == null) {
                        port = "3035";
                    }

                    props.put(Context.PROVIDER_URL,
                        "tcp://" + host + ":" + port + "/");
                    modeType =
                        "org.exolab.jms.jndi.mipc.IpcJndiInitialContextFactory";
                } else if (mode.equals("http")) {
                    System.out.println("Using HTTP");
                    String type = "http://";
                    if (cmdline.exists("secure")) {
                        if (port == null) {
                            port = "8443";
                        }
                        type = "https://";
                        modeType =
                            "org.exolab.jms.jndi.http.SslHttpJndiInitialContextFactory";
                    } else {
                        if (port == null) {
                            port = "8080";
                        }
                        modeType =
                            "org.exolab.jms.jndi.http.HttpJndiInitialContextFactory";
                    }

                    props.put(Context.PROVIDER_URL,
                        type + host + ":" + port + "/" +
                        "openjms/servlet/OpenJMSJndi");

                    String url = cmdline.value("url");
                    if (url == null) {
                        url = type + "localhost:8080";
                    }

                    // Client URL to allow server to send messages
View Full Code Here

  public static void main (String args[])
  {
    int width = 800;
    int height = 300;

    CommandLine cmdline = new CommandLine(args);
    if (cmdline.exists("help"))
    {
      // the help option has been speifie, print the usage information
      usage();
    }
    String md = cmdline.value("mode");
        String uri = "rmi://";
        String mode = rmiMode_;
        String host = "localhost";
        String port = "1099";
        String jndiServer = "JndiServer";
    if (md != null && md.equals("ipc")) {
            System.out.println("Using IPC mode");
            mode = ipcMode_;
            port = "3035";
            uri = "tcp://";
            jndiServer = "";
        }
       
    if (cmdline.exists("jndiport")) {
            port = cmdline.value("jndiport");
        }
        if (cmdline.exists("jndihost")) {
            host = cmdline.value("jndihost");
        }
        Hashtable props = new Hashtable();
        props.put(Context.PROVIDER_URL,
                   uri + host + ":" + port + '/' + jndiServer);
        props.put(Context.INITIAL_CONTEXT_FACTORY, mode);
View Full Code Here

TOP

Related Classes of org.exolab.jms.util.CommandLine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.