Search in sources :

Example 1 with TcpSock

use of tezc.base.transport.sock.TcpSock in project tezcRaft by tezc.

the class Client method handleTryConnect.

/**
 * Handle try connect callback
 */
public void handleTryConnect() {
    if (connectionState == ConnectionState.CONNECT_IN_PROGRESS) {
        sock.close();
        this.sock = new TcpSock(this, null);
        connectionState = ConnectionState.WILL_CONNECT;
    }
    if (connectionState == ConnectionState.WILL_CONNECT) {
        connectionState = ConnectionState.CONNECT_IN_PROGRESS;
        TransportRecord record = getNextTransport();
        worker.logInfo("trying to connect to", record.hostName, ":", record.port);
        if (sock.connect(record.hostName, record.port)) {
            handleConnectEvent(sock);
        } else {
            worker.register(sock, SelectionKey.OP_CONNECT);
        }
    }
}
Also used : TransportRecord(tezc.core.record.TransportRecord) TcpSock(tezc.base.transport.sock.TcpSock)

Example 2 with TcpSock

use of tezc.base.transport.sock.TcpSock in project tezcRaft by tezc.

the class Connection method handleTryConnect.

/**
 * TryConnect timeout occured
 */
public void handleTryConnect() {
    if (connectionState == ConnectionState.CONNECT_IN_PROGRESS) {
        sock.close();
        this.sock = new TcpSock(this, null);
        connectionState = ConnectionState.WILL_CONNECT;
    }
    if (connectionState == ConnectionState.WILL_CONNECT) {
        connectionState = ConnectionState.CONNECT_IN_PROGRESS;
        TransportRecord record = getNextTransport();
        worker.logInfo("trying to connect to", record.hostName, " ", record.port);
        if (sock.connect(record.hostName, record.port)) {
            handleConnectEvent(sock);
        } else {
            worker.register(sock, SelectionKey.OP_CONNECT);
        }
    }
}
Also used : TransportRecord(tezc.core.record.TransportRecord) TcpSock(tezc.base.transport.sock.TcpSock)

Example 3 with TcpSock

use of tezc.base.transport.sock.TcpSock in project tezcRaft by tezc.

the class Connection method start.

/**
 * Start this connection
 *
 * @param worker new worker
 */
public void start(IOWorker worker) {
    setWorker(worker);
    if (sock == null) {
        sock = new TcpSock(this, null);
        connectionState = ConnectionState.WILL_CONNECT;
        startConnectTimer();
    } else {
        connectionState = ConnectionState.CONNECTED;
        worker.register(sock, SelectionKey.OP_READ);
    }
    sock.setOwner(this);
}
Also used : TcpSock(tezc.base.transport.sock.TcpSock)

Example 4 with TcpSock

use of tezc.base.transport.sock.TcpSock in project tezcRaft by tezc.

the class TcpListener method accept.

/**
 * Accept TCP connection
 *
 * @return new Sock object for accepted connection
 *
 * @exception UncheckedIOException if channel fails to accept
 */
public TcpSock accept() {
    try {
        SocketChannel incoming = channel.accept();
        incoming.configureBlocking(false);
        incoming.socket().setTcpNoDelay(true);
        return new TcpSock(null, incoming);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : SocketChannel(java.nio.channels.SocketChannel) TcpSock(tezc.base.transport.sock.TcpSock) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Example 5 with TcpSock

use of tezc.base.transport.sock.TcpSock in project tezcRaft by tezc.

the class Client method start.

/**
 * Start client
 */
public void start() {
    if (sock == null) {
        sock = new TcpSock(this, null);
        connectionState = ConnectionState.WILL_CONNECT;
        startConnectTimer();
    } else {
        connectionState = ConnectionState.CONNECTED;
        worker.register(sock, SelectionKey.OP_READ);
    }
    sock.setOwner(this);
    worker.start();
}
Also used : TcpSock(tezc.base.transport.sock.TcpSock)

Aggregations

TcpSock (tezc.base.transport.sock.TcpSock)5 TransportRecord (tezc.core.record.TransportRecord)2 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 SocketChannel (java.nio.channels.SocketChannel)1