Package org.exolab.jms.util

Examples of org.exolab.jms.util.CommandLine


  /**
   * @param args the command line arguments
   */
  public static void main (String args[])
  {
    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


   */
  public static void main (String args[])
  {
    try
    {
      CommandLine cmdline = new CommandLine(args);
      if (cmdline.exists("help"))
      {
        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

    {
        try
        {
            // create the mock app server
            ExoLabApplicationServer server = new ExoLabApplicationServer(
                new CommandLine(args));

            // start it up.
            (new Thread(server)).start();
        }
        catch (Exception exception)
View Full Code Here

     *
     * @param args command line args
     * @throws Exception for any errror
     */
    public static void main(String[] args) throws Exception {
        CommandLine commands = new CommandLine(args);

        String dbPath = commands.value("db");
        String configPath = commands.value("config");
        String outputPath = commands.value("output");
        if ((dbPath == null && configPath == null) || outputPath == null) {
            usage();
            System.exit(1);
        } else {
            try {
View Full Code Here

     * Main line.
     *
     * @param args command line arguments
     */
    public static void main(String[] args) {
        CommandLine commands = new CommandLine(args);

        String path = commands.value("config");
        if (path == null) {
            usage();
            System.exit(1);
        } else {
            try {
                Configuration config = ConfigurationReader.read(path);

                String database = commands.value("db");
                if (database == null) {
                    database = "openjms_migdb";
                }
                boolean delete = commands.exists("delete");
                Importer importer = new Importer(config, database, delete);
                importer.apply();
                System.exit(0);
            } catch (Exception exception) {
                exception.printStackTrace();
View Full Code Here

     *
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        try {
            CommandLine cmdline = new CommandLine(args);

            boolean helpSet = cmdline.exists("help");
            boolean configSet = cmdline.exists("config");
            boolean stopServer = cmdline.exists("stopServer");
            String username = cmdline.value("u");
            String password = cmdline.value("p");

            if (helpSet) {
                usage();
            } else if (!configSet && !stopServer && args.length != 0) {
                // invalid argument specified
                usage();
            } else {
                String configFile = cmdline.value("config");
                if (configFile == null) {
                    String home = getOpenJMSHome();
                    configFile = home + "/config/openjms.xml";
                }
                Configuration config = new ConfigurationLoader().load(configFile);
View Full Code Here

     * argument, instantiates an instance of the server class and calls the init
     * routine on it.
     */
    public static void main(String[] args) {
        try {
            CommandLine cmdline = new CommandLine(args);

            boolean helpSet = cmdline.exists("help");
            boolean versionSet = cmdline.exists("version");
            boolean configSet = cmdline.exists("config");

            if (helpSet) {
                usage();
            } else if (versionSet) {
                version();
            } else if (!configSet && args.length != 0) {
                // invalid argument specified
                usage();
            } else {
                String config = cmdline.value("config",
                                              getOpenJMSHome()
                                              + "/config/openjms.xml");
                JmsServer server = new JmsServer(config);
                server.init();
            }
View Full Code Here

    public void close() throws SQLException {
        _tool.close();
    }

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

        DBTool tool = null;
        String config = commands.value("config");
        if (config != null) {
            try {
                tool = new DBTool(config);
            } catch (Exception exception) {
                _log.error(exception, exception);
                System.exit(1);
            }
        } else {
            usage();
            System.exit(1);
        }
        boolean create = commands.exists("create");
        boolean drop = commands.exists("drop");
        boolean recreate = commands.exists("recreate");
        boolean delete = commands.exists("delete");
        boolean migrate = commands.exists("migrate");
        String schema = commands.value("schema");
        if (create) {
            try {
                if (schema != null) {
                    tool.create(schema);
                } else {
View Full Code Here

* message to arrive down a specific queue and then exit
*/
public class SimpleReceiver {
    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) {
                    // 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")) {
                            // no ack mode
                            ackMode = -1;
                        }
                    }
                   
                    // 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");
                    }

                    QueueConnection connection =
                        factory.createQueueConnection();

                    // 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;
                    }
                   
                    // start the connection unless specified otherwise
                    if (!cmdline.exists("noStart")) {
                        connection.start();
                    }

                    QueueSession session =
                        connection.createQueueSession(false, ackMode);

                    // 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 {
                        // The queue object is therefore created as non
                        // persistent.
                        queue = (Queue)session.createQueue(queue_name);
                    }

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

                    // if the 'name' option has been specified then assume a
                    // durable subscriber otherwise transient
                    QueueReceiver receiver = null;
                    if (cmdline.exists("selector")) {
                        receiver = session.createReceiver(queue, "JMSPriority=1");
                    } else {
                        receiver = session.createReceiver(queue);
                    }

                    // if we are republishing the message then also create
                    // a sender
                    QueueSender sender = null;
                    if (cmdline.exists("republish")) {
                        sender = session.createSender(queue);
                    }

                    // return the number of messages to receive
                    int count = 1;
                    if (cmdline.exists("count")) {
                        try {
                            String value = cmdline.value("count");
                            count = Integer.parseInt(value);
                        } catch (Exception exception) {
                            System.err.println("Illegal count value");
                            System.exit(-1);
                        }
                    }

                    int index = 0;
                    int publish_count = 0;
                    for (; index < count; index++) {
                        Message message = receiver.receive();

                        if (message == null) {
                            System.err.println("No message received");
                            continue;
                        }
                        // only display the message details if the summary flag
                        // is not set.
                        if (!summary) {
                            System.out.print("[" + (index+1) + " of " + count +
                                             "] " + message.getJMSType());
                        }

                        String type = "unknown";
                        String id = "unset";
                        int priority = -1;

                        try {
                            if (message.getJMSDeliveryMode() ==
                                DeliveryMode.NON_PERSISTENT) {
                                type = "NON_PERSISTENT";
                            } else if (message.getJMSDeliveryMode() ==
                                DeliveryMode.PERSISTENT) {
                                type = "PERSISTENT";
                            }
                        } catch (JMSException ignore) {
                        }

                        try {
                            priority = message.getJMSPriority();
                            id = message.getJMSMessageID();
                        } catch (JMSException ignore) {
                        }

                        if (!summary) {
                            System.err.println(" JMSDeliveryMode=" + type + ", Priority=" +
                                               priority + ", JMSMessageID=" + id);
                        }

                        // if client acknowledgement, then ack it
                        if (ackMode == Session.CLIENT_ACKNOWLEDGE) {
                            message.acknowledge();
                        }

                        // if the publish flag has been set then publish the
                        // same message to the same queue
                        if (cmdline.exists("republish")) {
                            sender.send(session.createQueue(cmdline.value("republish")),
                                        message,
                                        message.getJMSDeliveryMode(),
                                        message.getJMSPriority(), 0);

                            if (!summary) {
                                System.err.println("[" + ++publish_count +
                                                   "] Published " + message.getJMSType() +
                                                   " JMSDeliveryMode=" + message.getJMSDeliveryMode() +
                                                   " ID=" + message.getJMSMessageID());
                            }
                        }

                        if (cmdline.exists("sleep")) {
                            Thread.sleep(Long.parseLong(cmdline.value("sleep")));
                        }

                    }
                    // close the session and connection
                    receiver.close();
View Full Code Here

* specified then an exception is raised.
*/
public class SimpleSender {
    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

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.