public ReceiveCallbackContext(Socket sock, IncomingMessageAcceptor ima)
 {
     Sock           = sock;
     RemoteEndPoint = sock.RemoteEndPoint;
     IMA            = ima;
     _buffer        = new IncomingMessageBuffer(ima.Log);
 }
        private void Initialize(IOptions <EndpointOptions> endpointOptions,
                                IOptions <SiloMessagingOptions> messagingOptions,
                                IOptions <NetworkingOptions> networkingOptions,
                                IOptions <StatisticsOptions> statisticsOptions)
        {
            if (log.IsEnabled(LogLevel.Trace))
            {
                log.Trace("Starting initialization.");
            }

            SocketManager = new SocketManager(networkingOptions, this.loggerFactory);
            var listeningEndpoint = endpointOptions.Value.GetListeningSiloEndpoint();

            ima = new IncomingMessageAcceptor(this,
                                              listeningEndpoint,
                                              SocketDirection.SiloToSilo,
                                              this.messageFactory,
                                              this.serializationManager,
                                              this.executorService,
                                              this.loggerFactory);
            InboundQueue  = new InboundMessageQueue(this.loggerFactory, statisticsOptions);
            OutboundQueue = new OutboundMessageQueue(this, messagingOptions, this.serializationManager, this.executorService, this.loggerFactory);

            sendQueueLengthCounter    = IntValueStatistic.FindOrCreate(StatisticNames.MESSAGE_CENTER_SEND_QUEUE_LENGTH, () => SendQueueLength);
            receiveQueueLengthCounter = IntValueStatistic.FindOrCreate(StatisticNames.MESSAGE_CENTER_RECEIVE_QUEUE_LENGTH, () => ReceiveQueueLength);

            if (log.IsEnabled(LogLevel.Trace))
            {
                log.Trace("Completed initialization.");
            }
        }
Esempio n. 3
0
        public void Dispose()
        {
            if (ima != null)
            {
                ima.Dispose();
                ima = null;
            }

            OutboundQueue.Dispose();

            GC.SuppressFinalize(this);
        }
Esempio n. 4
0
        private void Initialize(IPEndPoint here, int generation, IMessagingConfiguration config, ISiloPerformanceMetrics metrics = null)
        {
            if(log.IsVerbose3) log.Verbose3("Starting initialization.");

            SocketManager = new SocketManager(config);
            ima = new IncomingMessageAcceptor(this, here, SocketDirection.SiloToSilo, this.messageFactory, this.serializationManager);
            MyAddress = SiloAddress.New((IPEndPoint)ima.AcceptingSocket.LocalEndPoint, generation);
            MessagingConfiguration = config;
            InboundQueue = new InboundMessageQueue();
            OutboundQueue = new OutboundMessageQueue(this, config, this.serializationManager);
            Gateway = null;
            Metrics = metrics;
            
            sendQueueLengthCounter = IntValueStatistic.FindOrCreate(StatisticNames.MESSAGE_CENTER_SEND_QUEUE_LENGTH, () => SendQueueLength);
            receiveQueueLengthCounter = IntValueStatistic.FindOrCreate(StatisticNames.MESSAGE_CENTER_RECEIVE_QUEUE_LENGTH, () => ReceiveQueueLength);

            if (log.IsVerbose3) log.Verbose3("Completed initialization.");
        }
Esempio n. 5
0
        private void Initialize(IPEndPoint here, int generation, IMessagingConfiguration config, ISiloPerformanceMetrics metrics = null)
        {
            if(log.IsVerbose3) log.Verbose3("Starting initialization.");

            SocketManager = new SocketManager(config);
            ima = new IncomingMessageAcceptor(this, here, SocketDirection.SiloToSilo);
            MyAddress = SiloAddress.New((IPEndPoint)ima.AcceptingSocket.LocalEndPoint, generation);
            MessagingConfiguration = config;
            InboundQueue = new InboundMessageQueue();
            OutboundQueue = new OutboundMessageQueue(this, config);
            Gateway = null;
            Metrics = metrics;
            
            sendQueueLengthCounter = IntValueStatistic.FindOrCreate(StatisticNames.MESSAGE_CENTER_SEND_QUEUE_LENGTH, () => SendQueueLength);
            receiveQueueLengthCounter = IntValueStatistic.FindOrCreate(StatisticNames.MESSAGE_CENTER_RECEIVE_QUEUE_LENGTH, () => ReceiveQueueLength);

            if (log.IsVerbose3) log.Verbose3("Completed initialization.");
        }
 public ReceiveCallbackContext(Socket sock, IncomingMessageAcceptor ima)
 {
     batchingMode = ima.MessageCenter.MessagingConfiguration.UseMessageBatching;
     if (batchingMode)
     {
         phase            = ReceivePhase.MetaHeader;
         Sock             = sock;
         RemoteEndPoint   = sock.RemoteEndPoint;
         IMA              = ima;
         metaHeaderBuffer = new byte[Message.LENGTH_META_HEADER];
         metaHeader       = new List <ArraySegment <byte> >()
         {
             new ArraySegment <byte>(metaHeaderBuffer)
         };
         // LengthBuffer and Lengths cannot be allocated here because the sizes varies in response to the number of received messages
         lengthBuffer       = null;
         lengths            = null;
         header             = null;
         body               = null;
         headerBodies       = null;
         headerLengths      = null;
         bodyLengths        = null;
         headerBodiesLength = 0;
         numberOfMessages   = 0;
         offset             = 0;
     }
     else
     {
         phase          = ReceivePhase.Lengths;
         Sock           = sock;
         RemoteEndPoint = sock.RemoteEndPoint;
         IMA            = ima;
         lengthBuffer   = new byte[Message.LENGTH_HEADER_SIZE];
         lengths        = new List <ArraySegment <byte> >()
         {
             new ArraySegment <byte>(lengthBuffer)
         };
         header       = null;
         body         = null;
         headerLength = 0;
         bodyLength   = 0;
         offset       = 0;
     }
 }
Esempio n. 7
0
        private void Initialize(IPEndPoint here, int generation, IOptions <SiloMessagingOptions> messagingOptions, IOptions <NetworkingOptions> networkingOptions)
        {
            if (log.IsEnabled(LogLevel.Trace))
            {
                log.Trace("Starting initialization.");
            }

            SocketManager = new SocketManager(networkingOptions, this.loggerFactory);
            ima           = new IncomingMessageAcceptor(this, here, SocketDirection.SiloToSilo, this.messageFactory, this.serializationManager, this.executorService, this.loggerFactory);
            MyAddress     = SiloAddress.New((IPEndPoint)ima.AcceptingSocket.LocalEndPoint, generation);
            InboundQueue  = new InboundMessageQueue(this.loggerFactory);
            OutboundQueue = new OutboundMessageQueue(this, messagingOptions, this.serializationManager, this.executorService, this.loggerFactory);

            sendQueueLengthCounter    = IntValueStatistic.FindOrCreate(StatisticNames.MESSAGE_CENTER_SEND_QUEUE_LENGTH, () => SendQueueLength);
            receiveQueueLengthCounter = IntValueStatistic.FindOrCreate(StatisticNames.MESSAGE_CENTER_RECEIVE_QUEUE_LENGTH, () => ReceiveQueueLength);

            if (log.IsEnabled(LogLevel.Trace))
            {
                log.Trace("Completed initialization.");
            }
        }
Esempio n. 8
0
 private void StartReceiveAsync(Socket sock, SocketAsyncEventArgs readEventArgs, IncomingMessageAcceptor ima)
 {
     try
     {
         // Set up the async receive
         if (!sock.ReceiveAsync(readEventArgs))
         {
             ProcessReceive(readEventArgs);
         }
     }
     catch (Exception exception)
     {
         var socketException = exception as SocketException;
         var context         = readEventArgs.UserToken as ReceiveCallbackContext;
         ima.Log.Warn(ErrorCode.Messaging_IMA_NewBeginReceiveException,
                      $"Exception on new socket during ReceiveAsync with RemoteEndPoint " +
                      $"{socketException?.SocketErrorCode}: {context?.RemoteEndPoint}", exception);
         ima.SafeCloseSocket(sock);
         FreeSocketAsyncEventArgs(readEventArgs);
     }
 }
 public ReceiveCallbackContext(Socket sock, IncomingMessageAcceptor ima)
 {
     Sock = sock;
     RemoteEndPoint = sock.RemoteEndPoint;
     IMA = ima;
     _buffer = new IncomingMessageBuffer(ima.Log);
 }
Esempio n. 10
0
        public void Dispose()
        {
            if (ima != null)
            {
                ima.Dispose();
                ima = null;
            }

            OutboundQueue.Dispose();

            GC.SuppressFinalize(this);
        }