/// <summary> /// Rpc invocation with callback.<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="invokeCallback"> </param> /// <param name="timeoutMillis"> </param> /// <exception cref="RemotingException"> </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void invokeWithCallback(final Connection conn, final Object request, final InvokeContext invokeContext, final InvokeCallback invokeCallback, final int timeoutMillis) throws exception.RemotingException //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: public virtual void invokeWithCallback(Connection conn, object request, InvokeContext invokeContext, InvokeCallback invokeCallback, int timeoutMillis) { RemotingCommand requestCommand = toRemotingCommand(request, conn, invokeContext, timeoutMillis); preProcessInvokeContext(invokeContext, requestCommand, conn); base.invokeWithCallback(conn, requestCommand, invokeCallback, timeoutMillis); }
/// <param name="requestCommand"> </param> private void logDebugInfo(RemotingCommand requestCommand) { if (logger.IsEnabled(LogLevel.Debug)) { logger.LogDebug("Send request, requestId=" + requestCommand.Id); } }
/// <summary> /// Oneway invocation. /// </summary> /// <param name="conn"> </param> /// <param name="request"> </param> /// <exception cref="ThreadInterruptedException"> </exception> //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: //ORIGINAL LINE: protected void oneway(final Connection conn, final RemotingCommand request) protected internal virtual void oneway(Connection conn, RemotingCommand request) { try { var writeFlushTask = conn.Channel.WriteAndFlushAsync(request); writeFlushTask.ContinueWith((task) => { if (!task.IsCompletedSuccessfully) { logger.LogError("Invoke send failed. The address is {}", ((IPEndPoint)conn.Channel.RemoteAddress).ToString(), task.Exception); } }); } catch (Exception e) { if (null == conn) { logger.LogError("Conn is null"); } else { logger.LogError("Exception caught when sending invocation. The address is {}", ((IPEndPoint)conn.Channel.RemoteAddress).ToString(), e); } } }
/// <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); } }
/// <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)); }
/// <summary> /// Send response using remoting context if necessary.<br> /// If request type is oneway, no need to send any response nor exception. /// </summary> /// <param name="ctx"> remoting context </param> /// <param name="type"> type code </param> /// <param name="response"> remoting command </param> //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: //ORIGINAL LINE: public void sendResponseIfNecessary(final RemotingContext ctx, byte type, final RemotingCommand response) public virtual void sendResponseIfNecessary(RemotingContext ctx, byte type, RemotingCommand response) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int id = response.getId(); int id = response.Id; if (type != RpcCommandType.REQUEST_ONEWAY) { RemotingCommand serializedResponse = response; try { response.serialize(); } catch (SerializationException e) { string errMsg = "SerializationException occurred when sendResponseIfNecessary in RpcRequestProcessor, id=" + id; logger.LogError(errMsg, e); serializedResponse = CommandFactory.createExceptionResponse(id, ResponseStatus.SERVER_SERIAL_EXCEPTION, e); try { serializedResponse.serialize(); // serialize again for exception response } catch (SerializationException) { // should not happen logger.LogError("serialize SerializationException response failed!"); } } catch (System.Exception t) { string errMsg = "Serialize RpcResponseCommand failed when sendResponseIfNecessary in RpcRequestProcessor, id=" + id; logger.LogError(errMsg, t); serializedResponse = CommandFactory.createExceptionResponse(id, t, errMsg); } var writeFlushTask = ctx.writeAndFlush(serializedResponse); writeFlushTask.ContinueWith((task) => { if (logger.IsEnabled(LogLevel.Debug)) { logger.LogDebug("Rpc response sent! requestId=" + id + ". The address is " + ctx.ChannelContext.Channel.RemoteAddress.ToString()); } if (!task.IsCompletedSuccessfully) { logger.LogError("Rpc response send failed! id=" + id + ". The address is " + ctx.ChannelContext.Channel.RemoteAddress.ToString(), task.Exception); } }); //.addListener(new ChannelFutureListenerAnonymousInnerClass(this, ctx, id)); } else { if (logger.IsEnabled(LogLevel.Debug)) { logger.LogDebug("Oneway rpc request received, do not send response, id=" + id + ", the address is " + ctx.ChannelContext.Channel.RemoteAddress.ToString()); } } }
/// <summary> /// Process the remoting command with its own executor or with the defaultExecutor if its own if null. /// </summary> /// <param name="ctx"> RemotingContext </param> /// <param name="msg"> T </param> /// <param name="defaultExecutor"> ExecutorService, default executor </param> public virtual void process(RemotingContext ctx, RemotingCommand msg, ExecutorService defaultExecutor) { ProcessTask task = new ProcessTask(this, ctx, msg); if (Executor != null) { Executor.execute(task); } else { defaultExecutor.execute(task); } }
/// <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); }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: //ORIGINAL LINE: @Override public rpc.protocol.RpcResponseCommand createResponse(final Object responseObject, final RemotingCommand requestCmd) public virtual RemotingCommand createResponse(object responseObject, RemotingCommand requestCmd) { RpcResponseCommand response = new RpcResponseCommand(requestCmd.Id, responseObject); if (null != responseObject) { //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: response.ResponseClass = responseObject.GetType(); } else { response.ResponseClass = null; } response.Serializer = requestCmd.Serializer; response.ProtocolSwitch = requestCmd.ProtocolSwitch; response.ResponseStatus = ResponseStatus.SUCCESS; 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); } }
/// <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); }
public ProcessTask(AbstractRemotingProcessor outerInstance, RemotingContext ctx, RemotingCommand msg) { this.outerInstance = outerInstance; this.ctx = ctx; this.msg = msg; }
/// <seealso cref= RpcRemoting#preProcessInvokeContext(InvokeContext, RemotingCommand, Connection) </seealso> protected internal override void preProcessInvokeContext(InvokeContext invokeContext, RemotingCommand cmd, Connection connection) { if (null != invokeContext) { invokeContext.putIfAbsent(InvokeContext.CLIENT_LOCAL_IP, ((IPEndPoint)connection.Channel.LocalAddress).Address); invokeContext.putIfAbsent(InvokeContext.CLIENT_LOCAL_PORT, ((IPEndPoint)connection.Channel.LocalAddress).Port); invokeContext.putIfAbsent(InvokeContext.CLIENT_REMOTE_IP, ((IPEndPoint)connection.Channel.RemoteAddress).Address); invokeContext.putIfAbsent(InvokeContext.CLIENT_REMOTE_PORT, ((IPEndPoint)connection.Channel.RemoteAddress).Port); invokeContext.putIfAbsent(InvokeContext.BOLT_INVOKE_REQUEST_ID, cmd.Id); } }
/// <summary> /// Create invoke future with <seealso cref="InvokeContext"/>. </summary> /// <param name="conn"> </param> /// <param name="request"> </param> /// <param name="invokeContext"> </param> /// <param name="invokeCallback"> /// @return </param> //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: //ORIGINAL LINE: protected abstract InvokeFuture createInvokeFuture(final Connection conn, final RemotingCommand request, final InvokeContext invokeContext, final InvokeCallback invokeCallback); protected internal abstract InvokeFuture createInvokeFuture(Connection conn, RemotingCommand request, InvokeContext invokeContext, InvokeCallback invokeCallback);
/// <summary> /// Create invoke future with <seealso cref="InvokeContext"/>. </summary> /// <param name="request"> </param> /// <param name="invokeContext"> /// @return </param> //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: //ORIGINAL LINE: protected abstract InvokeFuture createInvokeFuture(final RemotingCommand request, final InvokeContext invokeContext); protected internal abstract InvokeFuture createInvokeFuture(RemotingCommand request, InvokeContext invokeContext);
/// <seealso cref= BaseRemoting#createInvokeFuture(RemotingCommand, InvokeContext) </seealso> protected internal override InvokeFuture createInvokeFuture(RemotingCommand request, InvokeContext invokeContext) { return(new DefaultInvokeFuture(request.Id, null, null, request.ProtocolCode.FirstByte, CommandFactory, invokeContext)); }
protected internal abstract void preProcessInvokeContext(InvokeContext invokeContext, RemotingCommand cmd, Connection connection);
/// <seealso cref= AbstractRemotingProcessor#process(RemotingContext, RemotingCommand, java.util.concurrent.ExecutorService) </seealso> public override void process(RemotingContext ctx, RemotingCommand cmd, ExecutorService defaultExecutor) { var rpcRequestCommand = (RpcRequestCommand)cmd; if (!deserializeRequestCommand(ctx, rpcRequestCommand, RpcDeserializeLevel.DESERIALIZE_CLAZZ)) { return; } UserProcessor userProcessor = ctx.getUserProcessor(rpcRequestCommand.RequestClass); if (userProcessor == null) { string errMsg = "No user processor found for request: " + rpcRequestCommand.RequestClass; logger.LogError(errMsg); sendResponseIfNecessary(ctx, rpcRequestCommand.Type, CommandFactory.createExceptionResponse(cmd.Id, errMsg)); return; // must end process } // set timeout check state from user's processor ctx.setTimeoutDiscard(userProcessor.timeoutDiscard()); // to check whether to process in io thread if (userProcessor.processInIOThread()) { if (!deserializeRequestCommand(ctx, rpcRequestCommand, RpcDeserializeLevel.DESERIALIZE_ALL)) { return; } // process in io thread new ProcessTask(this, ctx, rpcRequestCommand).run(); return; // end } Executor executor; // to check whether get executor using executor selector if (null == userProcessor.ExecutorSelector) { executor = userProcessor.Executor; } else { // in case haven't deserialized in io thread // it need to deserialize clazz and header before using executor dispath strategy if (!deserializeRequestCommand(ctx, rpcRequestCommand, RpcDeserializeLevel.DESERIALIZE_HEADER)) { return; } //try get executor with strategy executor = userProcessor.ExecutorSelector.select(rpcRequestCommand.RequestClass, rpcRequestCommand.RequestHeader); } // Till now, if executor still null, then try default if (executor == null) { executor = Executor ?? defaultExecutor; } // use the final executor dispatch process task executor.execute(new ProcessTask(this, ctx, rpcRequestCommand)); }
/// <summary> /// Wrap the writeAndFlush method. /// </summary> /// <param name="msg"> /// @return </param> public virtual Task writeAndFlush(RemotingCommand msg) { return(channelContext.WriteAndFlushAsync(msg)); }
public override void doProcess(RemotingContext ctx, RemotingCommand msg) { doProcess(ctx, (RpcRequestCommand)msg); }
/// <seealso cref= BaseRemoting#createInvokeFuture(Connection, RemotingCommand, InvokeContext, InvokeCallback) </seealso> protected internal override InvokeFuture createInvokeFuture(Connection conn, RemotingCommand request, InvokeContext invokeContext, InvokeCallback invokeCallback) { return(new DefaultInvokeFuture(request.Id, new RpcInvokeCallbackListener(((IPEndPoint)conn.Channel?.RemoteAddress)?.ToString()), invokeCallback, request.ProtocolCode.FirstByte, CommandFactory, invokeContext)); }
/// <summary> /// Do the process. /// </summary> /// <param name="ctx"> RemotingContext </param> /// <param name="msg"> T </param> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public abstract void doProcess(RemotingContext ctx, T msg) throws Exception; public abstract void doProcess(RemotingContext ctx, RemotingCommand msg);
/// <seealso cref= InvokeFuture#putResponse(RemotingCommand) </seealso> public virtual void putResponse(RemotingCommand response) { responseCommand = (ResponseCommand)response; countDownLatch.countDown(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: @Override public void doProcess(RemotingContext ctx, RemotingCommand msg) throws Exception public override void doProcess(RemotingContext ctx, RemotingCommand msg) { logger.LogError("No processor available for command code {}, msgId {}", msg.CmdCode, msg.Id); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: @Override public void doProcess(com.alipay.remoting.RemotingContext ctx, com.alipay.remoting.RemotingCommand msg) throws Exception public override void doProcess(RemotingContext ctx, RemotingCommand msg) { heartBeatTimes.incrementAndGet(); logger.LogWarning("heart beat received:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")); }