private void doStart() { try { String serviceURL = "service:jmx:rmi://" + jmxConfiguration.getHost().getHostName() + "/jndi/rmi://" + jmxConfiguration.getHost().getHostName() + ":" + jmxConfiguration.getHost().getPort() + "/jmxrmi"; restrictingRMISocketFactory = new RestrictingRMISocketFactory(jmxConfiguration.getHost().getHostName()); LocateRegistry.createRegistry(jmxConfiguration.getHost().getPort(), restrictingRMISocketFactory, restrictingRMISocketFactory); Map<String, ?> environment = ImmutableMap.of(); jmxConnectorServer = JMXConnectorServerFactory.newJMXConnectorServer(new JMXServiceURL(serviceURL), environment, ManagementFactory.getPlatformMBeanServer()); jmxConnectorServer.start(); } catch (Exception e) { throw new RuntimeException(e); } }
public Cluster build() { Preconditions.checkState(!(servers.isPresent() && host.isPresent()), "You can't specify a list of servers and a host at the same time"); Preconditions.checkState(!(servers.isPresent() && port.isPresent()), "You can't specify a list of servers and a port at the same time"); Preconditions.checkState(username.isPresent() == password.isPresent(), "If you specify username, you must specify password"); Cluster.Builder clusterBuilder = Cluster.builder(); getServers().forEach( (server) -> clusterBuilder.addContactPoint(server.getHostName()).withPort(server.getPort()) ); username.map(username -> password.map(password -> clusterBuilder.withCredentials(username, password))); clusterBuilder.withQueryOptions(queryOptions()); SocketOptions socketOptions = new SocketOptions(); readTimeoutMillis.ifPresent(socketOptions::setReadTimeoutMillis); connectTimeoutMillis.ifPresent(socketOptions::setConnectTimeoutMillis); clusterBuilder.withSocketOptions(socketOptions); poolingOptions.ifPresent(clusterBuilder::withPoolingOptions); Cluster cluster = clusterBuilder.build(); try { queryLogger.map(queryLoggerConfiguration -> cluster.register(queryLoggerConfiguration.getQueryLogger())); return cluster; } catch (Exception e) { cluster.close(); throw e; } }
public Cluster build() { Preconditions.checkState(!(servers.isPresent() && host.isPresent()), "You can't specify a list of servers and a host at the same time"); Preconditions.checkState(!(servers.isPresent() && port.isPresent()), "You can't specify a list of servers and a port at the same time"); Preconditions.checkState(username.isPresent() == password.isPresent(), "If you specify username, you must specify password"); Cluster.Builder clusterBuilder = Cluster.builder(); getServers().forEach( (server) -> clusterBuilder.addContactPoint(server.getHostName()).withPort(server.getPort()) ); username.map(username -> password.map(password -> clusterBuilder.withCredentials(username, password))); clusterBuilder.withQueryOptions(queryOptions()); SocketOptions socketOptions = new SocketOptions(); readTimeoutMillis.ifPresent(socketOptions::setReadTimeoutMillis); connectTimeoutMillis.ifPresent(socketOptions::setConnectTimeoutMillis); clusterBuilder.withSocketOptions(socketOptions); poolingOptions.ifPresent(clusterBuilder::withPoolingOptions); Cluster cluster = clusterBuilder.build(); try { queryLogger.map(queryLoggerConfiguration -> cluster.register(queryLoggerConfiguration.getQueryLogger())); return cluster; } catch (Exception e) { cluster.close(); throw e; } }
@Override public Client get() { TransportClient transportClient = TransportClient.builder().build(); ConsumerChainer<Host> consumer = Throwing.consumer(host -> transportClient .addTransportAddress( new InetSocketTransportAddress( InetAddress.getByName(host.getHostName()), host.getPort()))); hosts.forEach(consumer.sneakyThrow()); return transportClient; } }
private MailetConfigImpl spamAssassinMailetConfig() { BaseConfiguration baseConfiguration = new BaseConfiguration(); Host host = Host.from(spamAssassinExtension.getSpamAssassin().getIp(), spamAssassinExtension.getSpamAssassin().getBindingPort()); baseConfiguration.addProperty(org.apache.james.transport.mailets.SpamAssassin.SPAMD_HOST, host.getHostName()); baseConfiguration.addProperty(org.apache.james.transport.mailets.SpamAssassin.SPAMD_PORT, host.getPort()); MailetConfigImpl mailetConfig = new MailetConfigImpl(); mailetConfig.setConfiguration(baseConfiguration); return mailetConfig; }
private CassandraCluster(CassandraModule module, Host host) throws RuntimeException { this.module = module; try { cluster = ClusterBuilder.builder() .host(host.getHostName()) .port(host.getPort()) .build(); session = new SessionWithInitializedTablesFactory( ClusterConfiguration.builder() .host(host) .keyspace(KEYSPACE) .replicationFactor(1) .build(), ClusterWithKeyspaceCreatedFactory .config(cluster, KEYSPACE) .replicationFactor(1) .disableDurableWrites() .clusterWithInitializedKeyspace(), module) .get(); typesProvider = new CassandraTypesProvider(module, session); } catch (Exception exception) { throw new RuntimeException(exception); } }
private CassandraCluster(CassandraModule module, Host host) throws RuntimeException { this.module = module; try { cluster = ClusterBuilder.builder() .host(host.getHostName()) .port(host.getPort()) .build(); session = new SessionWithInitializedTablesFactory( ClusterConfiguration.builder() .host(host) .keyspace(KEYSPACE) .replicationFactor(1) .build(), ClusterWithKeyspaceCreatedFactory .config(cluster, KEYSPACE) .replicationFactor(1) .disableDurableWrites() .clusterWithInitializedKeyspace(), module) .get(); typesProvider = new CassandraTypesProvider(module, session); } catch (Exception exception) { throw new RuntimeException(exception); } }
private static Supplier<Session> createSession(DockerCassandraExtension.DockerCassandra cassandraServer) { Host host = cassandraServer.getHost(); Cluster cluster = ClusterBuilder.builder() .host(host.getHostName()) .port(host.getPort()) .build(); return () -> new SessionWithInitializedTablesFactory( ClusterConfiguration.builder() .host(host) .keyspace(KEYSPACE) .replicationFactor(1) .build(), ClusterWithKeyspaceCreatedFactory .config(cluster, KEYSPACE) .replicationFactor(1) .disableDurableWrites() .clusterWithInitializedKeyspace(), MODULE).get(); }