org.apache.mina.core.service.IoHandler Java Examples
The following examples show how to use
org.apache.mina.core.service.IoHandler.
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: MinaTcpClient.java From game-server with MIT License | 6 votes |
/** * 初始化tcp连接 * @param clientProtocolHandler */ private void init(IoHandler clientProtocolHandler) { connector = new NioSocketConnector(); DefaultIoFilterChainBuilder chain = connector.getFilterChain(); chain.addLast("codec", codecFilter); if(filters != null){ filters.forEach((key, filter)->{ if("ssl".equalsIgnoreCase(key) || "tls".equalsIgnoreCase(key)){ //ssl过滤器必须添加到首部 chain.addFirst(key, filter); }else{ chain.addLast(key, filter); } }); } connector.setHandler(clientProtocolHandler); connector.setConnectTimeoutMillis(60000L); connector.setConnectTimeoutCheckInterval(10000); }
Example #2
Source File: NetManager.java From GameServer with Apache License 2.0 | 6 votes |
public void startListner(IoHandler iohandler,int listenPort) throws Exception{ acceptor = new NioSocketAcceptor(); acceptor.setBacklog(100); acceptor.setReuseAddress(true); acceptor.setHandler(iohandler); DefaultIoFilterChainBuilder chain = acceptor.getFilterChain(); IoFilter protocol = new ProtocolCodecFilter(new GameProtocolcodecFactory()); chain.addLast("codec", protocol); threadpool = new OrderedThreadPoolExecutor(500); threadpool.setThreadFactory(new ServerThreadFactory("OrderedThreadPool")); chain.addLast("threadPool", new ExecutorFilter(threadpool)); int recsize = 5120; int sendsize = 40480; int timeout = 10; SocketSessionConfig sc = acceptor.getSessionConfig(); sc.setReuseAddress(true);// 设置每一个非主监听连接的端口可以重用 sc.setReceiveBufferSize(recsize);// 设置输入缓冲区的大小 sc.setSendBufferSize(sendsize);// 设置输出缓冲区的大小 sc.setTcpNoDelay(true);// flush函数的调用 设置为非延迟发送,为true则不组装成大包发送,收到东西马上发出 sc.setSoLinger(0); sc.setIdleTime(IdleStatus.READER_IDLE, timeout); acceptor.bind(new InetSocketAddress(listenPort)); }
Example #3
Source File: TCPTestServer.java From streamsx.topology with Apache License 2.0 | 6 votes |
/** * Initialize the MINA server. */ public TCPTestServer(int port, boolean loopback, IoHandler handler) throws Exception { acceptor = new NioSocketAcceptor(); IoFilter tupleEncoder = new ProtocolCodecFilter(new TestTupleEncoder(), new TestTupleDecoder()); acceptor.getFilterChain().addLast("testtuples", tupleEncoder); acceptor.setHandler(handler); // Get the bind address now so the majority of // errors are caught at initialization time. bindAddress = new InetSocketAddress( loopback ? InetAddress.getLoopbackAddress() : InetAddress.getLocalHost(), port); }
Example #4
Source File: ProxyConnector.java From neoscada with Eclipse Public License 1.0 | 5 votes |
/** * Connects to the specified <code>address</code>. If communication starts * successfully, events are fired to the connector's <code>handler</code>. * * @param remoteAddress the remote address to connect to * @param localAddress the local address * @param sessionInitializer the session initializer * @return {@link ConnectFuture} that will tell the result of the connection attempt */ @SuppressWarnings("unchecked") @Override protected ConnectFuture connect0(final SocketAddress remoteAddress, final SocketAddress localAddress, final IoSessionInitializer<? extends ConnectFuture> sessionInitializer) { if (!proxyIoSession.isReconnectionNeeded()) { // First connection IoHandler handler = getHandler(); if (!(handler instanceof AbstractProxyIoHandler)) { throw new IllegalArgumentException("IoHandler must be an instance of AbstractProxyIoHandler"); } connector.setHandler(handler); future = new DefaultConnectFuture(); } ConnectFuture conFuture = connector.connect(proxyIoSession.getProxyAddress(), new ProxyIoSessionInitializer( sessionInitializer, proxyIoSession)); // If proxy does not use reconnection like socks the connector's // future is returned. If we're in the middle of a reconnection // then we send back the connector's future which is only used // internally while <code>future</code> will be used to notify // the user of the connection state. if (proxyIoSession.getRequest() instanceof SocksProxyRequest || proxyIoSession.isReconnectionNeeded()) { return conFuture; } return future; }
Example #5
Source File: MinaUdpClient.java From game-server with MIT License | 5 votes |
/** * 初始化tcp连接 * * @param clientProtocolHandler */ private void init(IoHandler clientProtocolHandler) { connector = new NioDatagramConnector(); connector.getFilterChain().addLast("codec", codecFilter); connector.setHandler(clientProtocolHandler); connector.setConnectTimeoutMillis(60000L); connector.setConnectTimeoutCheckInterval(10000); }
Example #6
Source File: MinaUdpClient.java From game-server with MIT License | 5 votes |
/** * <p>Constructor for MinaUdpClient.</p> * * @param minaClientConfig a {@link com.jzy.game.engine.mina.config.MinaClientConfig} object. * @param clientProtocolHandler a {@link org.apache.mina.core.service.IoHandler} object. * @param factory a {@link com.jzy.game.engine.mina.code.ProtocolCodecFactoryImpl} object. */ public MinaUdpClient(MinaClientConfig minaClientConfig, IoHandler clientProtocolHandler, ProtocolCodecFactoryImpl factory) { this.minaClientConfig = minaClientConfig; this.clientProtocolHandler = clientProtocolHandler; this.factory = factory; codecFilter =new ProtocolCodecFilter(this.factory); init(this.clientProtocolHandler); setMinaClientConfig(minaClientConfig); }
Example #7
Source File: SocketConnectorSupplier.java From sumk with Apache License 2.0 | 5 votes |
private IoHandler createClientHandler() { String clzName = AppInfo.get("sumk.rpc.clientHandler", "org.yx.rpc.client.ClientHandler"); try { return (IoHandler) Loader.newInstance(clzName, null, null); } catch (Exception e) { Logs.rpc().error("初始化clientHandler失败", e); throw ExceptionUtil.toRuntimeException(e); } }
Example #8
Source File: MinaServer.java From sumk with Apache License 2.0 | 5 votes |
private IoHandler createServerHandler(List<RequestHandler> handlers) { String clzName = AppInfo.get("sumk.rpc.serverHandler", "org.yx.rpc.server.ServerHandler"); try { return (IoHandler) Loader.newInstance(clzName, new Object[] { handlers }, new Class<?>[] { List.class }); } catch (Exception e) { Logs.rpc().error("初始化serverHandler失败", e); throw ExceptionUtil.toRuntimeException(e); } }
Example #9
Source File: MinaMultiTcpClient.java From game-server with MIT License | 5 votes |
/** * 添加客户端 * * @param service a {@link com.jzy.game.engine.mina.service.MinaClientService} object. * @param config a {@link com.jzy.game.engine.mina.config.MinaClientConfig} object. * @param clientProtocolHandler a {@link org.apache.mina.core.service.IoHandler} object. * @param factory a {@link com.jzy.game.engine.mina.code.ProtocolCodecFactoryImpl} object. */ public void addTcpClient(MinaClientService service, MinaClientConfig config, IoHandler clientProtocolHandler, ProtocolCodecFactoryImpl factory) { MinaTcpClient client = null; if (tcpClients.containsKey(config.getId())) { client = tcpClients.get(config.getId()); client.setMinaClientConfig(config); return; } client = new MinaTcpClient(service, config, clientProtocolHandler, factory); tcpClients.put(config.getId(), client); }
Example #10
Source File: MinaMultiTcpClient.java From game-server with MIT License | 5 votes |
/** * 添加客户端 * * @param service a {@link com.jzy.game.engine.mina.service.MinaClientService} object. * @param config a {@link com.jzy.game.engine.mina.config.MinaClientConfig} object. * @param clientProtocolHandler a {@link org.apache.mina.core.service.IoHandler} object. */ public void addTcpClient(MinaClientService service, MinaClientConfig config, IoHandler clientProtocolHandler) { MinaTcpClient client = null; if (tcpClients.containsKey(config.getId())) { client = tcpClients.get(config.getId()); client.setMinaClientConfig(config); return; } client = new MinaTcpClient(service, config, clientProtocolHandler); tcpClients.put(config.getId(), client); }
Example #11
Source File: DummySession.java From neoscada with Eclipse Public License 1.0 | 5 votes |
/** * Sets the {@link IoHandler} which handles this session. */ public void setHandler(IoHandler handler) { if (handler == null) { throw new IllegalArgumentException("handler"); } this.handler = handler; }
Example #12
Source File: VmPipeSession.java From neoscada with Eclipse Public License 1.0 | 5 votes |
VmPipeSession(IoService service, IoServiceListenerSupport serviceListeners, VmPipeAddress localAddress, IoHandler handler, VmPipe remoteEntry) { super(service); config = new DefaultVmPipeSessionConfig(); this.serviceListeners = serviceListeners; lock = new ReentrantLock(); this.localAddress = localAddress; remoteAddress = serviceAddress = remoteEntry.getAddress(); filterChain = new VmPipeFilterChain(this); receivedMessageQueue = new LinkedBlockingQueue<Object>(); remoteSession = new VmPipeSession(this, remoteEntry); }
Example #13
Source File: GameClient.java From gameserver with Apache License 2.0 | 5 votes |
public GameClient(String remoteHost, int remotePort, IoHandler handler) { this.remoteHost = remoteHost; this.remotePort = remotePort; if ( handler == null ) { this.handler = this; } else { this.handler = handler; } }
Example #14
Source File: SimpleClient.java From gameserver with Apache License 2.0 | 5 votes |
/** * Create a new Client * @param filter * @param handler * @param remoteHost * @param remotePort */ public SimpleClient(IoFilter filter, IoHandler handler, String remoteHost, int remotePort) { this.ioFilter = filter; this.ioHandler = handler; this.remoteHost = remoteHost; this.remotePort = remotePort; this.connectKey = StringUtil.concat(remoteHost, Constant.COLON, remotePort); this.clientNo = SimpleClient.totalClientNo++; }
Example #15
Source File: ReloadProtocolCodecFilter.java From gameserver with Apache License 2.0 | 5 votes |
public ReloadProtocolCodecFilter(String ioFilterClassName, String ioHandlerClassName){ try { this.ioFilterClassName = ioFilterClassName; this.ioHandlerClassName = ioHandlerClassName; this.classLoader = ReloadClassLoader.currentClassLoader(); Class ioFilterClass = this.classLoader.loadClass(ioFilterClassName); Class ioHandlerClass = this.classLoader.loadClass(ioHandlerClassName); this.ioFilter = (IoFilter)ioFilterClass.newInstance(); this.ioHandler = (IoHandler)ioHandlerClass.newInstance(); } catch (Throwable e) { log.error("Failed to create ReloadProtocolCodecFilter", e); } }
Example #16
Source File: MinaTcpClient.java From game-server with MIT License | 5 votes |
/** * 使用默认消息解码工厂 * * @param service a {@link com.jzy.game.engine.mina.service.MinaClientService} object. * @param minaClientConfig a {@link com.jzy.game.engine.mina.config.MinaClientConfig} object. * @param clientProtocolHandler a {@link org.apache.mina.core.service.IoHandler} object. */ public MinaTcpClient(MinaClientService service, MinaClientConfig minaClientConfig, IoHandler clientProtocolHandler) { factory =new DefaultProtocolCodecFactory(); codecFilter = new ProtocolCodecFilter(factory); this.service = service; this.clientProtocolHandler = clientProtocolHandler; init(clientProtocolHandler); setMinaClientConfig(minaClientConfig); }
Example #17
Source File: MinaTcpClient.java From game-server with MIT License | 5 votes |
/** * <p>Constructor for MinaTcpClient.</p> * * @param service a {@link com.jzy.game.engine.mina.service.MinaClientService} object. * @param minaClientConfig a {@link com.jzy.game.engine.mina.config.MinaClientConfig} object. * @param clientProtocolHandler a {@link org.apache.mina.core.service.IoHandler} object. * @param factory a {@link com.jzy.game.engine.mina.code.ProtocolCodecFactoryImpl} object. */ public MinaTcpClient(MinaClientService service, MinaClientConfig minaClientConfig, IoHandler clientProtocolHandler, ProtocolCodecFactoryImpl factory) { this.factory=factory; codecFilter = new ProtocolCodecFilter(factory); this.service = service; this.clientProtocolHandler = clientProtocolHandler; init(clientProtocolHandler); setMinaClientConfig(minaClientConfig); }
Example #18
Source File: MinaTcpClient.java From game-server with MIT License | 5 votes |
/** * <p>Constructor for MinaTcpClient.</p> * * @param service a {@link com.jzy.game.engine.mina.service.MinaClientService} object. * @param minaClientConfig a {@link com.jzy.game.engine.mina.config.MinaClientConfig} object. * @param clientProtocolHandler a {@link org.apache.mina.core.service.IoHandler} object. * @param factory a {@link com.jzy.game.engine.mina.code.ProtocolCodecFactoryImpl} object. * @param filters a {@link java.util.Map} object. */ public MinaTcpClient(MinaClientService service, MinaClientConfig minaClientConfig, IoHandler clientProtocolHandler, ProtocolCodecFactoryImpl factory,Map<String, IoFilter> filters) { this.factory=factory; codecFilter = new ProtocolCodecFilter(factory); this.service = service; this.clientProtocolHandler = clientProtocolHandler; this.filters=filters; init(clientProtocolHandler); setMinaClientConfig(minaClientConfig); }
Example #19
Source File: ReloadProtocolCodecFilter.java From gameserver with Apache License 2.0 | 5 votes |
/** * Reload the internal instances. */ public void reload() { try { this.classLoader = ReloadClassLoader.newClassloader(this.classLoader.getClasspathURLs()); Class ioFilterClass = this.classLoader.loadClass(ioFilterClassName); Class ioHandlerClass = this.classLoader.loadClass(ioHandlerClassName); this.ioFilter = (IoFilter)ioFilterClass.newInstance(); this.ioHandler = (IoHandler)ioHandlerClass.newInstance(); } catch (Throwable e) { log.error("Reload error", e); } }
Example #20
Source File: ProtocolIoHandlerFactory.java From neoscada with Eclipse Public License 1.0 | 4 votes |
@Override public IoHandler create ( final ClientBaseConnection clientBaseConnection ) throws Exception { return new ClientProtocolConnectionHandler ( clientBaseConnection, this.protocolConfigurationFactory.createConfiguration ( true ) ); }
Example #21
Source File: DummySession.java From neoscada with Eclipse Public License 1.0 | 4 votes |
public IoHandler getHandler() { return handler; }
Example #22
Source File: LdapServer.java From MyVirtualDirectory with Apache License 2.0 | 4 votes |
public IoHandler getHandler() { return handler; }
Example #23
Source File: HandlerFactory.java From neoscada with Eclipse Public License 1.0 | 4 votes |
@Override public IoHandler create ( final ClientBaseConnection connection ) throws Exception { return new ClientConnectionHandler ( connection ); }
Example #24
Source File: LdapServer.java From MyVirtualDirectory with Apache License 2.0 | 4 votes |
public IoHandler getHandler() { return handler; }
Example #25
Source File: WrapperNioSocketAcceptor.java From sailfish-core with Apache License 2.0 | 4 votes |
public void setHandler(IoHandler handler) { nioSocketAcceptor.setHandler(handler); }
Example #26
Source File: WebSocketServerTest.java From red5-websocket with Apache License 2.0 | 4 votes |
@Override public IoHandler getHandler() { // TODO Auto-generated method stub return null; }
Example #27
Source File: NioSession.java From jane with GNU Lesser General Public License v3.0 | 4 votes |
@Override public IoHandler getHandler() { return service.getHandler(); }
Example #28
Source File: VmPipe.java From neoscada with Eclipse Public License 1.0 | 4 votes |
public IoHandler getHandler() { return handler; }
Example #29
Source File: VmPipe.java From neoscada with Eclipse Public License 1.0 | 4 votes |
VmPipe(VmPipeAcceptor acceptor, VmPipeAddress address, IoHandler handler, IoServiceListenerSupport listeners) { this.acceptor = acceptor; this.address = address; this.handler = handler; this.listeners = listeners; }
Example #30
Source File: WrapperNioSocketConnector.java From sailfish-core with Apache License 2.0 | 4 votes |
public void setHandler(IoHandler handler) { nioSocketConnector.setHandler(handler); }