List of usage examples for com.google.common.net HostAndPort fromParts
public static HostAndPort fromParts(String host, int port)
From source file:com.spotify.folsom.KetamaRunner.java
public static void main(final String[] args) throws Throwable { ImmutableList<HostAndPort> addresses = ImmutableList.of(HostAndPort.fromParts("127.0.0.1", 11211), HostAndPort.fromParts("127.0.0.1", 11213)); final BinaryMemcacheClient<String> client = new MemcacheClientBuilder<>(StringTranscoder.UTF8_INSTANCE) .withAddresses(addresses).connectBinary(); for (int i = 0; i < 10; i++) { final String key = "key" + i; final String value = "value" + i; checkKeyOkOrNotFound(client.delete(key)); client.set(key, value, 1000);/*from w w w .j a v a2s .com*/ System.out.println(client.get(key).get()); } client.shutdown(); }
From source file:org.excalibur.core.test.SshClientExample.java
public static void main(String[] args) throws AgentProxyException, IOException, JSchException { HostAndPort hostAndPort = HostAndPort.fromParts("ec2-54-83-158-5.compute-1.amazonaws.com", 22); LoginCredentials loginCredentials = LoginCredentials.builder() .privateKey(System.getProperty("user.home") + "/.ec2/leite.pem").user("ubuntu").build(); SshClient client = SshClientFactory.defaultSshClientFactory().create(hostAndPort, loginCredentials); client.connect();/* w w w. j a va 2 s . com*/ ExecutableResponse response = client.execute("uname -a && date && uptime && who"); System.out.println(response); // final OnlineChannel shell = client.shell(); // shell.getInput().write("sudo apt-get install maven -y\n".getBytes()); // shell.getInput().flush(); // // Thread t = new Thread(new Runnable() // { // @Override // public void run() // { // while (true) // { // BufferedReader reader = new BufferedReader(new InputStreamReader(shell.getOutput(), Charsets.US_ASCII)); // String line; // try // { // while ((line = reader.readLine()) != null) // { // System.out.println(line); // } // } // catch (IOException e) // { // e.printStackTrace(); // } // } // } // }); // t.setDaemon(true); // t.start(); client.put("/home/ubuntu/hi.txt", "Hi node!"); client.disconnect(); // JSch jsch = new JSch(); // jsch.addIdentity(loginCredentials.getPrivateKey()); // // Session session = jsch.getSession(loginCredentials.getUser(), hostAndPort.getHostText()); // // Properties config = new Properties(); // config.put("StrictHostKeyChecking", "no"); // // session.setConfig(config); // session.connect(); // // Channel shell = session.openChannel("shell"); // shell.setInputStream(System.in); // shell.setOutputStream(System.out); // shell.connect(0); }
From source file:io.soliton.time.TimeClient.java
public static void main(String... args) throws Exception { // Parse arguments TimeClient timeClient = new TimeClient(); new JCommander(timeClient, args); // Create client QuartzClient.Builder clientBuilder = QuartzClient .newClient(HostAndPort.fromParts(timeClient.hostname, timeClient.port)); if (timeClient.ssl) { clientBuilder.setSslContext(getSslContext()); }// w w w . j av a 2 s. c o m QuartzClient client = clientBuilder.build(); // Create service stub Time.TimeService.Interface timeService = Time.TimeService.newStub(client); CountDownLatch latch = new CountDownLatch(DateTimeZone.getAvailableIDs().size()); // For each known timezone, request its current local time. for (String timeZoneId : DateTimeZone.getAvailableIDs()) { DateTimeZone timeZone = DateTimeZone.forID(timeZoneId); Time.TimeRequest request = Time.TimeRequest.newBuilder().setTimezone(timeZoneId).build(); Futures.addCallback(timeService.getTime(request), new Callback(latch, timeZone), EXECUTOR); } latch.await(); client.close(); }
From source file:com.facebook.swift.perf.loadgenerator.LoadGenerator.java
public static void main(final String[] args) throws Exception { final LoadGeneratorCommandLineConfig config = new LoadGeneratorCommandLineConfig(); JCommander jCommander = new JCommander(config, args); if (config.displayUsage) { jCommander.usage();/* w w w. j a v a 2s. c o m*/ } else { injector = Guice.createInjector(Stage.PRODUCTION, new ConfigurationModule(new ConfigurationFactory(ImmutableMap.<String, String>of())), new LifeCycleModule(), new ThriftCodecModule(), new ThriftClientModule(), new Module() { @Override public void configure(Binder binder) { thriftClientBinder(binder).bindThriftClient(AsyncClientWorker.LoadTest.class); thriftClientBinder(binder).bindThriftClient(SyncClientWorker.LoadTest.class); binder.bind(LoadGeneratorCommandLineConfig.class).toInstance(config); binder.bind(LoadGenerator.class).in(Singleton.class); if (!config.asyncMode) { binder.bind(AbstractClientWorker.class).to(SyncClientWorker.class); } else { binder.bind(AbstractClientWorker.class).to(AsyncClientWorker.class); } TypeLiteral<NiftyClientConnector<? extends NiftyClientChannel>> channelConnectorType = new TypeLiteral<NiftyClientConnector<? extends NiftyClientChannel>>() { }; NiftyClientConnector<? extends NiftyClientChannel> connector; switch (config.transport) { case FRAMED: connector = new FramedClientConnector( HostAndPort.fromParts(config.serverAddress, config.serverPort)); break; case UNFRAMED: connector = new UnframedClientConnector( HostAndPort.fromParts(config.serverAddress, config.serverPort)); break; default: throw new IllegalStateException("Unknown transport"); } binder.bind(channelConnectorType).toInstance(connector); } }); injector.getInstance(LifeCycleManager.class).start(); } }
From source file:org.apache.accumulo.test.functional.ZombieTServer.java
public static void main(String[] args) throws Exception { Random random = new Random(System.currentTimeMillis() % 1000); int port = random.nextInt(30000) + 2000; AccumuloServerContext context = new AccumuloServerContext( new ServerConfigurationFactory(HdfsZooInstance.getInstance())); TransactionWatcher watcher = new TransactionWatcher(); final ThriftClientHandler tch = new ThriftClientHandler(context, watcher); Processor<Iface> processor = new Processor<Iface>(tch); ServerAddress serverPort = TServerUtils.startTServer(context.getConfiguration(), HostAndPort.fromParts("0.0.0.0", port), ThriftServerType.CUSTOM_HS_HA, processor, "ZombieTServer", "walking dead", 2, 1, 1000, 10 * 1024 * 1024, null, null, -1); String addressString = serverPort.address.toString(); String zPath = ZooUtil.getRoot(context.getInstance()) + Constants.ZTSERVERS + "/" + addressString; ZooReaderWriter zoo = ZooReaderWriter.getInstance(); zoo.putPersistentData(zPath, new byte[] {}, NodeExistsPolicy.SKIP); ZooLock zlock = new ZooLock(zPath); LockWatcher lw = new LockWatcher() { @Override//from ww w. j a va 2 s .c om public void lostLock(final LockLossReason reason) { try { tch.halt(Tracer.traceInfo(), null, null); } catch (Exception ex) { log.error("Exception", ex); System.exit(1); } } @Override public void unableToMonitorLockNode(Throwable e) { try { tch.halt(Tracer.traceInfo(), null, null); } catch (Exception ex) { log.error("Exception", ex); System.exit(1); } } }; byte[] lockContent = new ServerServices(addressString, Service.TSERV_CLIENT).toString().getBytes(UTF_8); if (zlock.tryLock(lw, lockContent)) { log.debug("Obtained tablet server lock " + zlock.getLockPath()); } // modify metadata synchronized (tch) { while (!tch.halted) { tch.wait(); } } System.exit(0); }
From source file:brooklyn.util.net.UserAndHostAndPort.java
public static UserAndHostAndPort fromParts(String user, String host, int port) { return new UserAndHostAndPort(user, HostAndPort.fromParts(host, port)); }
From source file:org.opendaylight.protocol.util.InetSocketAddressUtil.java
public static HostAndPort toHostAndPort(final InetSocketAddress address) { return HostAndPort.fromParts(address.getHostString(), address.getPort()); }
From source file:org.apache.druid.server.http.HostAndPortWithScheme.java
public static HostAndPortWithScheme fromParts(String scheme, String host, int port) { return new HostAndPortWithScheme(scheme, HostAndPort.fromParts(host, port)); }
From source file:org.apache.hadoop.hbase.net.Address.java
public static Address fromParts(String hostname, int port) { return new Address(HostAndPort.fromParts(hostname, port)); }
From source file:ezbake.common.openshift.OpenShiftUtil.java
public static HostAndPort getThriftPrivateInfo() { String ip = Preconditions.checkNotNull(System.getenv("OPENSHIFT_JAVA_THRIFTRUNNER_IP")); String port = Preconditions.checkNotNull(System.getenv("OPENSHIFT_JAVA_THRIFTRUNNER_TCP_PORT")); return HostAndPort.fromParts(ip, NumberUtils.toInt(port, -1)); }