示例#1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public ClusterNetworkIT(int nrOfServers, ClusterTestScript script) throws java.net.URISyntaxException
        public ClusterNetworkIT(int nrOfServers, ClusterTestScript script)
        {
            this._script = script;

            @out.Clear();
            @in.Clear();

            for (int i = 0; i < nrOfServers; i++)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.net.URI uri = new java.net.URI("neo4j://localhost:" + org.neo4j.ports.allocation.PortAuthority.allocatePort());
                URI uri = new URI("neo4j://localhost:" + PortAuthority.allocatePort());

                Monitors monitors = new Monitors();
                NetworkedServerFactory factory = new NetworkedServerFactory(_life, new MultiPaxosServerFactory(new ClusterConfiguration("default", NullLogProvider.Instance), NullLogProvider.Instance, monitors.NewMonitor(typeof(StateMachines.Monitor))), new FixedTimeoutStrategy(1000), 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();
                ProtocolServer server = factory.NewNetworkedServer(Config.defaults(MapUtil.stringMap(ClusterSettings.cluster_server.name(), uri.Host + ":" + uri.Port, ClusterSettings.server_id.name(), "" + i)), new InMemoryAcceptorInstanceStore(), electionCredentialsProvider);
                server.AddBindingListener(electionCredentialsProvider);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final Cluster cluster2 = server.newClient(Cluster.class);
                Cluster cluster2 = server.NewClient(typeof(Cluster));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicReference<ClusterConfiguration> config2 = clusterStateListener(uri, cluster2);
                AtomicReference <ClusterConfiguration> config2 = ClusterStateListener(uri, cluster2);

                _servers.Add(cluster2);
                @out.Add(cluster2);
                _configurations.Add(config2);
            }

            _life.start();
        }
示例#2
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");
            }
        }