use of com.google_voltpatches.common.net.HostAndPort in project voltdb by VoltDB.
the class AsyncBenchmark method connect.
/**
* Connect to a set of servers in parallel. Each will retry until
* connection. This call will block until all have connected.
*
* @param servers A comma separated list of servers using the hostname:port
* syntax (where :port is optional).
* @param port
* @throws InterruptedException if anything bad happens with the threads.
*/
static void connect(String servers) throws InterruptedException {
log.info("Connecting to Socket Streaming Interface...");
String[] serverArray = servers.split(",");
final CountDownLatch connections = new CountDownLatch(serverArray.length);
// use a new thread to connect to each server
for (final String server : serverArray) {
new Thread(new Runnable() {
@Override
public void run() {
// default port; assumed in system test so keep sync'd if it's changed
HostAndPort hap = HostAndPort.fromString(server).withDefaultPort(7001);
OutputStream writer = connectToOneServerWithRetry(hap.getHostText(), hap.getPort());
haplist.put(hap, writer);
connections.countDown();
}
}).start();
}
// block until all have connected
connections.await();
}
use of com.google_voltpatches.common.net.HostAndPort in project voltdb by VoltDB.
the class RegressionSuite method getClientChannel.
public SocketChannel getClientChannel(final boolean noTearDown) throws IOException {
final List<String> listeners = m_config.getListenerAddresses();
final Random r = new Random();
final String listener = listeners.get(r.nextInt(listeners.size()));
byte[] hashedPassword = ConnectionUtil.getHashedPassword(m_password);
HostAndPort hNp = HostAndPort.fromString(listener);
int port = Constants.DEFAULT_PORT;
if (hNp.hasPort()) {
port = hNp.getPort();
}
SSLEngine sslEngine = null;
boolean sslEnabled = Boolean.valueOf(System.getenv("ENABLE_SSL") == null ? Boolean.toString(Boolean.getBoolean("ENABLE_SSL")) : System.getenv("ENABLE_SSL"));
if (sslEnabled) {
SSLContext sslContext = SSLConfiguration.createSslContext(new SSLConfiguration.SslConfig());
sslEngine = sslContext.createSSLEngine("client", port);
sslEngine.setUseClientMode(true);
}
final SocketChannel channel = (SocketChannel) ConnectionUtil.getAuthenticatedConnection(hNp.getHostText(), m_username, hashedPassword, port, null, ClientAuthScheme.getByUnencodedLength(hashedPassword.length), sslEngine)[0];
channel.configureBlocking(true);
if (!noTearDown) {
synchronized (m_clientChannels) {
m_clientChannels.add(channel);
}
}
return channel;
}
Aggregations