Example usage for org.apache.commons.jcs.utils.props PropertyLoader loadProperties

List of usage examples for org.apache.commons.jcs.utils.props PropertyLoader loadProperties

Introduction

In this page you can find the example usage for org.apache.commons.jcs.utils.props PropertyLoader loadProperties.

Prototype

public static Properties loadProperties(final String name) 

Source Link

Document

A convenience overload of #loadProperties(String,ClassLoader) that uses the current thread's context classloader.

Usage

From source file:org.tinygroup.cache.jcs.applicationprocessor.JcsCacheProcessor.java

private void startCluster() {
    int registryPort = DEFAULT_REGISTRY_PORT;
    try {/*from  w w  w .j  ava2 s .  com*/
        Properties props = PropertyLoader.loadProperties(DEFAULT_PROPS_FILE_NAME);
        if (props != null) {
            String portS = props.getProperty("registry.port", String.valueOf(DEFAULT_REGISTRY_PORT));

            try {
                registryPort = Integer.parseInt(portS);
            } catch (NumberFormatException e) {
                LOGGER.errorMessage("Problem converting port to an int.", e);
            }
        }
    } catch (Exception e) {
        LOGGER.errorMessage("Problem loading props.", e);
    }

    // we will always use the local machine for the registry
    String registryHost;
    try {
        registryHost = InetAddress.getLocalHost().getHostAddress();
        LOGGER.logMessage(LogLevel.DEBUG, "registryHost =[{}]", registryHost);

        if ("localhost".equals(registryHost) || "127.0.0.1".equals(registryHost)) {
            LOGGER.logMessage(LogLevel.WARN,
                    "The local address [{}] is INVALID.  Other machines must be able to use the address to reach this server.",
                    registryHost);
        }

        try {
            LocateRegistry.createRegistry(registryPort);
        } catch (RemoteException e) {
            LOGGER.errorMessage("Problem creating registry.  It may already be started. {}", e, e.getMessage());
        } catch (Exception t) {
            LOGGER.errorMessage("Problem creating registry.", t);
        }

        try {
            RemoteCacheServerFactory.startup(registryHost, registryPort, "/" + DEFAULT_PROPS_FILE_NAME);
        } catch (IOException e) {
            LOGGER.errorMessage("Problem starting remote cache server.", e);
        }

        catch (Exception t) {
            LOGGER.errorMessage("Problem starting remote cache server.", t);
        }
    } catch (UnknownHostException e) {
        LOGGER.errorMessage("Could not get local address to use for the registry!", e);
    }
}