Beispiel #1
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
Beispiel #2
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;
            }
        }