예제 #1
0
 public void receive(Payload value)
 {
     try
     {
         _outerInstance.logger.Logger.fine(_uri + " received: " + serializer.receive(value));
     }
     catch (Exception e) when(e is IOException || e is ClassNotFoundException)
     {
         e.printStackTrace();
     }
 }
예제 #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");
            }
        }
예제 #3
0
        public override void StateTransition(StateTransition transition)
        {
            Log log = _logProvider.getLog(transition.OldState.GetType());

            if (log.DebugEnabled)
            {
                if (transition.OldState == HeartbeatState.heartbeat)
                {
                    return;
                }

                // The bulk of the message
                string        state = transition.OldState.GetType().BaseType.SimpleName;
                StringBuilder line  = (new StringBuilder(state)).Append(": ").Append(transition);

                // Who was this message from?
                if (transition.Message.hasHeader(HEADER_FROM))
                {
                    line.Append(" from:").Append(transition.Message.getHeader(HEADER_FROM));
                }

                if (transition.Message.hasHeader(INSTANCE))
                {
                    line.Append(" instance:").Append(transition.Message.getHeader(INSTANCE));
                }

                if (transition.Message.hasHeader(HEADER_CONVERSATION_ID))
                {
                    line.Append(" conversation-id:").Append(transition.Message.getHeader(HEADER_CONVERSATION_ID));
                }

                object payload = transition.Message.Payload;
                if (payload != null)
                {
                    if (payload is Payload)
                    {
                        try
                        {
                            payload = _atomicBroadcastSerializer.receive(( Payload )payload);
                        }
                        catch (Exception)
                        {
                            // Ignore
                        }
                    }

                    line.Append(" payload:").Append(Strings.prettyPrint(payload));
                }

                // Throttle
                string msg = line.ToString();
                if (msg.Equals(_lastLogMessage))
                {
                    return;
                }

                // Log it
                log.Debug(line.ToString());
                _lastLogMessage = msg;
            }
        }