Search in sources :

Example 1 with TransportRecord

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);
        }
    }
}
Also used : TransportRecord(tezc.core.record.TransportRecord) TcpSock(tezc.base.transport.sock.TcpSock)

Example 2 with TransportRecord

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);
        }
    }
}
Also used : TransportRecord(tezc.core.record.TransportRecord) TcpSock(tezc.base.transport.sock.TcpSock)

Example 3 with TransportRecord

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();
}
Also used : NodeRecord(tezc.core.record.NodeRecord) TransportRecord(tezc.core.record.TransportRecord) Config(tezc.core.Config) TlsConfig(tezc.base.transport.TlsConfig) RaftCluster(tezc.core.cluster.RaftCluster) TlsConfig(tezc.base.transport.TlsConfig) Tezc(tezc.Tezc)

Example 4 with TransportRecord

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) {
    }
}
Also used : TransportRecord(tezc.core.record.TransportRecord) Client(tezc.core.client.Client) ByteBuffer(java.nio.ByteBuffer)

Example 5 with TransportRecord

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;
}
Also used : TransportRecord(tezc.core.record.TransportRecord) NodeRecord(tezc.core.record.NodeRecord) RaftException(tezc.base.exception.RaftException) PeerNode(tezc.core.node.PeerNode)

Aggregations

TransportRecord (tezc.core.record.TransportRecord)5 TcpSock (tezc.base.transport.sock.TcpSock)2 NodeRecord (tezc.core.record.NodeRecord)2 ByteBuffer (java.nio.ByteBuffer)1 Tezc (tezc.Tezc)1 RaftException (tezc.base.exception.RaftException)1 TlsConfig (tezc.base.transport.TlsConfig)1 Config (tezc.core.Config)1 Client (tezc.core.client.Client)1 RaftCluster (tezc.core.cluster.RaftCluster)1 PeerNode (tezc.core.node.PeerNode)1