Search in sources :

Example 1 with TesseraServerFactory

use of com.quorum.tessera.server.TesseraServerFactory in project tessera by ConsenSys.

the class Main method main.

public static void main(String... args) throws Exception {
    Security.addProvider(new BouncyCastleProvider());
    final CommandLine commandLine = new CommandLine(new EnclaveCliAdapter());
    commandLine.registerConverter(Config.class, new ConfigConverter()).setSeparator(" ").setCaseInsensitiveEnumValuesAllowed(true);
    commandLine.execute(args);
    final CliResult cliResult = commandLine.getExecutionResult();
    if (cliResult == null) {
        System.exit(1);
    }
    if (!cliResult.getConfig().isPresent()) {
        System.exit(cliResult.getStatus());
    }
    final TesseraServerFactory restServerFactory = TesseraServerFactory.create(CommunicationType.REST);
    final Config config = cliResult.getConfig().get();
    ConfigFactory.create().store(config);
    final ServerConfig serverConfig = config.getServerConfigs().stream().findFirst().get();
    Enclave enclave = EnclaveServer.create();
    LOGGER.debug("Created enclave {}", enclave);
    final TesseraServer server = restServerFactory.createServer(serverConfig, Set.of(new EnclaveApplication(enclave)));
    server.start();
    CountDownLatch latch = new CountDownLatch(1);
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        try {
            server.stop();
        } catch (Exception ex) {
            LOGGER.error(null, ex);
        } finally {
        }
    }));
    latch.await();
}
Also used : ConfigConverter(com.quorum.tessera.cli.parsers.ConfigConverter) TesseraServerFactory(com.quorum.tessera.server.TesseraServerFactory) ServerConfig(com.quorum.tessera.config.ServerConfig) Config(com.quorum.tessera.config.Config) CountDownLatch(java.util.concurrent.CountDownLatch) ServerConfig(com.quorum.tessera.config.ServerConfig) TesseraServer(com.quorum.tessera.server.TesseraServer) CommandLine(picocli.CommandLine) CliResult(com.quorum.tessera.cli.CliResult) EnclaveCliAdapter(com.quorum.tessera.enclave.server.EnclaveCliAdapter) Enclave(com.quorum.tessera.enclave.Enclave) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Aggregations

CliResult (com.quorum.tessera.cli.CliResult)1 ConfigConverter (com.quorum.tessera.cli.parsers.ConfigConverter)1 Config (com.quorum.tessera.config.Config)1 ServerConfig (com.quorum.tessera.config.ServerConfig)1 Enclave (com.quorum.tessera.enclave.Enclave)1 EnclaveCliAdapter (com.quorum.tessera.enclave.server.EnclaveCliAdapter)1 TesseraServer (com.quorum.tessera.server.TesseraServer)1 TesseraServerFactory (com.quorum.tessera.server.TesseraServerFactory)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 BouncyCastleProvider (org.bouncycastle.jce.provider.BouncyCastleProvider)1 CommandLine (picocli.CommandLine)1