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);
}
}
}
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);
}
}
}
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);
}
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);
}
}
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();
}
Aggregations