Search in sources :

Example 1 with ServerIdElectionCredentialsProvider

use of org.neo4j.cluster.protocol.election.ServerIdElectionCredentialsProvider in project neo4j by neo4j.

the class NetworkMock method newTestProtocolServer.

protected TestProtocolServer newTestProtocolServer(int serverId, URI serverUri) {
    ProtocolServerFactory protocolServerFactory = new MultiPaxosServerFactory(new ClusterConfiguration("default", logService.getInternalLogProvider()), logService.getInternalLogProvider(), monitors.newMonitor(StateMachines.Monitor.class));
    ServerIdElectionCredentialsProvider electionCredentialsProvider = new ServerIdElectionCredentialsProvider();
    electionCredentialsProvider.listeningAt(serverUri);
    TestProtocolServer protocolServer = new TestProtocolServer(logService.getInternalLogProvider(), timeoutStrategy, protocolServerFactory, serverUri, new InstanceId(serverId), new InMemoryAcceptorInstanceStore(), electionCredentialsProvider);
    protocolServer.addStateTransitionListener(new StateTransitionLogger(logService.getInternalLogProvider(), new AtomicBroadcastSerializer(new ObjectStreamFactory(), new ObjectStreamFactory())));
    return protocolServer;
}
Also used : AtomicBroadcastSerializer(org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcastSerializer) StateTransitionLogger(org.neo4j.cluster.statemachine.StateTransitionLogger) ServerIdElectionCredentialsProvider(org.neo4j.cluster.protocol.election.ServerIdElectionCredentialsProvider) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) InMemoryAcceptorInstanceStore(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InMemoryAcceptorInstanceStore) ObjectStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectStreamFactory)

Example 2 with ServerIdElectionCredentialsProvider

use of org.neo4j.cluster.protocol.election.ServerIdElectionCredentialsProvider in project neo4j by neo4j.

the class MultiPaxosServer method start.

public void start() throws IOException {
    broadcastSerializer = new AtomicBroadcastSerializer(new ObjectStreamFactory(), new ObjectStreamFactory());
    final LifeSupport life = new LifeSupport();
    try {
        MessageTimeoutStrategy timeoutStrategy = new MessageTimeoutStrategy(new FixedTimeoutStrategy(5000)).timeout(HeartbeatMessage.sendHeartbeat, 200);
        Monitors monitors = new Monitors();
        NetworkedServerFactory serverFactory = new NetworkedServerFactory(life, new MultiPaxosServerFactory(new ClusterConfiguration("default", NullLogProvider.getInstance()), NullLogProvider.getInstance(), monitors.newMonitor(StateMachines.Monitor.class)), timeoutStrategy, NullLogProvider.getInstance(), new ObjectStreamFactory(), new ObjectStreamFactory(), monitors.newMonitor(NetworkReceiver.Monitor.class), monitors.newMonitor(NetworkSender.Monitor.class), monitors.newMonitor(NamedThreadFactory.Monitor.class));
        ServerIdElectionCredentialsProvider electionCredentialsProvider = new ServerIdElectionCredentialsProvider();
        server = serverFactory.newNetworkedServer(Config.embeddedDefaults(), new InMemoryAcceptorInstanceStore(), electionCredentialsProvider);
        server.addBindingListener(electionCredentialsProvider);
        server.addBindingListener(new BindingListener() {

            @Override
            public void listeningAt(URI me) {
                System.out.println("Listening at:" + me);
            }
        });
        cluster = server.newClient(Cluster.class);
        cluster.addClusterListener(new ClusterListener() {

            @Override
            public void enteredCluster(ClusterConfiguration clusterConfiguration) {
                System.out.println("Entered cluster:" + clusterConfiguration);
            }

            @Override
            public void joinedCluster(InstanceId instanceId, URI member) {
                System.out.println("Joined cluster:" + instanceId + " (at URI " + member + ")");
            }

            @Override
            public void leftCluster(InstanceId instanceId, URI member) {
                System.out.println("Left cluster:" + instanceId);
            }

            @Override
            public void leftCluster() {
                System.out.println("Left cluster");
            }

            @Override
            public void elected(String role, InstanceId instanceId, URI electedMember) {
                System.out.println(instanceId + " at URI " + electedMember + " was elected as " + role);
            }

            @Override
            public void unelected(String role, InstanceId instanceId, URI electedMember) {
                System.out.println(instanceId + " at URI " + electedMember + " was removed from " + role);
            }
        });
        Heartbeat heartbeat = server.newClient(Heartbeat.class);
        heartbeat.addHeartbeatListener(new HeartbeatListener() {

            @Override
            public void failed(InstanceId server) {
                System.out.println(server + " failed");
            }

            @Override
            public void alive(InstanceId server) {
                System.out.println(server + " alive");
            }
        });
        broadcast = server.newClient(AtomicBroadcast.class);
        broadcast.addAtomicBroadcastListener(new AtomicBroadcastListener() {

            @Override
            public void receive(Payload value) {
                try {
                    System.out.println(broadcastSerializer.receive(value));
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            }
        });
        life.start();
        String command;
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        while (!(command = reader.readLine()).equals("quit")) {
            String[] arguments = command.split(" ");
            Method method = getCommandMethod(arguments[0]);
            if (method != null) {
                String[] realArgs = new String[arguments.length - 1];
                System.arraycopy(arguments, 1, realArgs, 0, realArgs.length);
                try {
                    method.invoke(this, (Object[]) realArgs);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                }
            }
        }
        cluster.leave();
    } finally {
        life.shutdown();
        System.out.println("Done");
    }
}
Also used : FixedTimeoutStrategy(org.neo4j.cluster.timeout.FixedTimeoutStrategy) NetworkedServerFactory(org.neo4j.cluster.NetworkedServerFactory) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) URI(java.net.URI) AtomicBroadcastListener(org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcastListener) BindingListener(org.neo4j.cluster.BindingListener) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) ServerIdElectionCredentialsProvider(org.neo4j.cluster.protocol.election.ServerIdElectionCredentialsProvider) AtomicBroadcastSerializer(org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcastSerializer) InputStreamReader(java.io.InputStreamReader) InstanceId(org.neo4j.cluster.InstanceId) AtomicBroadcast(org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcast) StateMachines(org.neo4j.cluster.StateMachines) Cluster(org.neo4j.cluster.protocol.cluster.Cluster) IOException(java.io.IOException) Method(java.lang.reflect.Method) ObjectStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectStreamFactory) InvocationTargetException(java.lang.reflect.InvocationTargetException) HeartbeatListener(org.neo4j.cluster.protocol.heartbeat.HeartbeatListener) ClusterListener(org.neo4j.cluster.protocol.cluster.ClusterListener) Heartbeat(org.neo4j.cluster.protocol.heartbeat.Heartbeat) Monitors(org.neo4j.kernel.monitoring.Monitors) MultiPaxosServerFactory(org.neo4j.cluster.MultiPaxosServerFactory) BufferedReader(java.io.BufferedReader) MessageTimeoutStrategy(org.neo4j.cluster.timeout.MessageTimeoutStrategy) Payload(org.neo4j.cluster.protocol.atomicbroadcast.Payload)

Example 3 with ServerIdElectionCredentialsProvider

use of org.neo4j.cluster.protocol.election.ServerIdElectionCredentialsProvider in project neo4j by neo4j.

the class ArbiterBootstrapperIT method before.

@Before
public void before() throws Exception {
    directory = testDirectory.directory("temp");
    life = new LifeSupport();
    // So that the clients get started as they are added
    life.start();
    clients = new ClusterClient[2];
    for (int i = 1; i <= clients.length; i++) {
        Map<String, String> config = stringMap();
        config.put(cluster_server.name(), ":" + (5000 + i));
        config.put(server_id.name(), "" + i);
        config.put(initial_hosts.name(), ":5001");
        LifeSupport moduleLife = new LifeSupport();
        ClusterClientModule clusterClientModule = new ClusterClientModule(moduleLife, new Dependencies(), new Monitors(), Config.embeddedDefaults(config), NullLogService.getInstance(), new ServerIdElectionCredentialsProvider());
        ClusterClient client = clusterClientModule.clusterClient;
        CountDownLatch latch = new CountDownLatch(1);
        client.addClusterListener(new ClusterListener.Adapter() {

            @Override
            public void enteredCluster(ClusterConfiguration configuration) {
                latch.countDown();
                client.removeClusterListener(this);
            }
        });
        life.add(moduleLife);
        clients[i - 1] = client;
        assertTrue("Didn't join the cluster", latch.await(20, SECONDS));
    }
}
Also used : ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) CountDownLatch(java.util.concurrent.CountDownLatch) Adapter(org.neo4j.cluster.protocol.cluster.ClusterListener.Adapter) ClusterClient(org.neo4j.cluster.client.ClusterClient) ClusterListener(org.neo4j.cluster.protocol.cluster.ClusterListener) Monitors(org.neo4j.kernel.monitoring.Monitors) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) ServerIdElectionCredentialsProvider(org.neo4j.cluster.protocol.election.ServerIdElectionCredentialsProvider) Dependencies(org.neo4j.kernel.impl.util.Dependencies) ClusterClientModule(org.neo4j.cluster.client.ClusterClientModule) Before(org.junit.Before)

Aggregations

ClusterConfiguration (org.neo4j.cluster.protocol.cluster.ClusterConfiguration)3 ServerIdElectionCredentialsProvider (org.neo4j.cluster.protocol.election.ServerIdElectionCredentialsProvider)3 AtomicBroadcastSerializer (org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcastSerializer)2 ObjectStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectStreamFactory)2 ClusterListener (org.neo4j.cluster.protocol.cluster.ClusterListener)2 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)2 Monitors (org.neo4j.kernel.monitoring.Monitors)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 URI (java.net.URI)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Before (org.junit.Before)1 BindingListener (org.neo4j.cluster.BindingListener)1 InstanceId (org.neo4j.cluster.InstanceId)1 MultiPaxosServerFactory (org.neo4j.cluster.MultiPaxosServerFactory)1 NetworkedServerFactory (org.neo4j.cluster.NetworkedServerFactory)1 StateMachines (org.neo4j.cluster.StateMachines)1