示例#1
0
        public override void Stop()
        {
            if (_channelPool != null)
            {
                _channelPool.close(true);
                _bootstrap.releaseExternalResources();
                _channelPool = null;
            }

            _comExceptionHandler = NoOpComExceptionHandler;
            _msgLog.info(ToString() + " shutdown");
        }
示例#2
0
        public Client(string destinationHostNameOrIp, int destinationPort, string originHostNameOrIp, LogProvider logProvider, StoreId storeId, int frameLength, long readTimeout, int maxConcurrentChannels, int chunkSize, ResponseUnpacker responseUnpacker, ByteCounterMonitor byteCounterMonitor, RequestMonitor requestMonitor, LogEntryReader <ReadableClosablePositionAwareChannel> entryReader)
        {
            this._entryReader = entryReader;
            Debug.Assert(byteCounterMonitor != null);
            Debug.Assert(requestMonitor != null);

            this._byteCounterMonitor = byteCounterMonitor;
            this._requestMonitor     = requestMonitor;
            assertChunkSizeIsWithinFrameSize(chunkSize, frameLength);

            this._msgLog      = logProvider.getLog(this.GetType());
            this._storeId     = storeId;
            this._frameLength = frameLength;
            this._readTimeout = readTimeout;
            // ResourcePool no longer controls max concurrent channels. Use this value for the pool size
            this._maxUnusedChannels   = maxConcurrentChannels;
            this._comExceptionHandler = NoOpComExceptionHandler;

            if (destinationHostNameOrIp.Equals("0.0.0.0"))
            {
                // So it turns out that on Windows, connecting to 0.0.0.0 when specifying
                // an origin address will not succeed. But since we know we are
                // connecting to ourselves, and that we are listening on everything,
                // replacing with localhost is the proper thing to do.
                this._destination = new InetSocketAddress(LocalAddress, destinationPort);
            }
            else
            {
                // An explicit destination address is always correct
                this._destination = new InetSocketAddress(destinationHostNameOrIp, destinationPort);
            }

            if (string.ReferenceEquals(originHostNameOrIp, null) || originHostNameOrIp.Equals("0.0.0.0"))
            {
                _origin = null;
            }
            else
            {
                _origin = new InetSocketAddress(originHostNameOrIp, 0);
            }

            ProtocolVersion protocolVersion = ProtocolVersion;

            this._protocol         = CreateProtocol(chunkSize, protocolVersion.ApplicationProtocol);
            this._responseUnpacker = responseUnpacker;

            _msgLog.info(this.GetType().Name + " communication channel created towards " + _destination);
        }
示例#3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void clientShouldUseHandlersToHandleComExceptions()
        public virtual void ClientShouldUseHandlersToHandleComExceptions()
        {
            // Given
            const string comExceptionMessage = "The ComException";

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: MadeUpCommunicationInterface communication = mock(MadeUpCommunicationInterface.class, (org.mockito.stubbing.Answer<Response<?>>) ignored ->
            MadeUpCommunicationInterface communication = mock(typeof(MadeUpCommunicationInterface), (Answer <Response <object> >)ignored =>
            {
                throw new ComException(comExceptionMessage);
            });

            ComExceptionHandler handler = mock(typeof(ComExceptionHandler));

            _life.add(_builder.server(communication));
            MadeUpClient client = _life.add(_builder.client());

            client.ComExceptionHandler = handler;

            _life.start();

            // When
            ComException exceptionThrownOnRequest = null;

            try
            {
                client.Multiply(1, 10);
            }
            catch (ComException e)
            {
                exceptionThrownOnRequest = e;
            }

            // Then
            assertNotNull(exceptionThrownOnRequest);
            assertEquals(comExceptionMessage, exceptionThrownOnRequest.Message);

            ArgumentCaptor <ComException> exceptionCaptor = ArgumentCaptor.forClass(typeof(ComException));

            verify(handler).handle(exceptionCaptor.capture());
            assertEquals(comExceptionMessage, exceptionCaptor.Value.Message);
            verifyNoMoreInteractions(handler);
        }