/// <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 { } }
//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)); } }
public void Run(ITimeout timeout) { InvokeFuture future = conn.removeInvokeFuture(heartbeatId); if (future != null) { future.putResponse(outerInstance.commandFactory.createTimeoutResponse(conn.RemoteAddress)); future.tryAsyncExecuteInvokeCallbackAbnormally(); } }
/// <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> /// 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); } }