Search in sources :

Example 1 with LedgerBindingConfigException

use of com.jd.blockchain.tools.initializer.web.LedgerBindingConfigException in project jdchain-core by blockchain-jd-com.

the class PeerServerBooter method handle.

public static void handle(String[] args) {
    LedgerBindingConfig ledgerBindingConfig = null;
    ArgumentSet arguments = ArgumentSet.resolve(args, ArgumentSet.setting().prefix(LEDGERBIND_ARG, HOST_ARG, PORT_ARG, SPRING_CF_LOCATION));
    try {
        ArgumentSet.ArgEntry argLedgerBindConf = arguments.getArg(LEDGERBIND_ARG);
        ledgerBindConfigFile = argLedgerBindConf == null ? null : argLedgerBindConf.getValue();
        if (ledgerBindConfigFile == null) {
            LOGGER.info("Load build-in default configuration ...");
            ClassPathResource configResource = new ClassPathResource(LEDGER_BIND_CONFIG_NAME);
            if (configResource.exists()) {
                try (InputStream in = configResource.getInputStream()) {
                    ledgerBindingConfig = LedgerBindingConfig.resolve(in);
                }
            }
        } else {
            LOGGER.info("Load configuration,ledgerBindConfigFile position=" + ledgerBindConfigFile);
            File file = new File(ledgerBindConfigFile);
            if (file.exists()) {
                try {
                    ledgerBindingConfig = LedgerBindingConfig.resolve(file);
                } catch (LedgerBindingConfigException e) {
                    LOGGER.info("Load ledgerBindConfigFile content is empty !!!");
                }
            }
        }
        String host = null;
        ArgumentSet.ArgEntry hostArg = arguments.getArg(HOST_ARG);
        if (hostArg != null) {
            host = hostArg.getValue();
        }
        int port = 0;
        ArgumentSet.ArgEntry portArg = arguments.getArg(PORT_ARG);
        if (portArg != null) {
            try {
                port = Integer.parseInt(portArg.getValue());
            } catch (NumberFormatException e) {
            // ignore NumberFormatException of port argument;
            }
        }
        // spring config location;
        String springConfigLocation = null;
        ArgumentSet.ArgEntry spConfigLocation = arguments.getArg(SPRING_CF_LOCATION);
        if (spConfigLocation != null) {
            springConfigLocation = spConfigLocation.getValue();
        }
        PeerServerBooter booter = new PeerServerBooter(ledgerBindingConfig, host, port, springConfigLocation);
        LOGGER.debug("PeerServerBooter's urls=" + Arrays.toString(((URLClassLoader) booter.getClass().getClassLoader()).getURLs()));
        booter.start();
    } catch (Exception e) {
        LOGGER.error("Peer start error", e);
    }
}
Also used : InputStream(java.io.InputStream) ArgumentSet(utils.ArgumentSet) LedgerBindingConfigException(com.jd.blockchain.tools.initializer.web.LedgerBindingConfigException) LedgerBindingConfig(com.jd.blockchain.tools.initializer.LedgerBindingConfig) File(java.io.File) ClassPathResource(org.springframework.core.io.ClassPathResource) LedgerBindingConfigException(com.jd.blockchain.tools.initializer.web.LedgerBindingConfigException)

Example 2 with LedgerBindingConfigException

use of com.jd.blockchain.tools.initializer.web.LedgerBindingConfigException in project jdchain-core by blockchain-jd-com.

the class LedgerLoadTimer method loadLedgerBindingConfig.

private LedgerBindingConfig loadLedgerBindingConfig() throws Exception {
    LedgerBindingConfig ledgerBindingConfig = null;
    String ledgerBindConfigFile = PeerServerBooter.ledgerBindConfigFile;
    LOGGER.debug("--- Load " + LEDGER_BIND_CONFIG_NAME + " path = {}", ledgerBindConfigFile == null ? "Default" : ledgerBindConfigFile);
    if (ledgerBindConfigFile == null) {
        ClassPathResource configResource = new ClassPathResource(LEDGER_BIND_CONFIG_NAME);
        if (configResource.exists()) {
            try (InputStream in = configResource.getInputStream()) {
                ledgerBindingConfig = LedgerBindingConfig.resolve(in);
            } catch (LedgerBindingConfigException e) {
                LOGGER.debug("Load ledgerBindConfigFile content is empty !!!");
            }
        }
    } else {
        File file = new File(ledgerBindConfigFile);
        if (file.exists()) {
            try {
                ledgerBindingConfig = LedgerBindingConfig.resolve(file);
            } catch (LedgerBindingConfigException e) {
                LOGGER.debug("Load ledgerBindConfigFile content is empty !!!");
            }
        }
    }
    return ledgerBindingConfig;
}
Also used : InputStream(java.io.InputStream) LedgerBindingConfigException(com.jd.blockchain.tools.initializer.web.LedgerBindingConfigException) LedgerBindingConfig(com.jd.blockchain.tools.initializer.LedgerBindingConfig) File(java.io.File) ClassPathResource(org.springframework.core.io.ClassPathResource)

Aggregations

LedgerBindingConfig (com.jd.blockchain.tools.initializer.LedgerBindingConfig)2 LedgerBindingConfigException (com.jd.blockchain.tools.initializer.web.LedgerBindingConfigException)2 File (java.io.File)2 InputStream (java.io.InputStream)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2 ArgumentSet (utils.ArgumentSet)1