org.apache.mina.transport.socket.DefaultSocketSessionConfig Java Examples
The following examples show how to use
org.apache.mina.transport.socket.DefaultSocketSessionConfig.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CIMNioSocketAcceptor.java From cim with Apache License 2.0 | 6 votes |
private void bindWebPort() throws IOException { /* * 预制websocket握手请求的处理 */ INNER_HANDLER_MAP.put(CIMConstant.CLIENT_WEBSOCKET_HANDSHAKE, new WebsocketHandler()); webAcceptor = new NioSocketAcceptor(); ((DefaultSocketSessionConfig) webAcceptor.getSessionConfig()).setKeepAlive(true); ((DefaultSocketSessionConfig) webAcceptor.getSessionConfig()).setTcpNoDelay(true); webAcceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new WebMessageCodecFactory())); webAcceptor.getFilterChain().addLast("logger", new LoggingFilter()); webAcceptor.getFilterChain().addLast("executor", new ExecutorFilter(createWorkerExecutor())); webAcceptor.setHandler(this); webAcceptor.bind(new InetSocketAddress(webPort)); String logBanner = "\n\n" + "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n" + "* *\n" + "* *\n" + "* Websocket Server started on port {}. *\n" + "* *\n" + "* *\n" + "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n"; LOGGER.info(logBanner, webPort); }
Example #2
Source File: NioSocketAcceptor.java From jane with GNU Lesser General Public License v3.0 | 6 votes |
private ServerSocketChannel open(InetSocketAddress localAddress) throws IOException { if (localAddress == null) return null; ServerSocketChannel channel = ServerSocketChannel.open(); try { channel.configureBlocking(false); channel.setOption(StandardSocketOptions.SO_REUSEADDR, Boolean.valueOf(reuseAddress)); DefaultSocketSessionConfig config = getSessionConfig(); if (config.getSendBufferSize() >= 0) channel.setOption(StandardSocketOptions.SO_SNDBUF, config.getSendBufferSize()); if (config.getReceiveBufferSize() >= 0) channel.setOption(StandardSocketOptions.SO_RCVBUF, config.getReceiveBufferSize()); try { channel.bind(localAddress, backlog); } catch (IOException ioe) { close(channel); throw new IOException("error while binding on " + localAddress, ioe); } channel.register(selector, SelectionKey.OP_ACCEPT); return channel; } catch (Throwable e) { close(channel); throw e; } }
Example #3
Source File: MinaSocketServer.java From jforgame with Apache License 2.0 | 5 votes |
private SocketSessionConfig getSessionConfig() { SocketSessionConfig config = new DefaultSocketSessionConfig(); config.setKeepAlive(true); config.setReuseAddress(true); return config; }
Example #4
Source File: CIMNioSocketAcceptor.java From cim with Apache License 2.0 | 5 votes |
private void bindAppPort() throws IOException { appAcceptor = new NioSocketAcceptor(); ((DefaultSocketSessionConfig) appAcceptor.getSessionConfig()).setKeepAlive(true); ((DefaultSocketSessionConfig) appAcceptor.getSessionConfig()).setTcpNoDelay(true); KeepAliveFilter keepAliveFilter = new KeepAliveFilter(this, IdleStatus.BOTH_IDLE); keepAliveFilter.setRequestInterval(IDLE_HEART_REQUEST_TIME); keepAliveFilter.setRequestTimeout(HEART_RESPONSE_TIME_OUT); keepAliveFilter.setForwardEvent(true); appAcceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new AppMessageCodecFactory())); appAcceptor.getFilterChain().addLast("logger", new LoggingFilter()); appAcceptor.getFilterChain().addLast("heartbeat", keepAliveFilter); appAcceptor.getFilterChain().addLast("executor", new ExecutorFilter(createWorkerExecutor())); appAcceptor.setHandler(this); appAcceptor.bind(new InetSocketAddress(appPort)); String logBanner = "\n\n" + "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n" + "* *\n" + "* *\n" + "* App Socket Server started on port {}. *\n" + "* *\n" + "* *\n" + "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n"; LOGGER.info(logBanner, appPort); }
Example #5
Source File: GameProtocolCodecFilterTest.java From gameserver with Apache License 2.0 | 5 votes |
private void encodeAndDecodeProxyMessage(XinqiProxyMessage response, boolean checkDecoder) throws Exception { ProtobufEncoder encoder = new ProtobufEncoder(); ProtobufDecoder decoder = new ProtobufDecoder(); final ArrayList<Object> results = new ArrayList<Object>(); IoSession session = createNiceMock(IoSession.class); expect(session.getTransportMetadata()).andReturn( new DefaultTransportMetadata("testprovider", "default", false, true, InetSocketAddress.class, DefaultSocketSessionConfig.class, SessionMessage.class)).anyTimes(); IoBuffer buffer = (IoBuffer)ProtobufEncoder.encodeXinqiProxyMessage(response); ProtocolDecoderOutput deout = createNiceMock(ProtocolDecoderOutput.class); if ( checkDecoder ) { deout.write(anyObject()); expectLastCall().andAnswer(new IAnswer<Object>() { @Override public Object answer() throws Throwable { results.add(getCurrentArguments()[0]); return null; } }).times(1); } replay(session); replay(deout); decoder.decode(session, buffer, deout); verify(session); verify(deout); if ( checkDecoder ) { XinqiProxyMessage decodeMsg = (XinqiProxyMessage)results.get(0); assertEquals(response.userSessionKey, decodeMsg.userSessionKey); assertEquals(response.xinqi.payload.getClass(), decodeMsg.xinqi.payload.getClass()); } }
Example #6
Source File: CrossServer.java From jforgame with Apache License 2.0 | 5 votes |
private SocketSessionConfig getSessionConfig() { SocketSessionConfig config = new DefaultSocketSessionConfig(); config.setKeepAlive(true); config.setReuseAddress(true); return config; }
Example #7
Source File: AIProtocolCodecFilterTest.java From gameserver with Apache License 2.0 | 4 votes |
private SessionAIMessage encodeAndDecode(SessionAIMessage sessionMessage) throws Exception { AIProtobufEncoder encoder = new AIProtobufEncoder(); AIProtobufDecoder decoder = new AIProtobufDecoder(); final ArrayList<Object> results = new ArrayList<Object>(); IoSession session = createNiceMock(IoSession.class); expect(session.getTransportMetadata()).andReturn( new DefaultTransportMetadata("testprovider", "default", false, true, InetSocketAddress.class, DefaultSocketSessionConfig.class, SessionMessage.class)).anyTimes(); ProtocolEncoderOutput out = createNiceMock(ProtocolEncoderOutput.class); out.write(anyObject()); expectLastCall().andAnswer(new IAnswer<Object>() { @Override public Object answer() throws Throwable { results.add(getCurrentArguments()[0]); return null; } }).anyTimes(); replay(session); replay(out); encoder.encode(session, sessionMessage, out); verify(session); verify(out); assertTrue(results.get(0) instanceof IoBuffer ); IoBuffer buffer = (IoBuffer)results.get(0); results.remove(0); ProtocolDecoderOutput deout = createNiceMock(ProtocolDecoderOutput.class); deout.write(anyObject()); expectLastCall().andAnswer(new IAnswer<Object>() { @Override public Object answer() throws Throwable { results.add(getCurrentArguments()[0]); return null; } }).times(1); replay(deout); decoder.decode(session, buffer, deout); verify(deout); SessionAIMessage decodeMsg = (SessionAIMessage)results.get(0); return decodeMsg; }
Example #8
Source File: ProxyConnector.java From neoscada with Eclipse Public License 1.0 | 4 votes |
/** * Creates a new proxy connector. */ public ProxyConnector() { super(new DefaultSocketSessionConfig(), null); }
Example #9
Source File: AbstractIoService.java From jane with GNU Lesser General Public License v3.0 | 4 votes |
@Override public final DefaultSocketSessionConfig getSessionConfig() { return sessionConfig; }
Example #10
Source File: NetManager.java From jane with GNU Lesser General Public License v3.0 | 4 votes |
/** * 获取用于客户端的mina网络配置并可以修改 */ public final DefaultSocketSessionConfig getClientConfig() { return getConnector().getSessionConfig(); }
Example #11
Source File: NetManager.java From jane with GNU Lesser General Public License v3.0 | 4 votes |
/** * 获取用于服务器端的mina网络配置并可以修改 */ public final DefaultSocketSessionConfig getServerConfig() { return getAcceptor().getSessionConfig(); }
Example #12
Source File: NioSocketConnector.java From neoscada with Eclipse Public License 1.0 | 4 votes |
/** * Constructor for {@link NioSocketConnector} with default configuration (multiple thread model). */ public NioSocketConnector() { super(new DefaultSocketSessionConfig(), NioProcessor.class); ((DefaultSocketSessionConfig) getSessionConfig()).init(this); }
Example #13
Source File: GameProtocolCodecFilterTest.java From gameserver with Apache License 2.0 | 4 votes |
private void encodeAndDecode(XinqiMessage response, boolean checkDecoder) throws Exception { ProtobufEncoder encoder = new ProtobufEncoder(); ProtobufDecoder decoder = new ProtobufDecoder(); final ArrayList<Object> results = new ArrayList<Object>(); IoSession session = createNiceMock(IoSession.class); expect(session.getTransportMetadata()).andReturn( new DefaultTransportMetadata("testprovider", "default", false, true, InetSocketAddress.class, DefaultSocketSessionConfig.class, SessionMessage.class)).anyTimes(); ProtocolEncoderOutput out = createNiceMock(ProtocolEncoderOutput.class); out.write(anyObject()); expectLastCall().andAnswer(new IAnswer<Object>() { @Override public Object answer() throws Throwable { results.add(getCurrentArguments()[0]); return null; } }); replay(session); replay(out); encoder.encode(session, response, out); verify(session); verify(out); assertTrue(results.get(0) instanceof IoBuffer ); IoBuffer buffer = (IoBuffer)results.get(0); results.remove(0); ProtocolDecoderOutput deout = createNiceMock(ProtocolDecoderOutput.class); if ( checkDecoder ) { deout.write(anyObject()); expectLastCall().andAnswer(new IAnswer<Object>() { @Override public Object answer() throws Throwable { results.add(getCurrentArguments()[0]); return null; } }).times(1); } replay(deout); decoder.decode(session, buffer, deout); verify(deout); if ( checkDecoder ) { XinqiMessage decodeMsg = (XinqiMessage)results.get(0); assertEquals(response.payload.getClass(), decodeMsg.payload.getClass()); } }
Example #14
Source File: NioSocketAcceptor.java From neoscada with Eclipse Public License 1.0 | 4 votes |
/** * Constructor for {@link NioSocketAcceptor} using default parameters (multiple thread model). */ public NioSocketAcceptor() { super(new DefaultSocketSessionConfig(), NioProcessor.class); ((DefaultSocketSessionConfig) getSessionConfig()).init(this); }
Example #15
Source File: NioSocketAcceptor.java From neoscada with Eclipse Public License 1.0 | 2 votes |
/** * Constructor for {@link NioSocketAcceptor} with a given {@link Executor} for handling * connection events and a given {@link IoProcessor} for handling I/O events, useful for * sharing the same processor and executor over multiple {@link IoService} of the same type. * @param executor the executor for connection * @param processor the processor for I/O operations */ public NioSocketAcceptor(Executor executor, IoProcessor<NioSession> processor) { super(new DefaultSocketSessionConfig(), executor, processor); ((DefaultSocketSessionConfig) getSessionConfig()).init(this); }
Example #16
Source File: NioSocketConnector.java From neoscada with Eclipse Public License 1.0 | 2 votes |
/** * Constructor for {@link NioSocketConnector} with default configuration, and * given number of {@link NioProcessor} for multithreading I/O operations * @param processorCount the number of processor to create and place in a * {@link SimpleIoProcessorPool} */ public NioSocketConnector(int processorCount) { super(new DefaultSocketSessionConfig(), NioProcessor.class, processorCount); ((DefaultSocketSessionConfig) getSessionConfig()).init(this); }
Example #17
Source File: NioSocketAcceptor.java From neoscada with Eclipse Public License 1.0 | 2 votes |
/** * Constructor for {@link NioSocketAcceptor} with default configuration but a * specific {@link IoProcessor}, useful for sharing the same processor over multiple * {@link IoService} of the same type. * @param processor the processor to use for managing I/O events */ public NioSocketAcceptor(IoProcessor<NioSession> processor) { super(new DefaultSocketSessionConfig(), processor); ((DefaultSocketSessionConfig) getSessionConfig()).init(this); }
Example #18
Source File: NioSocketAcceptor.java From neoscada with Eclipse Public License 1.0 | 2 votes |
/** * Constructor for {@link NioSocketAcceptor} using default parameters, and * given number of {@link NioProcessor} for multithreading I/O operations. * * @param processorCount the number of processor to create and place in a * {@link SimpleIoProcessorPool} */ public NioSocketAcceptor(int processorCount) { super(new DefaultSocketSessionConfig(), NioProcessor.class, processorCount); ((DefaultSocketSessionConfig) getSessionConfig()).init(this); }
Example #19
Source File: NioSocketConnector.java From neoscada with Eclipse Public License 1.0 | 2 votes |
/** * Constructor for {@link NioSocketConnector} with default configuration with default configuration which will use a built-in * thread pool executor to manage the default number of processor instances. The processor class must have * a constructor that accepts ExecutorService or Executor as its single argument, or, failing that, a * no-arg constructor. The default number of instances is equal to the number of processor cores * in the system, plus one. * * @param processorClass the processor class. * @see org.apache.mina.core.service.SimpleIoProcessorPool#SimpleIoProcessorPool(Class, Executor, int) * @see org.apache.mina.core.service.SimpleIoProcessorPool#DEFAULT_SIZE * @since 2.0.0-M4 */ public NioSocketConnector(Class<? extends IoProcessor<NioSession>> processorClass) { super(new DefaultSocketSessionConfig(), processorClass); }
Example #20
Source File: ProxyConnector.java From neoscada with Eclipse Public License 1.0 | 2 votes |
/** * Creates a new proxy connector. * * @param connector Connector used to establish proxy connections. */ public ProxyConnector(final SocketConnector connector) { this(connector, new DefaultSocketSessionConfig(), null); }
Example #21
Source File: NioSocketConnector.java From neoscada with Eclipse Public License 1.0 | 2 votes |
/** * Constructor for {@link NioSocketConnector} with default configuration which will use a built-in * thread pool executor to manage the given number of processor instances. The processor class must have * a constructor that accepts ExecutorService or Executor as its single argument, or, failing that, a * no-arg constructor. * * @param processorClass the processor class. * @param processorCount the number of processors to instantiate. * @see org.apache.mina.core.service.SimpleIoProcessorPool#SimpleIoProcessorPool(Class, Executor, int) * @since 2.0.0-M4 */ public NioSocketConnector(Class<? extends IoProcessor<NioSession>> processorClass, int processorCount) { super(new DefaultSocketSessionConfig(), processorClass, processorCount); }
Example #22
Source File: IoService.java From jane with GNU Lesser General Public License v3.0 | 2 votes |
/** * @return the default configuration of the new {@link IoSession}s created by this service. */ DefaultSocketSessionConfig getSessionConfig();
Example #23
Source File: NioSocketConnector.java From neoscada with Eclipse Public License 1.0 | 2 votes |
/** * Constructor for {@link NioSocketConnector} with a given {@link Executor} for handling * connection events and a given {@link IoProcessor} for handling I/O events, useful for sharing * the same processor and executor over multiple {@link IoService} of the same type. * @param executor the executor for connection * @param processor the processor for I/O operations */ public NioSocketConnector(Executor executor, IoProcessor<NioSession> processor) { super(new DefaultSocketSessionConfig(), executor, processor); ((DefaultSocketSessionConfig) getSessionConfig()).init(this); }
Example #24
Source File: NioSocketConnector.java From neoscada with Eclipse Public License 1.0 | 2 votes |
/** * Constructor for {@link NioSocketConnector} with default configuration but a * specific {@link IoProcessor}, useful for sharing the same processor over multiple * {@link IoService} of the same type. * @param processor the processor to use for managing I/O events */ public NioSocketConnector(IoProcessor<NioSession> processor) { super(new DefaultSocketSessionConfig(), processor); ((DefaultSocketSessionConfig) getSessionConfig()).init(this); }