From bf5a8a7ec430579007aed7dfa3d15914a12fd7cb Mon Sep 17 00:00:00 2001 From: crusader Date: Fri, 4 May 2018 17:22:31 +0900 Subject: [PATCH] ing --- .../loafle/overflow/container/Container.java | 1 + .../configuration/ContainerConfiguration.java | 24 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/loafle/overflow/container/Container.java b/src/main/java/com/loafle/overflow/container/Container.java index f68afa6..ba6c3a6 100644 --- a/src/main/java/com/loafle/overflow/container/Container.java +++ b/src/main/java/com/loafle/overflow/container/Container.java @@ -5,6 +5,7 @@ package com.loafle.overflow.container; */ public class Container { public static final String PORT_NUMBER = "CONTAINER_PORT_NUMBER"; + public static final String CHANNEL_HANDLERS = "CONTAINER_CHANNEL_HANDLERS"; public static final String CRAWLERS = "CONTAINER_CRAWLERS"; public static final String SERVICES = "CONTAINER_SERVICES"; public static final String RPC_CLIENT_CODEC = "CONTAINER_RPC_CLIENT_CODEC"; diff --git a/src/main/java/com/loafle/overflow/container/configuration/ContainerConfiguration.java b/src/main/java/com/loafle/overflow/container/configuration/ContainerConfiguration.java index 9355475..738756a 100644 --- a/src/main/java/com/loafle/overflow/container/configuration/ContainerConfiguration.java +++ b/src/main/java/com/loafle/overflow/container/configuration/ContainerConfiguration.java @@ -2,6 +2,8 @@ package com.loafle.overflow.container.configuration; import java.net.InetSocketAddress; import java.net.SocketAddress; +import java.net.URI; +import java.net.URISyntaxException; import java.util.Arrays; import java.util.List; @@ -11,11 +13,13 @@ import com.loafle.commons.rpc.protocol.RPCClientCodec; import com.loafle.commons.rpc.protocol.json.JSONRPCClientCodec; import com.loafle.commons.rpc.registry.RPCRegistry; import com.loafle.commons.server.websocket.client.Client; +import com.loafle.overflow.config.container.ContainerProtocol; import com.loafle.overflow.container.Container; import com.loafle.overflow.container.client.handler.RPCClientHandler; import org.codehaus.jackson.map.ObjectMapper; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -38,6 +42,10 @@ public class ContainerConfiguration { @Autowired() private ObjectMapper objectMapper; + @Autowired(required=false) + @Qualifier(Container.CHANNEL_HANDLERS) + private List extraChannelHandlers; + @Bean(Client.CHANNEL_CLASS) public Class channelClass() { return NioSocketChannel.class; @@ -45,7 +53,17 @@ public class ContainerConfiguration { @Bean(Client.CHANNEL_HANDLERS) public List channelHandlers() { - return Arrays.asList(new RPCClientHandler()); + List chs = Arrays.asList(new RPCClientHandler()); + if (null != this.extraChannelHandlers) { + chs.addAll(this.extraChannelHandlers); + } + + return chs; + } + + @Bean(Client.SERVER_URI) + public URI probeURI() throws URISyntaxException { + return new URI(String.format("ws://127.0.0.1:%d%s", portNumber, ContainerProtocol.HTTPEntry_Container)); } @Bean(Container.RPC_CLIENT_CODEC) @@ -58,8 +76,4 @@ public class ContainerConfiguration { return new RPCRegistry(); } - @Bean(Client.SOCKET_ADDRESS) - public SocketAddress address() { - return new InetSocketAddress("127.0.0.1", portNumber); - } } \ No newline at end of file