コード例 #1
0
        /// <summary>
        /// get result with timeout specified
        ///
        /// if request done, resolve normal responseObject
        /// if request not done, throws InvokeTimeoutException
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public Object get(int timeoutMillis) throws rpc.exception.InvokeTimeoutException, exception.RemotingException, ThreadInterruptedException
        public virtual object get(int timeoutMillis)
        {
            future.waitResponse(timeoutMillis);
            if (!Done)
            {
                throw new InvokeTimeoutException("Future get result timeout!");
            }
            ResponseCommand responseCommand = (ResponseCommand)future.waitResponse();

            responseCommand.InvokeContext = future.InvokeContext;
            return(RpcResponseResolver.resolveResponseObject(responseCommand, addr));
        }
コード例 #2
0
            public virtual void onResponse(InvokeFuture future)
            {
                ResponseCommand response;

                try
                {
                    response = (ResponseCommand)future.waitResponse(0);
                }
                catch (ThreadInterruptedException e)
                {
                    logger.LogError("Heartbeat ack process error! Id={}, from remoteAddr={}", heartbeat.Id, ((IPEndPoint)ctx.Channel?.RemoteAddress)?.ToString(), e);
                    return;
                }
                if (response != null && response.ResponseStatus == ResponseStatus.SUCCESS)
                {
                    if (logger.IsEnabled(LogLevel.Debug))
                    {
                        logger.LogDebug("Heartbeat ack received! Id={}, from remoteAddr={}", response.Id, ((IPEndPoint)ctx.Channel?.RemoteAddress)?.ToString());
                    }
                    ctx.Channel.GetAttribute(Connection.HEARTBEAT_COUNT).Set(0);
                }
                else
                {
                    if (response != null && response.ResponseStatus == ResponseStatus.TIMEOUT)
                    {
                        logger.LogError("Heartbeat timeout! The address is {}", ((IPEndPoint)ctx.Channel?.RemoteAddress)?.ToString());
                    }
                    else
                    {
                        logger.LogError("Heartbeat exception caught! Error code={}, The address is {}", response?.ResponseStatus, ((IPEndPoint)ctx.Channel?.RemoteAddress)?.ToString());
                    }
                    int?times = (int?)ctx.Channel.GetAttribute(Connection.HEARTBEAT_COUNT).Get();
                    ctx.Channel.GetAttribute(Connection.HEARTBEAT_COUNT).Set(times + 1);
                }
            }
コード例 #3
0
        /// <summary>
        /// Synchronous invocation
        /// </summary>
        /// <param name="conn"> </param>
        /// <param name="request"> </param>
        /// <param name="timeoutMillis">
        /// @return </param>
        /// <exception cref="ThreadInterruptedException"> </exception>
        /// <exception cref="RemotingException"> </exception>
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: protected RemotingCommand invokeSync(final Connection conn, final RemotingCommand request, final int timeoutMillis) throws exception.RemotingException, ThreadInterruptedException
        //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
        protected internal virtual RemotingCommand invokeSync(Connection conn, RemotingCommand request, int timeoutMillis)
        {
            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final InvokeFuture future = createInvokeFuture(request, request.getInvokeContext());
            InvokeFuture future = createInvokeFuture(request, request.InvokeContext);

            conn.addInvokeFuture(future);
            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final int requestId = request.getId();
            int requestId = request.Id;

            try
            {
                var writeFlushTask = conn.Channel.WriteAndFlushAsync(request);
                writeFlushTask.ContinueWith((task) =>
                {
                    if (!task.IsCompletedSuccessfully)
                    {
                        conn.removeInvokeFuture(requestId);
                        future.putResponse(commandFactory.createSendFailedResponse(conn.RemoteAddress, task.Exception));
                        logger.LogError("Invoke send failed, id={}", requestId, task.Exception);
                    }
                });
            }
            catch (Exception e)
            {
                conn.removeInvokeFuture(requestId);
                future.putResponse(commandFactory.createSendFailedResponse(conn.RemoteAddress, e));
                logger.LogError("Exception caught when sending invocation, id={}", requestId, e);
            }
            RemotingCommand response = future.waitResponse(timeoutMillis);

            if (response == null)
            {
                conn.removeInvokeFuture(requestId);
                response = commandFactory.createTimeoutResponse(conn.RemoteAddress);
                logger.LogWarning("Wait response, request id={} timeout!", requestId);
            }

            return(response);
        }
コード例 #4
0
            /// <seealso cref= Runnable#run() </seealso>
            public void run()
            {
                InvokeCallback callback = future.InvokeCallback;
                // a lot of try-catches to protect thread pool
                ResponseCommand response = null;

                try
                {
                    response = (ResponseCommand)future.waitResponse(0);
                }
                catch (ThreadInterruptedException e)
                {
                    string msg = "Exception caught when getting response from InvokeFuture. The address is " + remoteAddress;
                    logger.LogError(msg, e);
                }
                if (response == null || response.ResponseStatus != ResponseStatus.SUCCESS)
                {
                    try
                    {
                        System.Exception e;
                        if (response == null)
                        {
                            e = new InvokeException("Exception caught in invocation. The address is " + remoteAddress + " responseStatus:" + ResponseStatus.UNKNOWN, future.Cause);
                        }
                        else
                        {
                            response.InvokeContext = future.InvokeContext;
                            switch (response.ResponseStatus)
                            {
                            case ResponseStatus.TIMEOUT:
                                e = new InvokeTimeoutException("Invoke timeout when invoke with callback.The address is " + remoteAddress);
                                break;

                            case ResponseStatus.CONNECTION_CLOSED:
                                e = new ConnectionClosedException("Connection closed when invoke with callback.The address is " + remoteAddress);
                                break;

                            case ResponseStatus.SERVER_THREADPOOL_BUSY:
                                e = new InvokeServerBusyException("Server thread pool busy when invoke with callback.The address is " + remoteAddress);
                                break;

                            case ResponseStatus.SERVER_EXCEPTION:
                                string             msg  = "Server exception when invoke with callback.Please check the server log! The address is " + remoteAddress;
                                RpcResponseCommand resp = (RpcResponseCommand)response;
                                resp.deserialize();
                                object ex = resp.ResponseObject;
                                if (ex != null && ex is System.Exception)
                                {
                                    e = new InvokeServerException(msg, (System.Exception)ex);
                                }
                                else
                                {
                                    e = new InvokeServerException(msg);
                                }
                                break;

                            default:
                                e = new InvokeException("Exception caught in invocation. The address is " + remoteAddress + " responseStatus:" + response.ResponseStatus, future.Cause);

                                break;
                            }
                        }
                        callback.onException(e);
                    }
                    catch (System.Exception e)
                    {
                        logger.LogError("Exception occurred in user defined InvokeCallback#onException() logic, The address is {}", remoteAddress, e);
                    }
                }
                else
                {
                    try
                    {
                        response.InvokeContext = future.InvokeContext;
                        RpcResponseCommand rpcResponse = (RpcResponseCommand)response;
                        response.deserialize();
                        try
                        {
                            callback.onResponse(rpcResponse.ResponseObject);
                        }
                        catch (System.Exception e)
                        {
                            logger.LogError("Exception occurred in user defined InvokeCallback#onResponse() logic.", e);
                        }
                    }
                    catch (CodecException e)
                    {
                        logger.LogError("CodecException caught on when deserialize response in RpcInvokeCallbackListener. The address is {}.", remoteAddress, e);
                    }
                    catch (System.Exception e)
                    {
                        logger.LogError("Exception caught in RpcInvokeCallbackListener. The address is {}", remoteAddress, e);
                    }
                    finally
                    {
                    }
                }         // enf of else
            }             // end of run