ing
This commit is contained in:
parent
b1253242d9
commit
55c6a58f37
|
@ -7,5 +7,8 @@ public class Container {
|
|||
public static final String PIDFILE_PATH = "CONTAINER_PIDFILE_PATH";
|
||||
public static final String CRAWLERS = "CONTAINER_CRAWLERS";
|
||||
public static final String PIPELINE_CHANNEL_HANDLERS = "CONTAINER_PIPELINE_CHANNEL_HANDLERS";
|
||||
public static final String RPC_SERVER_CODEC = "CONTAINER_RPC_SERVER_CODEC";
|
||||
public static final String RPC_REGISTRY = "CONTAINER_RPC_REGISTRY";
|
||||
public static final String RPC_INVOKER = "CONTAINER_RPC_INVOKER";
|
||||
|
||||
}
|
|
@ -60,7 +60,7 @@ public class ContainerConfiguration {
|
|||
return new LoggingHandler(LogLevel.INFO);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Bean(Container.RPC_SERVER_CODEC)
|
||||
public RPCServerCodec rpcServerCodec() {
|
||||
if (null != gson) {
|
||||
return new JSONRPCServerCodec(gson);
|
||||
|
@ -69,7 +69,7 @@ public class ContainerConfiguration {
|
|||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Bean({Container.RPC_INVOKER, Container.RPC_REGISTRY})
|
||||
public RPCRegistry rpcRegistry() {
|
||||
return new RPCRegistry();
|
||||
}
|
||||
|
|
|
@ -6,12 +6,15 @@ import com.loafle.commons.rpc.protocol.RPCServerRequestCodec;
|
|||
import com.loafle.commons.rpc.registry.RPCInvoker;
|
||||
import com.loafle.commons.server.socket.handler.codec.SocketFrame;
|
||||
import com.loafle.commons.server.socket.handler.codec.TextSocketFrame;
|
||||
import com.loafle.overflow.container.Container;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
|
||||
|
@ -23,8 +26,10 @@ public class RPCServerHandler extends SimpleChannelInboundHandler<SocketFrame> {
|
|||
private static final Logger logger = LoggerFactory.getLogger(RPCServerHandler.class);
|
||||
|
||||
@Autowired
|
||||
@Qualifier(Container.RPC_SERVER_CODEC)
|
||||
private RPCServerCodec serverCodec;
|
||||
@Autowired
|
||||
@Autowired()
|
||||
@Qualifier(Container.RPC_INVOKER)
|
||||
private RPCInvoker rpcInvoker;
|
||||
|
||||
public RPCServerHandler() {
|
||||
|
@ -33,13 +38,15 @@ public class RPCServerHandler extends SimpleChannelInboundHandler<SocketFrame> {
|
|||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, SocketFrame frame) throws Exception {
|
||||
if (frame instanceof TextSocketFrame) {
|
||||
ByteBuf buff = null;
|
||||
byte[] requestBytes = null;
|
||||
RPCServerRequestCodec requestCodec = null;
|
||||
Object reply = null;
|
||||
RPCException error = null;
|
||||
try {
|
||||
requestBytes = new byte[frame.content().readableBytes()];
|
||||
frame.content().readBytes(requestBytes);
|
||||
buff = frame.content();
|
||||
requestBytes = new byte[buff.readableBytes()];
|
||||
buff.getBytes(buff.readerIndex(), requestBytes);
|
||||
|
||||
requestCodec = this.serverCodec.request(requestBytes);
|
||||
reply = this.rpcInvoker.invoke(requestCodec);
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.Map;
|
|||
|
||||
import com.loafle.commons.rpc.RPCException;
|
||||
import com.loafle.commons.rpc.registry.RPCRegistry;
|
||||
import com.loafle.overflow.container.Container;
|
||||
import com.loafle.overflow.core.annotation.ProbeAPI;
|
||||
import com.loafle.overflow.core.annotation.RPCService;
|
||||
|
||||
|
@ -14,6 +15,7 @@ import org.slf4j.LoggerFactory;
|
|||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
|
@ -29,6 +31,7 @@ public class Service implements InitializingBean, ApplicationContextAware {
|
|||
private ApplicationContext applicationContext;
|
||||
|
||||
@Autowired
|
||||
@Qualifier(Container.RPC_REGISTRY)
|
||||
private RPCRegistry rpcRegistry;
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue
Block a user