use of tezc.core.record.TransportRecord 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.core.record.TransportRecord 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.core.record.TransportRecord in project tezcRaft by tezc.
the class App method start.
public void start(List<State> states, String name) throws IOException {
TlsConfig tlsConfig = new TlsConfig(null, null, null, null, null, null, null, null, null, null);
Config config = new Config();
config.setLogLevel("DEBUG");
config.setTlsConfig(tlsConfig);
Tezc tezc = new Tezc("./cluster1/" + name, this, config);
RaftCluster cluster = tezc.openCluster("cluster1", states);
if (!cluster.isStarted()) {
NodeRecord nodeRecord1 = new NodeRecord("node0", "group0");
nodeRecord1.addTransport(new TransportRecord("tcp", "127.0.0.1", 9090));
/*NodeRecord nodeRecord2 = new NodeRecord("node1", "group0");
nodeRecord2.addTransport(new TransportRecord("tcp", "127.0.0.1", 9091));
NodeRecord nodeRecord3 = new NodeRecord("node2", "group1");
nodeRecord3.addTransport(new TransportRecord("tcp", "127.0.0.1", 9092));*/
cluster.setLocal(Integer.parseInt(name));
cluster.addNode(nodeRecord1);
// cluster.addNode(nodeRecord2);
// cluster.addNode(nodeRecord3);
}
cluster.run();
}
use of tezc.core.record.TransportRecord in project tezcRaft by tezc.
the class ClientTest method main.
public static void main(String[] args) {
try {
Thread.sleep(2000);
Client client = new Client(null, "cluster1", "client0", "group0");
client.addTransport(new TransportRecord("tcp", "127.0.0.1", 9090));
client.start();
Thread.sleep(8000);
ByteBuffer bbuf = ByteBuffer.allocate(22);
bbuf.flip();
client.sendRequest(false, 1, bbuf);
Thread.sleep(100000);
} catch (Exception e) {
}
}
use of tezc.core.record.TransportRecord in project tezcRaft by tezc.
the class Cluster method start.
/**
* Start cluster
*
* @throws RaftException on a missing configuration
*/
public void start() {
electionTimer = new ElectionTimer(this, true, new Random().nextInt(150) + 500, worker.timestamp() + 500);
heartBeatTimer = new HeartBeatTimer(this, true, 2000, worker.timestamp() + 150);
startLog();
if (!isStarted() && nodeId == -1) {
worker.logInfo("Cannot start cluster ", clusterRecord);
throw new RaftException("Local record is not set :" + clusterRecord);
}
local = clusterRecord.getRecord(nodeId);
for (TransportRecord record : local.transports) {
worker.listenAt(record);
}
for (TransportRecord record : local.secureTransports) {
worker.listenAt(record);
}
for (NodeRecord record : clusterRecord.nodes) {
if (record.id != local.id) {
nodes.add(new PeerNode(worker, this, null, local, record, PeerNode.Type.PEER));
}
}
startElectionTimer();
active = true;
}
Aggregations