use of com.google.common.net.HostAndPort in project legacy-jclouds-examples by jclouds.
the class CloudServersPublish method awaitSsh.
private void awaitSsh(String ip) throws TimeoutException {
SocketOpen socketOpen = compute.getContext().utils().injector().getInstance(SocketOpen.class);
Predicate<HostAndPort> socketTester = retry(socketOpen, 300, 5, 5, SECONDS);
socketTester.apply(HostAndPort.fromParts(ip, 22));
}
use of com.google.common.net.HostAndPort in project legacy-jclouds-examples by jclouds.
the class MainApp method main.
public static void main(String[] args) {
if (args.length < PARAMETERS)
throw new IllegalArgumentException(INVALID_SYNTAX);
String provider = args[0];
String identity = args[1];
String credential = args[2];
String groupName = args[3];
Action action = Action.valueOf(args[4].toUpperCase());
// note that you can check if a provider is present ahead of time
checkArgument(contains(allKeys, provider), "provider %s not in supported list: %s", provider, allKeys);
MinecraftController controller = initController(provider, identity, credential, groupName);
System.out.printf(">> initialized controller %s%n", controller);
try {
switch(action) {
case ADD:
System.out.printf(">> adding a server to group %s%n", groupName);
HostAndPort server = controller.add();
System.out.printf("<< server %s%n", server);
break;
case LIST:
System.out.printf(">> listing servers in group %s%n", groupName);
Iterable<HostAndPort> servers = controller.list();
System.out.printf("<< servers %s%n", servers);
break;
case TAIL:
System.out.printf(">> tailing all servers in group %s%n", groupName);
Map<HostAndPort, String> output = controller.tail();
System.out.printf("<< output %s%n", output);
break;
case PIDS:
System.out.printf(">> getting pids of all servers in group %s%n", groupName);
Map<HostAndPort, String> pids = controller.pids();
System.out.printf("<< pids %s%n", pids);
break;
case DESTROY:
System.out.printf(">> destroying group %s%n", groupName);
Iterable<HostAndPort> destroyed = controller.destroy();
System.out.printf("<< destroyed servers %s%n", destroyed);
break;
}
} catch (RuntimeException e) {
error = 1;
e.printStackTrace();
} finally {
controller.close();
System.exit(error);
}
}
use of com.google.common.net.HostAndPort in project PayFile by mikehearn.
the class ConnectServerController method initialize.
// Called by FXMLLoader
public void initialize() {
server.textProperty().addListener((observableValue, prev, current) -> connectBtn.setDisable(current.trim().isEmpty()));
defaultTitle = titleLabel.getText();
// Restore the server used last time, minus the port part if it was the default.
HostAndPort lastServer = Settings.getLastServer();
if (lastServer != null)
server.setText(lastServer.getPort() == PayFileClient.PORT ? lastServer.getHostText() : lastServer.toString());
}
use of com.google.common.net.HostAndPort in project PayFile by mikehearn.
the class ConnectServerController method maybeSettleLastServer.
/**
* Possibly reconnect to the last paid server and ask it to give us back the money. Note that after 24 hours this
* channel will expire anyway, so if the server is gone, it's not the end of the world, we'll still get the money
* back. The returned future completes immediately if nothing needs to be done.
*/
private CompletableFuture<Void> maybeSettleLastServer(HostAndPort newServerName) {
final HostAndPort lastPaidServer = Settings.getLastPaidServer();
// If we didn't have a payment channel, or we did but it's with the same server we're connecting to, ignore.
if (lastPaidServer == null || newServerName.equals(lastPaidServer))
return CompletableFuture.completedFuture(null);
BigInteger amountInLastServer = PayFileClient.getBalanceForServer(lastPaidServer.getHostText(), lastPaidServer.getPort(), Main.bitcoin.wallet());
// If the last server we paid was already settled, ignore.
if (amountInLastServer.compareTo(BigInteger.ZERO) == 0)
return CompletableFuture.completedFuture(null);
// Otherwise we have some money locked up with the last server. Ask for it back.
final CompletableFuture<Void> future = new CompletableFuture<>();
titleLabel.setText(String.format("Contacting %s to request early settlement ...", lastPaidServer));
log.info("Connecting to {}", lastPaidServer);
Main.connect(lastPaidServer, REFUND_CONNECT_TIMEOUT_MSEC).whenCompleteAsync((client, ex) -> {
if (ex == null) {
log.info("Connected. Requesting early settlement.");
titleLabel.setText("Requesting early settlement ...");
client.settlePaymentChannel().whenCompleteAsync((v, settleEx) -> {
if (settleEx == null) {
log.info("Settled. Proceeding ...");
client.disconnect();
future.complete(null);
} else {
crashAlert(settleEx);
}
}, Platform::runLater);
} else {
log.error("Failed to connect", ex);
titleLabel.setText(defaultTitle);
informUserTheyMustWait(lastPaidServer);
}
}, Platform::runLater);
return future;
}
use of com.google.common.net.HostAndPort in project zipkin by openzipkin.
the class DefaultSessionFactory method parseContactPoints.
static List<InetSocketAddress> parseContactPoints(Cassandra3Storage cassandra) {
List<InetSocketAddress> result = new LinkedList<>();
for (String contactPoint : cassandra.contactPoints.split(",")) {
HostAndPort parsed = HostAndPort.fromString(contactPoint);
result.add(new InetSocketAddress(parsed.getHostText(), parsed.getPortOrDefault(9042)));
}
return result;
}
Aggregations