示例#1
0
        /// <seealso cref= AbstractRemotingProcessor#doProcess </seealso>
        public override void doProcess(RemotingContext ctx, RemotingCommand cmd)
        {
            Connection   conn   = ctx.ChannelContext.Channel.GetAttribute(Connection.CONNECTION).Get();
            InvokeFuture future = conn.removeInvokeFuture(cmd.Id);

            try
            {
                if (future != null)
                {
                    future.putResponse(cmd);
                    future.cancelTimeout();
                    try
                    {
                        future.executeInvokeCallback();
                    }
                    catch (System.Exception e)
                    {
                        logger.LogError("Exception caught when executing invoke callback, id={}", cmd.Id, e);
                    }
                }
                else
                {
                    logger.LogWarning("Cannot find InvokeFuture, maybe already timeout, id={}, from={} ", cmd.Id, ctx.ChannelContext.Channel.RemoteAddress.ToString());
                }
            }
            finally
            {
            }
        }
示例#2
0
        /// <seealso cref= InvokeCallbackListener#onResponse(InvokeFuture) </seealso>
        public virtual void onResponse(InvokeFuture future)
        {
            InvokeCallback callback = future.InvokeCallback;

            if (callback != null)
            {
                CallbackTask task = new CallbackTask(this, RemoteAddress, future);
                if (callback.Executor != null)
                {
                    // There is no need to switch classloader, because executor is provided by user.
                    try
                    {
                        callback.Executor.execute(task);
                    }
                    catch (RejectedExecutionException)
                    {
                        logger.LogWarning("Callback thread pool busy.");
                    }
                }
                else
                {
                    task.run();
                }
            }
        }
 public TimerTaskAnonymousInnerClass2(BaseRemoting outerInstance, Connection conn, InvokeFuture future, int requestId)
 {
     this.outerInstance = outerInstance;
     this.conn          = conn;
     this.future        = future;
     this.requestId     = requestId;
 }
示例#4
0
 public TimerTaskAnonymousInnerClass(RpcHeartbeatTrigger outerInstance, Connection conn, InvokeFuture future, int heartbeatId)
 {
     this.outerInstance = outerInstance;
     this.conn          = conn;
     this.future        = future;
     this.heartbeatId   = heartbeatId;
 }
示例#5
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);
                }
            }
 //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
 //ORIGINAL LINE: @Override public void doProcess(final RemotingContext ctx, RemotingCommand msg)
 public override void doProcess(RemotingContext ctx, RemotingCommand msg)
 {
     if (msg is HeartbeatCommand)
     { // process the heartbeat
       //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
       //ORIGINAL LINE: final int id = msg.getId();
         int id = msg.Id;
         if (logger.IsEnabled(LogLevel.Debug))
         {
             logger.LogDebug("Heartbeat received! Id=" + id + ", from " + ctx.ChannelContext.Channel.RemoteAddress.ToString());
         }
         HeartbeatAckCommand ack = new HeartbeatAckCommand();
         ack.Id = id;
         var writeFlushTask = ctx.writeAndFlush(ack);
         writeFlushTask.ContinueWith((task) =>
         {
             if (task.IsCompletedSuccessfully)
             {
                 if (logger.IsEnabled(LogLevel.Debug))
                 {
                     logger.LogDebug("Send heartbeat ack done! Id={}, to remoteAddr={}", id, ctx.ChannelContext.Channel.RemoteAddress.ToString());
                 }
             }
             else
             {
                 logger.LogError("Send heartbeat ack failed! Id={}, to remoteAddr={}", id, ctx.ChannelContext.Channel.RemoteAddress.ToString());
             }
         });
         //.addListener(new ChannelFutureListenerAnonymousInnerClass(this, ctx, id));
     }
     else if (msg is HeartbeatAckCommand)
     {
         Connection   conn   = (Connection)ctx.ChannelContext.Channel.GetAttribute(Connection.CONNECTION).Get();
         InvokeFuture future = conn.removeInvokeFuture(msg.Id);
         if (future != null)
         {
             future.putResponse(msg);
             future.cancelTimeout();
             try
             {
                 future.executeInvokeCallback();
             }
             catch (Exception e)
             {
                 logger.LogError("Exception caught when executing heartbeat invoke callback. From {}", ctx.ChannelContext.Channel.RemoteAddress.ToString(), e);
             }
         }
         else
         {
             logger.LogWarning("Cannot find heartbeat InvokeFuture, maybe already timeout. Id={}, From {}", msg.Id, ctx.ChannelContext.Channel.RemoteAddress.ToString());
         }
     }
     else
     {
         //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
         throw new Exception("Cannot process command: " + msg.GetType().FullName);
     }
 }
            public void Run(ITimeout timeout)
            {
                InvokeFuture future = conn.removeInvokeFuture(requestId);

                if (future != null)
                {
                    future.putResponse(outerInstance.commandFactory.createTimeoutResponse(conn.RemoteAddress));
                }
            }
示例#8
0
        /// <summary>
        /// Rpc invocation with future returned.<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>
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public RpcResponseFuture invokeWithFuture(final Connection conn, final Object request, final InvokeContext invokeContext, final int timeoutMillis) throws exception.RemotingException
        //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
        public virtual RpcResponseFuture invokeWithFuture(Connection conn, object request, InvokeContext invokeContext, int timeoutMillis)
        {
            RemotingCommand requestCommand = toRemotingCommand(request, conn, invokeContext, timeoutMillis);

            preProcessInvokeContext(invokeContext, requestCommand, conn);
            InvokeFuture future = base.invokeWithFuture(conn, requestCommand, timeoutMillis);

            return(new RpcResponseFuture(((IPEndPoint)conn.Channel.RemoteAddress).ToString(), future));
        }
示例#9
0
        public static void addIdGroupCallbackMapping(int?id, InvokeFuture callback, IChannel channel)
        {
            Connection connection = getConnectionFromChannel(channel);

            if (connection != null)
            {
                connection.addInvokeFuture(callback);
            }
        }
示例#10
0
            public void Run(ITimeout timeout)
            {
                InvokeFuture future = conn.removeInvokeFuture(heartbeatId);

                if (future != null)
                {
                    future.putResponse(outerInstance.commandFactory.createTimeoutResponse(conn.RemoteAddress));
                    future.tryAsyncExecuteInvokeCallbackAbnormally();
                }
            }
 /// <summary>
 /// Add an InvokeFuture
 /// </summary>
 /// <param name="future"> InvokeFuture </param>
 /// <returns> previous InvokeFuture with same invoke id </returns>
 public virtual InvokeFuture addInvokeFuture(InvokeFuture future)
 {
     if (!invokeFutureMap.ContainsKey(future.invokeId()))
     {
         invokeFutureMap.AddOrUpdate(future.invokeId(), future, (key, value) => future);
         return(null);
     }
     else
     {
         invokeFutureMap.TryGetValue(future.invokeId(), out var result);
         return(result);
     }
 }
        /// <summary>
        /// Invocation with callback.
        /// </summary>
        /// <param name="conn"> </param>
        /// <param name="request"> </param>
        /// <param name="invokeCallback"> </param>
        /// <param name="timeoutMillis"> </param>
        /// <exception cref="ThreadInterruptedException"> </exception>
        //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
        //ORIGINAL LINE: protected void invokeWithCallback(final Connection conn, final RemotingCommand request, final InvokeCallback invokeCallback, final int timeoutMillis)
        protected internal virtual void invokeWithCallback(Connection conn, RemotingCommand request, InvokeCallback invokeCallback, int timeoutMillis)
        {
            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final InvokeFuture future = createInvokeFuture(conn, request, request.getInvokeContext(), invokeCallback);
            InvokeFuture future = createInvokeFuture(conn, request, request.InvokeContext, invokeCallback);

            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
            {
                ITimeout timeout = TimerHolder.Timer.NewTimeout(new TimerTaskAnonymousInnerClass(this, conn, future, requestId), TimeSpan.FromMilliseconds(timeoutMillis));
                future.addTimeout(timeout);
                var writeFlushTask = conn.Channel.WriteAndFlushAsync(request);
                writeFlushTask.ContinueWith((task) =>
                {
                    if (!task.IsCompletedSuccessfully)
                    {
                        InvokeFuture f = conn.removeInvokeFuture(requestId);
                        if (f != null)
                        {
                            f.cancelTimeout();
                            f.putResponse(commandFactory.createSendFailedResponse(conn.RemoteAddress, task.Exception));
                            f.tryAsyncExecuteInvokeCallbackAbnormally();
                        }
                        logger.LogError("Invoke send failed. The address is {}", ((IPEndPoint)conn.Channel.RemoteAddress).ToString(), task.Exception);
                    }
                });
            }
            catch (Exception e)
            {
                InvokeFuture f = conn.removeInvokeFuture(requestId);
                if (f != null)
                {
                    f.cancelTimeout();
                    f.putResponse(commandFactory.createSendFailedResponse(conn.RemoteAddress, e));
                    f.tryAsyncExecuteInvokeCallbackAbnormally();
                }
                logger.LogError("Exception caught when sending invocation. The address is {}", ((IPEndPoint)conn.Channel.RemoteAddress).ToString(), e);
            }
        }
        /// <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);
        }
 /// <summary>
 /// Constructor
 /// </summary>
 public RpcResponseFuture(string addr, InvokeFuture future)
 {
     this.addr   = addr;
     this.future = future;
 }
示例#15
0
 ///
 public CallbackTask(RpcInvokeCallbackListener outerInstance, string remoteAddress, InvokeFuture future)
 {
     this.outerInstance = outerInstance;
     this.remoteAddress = remoteAddress;
     this.future        = future;
 }