Beispiel #1
0
        public ClusterClient(LifeSupport life, ProtocolServer protocolServer)
        {
            this._life           = life;
            this._protocolServer = protocolServer;

            _cluster   = protocolServer.NewClient(typeof(Cluster));
            _broadcast = protocolServer.NewClient(typeof(AtomicBroadcast));
            _heartbeat = protocolServer.NewClient(typeof(Heartbeat));
            _snapshot  = protocolServer.NewClient(typeof(Snapshot));
            _election  = protocolServer.NewClient(typeof(Election));
        }
Beispiel #2
0
            public override void run()
            {
                AtomicBroadcast broadcast = _servers[server - 1].newClient(typeof(AtomicBroadcast));

                try
                {
                    broadcast.broadcast(serializer.broadcast(value));
                }
                catch (IOException e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                }
            }
Beispiel #3
0
        public PaxosClusterMemberAvailability(InstanceId myId, BindingNotifier binding, AtomicBroadcast atomicBroadcast, LogProvider logProvider, ObjectInputStreamFactory objectInputStreamFactory, ObjectOutputStreamFactory objectOutputStreamFactory)
        {
            this._myId                      = myId;
            this._binding                   = binding;
            this._atomicBroadcast           = atomicBroadcast;
            this._objectInputStreamFactory  = objectInputStreamFactory;
            this._objectOutputStreamFactory = objectOutputStreamFactory;
            this._log = logProvider.getLog(this.GetType());

            _bindingListener = me =>
            {
                _serverClusterId = me;
                PaxosClusterMemberAvailability.this._log.info("Listening at:" + me);
            };
        }
Beispiel #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testFailure() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TestFailure()
        {
            ScriptableNetworkFailureLatencyStrategy networkLatency = new ScriptableNetworkFailureLatencyStrategy();
            NetworkMock network = new NetworkMock(NullLogService.Instance, new Monitors(), 50, new MultipleFailureLatencyStrategy(networkLatency), new MessageTimeoutStrategy(new FixedTimeoutStrategy(1000)));

            IList <TestProtocolServer> nodes = new List <TestProtocolServer>();

            TestProtocolServer server = network.AddServer(1, URI.create("cluster://server1"));

            server.NewClient(typeof(Cluster)).create("default");
            network.TickUntilDone();
            nodes.Add(server);

            for (int i = 1; i < 3; i++)
            {
                TestProtocolServer protocolServer = network.AddServer(i + 1, new URI("cluster://server" + (i + 1)));
                protocolServer.NewClient(typeof(Cluster)).join("default", new URI("cluster://server1"));
                network.Tick(10);
                nodes.Add(protocolServer);
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcast atomicBroadcast = nodes.get(0).newClient(org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcast.class);
            AtomicBroadcast     atomicBroadcast     = nodes[0].NewClient(typeof(AtomicBroadcast));
            ObjectStreamFactory objectStreamFactory = new ObjectStreamFactory();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcastSerializer serializer = new org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcastSerializer(objectStreamFactory, objectStreamFactory);
            AtomicBroadcastSerializer serializer = new AtomicBroadcastSerializer(objectStreamFactory, objectStreamFactory);

            atomicBroadcast.Broadcast(serializer.Broadcast(new DaPayload()));

            networkLatency.NodeIsDown("cluster://server2");
            networkLatency.NodeIsDown("cluster://server3");

            atomicBroadcast.Broadcast(serializer.Broadcast(new DaPayload()));
            network.Tick(100);
            networkLatency.NodeIsUp("cluster://server3");
            network.Tick(1000);

            foreach (TestProtocolServer node in nodes)
            {
                node.NewClient(typeof(Cluster)).leave();
                network.Tick(10);
            }
        }
Beispiel #5
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: public PaxosClusterMemberEvents(final org.neo4j.cluster.protocol.snapshot.Snapshot snapshot, org.neo4j.cluster.protocol.cluster.Cluster cluster, org.neo4j.cluster.protocol.heartbeat.Heartbeat heartbeat, org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcast atomicBroadcast, org.neo4j.logging.LogProvider logProvider, System.Predicate<ClusterMembersSnapshot> validator, System.Func<Iterable<MemberIsAvailable>, MemberIsAvailable, Iterable<MemberIsAvailable>> snapshotFilter, org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory lenientObjectInputStream, org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory lenientObjectOutputStream, org.neo4j.helpers.NamedThreadFactory.Monitor namedThreadFactoryMonitor)
        public PaxosClusterMemberEvents(Snapshot snapshot, Cluster cluster, Heartbeat heartbeat, AtomicBroadcast atomicBroadcast, LogProvider logProvider, System.Predicate <ClusterMembersSnapshot> validator, System.Func <IEnumerable <MemberIsAvailable>, MemberIsAvailable, IEnumerable <MemberIsAvailable> > snapshotFilter, ObjectInputStreamFactory lenientObjectInputStream, ObjectOutputStreamFactory lenientObjectOutputStream, NamedThreadFactory.Monitor namedThreadFactoryMonitor)
        {
            this._snapshot                  = snapshot;
            this._cluster                   = cluster;
            this._heartbeat                 = heartbeat;
            this._atomicBroadcast           = atomicBroadcast;
            this._lenientObjectInputStream  = lenientObjectInputStream;
            this._lenientObjectOutputStream = lenientObjectOutputStream;
            this._namedThreadFactoryMonitor = namedThreadFactoryMonitor;
            this._log = logProvider.getLog(this.GetType());

            _clusterListener = new ClusterListenerImpl(this);

            _atomicBroadcastListener = new AtomicBroadcastListenerImpl(this);

            this._snapshotValidator = validator;

            _clusterMembersSnapshot = new ClusterMembersSnapshot(snapshotFilter);
        }
Beispiel #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void start() throws java.io.IOException
        public virtual void Start()
        {
            _broadcastSerializer = new AtomicBroadcastSerializer(new ObjectStreamFactory(), new ObjectStreamFactory());
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.lifecycle.LifeSupport life = new org.neo4j.kernel.lifecycle.LifeSupport();
            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.Instance), NullLogProvider.Instance, monitors.NewMonitor(typeof(StateMachines.Monitor))), timeoutStrategy, NullLogProvider.Instance, new ObjectStreamFactory(), new ObjectStreamFactory(), monitors.NewMonitor(typeof(NetworkReceiver.Monitor)), monitors.NewMonitor(typeof(NetworkSender.Monitor)), monitors.NewMonitor(typeof(NamedThreadFactory.Monitor)));

                ServerIdElectionCredentialsProvider electionCredentialsProvider = new ServerIdElectionCredentialsProvider();
                _server = serverFactory.NewNetworkedServer(Config.defaults(), new InMemoryAcceptorInstanceStore(), electionCredentialsProvider);
                _server.addBindingListener(electionCredentialsProvider);
                _server.addBindingListener(me => Console.WriteLine("Listening at:" + me));

                Cluster = _server.newClient(typeof(Cluster));
                Cluster.addClusterListener(new ClusterListenerAnonymousInnerClass(this));

                Heartbeat heartbeat = _server.newClient(typeof(Heartbeat));
                heartbeat.AddHeartbeatListener(new HeartbeatListenerAnonymousInnerClass(this));

                Broadcast = _server.newClient(typeof(AtomicBroadcast));
                Broadcast.addAtomicBroadcastListener(value =>
                {
                    try
                    {
                        Console.WriteLine(_broadcastSerializer.receive(value));
                    }
                    catch (Exception e) when(e is IOException || e is ClassNotFoundException)
                    {
                        e.printStackTrace();
                    }
                });

                life.Start();

                string       command;
                StreamReader reader = new StreamReader(System.in);
                while (!(command = reader.ReadLine()).Equals("quit"))
                {
                    string[] arguments = command.Split(" ", true);
                    System.Reflection.MethodInfo method = GetCommandMethod(arguments[0]);
                    if (method != null)
                    {
                        string[] realArgs = new string[arguments.Length - 1];
                        Array.Copy(arguments, 1, realArgs, 0, realArgs.Length);
                        try
                        {
                            method.invoke(this, ( object[] )realArgs);
                        }
                        catch (Exception e) when(e is IllegalAccessException || e is System.ArgumentException || e is InvocationTargetException)
                        {
                            e.printStackTrace();
                        }
                    }
                }

                Cluster.leave();
            }
            finally
            {
                life.Shutdown();
                Console.WriteLine("Done");
            }
        }