use of com.quorum.tessera.config.util.IntervalPropertyHelper in project tessera by ConsenSys.
the class ClientFactory method buildFrom.
/**
* Creates a new client, which may or may not be SSL enabled or a unix socket enabled depending on
* the configuration.
*
* @param config
* @return
* @see Client
*/
public Client buildFrom(final ServerConfig config) {
final ClientBuilder clientBuilder = ClientBuilder.newBuilder();
final long pollInterval = new IntervalPropertyHelper(config.getProperties()).partyInfoInterval();
final long timeout = Math.round(Math.ceil(pollInterval * 0.75));
clientBuilder.connectTimeout(timeout, TimeUnit.MILLISECONDS);
clientBuilder.readTimeout(timeout, TimeUnit.MILLISECONDS);
clientBuilder.register(VersionHeaderDecorator.class);
if (config.isUnixSocket()) {
Configuration clientConfig = createUnixServerSocketConfig();
URI unixfile = config.getServerUri();
return ClientBuilder.newClient(clientConfig).property("unixfile", unixfile);
} else if (config.isSsl()) {
final SSLContext sslContext = sslContextFactory.from(config.getServerUri().toString(), config.getSslConfig());
return clientBuilder.sslContext(sslContext).build();
} else {
return clientBuilder.build();
}
}
use of com.quorum.tessera.config.util.IntervalPropertyHelper in project tessera by ConsenSys.
the class ScheduledServiceFactory method build.
public void build() {
IntervalPropertyHelper intervalPropertyHelper = new IntervalPropertyHelper(config.getP2PServerConfig().getProperties());
LOGGER.info("Creating p2p client");
P2pClient p2pClient = P2pClient.create();
LOGGER.info("Created p2p client {}", p2pClient);
if (enableSync) {
ResendPartyStore resendPartyStore = ResendPartyStore.create();
TransactionRequester transactionRequester = TransactionRequester.create();
SyncPoller syncPoller = new SyncPoller(resendPartyStore, transactionRequester, p2pClient);
ScheduledExecutorService scheduledExecutorService = java.util.concurrent.Executors.newSingleThreadScheduledExecutor();
tesseraScheduledExecutors.add(new TesseraScheduledExecutor(scheduledExecutorService, syncPoller, intervalPropertyHelper.syncInterval(), 5000L));
}
LOGGER.info("Creating EnclaveKeySynchroniser");
final EnclaveKeySynchroniser enclaveKeySynchroniser = ServiceLoader.load(EnclaveKeySynchroniser.class).stream().map(ServiceLoader.Provider::get).findFirst().get();
LOGGER.info("Created EnclaveKeySynchroniser {}", enclaveKeySynchroniser);
tesseraScheduledExecutors.add(new TesseraScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor(), () -> enclaveKeySynchroniser.syncKeys(), intervalPropertyHelper.enclaveKeySyncInterval(), 5000L));
LOGGER.info("Creating PartyInfoBroadcaster");
PartyInfoBroadcaster partyInfoPoller = new PartyInfoBroadcaster(p2pClient);
LOGGER.info("Created PartyInfoBroadcaster {}", partyInfoPoller);
tesseraScheduledExecutors.add(new TesseraScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor(), partyInfoPoller, intervalPropertyHelper.partyInfoInterval(), 5000L));
tesseraScheduledExecutors.forEach(TesseraScheduledExecutor::start);
LOGGER.info("Creating Enclave");
Enclave enclave = Enclave.create();
LOGGER.info("Created Enclave {}", enclave);
serviceContainer = new ServiceContainer(enclave);
LOGGER.info("Starting Enclave");
serviceContainer.start();
LOGGER.info("Started Enclave");
}
use of com.quorum.tessera.config.util.IntervalPropertyHelper in project tessera by ConsenSys.
the class RecoveryClientProvider method provider.
public static RecoveryClient provider() {
final Config config = ConfigFactory.create().getConfig();
final ServerConfig serverConfig = config.getP2PServerConfig();
final Map<String, String> properties = serverConfig.getProperties();
final String waitTime = new IntervalPropertyHelper(properties).resendWaitTime();
final SSLContextFactory clientSSLContextFactory = ClientSSLContextFactory.create();
final ClientFactory clientFactory = new ClientFactory(clientSSLContextFactory);
final Client client = clientFactory.buildFrom(config.getP2PServerConfig());
client.property("jersey.config.client.readTimeout", waitTime);
return new RestRecoveryClient(client);
}
use of com.quorum.tessera.config.util.IntervalPropertyHelper in project tessera by ConsenSys.
the class ResendClientProvider method provider.
public static ResendClient provider() {
final Config config = ConfigFactory.create().getConfig();
final ServerConfig serverConfig = config.getP2PServerConfig();
final Map<String, String> properties = serverConfig.getProperties();
final String waitTime = new IntervalPropertyHelper(properties).resendWaitTime();
final SSLContextFactory clientSSLContextFactory = ClientSSLContextFactory.create();
final ClientFactory clientFactory = new ClientFactory(clientSSLContextFactory);
final Client client = clientFactory.buildFrom(config.getP2PServerConfig());
client.property("jersey.config.client.readTimeout", waitTime);
return new RestResendClient(client);
}
Aggregations