Search in sources :

Example 6 with HostAndPort

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();
}
Also used : HostAndPort(com.google_voltpatches.common.net.HostAndPort) OutputStream(java.io.OutputStream) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 7 with HostAndPort

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;
}
Also used : HostAndPort(com.google_voltpatches.common.net.HostAndPort) SocketChannel(java.nio.channels.SocketChannel) SSLConfiguration(org.voltcore.utils.ssl.SSLConfiguration) Random(java.util.Random) SSLEngine(javax.net.ssl.SSLEngine) SSLContext(javax.net.ssl.SSLContext)

Aggregations

HostAndPort (com.google_voltpatches.common.net.HostAndPort)7 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 Random (java.util.Random)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 JSONException (org.json_voltpatches.JSONException)2 VoltLogger (org.voltcore.logging.VoltLogger)2 HostMessenger (org.voltcore.messaging.HostMessenger)2 Supplier (com.google_voltpatches.common.base.Supplier)1 EOFException (java.io.EOFException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketException (java.net.SocketException)1 ClosedByInterruptException (java.nio.channels.ClosedByInterruptException)1 ClosedSelectorException (java.nio.channels.ClosedSelectorException)1 ServerSocketChannel (java.nio.channels.ServerSocketChannel)1 SocketChannel (java.nio.channels.SocketChannel)1 ExecutionException (java.util.concurrent.ExecutionException)1 SSLContext (javax.net.ssl.SSLContext)1