public BlockingRpcServer(final Class<?> protocol, final Object instance, final InetSocketAddress bindAddress, final int workerNum) throws Exception { super(protocol.getSimpleName(), bindAddress); String serviceClassName = protocol.getName() + "$" + protocol.getSimpleName() + "Service"; Class<?> serviceClass = Class.forName(serviceClassName); Class<?> interfaceClass = Class.forName(serviceClassName + "$BlockingInterface"); Method method = serviceClass.getMethod( "newReflectiveBlockingService", interfaceClass); this.service = (BlockingService) method.invoke(null, instance); this.initializer = new ProtoChannelInitializer(new ServerHandler(), RpcRequest.getDefaultInstance()); super.init(this.initializer, workerNum); }
@Override public void operationComplete(final ChannelFuture future) throws Exception { if (future.isSuccess()) { getHandler().registerCallback(rpcRequest.getId(), callback); } else { if (!future.channel().isActive() && retry < maxRetryNum) { /* schedule the current request for the retry */ LOG.warn(future.cause() + " Try to reconnect :" + getKey().addr); final EventLoop loop = future.channel().eventLoop(); loop.schedule(new Runnable() { @Override public void run() { doConnect(getKey().addr).addListener(new GenericFutureListener<ChannelFuture>() { @Override public void operationComplete(ChannelFuture future) throws Exception { invoke(rpcRequest, callback, retry + 1); } }); } }, RpcConstants.DEFAULT_PAUSE, TimeUnit.MILLISECONDS); } else { /* Max retry count has been exceeded or internal failure */ getHandler().registerCallback(rpcRequest.getId(), callback); getHandler().exceptionCaught(getChannel().pipeline().lastContext(), new RecoverableException(rpcRequest.getId(), future.cause())); } } } });
public int getSerializedSize() { int size = memoizedSerializedSize; if (size != -1) return size; size = 0; if (((bitField0_ & 0x00000001) == 0x00000001)) { size += com.google.protobuf.CodedOutputStream .computeInt32Size(1, id_); } if (((bitField0_ & 0x00000002) == 0x00000002)) { size += com.google.protobuf.CodedOutputStream .computeBytesSize(2, getMethodNameBytes()); } if (((bitField0_ & 0x00000004) == 0x00000004)) { size += com.google.protobuf.CodedOutputStream .computeBytesSize(3, requestMessage_); } size += getUnknownFields().getSerializedSize(); memoizedSerializedSize = size; return size; }
@Override protected void channelRead0(final ChannelHandlerContext ctx, final RpcRequest request) throws Exception { String methodName = request.getMethodName(); final MethodDescriptor methodDescriptor = service.getDescriptorForType().findMethodByName(methodName); exceptionCaught(ctx, new RemoteCallException(request.getId(), new NoSuchMethodException(methodName))); return; if (request.hasRequestMessage()) { paramProto = service.getRequestPrototype(methodDescriptor).newBuilderForType() .mergeFrom(request.getRequestMessage()).build(); final RpcCallback<Message> callback = !request.hasId() ? null : new RpcCallback<Message>() { exceptionCaught(ctx, e); } catch (Throwable throwable) { exceptionCaught(ctx, new RemoteCallException(request.getId(), methodDescriptor, throwable));
@Override protected void channelRead0(final ChannelHandlerContext ctx, final RpcRequest request) throws Exception { String methodName = request.getMethodName(); final MethodDescriptor methodDescriptor = service.getDescriptorForType().findMethodByName(methodName); exceptionCaught(ctx, new RemoteCallException(request.getId(), new NoSuchMethodException(methodName))); return; if (request.hasRequestMessage()) { paramProto = service.getRequestPrototype(methodDescriptor).newBuilderForType() .mergeFrom(request.getRequestMessage()).build(); final RpcCallback<Message> callback = !request.hasId() ? null : new RpcCallback<Message>() { exceptionCaught(ctx, e); } catch (Throwable throwable) { exceptionCaught(ctx, new RemoteCallException(request.getId(), methodDescriptor, throwable));
@Override protected void channelRead0(ChannelHandlerContext ctx, RpcRequest request) throws Exception { String methodName = request.getMethodName(); MethodDescriptor methodDescriptor = service.getDescriptorForType().findMethodByName(methodName); throw new RemoteCallException(request.getId(), new NoSuchMethodException(methodName)); if (request.hasRequestMessage()) { try { paramProto = service.getRequestPrototype(methodDescriptor).newBuilderForType() .mergeFrom(request.getRequestMessage()).build(); throw new RemoteCallException(request.getId(), methodDescriptor, t); returnValue = service.callBlockingMethod(methodDescriptor, controller, paramProto); } catch (Throwable t) { throw new RemoteCallException(request.getId(), methodDescriptor, t); RpcResponse.Builder builder = RpcResponse.newBuilder().setId(request.getId());
@Override protected void channelRead0(final ChannelHandlerContext ctx, final RpcRequest request) throws Exception { String methodName = request.getMethodName(); final MethodDescriptor methodDescriptor = service.getDescriptorForType().findMethodByName(methodName); if (methodDescriptor == null) { exceptionCaught(ctx, new RemoteCallException(request.getId(), new NoSuchMethodException(methodName))); return; } try { Message paramProto = null; if (request.hasRequestMessage()) { paramProto = service.getRequestPrototype(methodDescriptor).newBuilderForType() .mergeFrom(request.getRequestMessage()).build(); } RpcController controller = new NettyRpcController(); Message returnValue = service.callBlockingMethod(methodDescriptor, controller, paramProto); RpcProtos.RpcResponse.Builder builder = RpcProtos.RpcResponse.newBuilder().setId(request.getId()); if (returnValue != null) { builder.setResponseMessage(returnValue.toByteString()); } if (controller.failed()) { builder.setErrorMessage(controller.errorText()); } ctx.writeAndFlush(builder.build()); } catch (RemoteCallException e) { exceptionCaught(ctx, e); } catch (Throwable throwable) { exceptionCaught(ctx, new RemoteCallException(request.getId(), methodDescriptor, throwable)); } }
@Override protected void channelRead0(final ChannelHandlerContext ctx, final RpcRequest request) throws Exception { String methodName = request.getMethodName(); MethodDescriptor methodDescriptor = service.getDescriptorForType().findMethodByName(methodName); throw new RemoteCallException(request.getId(), new NoSuchMethodException(methodName)); if (request.hasRequestMessage()) { try { paramProto = service.getRequestPrototype(methodDescriptor).newBuilderForType() .mergeFrom(request.getRequestMessage()).build(); } catch (Throwable t) { throw new RemoteCallException(request.getId(), methodDescriptor, t); RpcCallback<Message> callback = !request.hasId() ? null : new RpcCallback<Message>() {
@Override public void operationComplete(final ChannelFuture future) throws Exception { if (future.isSuccess()) { getHandler().registerCallback(rpcRequest.getId(), callback); } else { if (!future.channel().isActive() && retry < maxRetryNum) { /* schedule the current request for the retry */ LOG.warn(future.cause() + " Try to reconnect :" + getKey().addr); final EventLoop loop = future.channel().eventLoop(); loop.schedule(new Runnable() { @Override public void run() { doConnect(getKey().addr).addListener(new GenericFutureListener<ChannelFuture>() { @Override public void operationComplete(ChannelFuture future) throws Exception { invoke(rpcRequest, callback, retry + 1); } }); } }, RpcConstants.DEFAULT_PAUSE, TimeUnit.MILLISECONDS); } else { /* Max retry count has been exceeded or internal failure */ getHandler().registerCallback(rpcRequest.getId(), callback); getHandler().exceptionCaught(getChannel().pipeline().lastContext(), new RecoverableException(rpcRequest.getId(), future.cause())); } } } });
@Override protected void channelRead0(final ChannelHandlerContext ctx, final RpcRequest request) throws Exception { String methodName = request.getMethodName(); final MethodDescriptor methodDescriptor = service.getDescriptorForType().findMethodByName(methodName); if (methodDescriptor == null) { exceptionCaught(ctx, new RemoteCallException(request.getId(), new NoSuchMethodException(methodName))); return; } try { Message paramProto = null; if (request.hasRequestMessage()) { paramProto = service.getRequestPrototype(methodDescriptor).newBuilderForType() .mergeFrom(request.getRequestMessage()).build(); } RpcController controller = new NettyRpcController(); Message returnValue = service.callBlockingMethod(methodDescriptor, controller, paramProto); RpcProtos.RpcResponse.Builder builder = RpcProtos.RpcResponse.newBuilder().setId(request.getId()); if (returnValue != null) { builder.setResponseMessage(returnValue.toByteString()); } if (controller.failed()) { builder.setErrorMessage(controller.errorText()); } ctx.writeAndFlush(builder.build()); } catch (RemoteCallException e) { exceptionCaught(ctx, e); } catch (Throwable throwable) { exceptionCaught(ctx, new RemoteCallException(request.getId(), methodDescriptor, throwable)); } }
public int getSerializedSize() { int size = memoizedSerializedSize; if (size != -1) return size; size = 0; if (((bitField0_ & 0x00000001) == 0x00000001)) { size += com.google.protobuf.CodedOutputStream .computeInt32Size(1, id_); } if (((bitField0_ & 0x00000002) == 0x00000002)) { size += com.google.protobuf.CodedOutputStream .computeBytesSize(2, getMethodNameBytes()); } if (((bitField0_ & 0x00000004) == 0x00000004)) { size += com.google.protobuf.CodedOutputStream .computeBytesSize(3, requestMessage_); } size += getUnknownFields().getSerializedSize(); memoizedSerializedSize = size; return size; }
public org.apache.tajo.rpc.RpcProtos.RpcRequest buildPartial() { org.apache.tajo.rpc.RpcProtos.RpcRequest result = new org.apache.tajo.rpc.RpcProtos.RpcRequest(this); int from_bitField0_ = bitField0_; int to_bitField0_ = 0; if (((from_bitField0_ & 0x00000001) == 0x00000001)) { to_bitField0_ |= 0x00000001; } result.id_ = id_; if (((from_bitField0_ & 0x00000002) == 0x00000002)) { to_bitField0_ |= 0x00000002; } result.methodName_ = methodName_; if (((from_bitField0_ & 0x00000004) == 0x00000004)) { to_bitField0_ |= 0x00000004; } result.requestMessage_ = requestMessage_; result.bitField0_ = to_bitField0_; onBuilt(); return result; }
public org.apache.tajo.rpc.RpcProtos.RpcRequest buildPartial() { org.apache.tajo.rpc.RpcProtos.RpcRequest result = new org.apache.tajo.rpc.RpcProtos.RpcRequest(this); int from_bitField0_ = bitField0_; int to_bitField0_ = 0; if (((from_bitField0_ & 0x00000001) == 0x00000001)) { to_bitField0_ |= 0x00000001; } result.id_ = id_; if (((from_bitField0_ & 0x00000002) == 0x00000002)) { to_bitField0_ |= 0x00000002; } result.methodName_ = methodName_; if (((from_bitField0_ & 0x00000004) == 0x00000004)) { to_bitField0_ |= 0x00000004; } result.requestMessage_ = requestMessage_; result.bitField0_ = to_bitField0_; onBuilt(); return result; }
public org.apache.tajo.rpc.RpcProtos.RpcRequest buildPartial() { org.apache.tajo.rpc.RpcProtos.RpcRequest result = new org.apache.tajo.rpc.RpcProtos.RpcRequest(this); int from_bitField0_ = bitField0_; int to_bitField0_ = 0; if (((from_bitField0_ & 0x00000001) == 0x00000001)) { to_bitField0_ |= 0x00000001; } result.id_ = id_; if (((from_bitField0_ & 0x00000002) == 0x00000002)) { to_bitField0_ |= 0x00000002; } result.methodName_ = methodName_; if (((from_bitField0_ & 0x00000004) == 0x00000004)) { to_bitField0_ |= 0x00000004; } result.requestMessage_ = requestMessage_; result.bitField0_ = to_bitField0_; onBuilt(); return result; }
public int getSerializedSize() { int size = memoizedSerializedSize; if (size != -1) return size; size = 0; if (((bitField0_ & 0x00000001) == 0x00000001)) { size += com.google.protobuf.CodedOutputStream .computeInt32Size(1, id_); } if (((bitField0_ & 0x00000002) == 0x00000002)) { size += com.google.protobuf.CodedOutputStream .computeBytesSize(2, getMethodNameBytes()); } if (((bitField0_ & 0x00000004) == 0x00000004)) { size += com.google.protobuf.CodedOutputStream .computeBytesSize(3, requestMessage_); } size += getUnknownFields().getSerializedSize(); memoizedSerializedSize = size; return size; }
public BlockingRpcServer(final Class<?> protocol, final Object instance, final InetSocketAddress bindAddress, final int threads) throws Exception { super(protocol.getSimpleName(), bindAddress); String serviceClassName = protocol.getName() + "$" + protocol.getSimpleName() + "Service"; Class<?> serviceClass = Class.forName(serviceClassName); Class<?> interfaceClass = Class.forName(serviceClassName + "$BlockingInterface"); Method method = serviceClass.getMethod( "newReflectiveBlockingService", interfaceClass); this.service = (BlockingService) method.invoke(null, instance); this.initializer = new ProtoServerChannelInitializer(new ServerHandler(), RpcRequest.getDefaultInstance()); super.init(this.initializer, threads); }
public BlockingRpcServer(final Class<?> protocol, final Object instance, final InetSocketAddress bindAddress, final int threads) throws Exception { super(protocol.getSimpleName(), bindAddress); String serviceClassName = protocol.getName() + "$" + protocol.getSimpleName() + "Service"; Class<?> serviceClass = Class.forName(serviceClassName); Class<?> interfaceClass = Class.forName(serviceClassName + "$BlockingInterface"); Method method = serviceClass.getMethod( "newReflectiveBlockingService", interfaceClass); this.service = (BlockingService) method.invoke(null, instance); this.initializer = new ProtoServerChannelInitializer(new ServerHandler(), RpcRequest.getDefaultInstance()); super.init(this.initializer, threads); }
public AsyncRpcServer(final Class<?> protocol, final Object instance, final InetSocketAddress bindAddress, final int workerNum) throws Exception { super(protocol.getSimpleName(), bindAddress); String serviceClassName = protocol.getName() + "$" + protocol.getSimpleName() + "Service"; Class<?> serviceClass = Class.forName(serviceClassName); Class<?> interfaceClass = Class.forName(serviceClassName + "$Interface"); Method method = serviceClass.getMethod("newReflectiveService", interfaceClass); this.service = (Service) method.invoke(null, instance); this.initializer = new ProtoChannelInitializer(new ServerHandler(), RpcRequest.getDefaultInstance()); super.init(this.initializer, workerNum); }
public AsyncRpcServer(final Class<?> protocol, final Object instance, final InetSocketAddress bindAddress, final int threads) throws Exception { super(protocol.getSimpleName(), bindAddress); String serviceClassName = protocol.getName() + "$" + protocol.getSimpleName() + "Service"; Class<?> serviceClass = Class.forName(serviceClassName); Class<?> interfaceClass = Class.forName(serviceClassName + "$Interface"); Method method = serviceClass.getMethod("newReflectiveService", interfaceClass); this.service = (Service) method.invoke(null, instance); this.initializer = new ProtoServerChannelInitializer(new ServerHandler(), RpcRequest.getDefaultInstance()); super.init(this.initializer, threads); }
public Builder mergeFrom(org.apache.tajo.rpc.RpcProtos.RpcRequest other) { if (other == org.apache.tajo.rpc.RpcProtos.RpcRequest.getDefaultInstance()) return this; if (other.hasId()) { setId(other.getId()); } if (other.hasMethodName()) { bitField0_ |= 0x00000002; methodName_ = other.methodName_; onChanged(); } if (other.hasRequestMessage()) { setRequestMessage(other.getRequestMessage()); } this.mergeUnknownFields(other.getUnknownFields()); return this; }