Example usage for java.lang System getProperty

List of usage examples for java.lang System getProperty

Introduction

In this page you can find the example usage for java.lang System getProperty.

Prototype

public static String getProperty(String key, String def) 

Source Link

Document

Gets the system property indicated by the specified key.

Usage

From source file:RedPenRunner.java

public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption("h", "help", false, "help");
    options.addOption("v", "version", false, "print the version information and exit");

    OptionBuilder.withLongOpt("port");
    OptionBuilder.withDescription("port number");
    OptionBuilder.hasArg();/*from  www  . j a  v  a  2s. c  om*/
    OptionBuilder.withArgName("PORT");
    options.addOption(OptionBuilder.create("p"));

    OptionBuilder.withLongOpt("key");
    OptionBuilder.withDescription("stop key");
    OptionBuilder.hasArg();
    OptionBuilder.withArgName("STOP_KEY");
    options.addOption(OptionBuilder.create("k"));

    OptionBuilder.withLongOpt("conf");
    OptionBuilder.withDescription("configuration file");
    OptionBuilder.hasArg();
    OptionBuilder.withArgName("CONFIG_FILE");
    options.addOption(OptionBuilder.create("c"));

    OptionBuilder.withLongOpt("lang");
    OptionBuilder.withDescription("Language of error messages");
    OptionBuilder.hasArg();
    OptionBuilder.withArgName("LANGUAGE");
    options.addOption(OptionBuilder.create("L"));

    CommandLineParser parser = new BasicParser();
    CommandLine commandLine = null;

    try {
        commandLine = parser.parse(options, args);
    } catch (Exception e) {
        printHelp(options);
        System.exit(-1);
    }

    int portNum = 8080;
    String language = "en";
    if (commandLine.hasOption("h")) {
        printHelp(options);
        System.exit(0);
    }
    if (commandLine.hasOption("v")) {
        System.out.println(RedPen.VERSION);
        System.exit(0);
    }
    if (commandLine.hasOption("p")) {
        portNum = Integer.parseInt(commandLine.getOptionValue("p"));
    }
    if (commandLine.hasOption("L")) {
        language = commandLine.getOptionValue("L");
    }
    if (isPortTaken(portNum)) {
        System.err.println("port is taken...");
        System.exit(1);
    }

    // set language
    if (language.equals("ja")) {
        Locale.setDefault(new Locale("ja", "JA"));
    } else {
        Locale.setDefault(new Locale("en", "EN"));
    }

    final String contextPath = System.getProperty("redpen.home", "/");

    Server server = new Server(portNum);
    ProtectionDomain domain = RedPenRunner.class.getProtectionDomain();
    URL location = domain.getCodeSource().getLocation();

    HandlerList handlerList = new HandlerList();
    if (commandLine.hasOption("key")) {
        // Add Shutdown handler only when STOP_KEY is specified
        ShutdownHandler shutdownHandler = new ShutdownHandler(commandLine.getOptionValue("key"));
        handlerList.addHandler(shutdownHandler);
    }

    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath(contextPath);
    if (location.toExternalForm().endsWith("redpen-server/target/classes/")) {
        // use redpen-server/target/redpen-server instead, because target/classes doesn't contain web resources.
        webapp.setWar(location.toExternalForm() + "../redpen-server/");
    } else {
        webapp.setWar(location.toExternalForm());
    }
    if (commandLine.hasOption("c")) {
        webapp.setInitParameter("redpen.conf.path", commandLine.getOptionValue("c"));
    }

    handlerList.addHandler(webapp);
    server.setHandler(handlerList);

    server.start();
    server.join();
}

From source file:ProxyAuthTest.java

public static void main(String[] args) throws Exception {
    if (args.length < 4) {
        System.out.println("Usage ProxyAuthTest <host> <port> <server_principal> <proxy_user> [testTab]");
        System.exit(1);/*  ww w  . j av  a2s. c o m*/
    }

    File currentResultFile = null;
    String[] beeLineArgs = {};

    Class.forName(driverName);
    String host = args[0];
    String port = args[1];
    String serverPrincipal = args[2];
    String proxyUser = args[3];
    String url = null;
    if (args.length > 4) {
        tabName = args[4];
    }

    generateData();
    generateSQL(null);

    try {
        /*
         * Connect via kerberos and get delegation token
         */
        url = "jdbc:hive2://" + host + ":" + port + "/default;principal=" + serverPrincipal;
        con = DriverManager.getConnection(url);
        System.out.println("Connected successfully to " + url);
        // get delegation token for the given proxy user
        String token = ((HiveConnection) con).getDelegationToken(proxyUser, serverPrincipal);
        if ("true".equals(System.getProperty("proxyAuth.debug", "false"))) {
            System.out.println("Got token: " + token);
        }
        con.close();

        // so that beeline won't kill the JVM
        System.setProperty(BEELINE_EXIT, "true");

        // connect using principal via Beeline with inputStream
        url = "jdbc:hive2://" + host + ":" + port + "/default;principal=" + serverPrincipal;
        currentResultFile = generateSQL(null);
        beeLineArgs = new String[] { "-u", url, "-n", "foo", "-p", "bar" };
        System.out.println("Connection with kerberos, user/password via args, using input rediction");
        BeeLine.mainWithInputRedirection(beeLineArgs, inpStream);
        compareResults(currentResultFile);

        // connect using principal via Beeline with inputStream
        url = "jdbc:hive2://" + host + ":" + port + "/default;principal=" + serverPrincipal;
        currentResultFile = generateSQL(null);
        beeLineArgs = new String[] { "-u", url, "-n", "foo", "-p", "bar", "-f", scriptFileName };
        System.out.println("Connection with kerberos, user/password via args, using input script");
        BeeLine.main(beeLineArgs);
        compareResults(currentResultFile);

        // connect using principal via Beeline with inputStream
        url = "jdbc:hive2://" + host + ":" + port + "/default;principal=" + serverPrincipal;
        currentResultFile = generateSQL(url + " foo bar ");
        beeLineArgs = new String[] { "-u", url, "-f", scriptFileName };
        System.out.println("Connection with kerberos, user/password via connect, using input script");
        BeeLine.main(beeLineArgs);
        compareResults(currentResultFile);

        // connect using principal via Beeline with inputStream
        url = "jdbc:hive2://" + host + ":" + port + "/default;principal=" + serverPrincipal;
        currentResultFile = generateSQL(url + " foo bar ");
        beeLineArgs = new String[] { "-u", url, "-f", scriptFileName };
        System.out.println("Connection with kerberos, user/password via connect, using input redirect");
        BeeLine.mainWithInputRedirection(beeLineArgs, inpStream);
        compareResults(currentResultFile);

        /*
         * Connect using the delegation token passed via configuration object
         */
        System.out.println("Store token into ugi and try");
        storeTokenInJobConf(token);
        url = "jdbc:hive2://" + host + ":" + port + "/default;auth=delegationToken";
        con = DriverManager.getConnection(url);
        System.out.println("Connecting to " + url);
        runTest();
        con.close();

        // connect using token via Beeline with inputStream
        url = "jdbc:hive2://" + host + ":" + port + "/default";
        currentResultFile = generateSQL(null);
        beeLineArgs = new String[] { "-u", url, "-n", "foo", "-p", "bar", "-a", "delegationToken" };
        System.out.println("Connection with token, user/password via args, using input redirection");
        BeeLine.mainWithInputRedirection(beeLineArgs, inpStream);
        compareResults(currentResultFile);

        // connect using token via Beeline using script
        url = "jdbc:hive2://" + host + ":" + port + "/default";
        currentResultFile = generateSQL(null);
        beeLineArgs = new String[] { "-u", url, "-n", "foo", "-p", "bar", "-a", "delegationToken", "-f",
                scriptFileName };
        System.out.println("Connection with token, user/password via args, using input script");
        BeeLine.main(beeLineArgs);
        compareResults(currentResultFile);

        // connect using token via Beeline using script
        url = "jdbc:hive2://" + host + ":" + port + "/default";
        currentResultFile = generateSQL(url + " foo bar ");
        beeLineArgs = new String[] { "-a", "delegationToken", "-f", scriptFileName };
        System.out.println("Connection with token, user/password via connect, using input script");
        BeeLine.main(beeLineArgs);
        compareResults(currentResultFile);

        // connect using token via Beeline using script
        url = "jdbc:hive2://" + host + ":" + port + "/default";
        currentResultFile = generateSQL(url + " foo bar ");
        System.out.println("Connection with token, user/password via connect, using input script");
        beeLineArgs = new String[] { "-f", scriptFileName, "-a", "delegationToken" };
        BeeLine.main(beeLineArgs);
        compareResults(currentResultFile);

        /*
         * Connect via kerberos with trusted proxy user
         */
        url = "jdbc:hive2://" + host + ":" + port + "/default;principal=" + serverPrincipal
                + ";hive.server2.proxy.user=" + proxyUser;
        con = DriverManager.getConnection(url);
        System.out.println("Connected successfully to " + url);
        runTest();

        ((HiveConnection) con).cancelDelegationToken(token);
        con.close();
    } catch (SQLException e) {
        System.out.println("*** SQLException: " + e.getMessage() + " : " + e.getSQLState());
        e.printStackTrace();
    }

    /* verify the connection fails after canceling the token */
    try {
        url = "jdbc:hive2://" + host + ":" + port + "/default;auth=delegationToken";
        con = DriverManager.getConnection(url);
        throw new Exception("connection should have failed after token cancelation");
    } catch (SQLException e) {
        // Expected to fail due to canceled token
    }
}

From source file:com.google.cloud.bigtable.hbase.ManyThreadDriver.java

public static void main(String[] args) throws Exception {
    // Consult system properties to get project/instance
    // TODO Use standard hbase system properties?
    String projectId = requiredProperty("bigtable.projectID");
    String instanceId = requiredProperty("bigtable.instanceID");
    String table = System.getProperty("bigtable.table", "ManyThreadDriver");
    runTest(projectId, instanceId, table);
}

From source file:org.acme.insurance.policyquote.test.WorkServiceMain.java

public static void main(String... args) throws Exception {
    serverHostname = System.getProperty("serverHostname", serverHostname);

    Set<String> policies = new HashSet<String>();
    for (String arg : args) {
        arg = Strings.trimToNull(arg);//from   w  w  w  .j a  v  a2 s  .  c  om
        if (arg != null) {
            if (arg.equals(CONFIDENTIALITY) || arg.equals(CLIENT_AUTHENTICATION) || arg.equals(HELP)) {
                policies.add(arg);
            } else {
                LOGGER.error(MAVEN_USAGE);
                throw new Exception(MAVEN_USAGE);
            }
        }
    }
    if (policies.contains(HELP)) {
        LOGGER.info(MAVEN_USAGE);
    } else {
        final String scheme;
        final int port;
        if (policies.contains(CONFIDENTIALITY)) {
            LOGGER.info("Invoking service via SSL...");
            scheme = "https";
            port = 443;
            SSLContext sslcontext = SSLContext.getInstance("TLS");
            sslcontext.init(null, null, null);
            SSLSocketFactory sf = new SSLSocketFactory(sslcontext, SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
            Scheme https = new Scheme(scheme, port, sf);
            SchemeRegistry sr = new SchemeRegistry();
            sr.register(https);
        } else {
            scheme = "http";
            port = 8080;
        }
        Element assertion = policies.contains(CLIENT_AUTHENTICATION) ? getAssertion() : null;
        invokeWorkService(scheme, port, assertion);
    }
}

From source file:sample.contact.ClientApplication.java

public static void main(String[] args) {
    String username = System.getProperty("username", "");
    String password = System.getProperty("password", "");
    String nrOfCallsString = System.getProperty("nrOfCalls", "");

    if ("".equals(username) || "".equals(password)) {
        System.out.println(/*from   www.j a  v a 2s.c  om*/
                "You need to specify the user ID to use, the password to use, and optionally a number of calls "
                        + "using the username, password, and nrOfCalls system properties respectively. eg for user rod, "
                        + "use: -Dusername=rod -Dpassword=koala' for a single call per service and "
                        + "use: -Dusername=rod -Dpassword=koala -DnrOfCalls=10 for ten calls per service.");
        System.exit(-1);
    } else {
        int nrOfCalls = 1;

        if (!"".equals(nrOfCallsString)) {
            nrOfCalls = Integer.parseInt(nrOfCallsString);
        }

        ListableBeanFactory beanFactory = new FileSystemXmlApplicationContext("clientContext.xml");
        ClientApplication client = new ClientApplication(beanFactory);

        client.invokeContactService(new UsernamePasswordAuthenticationToken(username, password), nrOfCalls);
        System.exit(0);
    }
}

From source file:Cresendo.java

public static void main(String[] args) {
    String cfgFileReceiver = null; // Path to config file for eif receiver agent
    String cfgFileEngine = null; // Path to config file for xml event engine
    Options opts = null; // Command line options
    HelpFormatter hf = null; // Command line help formatter

    // Setup the message record which will contain text written to the log file
    ///*from  w  w w. j a  v  a 2 s  .  com*/
    // The message logger object is created when the "-l" is processed
    // as this object need to be associated with a log file
    //
    LogRecord msg = new LogRecord(LogRecord.TYPE_INFO, "Cresendo", "main", "", "", "", "", "");

    // Get the directory separator (defaults to "/")
    //
    dirSep = System.getProperty("file.separator", "/");

    // Initialise the structure containing the event handler objects
    //
    Vector<IEventHandler> eventHandler = new Vector<IEventHandler>(10, 10);

    // Process the command line arguments
    //
    try {
        opts = new Options();
        hf = new HelpFormatter();

        opts.addOption("h", "help", false, "Command line arguments help");
        opts.addOption("i", "instance name", true, "Name of cresendo instance");
        opts.addOption("l", "log dir", true, "Path to log file directory");
        opts.addOption("c", "config dir", true, "Path to configuarion file directory");

        opts.getOption("l").setRequired(true);
        opts.getOption("c").setRequired(true);

        BasicParser parser = new BasicParser();
        CommandLine cl = parser.parse(opts, args);

        // Print out some help and exit
        //
        if (cl.hasOption('h')) {
            hf.printHelp("Options", opts);
            System.exit(0);
        }

        // Set the instance name
        //
        if (cl.hasOption('i')) {
            instanceName = cl.getOptionValue('i'); // Set to something other than "default"
        }

        // Setup the message and trace logging objects for the EventEngine
        //
        if (cl.hasOption('l')) {
            // Setup the the paths to the message, trace and status log files
            //
            logDir = cl.getOptionValue("l");

            logPath = logDir + dirSep + instanceName + "-engine.log";
            tracePath = logDir + dirSep + instanceName + "-engine.trace";
            statusPath = logDir + dirSep + instanceName + "-engine.status";
        } else {
            // NOTE:  This should be picked up by the MissingOptionException catch below
            //        but I couldn't get this to work so I added the following code:
            //
            hf.printHelp("Option 'l' is a required option", opts);
            System.exit(1);
        }

        // Read the receiver and engine config files in the config directory
        //
        if (cl.hasOption('c')) {
            // Setup and check path to eif config file for TECAgent receiver object
            //
            configDir = cl.getOptionValue("c");
            cfgFileReceiver = configDir + dirSep + instanceName + ".conf";
            checkConfigFile(cfgFileReceiver);

            // Setup and check path to xml config file for the EventEngine
            //
            cfgFileEngine = cl.getOptionValue("c") + dirSep + instanceName + ".xml";
            checkConfigFile(cfgFileEngine);

        } else {
            // NOTE:  This should be picked up by the MissingOptionException catch below
            //        but I couldn't get this to work so I added the following code:
            //
            hf.printHelp("Option 'c' is a required option", opts);
            System.exit(1);
        }
    } catch (UnrecognizedOptionException e) {
        hf.printHelp(e.toString(), opts);
        System.exit(1);
    } catch (MissingOptionException e) {
        hf.printHelp(e.toString(), opts);
        System.exit(1);
    } catch (MissingArgumentException e) {
        hf.printHelp(e.toString(), opts);
        System.exit(1);
    } catch (ParseException e) {
        e.printStackTrace();
        System.exit(1);
    } catch (Exception e) {
        System.err.println(e.toString());
        System.exit(1);
    }

    // Main program
    //
    try {
        // =====================================================================
        // Setup the message, trace and status logger objects
        //
        try {
            msgHandler = new FileHandler("cresendo", "message handler", logPath);
            msgHandler.openDevice();

            msgLogger = new MessageLogger("cresendo", "message log");
            msgLogger.addHandler(msgHandler);

            trcHandler = new FileHandler("cresendo", "trace handler", tracePath);
            trcHandler.openDevice();

            trcLogger = new TraceLogger("cresendo", "trace log");
            trcLogger.addHandler(trcHandler);

            statLogger = new StatusLogger(statusPath);
        } catch (Exception e) {
            System.err.println(e.toString());
            System.exit(1);
        }

        // Add the shutdown hook
        //
        Runtime.getRuntime().addShutdownHook(new ShutdownThread(msgLogger, instanceName));

        // ---------------------------------------------------------------------
        // =====================================================================
        // Load and parse the xml event engine configuration file
        //
        //
        msg.setText("Loading xml engine from: '" + cfgFileEngine + "'");

        try {
            XMLConfiguration xmlProcessor = new XMLConfiguration();
            xmlProcessor.setFileName(cfgFileEngine);

            // Validate the xml against a document type declaration
            //
            xmlProcessor.setValidating(true);

            // Don't interpolate the tag contents by splitting them on a delimiter
            // (ie by default a comma)
            //
            xmlProcessor.setDelimiterParsingDisabled(true);

            // This will throw a ConfigurationException if the xml document does not
            // conform to its dtd.  By doing this we hopefully catch any errors left
            // behind after the xml configuration file has been edited.
            //
            xmlProcessor.load();

            // Setup the trace flag
            //
            ConfigurationNode engine = xmlProcessor.getRootNode();
            List rootAttribute = engine.getAttributes();

            for (Iterator it = rootAttribute.iterator(); it.hasNext();) {
                ConfigurationNode attr = (ConfigurationNode) it.next();

                String attrName = attr.getName();
                String attrValue = (String) attr.getValue();

                if (attrValue == null || attrValue == "") {
                    System.err.println("\n  Error: The value of the attribute '" + attrName + "'"
                            + "\n         in the xml file '" + cfgFileEngine + "'" + "\n         is not set");
                    System.exit(1);
                }

                if (attrName.matches("trace")) {
                    if (attrValue.matches("true") || attrValue.matches("on")) {
                        trcLogger.setLogging(true);
                    }
                }

                if (attrName.matches("status")) {
                    if (attrValue.matches("true") || attrValue.matches("on")) {
                        statLogger.setLogging(true);
                    } else {
                        statLogger.setLogging(false);
                    }
                }

                if (attrName.matches("interval")) {
                    if (!attrValue.matches("[0-9]+")) {
                        System.err.println("\n  Error: The value of the interval attribute in: '"
                                + cfgFileEngine + "'" + "\n         should only contain digits from 0 to 9."
                                + "\n         It currently contains: '" + attrValue + "'");
                        System.exit(1);
                    }

                    statLogger.setInterval(Integer.parseInt(attrValue));
                }
            }

            // Now build and instantiate the list of classes that will process events
            // received by the TECAgent receiver in a chain like manner.
            //
            List classes = xmlProcessor.configurationsAt("class");

            for (Iterator it = classes.iterator(); it.hasNext();) {
                HierarchicalConfiguration sub = (HierarchicalConfiguration) it.next();

                // sub contains now all data contained in a single <class></class> tag set
                //
                String className = sub.getString("name");

                // Log message
                //
                msg.setText(msg.getText() + "\n  Instantiated event handler class: '" + className + "'");

                // The angle brackets describing the class of object held by the
                // Vector are implemented by Java 1.5 and have 2 effects.
                //
                // 1. The list accepts only elements of that class and nothing else
                // (Of course thanks to Auto-Wrap you can also add double-values)
                //
                // 2. the get(), firstElement() ... Methods don't return a Object, but
                //    they deliver an element of the class.
                //
                Vector<Class> optTypes = new Vector<Class>(10, 10);
                Vector<Object> optValues = new Vector<Object>(10, 10);

                for (int i = 0; i <= sub.getMaxIndex("option"); i++) {
                    Object optValue = null;
                    String optVarName = sub.getString("option(" + i + ")[@varname]");
                    String optJavaType = sub.getString("option(" + i + ")[@javatype]");

                    // Use the specified java type in order to make the method call
                    // to the heirarchical sub object [painful :-((]
                    //
                    if (optJavaType.matches("byte")) {
                        optTypes.addElement(byte.class);
                        optValue = sub.getByte("option(" + i + ")");

                        if (optValue == null) // Catch nulls
                        {
                            optValue = 0; // Set to something nullish
                        }
                    } else if (optJavaType.matches("short")) {
                        optTypes.addElement(byte.class);
                        optValue = sub.getShort("option(" + i + ")");

                        if (optValue == null) // Catch nulls
                        {
                            optValue = 0; // Set to something nullish
                        }
                    } else if (optJavaType.matches("int")) {
                        optTypes.addElement(int.class);
                        optValue = sub.getInt("option(" + i + ")");

                        if (optValue == null) // Catch nulls
                        {
                            optValue = 0; // Set to something nullish
                        }
                    } else if (optJavaType.matches("long")) {
                        optTypes.addElement(long.class);
                        optValue = sub.getLong("option(" + i + ")");

                        if (optValue == null) // Catch nulls
                        {
                            optValue = 0; // Set to something nullish
                        }
                    } else if (optJavaType.matches("float")) {
                        optTypes.addElement(float.class);
                        optValue = sub.getFloat("option(" + i + ")");

                        if (optValue == null) // Catch nulls
                        {
                            optValue = 0.0; // Set to something nullish
                        }
                    } else if (optJavaType.matches("double")) {
                        optTypes.addElement(double.class);
                        optValue = sub.getDouble("option(" + i + ")");

                        if (optValue == null) // Catch nulls
                        {
                            optValue = 0.0; // Set to something nullish
                        }
                    } else if (optJavaType.matches("boolean")) {
                        optTypes.addElement(boolean.class);
                        optValue = sub.getBoolean("option(" + i + ")");

                        if (optValue == null) // Catch nulls
                        {
                            optValue = false; // Set to something nullish
                        }
                    } else if (optJavaType.matches("String")) {
                        optTypes.addElement(String.class);
                        optValue = sub.getString("option(" + i + ")");

                        if (optValue == null) // Catch nulls
                        {
                            optValue = ""; // Set it to something nullish
                        }
                    } else {
                        System.err.println(
                                "Error: Unsupported java type found in xml config: '" + optJavaType + "'");
                        System.exit(1);
                    }

                    // Add option value element
                    //
                    //              System.out.println("Option value is: '" + optValue.toString() + "'\n");
                    //
                    optValues.addElement(optValue);

                    // Append to message text
                    //
                    String msgTemp = msg.getText();
                    msgTemp += "\n      option name: '" + optVarName + "'";
                    msgTemp += "\n      option type: '" + optJavaType + "'";
                    msgTemp += "\n     option value: '" + optValues.lastElement().toString() + "'";
                    msg.setText(msgTemp);
                }

                try {
                    // Instantiate the class with the java reflection api
                    //
                    Class klass = Class.forName(className);

                    // Setup an array of paramater types in order to retrieve the matching constructor
                    //
                    Class[] types = optTypes.toArray(new Class[optTypes.size()]);

                    // Get the constructor for the class which matches the parameter types
                    //
                    Constructor konstruct = klass.getConstructor(types);

                    // Create an instance of the event handler
                    //
                    IEventHandler eventProcessor = (IEventHandler) konstruct.newInstance(optValues.toArray());

                    // Add the instance to the list of event handlers
                    //
                    eventHandler.addElement(eventProcessor);

                } catch (InvocationTargetException e) {
                    System.err.println("Error: " + e.toString());
                    System.exit(1);
                } catch (ClassNotFoundException e) {
                    System.err.println("Error: class name not found: '" + className + "' \n" + e.toString());
                    System.exit(1);
                } catch (Exception e) {
                    System.err.println(
                            "Error: failed to instantiate class: '" + className + "' \n" + e.toString());
                    System.exit(1);
                }
            }
        } catch (ConfigurationException cex) // Something went wrong loading the xml file
        {
            System.err.println("\n" + "Error loading XML file: " + cfgFileEngine + "\n" + cex.toString());
            System.exit(1);
        } catch (Exception e) {
            System.err.println(e.toString());
            System.exit(1);
        }

        // ---------------------------------------------------------------------
        // =====================================================================
        // Setup the TECAgent receiver 
        // 
        Reader cfgIn = null;

        try {
            cfgIn = new FileReader(cfgFileReceiver);
        } catch (Exception e) {
            System.err.println(e.toString());
            System.exit(1);
        }

        // Start the TECAgent receiver and register the event engine handler
        //
        TECAgent receiver = new TECAgent(cfgIn, TECAgent.RECEIVER_MODE, false);

        EventEngine ee = new EventEngine(eventHandler, msgLogger, trcLogger);

        receiver.registerListener(ee);

        // Construct message and send it to the message log
        //
        String text = "\n  Cresendo instance '" + instanceName + "' listening for events on port '"
                + receiver.getConfigVal("ServerPort") + "'";

        msg.setText(msg.getText() + text);
        msgLogger.log(msg); // Send message to log

        // ---------------------------------------------------------------------
        // =====================================================================
        // Initiate status logging
        //
        if (statLogger.isLogging()) {
            int seconds = statLogger.getInterval();

            while (true) {
                try {
                    statLogger.log();
                } catch (Exception ex) {
                    System.err.println("\n  An error occurred while writing to '" + statusPath + "'" + "\n  '"
                            + ex.toString() + "'");
                }

                Thread.sleep(seconds * 1000); // Convert sleep time to milliseconds
            }
        }

        // ---------------------------------------------------------------------
    } catch (Exception e) {
        System.err.println(e.toString());
        System.exit(1);
    }
}

From source file:ch.admin.suis.msghandler.common.MessageHandlerService.java

/**
 * @param args arguments to start the MsgHandlerService accordingly.
 *///w  w w . ja va  2s  .  c  o  m
public static void main(String[] args) {
    // initialize the log4j to watch every minute (by default)
    PropertyConfigurator.configureAndWatch(System.getProperty("log4j.configuration", "log4j.properties"));

    final MessageHandlerService service = new MessageHandlerService();

    // start the receiver process if everything is ok
    WrapperManager.start(service, args);
}

From source file:Main.java

public static boolean isOSX() {
    return System.getProperty("os.name", "").toLowerCase().startsWith("mac os x");
}

From source file:Main.java

public static boolean isWindows() {
    return System.getProperty("os.name", "").toLowerCase().startsWith("windows ");
}

From source file:Main.java

public static String getSysProp(String inSysProperty, String defaultValue) {

    String outPropertyValue = null;

    try {//from w w w  . ja  va  2 s.c o m
        outPropertyValue = System.getProperty(inSysProperty, defaultValue);
        if (inSysProperty.equals("password")) {
            System.out.println(inSysProperty + "=*****");
        } else {
            System.out.println(inSysProperty + "=" + outPropertyValue);
        }
    } catch (Exception e) {
        System.out.println("Error Reading Required System Property '" + inSysProperty + "'");
    }

    return (outPropertyValue);

}