コード例 #1
0
        /// <summary>
        /// Convert remoting response command to application response object.
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private static Object toResponseObject(ResponseCommand responseCommand) throws exception.CodecException
        private static object toResponseObject(ResponseCommand responseCommand)
        {
            RpcResponseCommand response = (RpcResponseCommand)responseCommand;

            response.deserialize();
            return(response.ResponseObject);
        }
コード例 #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public Object get() throws exception.RemotingException, ThreadInterruptedException
        public virtual object get()
        {
            ResponseCommand responseCommand = (ResponseCommand)future.waitResponse();

            responseCommand.InvokeContext = future.InvokeContext;
            return(RpcResponseResolver.resolveResponseObject(responseCommand, addr));
        }
コード例 #3
0
        public virtual RemotingCommand createTimeoutResponse(IPEndPoint address)
        {
            ResponseCommand responseCommand = new ResponseCommand();

            responseCommand.ResponseStatus     = ResponseStatus.TIMEOUT;
            responseCommand.ResponseTimeMillis = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();
            responseCommand.ResponseHost       = address;
            return(responseCommand);
        }
コード例 #4
0
        public virtual RemotingCommand createConnectionClosedResponse(IPEndPoint address, string message)
        {
            ResponseCommand responseCommand = new ResponseCommand();

            responseCommand.ResponseStatus     = ResponseStatus.CONNECTION_CLOSED;
            responseCommand.ResponseTimeMillis = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();
            responseCommand.ResponseHost       = address;
            return(responseCommand);
        }
コード例 #5
0
        //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
        //ORIGINAL LINE: @Override public RemotingCommand createSendFailedResponse(final java.net.IPEndPoint address, Throwable throwable)
        public virtual RemotingCommand createSendFailedResponse(IPEndPoint address, System.Exception throwable)
        {
            ResponseCommand responseCommand = new ResponseCommand();

            responseCommand.ResponseStatus     = ResponseStatus.CLIENT_SEND_ERROR;
            responseCommand.ResponseTimeMillis = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();
            responseCommand.ResponseHost       = address;
            responseCommand.Cause = throwable;
            return(responseCommand);
        }
コード例 #6
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));
        }
コード例 #7
0
        /// <summary>
        /// Detail your error msg with the error msg returned from response command
        /// </summary>
        private static string detailErrMsg(string clientErrMsg, ResponseCommand responseCommand)
        {
            RpcResponseCommand resp = (RpcResponseCommand)responseCommand;

            if (!string.IsNullOrWhiteSpace(resp.ErrorMsg))
            {
                return(string.Format("{0}, ServerErrorMsg:{1}", clientErrMsg, resp.ErrorMsg));
            }
            else
            {
                return(string.Format("{0}, ServerErrorMsg:null", clientErrMsg));
            }
        }
コード例 #8
0
        /// <summary>
        /// Convert remoting response command to throwable if it is a throwable, otherwise return null.
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private static Throwable toThrowable(ResponseCommand responseCommand) throws exception.CodecException
        private static Exception toThrowable(ResponseCommand responseCommand)
        {
            RpcResponseCommand resp = (RpcResponseCommand)responseCommand;

            resp.deserialize();
            object ex = resp.ResponseObject;

            if (ex != null && ex is Exception)
            {
                return((Exception)ex);
            }
            return(null);
        }
コード例 #9
0
        /// <summary>
        /// Synchronous rpc invocation.<br>
        /// Notice! DO NOT modify the request object concurrently when this method is called.
        /// </summary>
        /// <param name="conn"> </param>
        /// <param name="request"> </param>
        /// <param name="invokeContext"> </param>
        /// <param name="timeoutMillis">
        /// @return </param>
        /// <exception cref="RemotingException"> </exception>
        /// <exception cref="ThreadInterruptedException"> </exception>
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public Object invokeSync(final Connection conn, final Object request, final InvokeContext invokeContext, final int timeoutMillis) throws exception.RemotingException, ThreadInterruptedException
        //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
        public virtual object invokeSync(Connection conn, object request, InvokeContext invokeContext, int timeoutMillis)
        {
            RemotingCommand requestCommand = toRemotingCommand(request, conn, invokeContext, timeoutMillis);

            preProcessInvokeContext(invokeContext, requestCommand, conn);
            ResponseCommand responseCommand = (ResponseCommand)base.invokeSync(conn, requestCommand, timeoutMillis);

            responseCommand.InvokeContext = invokeContext;

            object responseObject = RpcResponseResolver.resolveResponseObject(responseCommand, ((IPEndPoint)conn.Channel?.RemoteAddress)?.ToString());

            return(responseObject);
        }
コード例 #10
0
        /// <summary>
        /// Analyze the response command and generate the response object.
        /// </summary>
        /// <param name="responseCommand"> response command </param>
        /// <param name="addr"> response address </param>
        /// <returns> response object </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static Object resolveResponseObject(ResponseCommand responseCommand, String addr) throws exception.RemotingException
        public static object resolveResponseObject(ResponseCommand responseCommand, string addr)
        {
            preProcess(responseCommand, addr);
            if (responseCommand.ResponseStatus == ResponseStatus.SUCCESS)
            {
                return(toResponseObject(responseCommand));
            }
            else
            {
                string msg = string.Format("Rpc invocation exception: {0}, the address is {1}, id={2}", responseCommand.ResponseStatus, addr, responseCommand.Id);
                logger.LogWarning(msg);
                if (responseCommand.Cause != null)
                {
                    throw new InvokeException(msg, responseCommand.Cause);
                }
                else
                {
                    throw new InvokeException(msg + ", please check the server log for more.");
                }
            }
        }
コード例 #11
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
コード例 #12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private static void preProcess(ResponseCommand responseCommand, String addr) throws exception.RemotingException
        private static void preProcess(ResponseCommand responseCommand, string addr)
        {
            RemotingException e   = null;
            string            msg = null;

            if (responseCommand == null)
            {
                msg = string.Format("Rpc invocation timeout[responseCommand null]! the address is {0}", addr);
                e   = new InvokeTimeoutException(msg);
            }
            else
            {
                switch (responseCommand.ResponseStatus)
                {
                case ResponseStatus.TIMEOUT:
                    msg = string.Format("Rpc invocation timeout[responseCommand TIMEOUT]! the address is {0}", addr);
                    e   = new InvokeTimeoutException(msg);
                    break;

                case ResponseStatus.CLIENT_SEND_ERROR:
                    msg = string.Format("Rpc invocation send failed! the address is {0}", addr);
                    e   = new InvokeSendFailedException(msg, responseCommand.Cause);
                    break;

                case ResponseStatus.CONNECTION_CLOSED:
                    msg = string.Format("Connection closed! the address is {0}", addr);
                    e   = new ConnectionClosedException(msg);
                    break;

                case ResponseStatus.SERVER_THREADPOOL_BUSY:
                    msg = string.Format("Server thread pool busy! the address is {0}, id={1}", addr, responseCommand.Id);
                    e   = new InvokeServerBusyException(msg);
                    break;

                case ResponseStatus.CODEC_EXCEPTION:
                    msg = string.Format("Codec exception! the address is {0}, id={1}", addr, responseCommand.Id);
                    e   = new CodecException(msg);
                    break;

                case ResponseStatus.SERVER_SERIAL_EXCEPTION:
                    msg = string.Format("Server serialize response exception! the address is {0}, id={1}, serverSide=true", addr, responseCommand.Id);
                    e   = new SerializationException(detailErrMsg(msg, responseCommand), toThrowable(responseCommand), true);
                    break;

                case ResponseStatus.SERVER_DESERIAL_EXCEPTION:
                    msg = string.Format("Server deserialize request exception! the address is {0}, id={1}, serverSide=true", addr, responseCommand.Id);
                    e   = new DeserializationException(detailErrMsg(msg, responseCommand), toThrowable(responseCommand), true);
                    break;

                case ResponseStatus.SERVER_EXCEPTION:
                    msg = string.Format("Server exception! Please check the server log, the address is {0}, id={1}", addr, responseCommand.Id);
                    e   = new InvokeServerException(detailErrMsg(msg, responseCommand), toThrowable(responseCommand));
                    break;

                default:
                    break;
                }
            }
            if (!string.IsNullOrWhiteSpace(msg))
            {
                logger.LogWarning(msg);
            }
            if (null != e)
            {
                throw e;
            }
        }
コード例 #13
0
 /// <seealso cref= InvokeFuture#putResponse(RemotingCommand) </seealso>
 public virtual void putResponse(RemotingCommand response)
 {
     responseCommand = (ResponseCommand)response;
     countDownLatch.countDown();
 }