コード例 #1
0
        // Used for holding enough info to handle receive completion
        internal IncomingMessageAcceptor(MessageCenter msgCtr, IPEndPoint here, SocketDirection socketDirection, MessageFactory messageFactory, SerializationManager serializationManager,
                                         ExecutorService executorService, ILoggerFactory loggerFactory)
            : base(executorService, loggerFactory)
        {
            this.loggerFactory = loggerFactory;
            Log                       = new LoggerWrapper <IncomingMessageAcceptor>(loggerFactory);
            MessageCenter             = msgCtr;
            listenAddress             = here;
            this.MessageFactory       = messageFactory;
            this.receiveEventArgsPool = new ConcurrentObjectPool <SaeaPoolWrapper>(() => this.CreateSocketReceiveAsyncEventArgsPoolWrapper());
            this.serializationManager = serializationManager;
            if (here == null)
            {
                listenAddress = MessageCenter.MyAddress.Endpoint;
            }

            AcceptingSocket = MessageCenter.SocketManager.GetAcceptingSocketForEndpoint(listenAddress);
            Log.Info(ErrorCode.Messaging_IMA_OpenedListeningSocket, "Opened a listening socket at address " + AcceptingSocket.LocalEndPoint);
            OpenReceiveSockets = new HashSet <Socket>();
            OnFault            = FaultBehavior.CrashOnFault;
            SocketDirection    = socketDirection;

            checkedOutSocketEventArgsCounter = CounterStatistic.FindOrCreate(StatisticNames.MESSAGE_ACCEPTOR_CHECKED_OUT_SOCKET_EVENT_ARGS, false);
            checkedInSocketEventArgsCounter  = CounterStatistic.FindOrCreate(StatisticNames.MESSAGE_ACCEPTOR_CHECKED_IN_SOCKET_EVENT_ARGS, false);

            IntValueStatistic.FindOrCreate(StatisticNames.MESSAGE_ACCEPTOR_IN_USE_SOCKET_EVENT_ARGS,
                                           () => checkedOutSocketEventArgsCounter.GetCurrentValue() - checkedInSocketEventArgsCounter.GetCurrentValue());
        }
コード例 #2
0
ファイル: BaseConvert.cs プロジェクト: leidegre/bcl2
        // We use object pooling in the following way, if the pool is empty
        // a new object is created, this is effectively just as expensive as
        // creating a new string builder, if we succeed with our operation
        // we return (possibly a new string builder) to the pool.
        // IT'S IMPORTANT THAT WE RESET THE STRING BUILDER BEFORE PUTTING IT BACK IN THE POOL.
        // If an exception occurs between the getting and putting back we simply
        // allow the object to get lost in the ether. It will eventually get garbage collected.

        public static string Encode(this BaseConverter converter, int v)
        {
            var sb = ConcurrentObjectPool <StringBuilder> .Get();

            converter.Encode(v, sb);
            var s = sb.ToString();

            // reset
            sb.Length = 0;
            ConcurrentObjectPool <StringBuilder> .Put(sb);

            return(s);
        }
コード例 #3
0
ファイル: BaseConvert.cs プロジェクト: leidegre/bcl2
        public static string Encode(this BaseConverter converter, byte[] bytes, int offset, int length)
        {
            var sb = ConcurrentObjectPool <StringBuilder> .Get();

            converter.Encode(bytes, offset, length, sb);
            var s = sb.ToString();

            // reset
            sb.Length = 0;
            ConcurrentObjectPool <StringBuilder> .Put(sb);

            return(s);
        }
コード例 #4
0
ファイル: BaseConvert.cs プロジェクト: leidegre/bcl2
        public static byte[] DecodeBytes(this BaseConverter converter, string s, int startIndex, int length)
        {
            var buffer = ConcurrentObjectPool <MemoryStream> .Get();

            converter.DecodeBytes(s, startIndex, length, buffer);
            var bytes = new byte[buffer.Length];

            buffer.Position = 0;
            buffer.Read(bytes, 0, bytes.Length);
            // reset
            buffer.SetLength(0);
            ConcurrentObjectPool <MemoryStream> .Put(buffer);

            return(bytes);
        }
コード例 #5
0
 /// <summary>
 /// Clears current message pool.
 /// </summary>
 public static void Clear()
 {
     s_pool = new ConcurrentObjectPool <Message>(MAX_POOL_SIZE);
 }
コード例 #6
0
 static MessagePool()
 {
     s_pool = new ConcurrentObjectPool <Message>(MAX_POOL_SIZE);
 }