List of usage examples for com.google.common.net HostAndPort fromParts
public static HostAndPort fromParts(String host, int port)
From source file:org.apache.ratis.protocol.RaftPeer.java
/** Construct a peer with the given id and address. */ public RaftPeer(String id, InetSocketAddress address) { this(id, address == null ? null : HostAndPort.fromParts(address.getAddress().getHostAddress(), address.getPort()).toString()); }
From source file:org.apache.accumulo.test.performance.thrift.NullTserver.java
public static void main(String[] args) throws Exception { Opts opts = new Opts(); opts.parseArgs(NullTserver.class.getName(), args); // modify metadata ZooKeeperInstance zki = new ZooKeeperInstance( new ClientConfiguration().withInstance(opts.iname).withZkHosts(opts.keepers)); AccumuloServerContext context = new AccumuloServerContext(new ServerConfigurationFactory(zki)); TransactionWatcher watcher = new TransactionWatcher(); ThriftClientHandler tch = new ThriftClientHandler( new AccumuloServerContext(new ServerConfigurationFactory(HdfsZooInstance.getInstance())), watcher); Processor<Iface> processor = new Processor<Iface>(tch); TServerUtils.startTServer(context.getConfiguration(), HostAndPort.fromParts("0.0.0.0", opts.port), ThriftServerType.CUSTOM_HS_HA, processor, "NullTServer", "null tserver", 2, 1, 1000, 10 * 1024 * 1024, null, null, -1); HostAndPort addr = HostAndPort.fromParts(InetAddress.getLocalHost().getHostName(), opts.port); String tableId = Tables.getTableId(zki, opts.tableName); // read the locations for the table Range tableRange = new KeyExtent(tableId, null, null).toMetadataRange(); MetaDataTableScanner s = new MetaDataTableScanner(context, tableRange); long randomSessionID = opts.port; TServerInstance instance = new TServerInstance(addr, randomSessionID); List<Assignment> assignments = new ArrayList<Assignment>(); while (s.hasNext()) { TabletLocationState next = s.next(); assignments.add(new Assignment(next.extent, instance)); }/*from w ww.ja v a2 s. c o m*/ s.close(); // point them to this server MetaDataStateStore store = new MetaDataStateStore(context); store.setLocations(assignments); while (true) { sleepUninterruptibly(10, TimeUnit.SECONDS); } }
From source file:com.torodb.packaging.guice.MongoServerModule.java
@Provides public MongodServerConfig createMongodServerConfig() { return new MongodServerConfig( HostAndPort.fromParts(protocolListenerConfig.getBindIp(), protocolListenerConfig.getPort())); }
From source file:io.bazel.rules.closure.webfiles.server.NetworkUtils.java
/** Turns {@code address} into a more human readable form. */ static HostAndPort createUrlAddress(HostAndPort address) { if (address.getHost().equals("::") || address.getHost().equals("0.0.0.0")) { return address.getPortOrDefault(80) == 80 ? HostAndPort.fromHost(getCanonicalHostName()) : HostAndPort.fromParts(getCanonicalHostName(), address.getPort()); } else {/*from w w w .j ava 2s .co m*/ return address.getPortOrDefault(80) == 80 ? HostAndPort.fromHost(address.getHost()) : address; } }
From source file:com.facebook.nifty.client.HttpClientConnector.java
public HttpClientConnector(URI uri) { super(HostAndPort.fromParts(checkNotNull(uri).getHost(), getPort(uri))); checkArgument(uri.isAbsolute() && !uri.isOpaque(), "HttpClientConnector requires an absolute URI with a path"); this.endpointUri = uri; }
From source file:com.facebook.presto.hive.metastore.thrift.StaticHiveCluster.java
public StaticHiveCluster(List<URI> metastoreUris, String metastoreUsername, HiveMetastoreClientFactory clientFactory) { requireNonNull(metastoreUris, "metastoreUris is null"); checkArgument(!metastoreUris.isEmpty(), "metastoreUris must specify at least one URI"); this.addresses = metastoreUris.stream().map(StaticHiveCluster::checkMetastoreUri) .map(uri -> HostAndPort.fromParts(uri.getHost(), uri.getPort())).collect(toList()); this.metastoreUsername = metastoreUsername; this.clientFactory = requireNonNull(clientFactory, "clientFactory is null"); }
From source file:dk.dma.ais.reader.AisReaderMXBean.java
/** {@inheritDoc} */ @Override// w ww . j a v a 2s . c o m public void addHost(String hostName, int port) { HostAndPort hap = HostAndPort.fromParts(hostName, port); reader.addHostPort(hap); }
From source file:org.excalibur.core.deployment.domain.task.RemoteExecutionTask.java
@Override protected TaskResult<String> doExecute(TaskContext context) { TaskResultBuilder<String> result = new TaskResultBuilder<String>(); result.setTask(this); RemoteExecutionContext remoteContext = RemoteExecutionContext.class.cast(context.getExecutionContext()); HostAndPort hostAndPort = HostAndPort .fromParts(remoteContext.getRemoteHost().getConfiguration().getPublicDnsName(), 22); SshClient client = SshClientFactory.defaultSshClientFactory().create(hostAndPort, remoteContext.getLoginCredentials()); client.connect();/*from w w w . j ava 2s. c o m*/ try { result.setStartTimeInMillis(System.currentTimeMillis()); ExecutableResponse response = client.execute(this.getDescription().getExecutable()); result.setFinishTimeInMillis(System.currentTimeMillis()) .setState(response.getExitStatus() == 0 ? TaskState.SUCCESS : TaskState.FAILED) .setTaskResult(response.getOutput()).setState(response.getError()); } catch (Exception exception) { result.setState(TaskState.ERROR, exception); context.getLogger().addLogEntry(new LogEntryImpl(Exceptions.toString(exception))); } finally { client.disconnect(); } return result.build(); }
From source file:com.facebook.presto.hive.StaticHiveCluster.java
public StaticHiveCluster(List<URI> metastoreUris, HiveMetastoreClientFactory clientFactory) { requireNonNull(metastoreUris, "metastoreUris is null"); checkArgument(!metastoreUris.isEmpty(), "metastoreUris must specify at least one URI"); this.addresses = metastoreUris.stream().map(StaticHiveCluster::checkMetastoreUri) .map(uri -> HostAndPort.fromParts(uri.getHost(), uri.getPort())).collect(toList()); this.clientFactory = requireNonNull(clientFactory, "clientFactory is null"); }
From source file:com.torodb.mongodb.repl.oplogreplier.DefaultOplogTestContext.java
private OplogFetcher createOplogFetcher(Stream<OplogOperation> opsStream) { return new LimitedOplogFetcher(new IteratorMongoCursor<>("local", "oplog.rs", 1, HostAndPort.fromParts("localhost", 27017), opsStream.iterator())); }