コード例 #1
0
 public DefaultClientChannelInboundHandler(
     CommandProcessorManager cmdProcessorManager,
     Arch.CMessaging.Client.MetaEntity.Entity.Endpoint endpoint,
     EndpointSession endpointSession,
     DefaultEndpointClient endpointClient,
     CoreConfig config)
 {
     this.cmdProcessorManager = cmdProcessorManager;
     this.endpoint = endpoint;
     this.endpointSession = endpointSession;
     this.endpointClient = endpointClient;
     this.config = config;
 }
コード例 #2
0
 private Bootstrap CreateBootstrap(Endpoint endpoint, EndpointSession endpointSession)
 {
     return new Bootstrap()
         .Option(SessionOption.SO_KEEPALIVE, true)
         .Option(SessionOption.CONNECT_TIMEOUT_MILLIS, 5000)
         .Option(SessionOption.TCP_NODELAY, true)
         .Option(SessionOption.SO_SNDBUF, config.SendBufferSize)
         .Option(SessionOption.SO_RCVBUF, config.ReceiveBufferSize)
         .Option(SessionOption.ANY_IDLE_TIME, config.EndpointSessionMaxIdleTime)
         .OnSessionDestroyed((session) => this.RemoveSession(endpoint, endpointSession))
         .Handler(chain =>
         {
             chain.AddLast(
                 new ExceptionHandler(),
                 new MagicNumberPrepender(),
                 new LengthFieldPrepender(4),
                 new ProtocolCodecFilter(new CommandCodecFactory()));
         })
         .Handler(new DefaultClientChannelInboundHandler(commandProcessorManager, endpoint, endpointSession, this, config));
 }
コード例 #3
0
 public void RemoveSession(Endpoint endpoint, EndpointSession endpointSession)
 {
     EndpointSession removedSession = null;
     if (Endpoint.BROKER.Equals(endpoint.Type) && sessions.ContainsKey(endpoint))
     {
         lock (syncRoot)
         {
             if (sessions.ContainsKey(endpoint))
             {
                 EndpointSession tmp = sessions[endpoint];
                 if (tmp == endpointSession)
                 {
                     sessions.TryRemove(endpoint, out removedSession);
                 }
             }
         }
     }
     if (removedSession != null)
     {
         log.Info(string.Format("Closing idle connection to broker({0}:{1})", endpoint.Host, endpoint.Port));
         removedSession.Close();
     }
 }
コード例 #4
0
 private void Connect(Endpoint endpoint, EndpointSession endpointSession)
 {
     Debug.WriteLine("producer try connect {0}:{1}", endpoint.Host, endpoint.Port);
     var future = CreateBootstrap(endpoint, endpointSession)
         .Connect(new IPEndPoint(IPAddress.Parse(endpoint.Host), endpoint.Port));
     future.Complete += (s, e) =>
     {
         var connectFuture = e.Future as DefaultConnectFuture;
         if (!endpointSession.IsClosed)
         {
             if (!connectFuture.Connected)
             {
                 Log.Error(string.Format("producer try connect failed at {0}:{1}", endpoint.Host, endpoint.Port));
                 if (metaService.ContainsEndpoint(endpoint))
                 {
                     endpointSession.SetSessionFuture(null);
                     System.Threading.Thread.Sleep(config.EndpointSessionAutoReconnectDelay * 1000);
                     Debug.WriteLine("producer try connect failed at {0}:{1}", endpoint.Host, endpoint.Port);
                     Connect(endpoint, endpointSession);
                 }
             }
             else
             {
                 Log.Info(String.Format("Connected to broker {0}", connectFuture.Session.RemoteEndPoint.ToString()));
                 endpointSession.SetSessionFuture(connectFuture);
             }
         }
         else
         {
             if (connectFuture.Connected)
                 future.Session.Close(true);
         }
     };
 }
コード例 #5
0
 private EndpointSession CreateSession(Endpoint endpoint)
 {
     var session = new EndpointSession(this);
     Connect(endpoint, session);
     return session;
 }