org.apache.mina.core.service.IoHandlerAdapter Java Examples
The following examples show how to use
org.apache.mina.core.service.IoHandlerAdapter.
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: TCPTesterRuntime.java From streamsx.topology with Apache License 2.0 | 6 votes |
/** * Add a TCP server that will list for tuples to be directed to handlers. * Adds a sink to the topology to capture those tuples and deliver them to * the current jvm to run Junit type tests. */ private void addTCPServerAndSink() throws Exception { tcpServer = new TCPTestServer(0, this.contextType == StreamsContext.Type.STANDALONE_TESTER, new IoHandlerAdapter() { @Override public void messageReceived(IoSession session, Object message) throws Exception { TestTuple tuple = (TestTuple) message; TestTupleInjector injector = injectors.get(tuple.getTesterId()); injector.tuple(tuple.getTupleData()); } }); InetSocketAddress testAddr = tcpServer.start(); addTesterSink(testAddr); }
Example #2
Source File: TCPTestClient.java From streamsx.topology with Apache License 2.0 | 5 votes |
public TCPTestClient(InetSocketAddress addr) { this.addr = addr; connector.setConnectTimeoutMillis(5000); IoFilter tupleEncoder = new ProtocolCodecFilter(new TestTupleEncoder(), new TestTupleDecoder()); connector.getFilterChain().addLast("tuples", tupleEncoder); connector.setHandler(new IoHandlerAdapter()); }
Example #3
Source File: UDPConduit.java From cxf with Apache License 2.0 | 5 votes |
public UDPConduit(EndpointReferenceType t, final Bus bus) { super(t); this.bus = bus; connector.getSessionConfig().setReadBufferSize(64 * 1024); connector.getSessionConfig().setSendBufferSize(64 * 1024); connector.setHandler(new IoHandlerAdapter() { public void messageReceived(IoSession session, Object buf) { Message message = (Message)session.getAttribute(CXF_MESSAGE_ATTR); dataReceived(message, (IoBuffer)buf, true, false); } }); }
Example #4
Source File: NetConnector.java From oim-fx with MIT License | 4 votes |
public NetConnector(IoHandlerAdapter handler) { this.handler = handler; initConnector(); }
Example #5
Source File: ClientFrame.java From oim-fx with MIT License | 4 votes |
private void initNet() { nc = new NetConnector(new IoHandlerAdapter() { public void sessionCreated(IoSession session) throws Exception { } public void sessionOpened(IoSession session) throws Exception { System.out.println("getRemoteAddress:" + session.getRemoteAddress()); System.out.println("getLocalAddress:" + session.getLocalAddress()); System.out.println("getServiceAddress:" + session.getServiceAddress()); SocketAddress socketAddress = session.getLocalAddress(); nc.closeConnect(); if (socketAddress instanceof InetSocketAddress) { InetSocketAddress isa = (InetSocketAddress) socketAddress; port = isa.getPort(); server.startServer(port); } } public void sessionClosed(IoSession session) throws Exception { } public void sessionIdle(IoSession session, IdleStatus status) throws Exception { } public void messageReceived(IoSession session, Object message) throws Exception { } public void messageSent(IoSession session, Object message) throws Exception { } public void inputClosed(IoSession session) throws Exception { session.closeNow(); } }); ConnectData connectData = new ConnectData(); connectData.setAddress("192.168.10.100"); connectData.setPort(13000); nc.connect(connectData); nnc = new NetConnector(new IoHandlerAdapter() { public void sessionCreated(IoSession session) throws Exception { } public void sessionOpened(IoSession session) throws Exception { System.out.println("getRemoteAddress:" + session.getRemoteAddress()); System.out.println("getLocalAddress:" + session.getLocalAddress()); System.out.println("getServiceAddress:" + session.getServiceAddress()); } public void sessionClosed(IoSession session) throws Exception { } public void sessionIdle(IoSession session, IdleStatus status) throws Exception { } public void messageReceived(IoSession session, Object message) throws Exception { } public void messageSent(IoSession session, Object message) throws Exception { } public void inputClosed(IoSession session) throws Exception { session.closeNow(); } }); //nnc.setDefaultPort(nc.getPort()); }
Example #6
Source File: SocketConnector.java From oim-fx with MIT License | 4 votes |
public SocketConnector(IoHandlerAdapter handler) { this.handler = handler; initConnector(); }
Example #7
Source File: RemoteConnector.java From oim-fx with MIT License | 4 votes |
public RemoteConnector(IoHandlerAdapter handler) { this.handler = handler; initConnector(); }
Example #8
Source File: RemoteModule.java From oim-fx with MIT License | 4 votes |
private void init() { connector = new RemoteConnector(new IoHandlerAdapter() { JsonParser jp = new JsonParser(); @Override public void sessionOpened(IoSession session) throws Exception { Map<String, Object> bodyMap = new HashMap<String, Object>(); bodyMap.put("userId", userId); bodyMap.put("action", action_auth); String json = OnlyJsonUtil.objectToJson(bodyMap); BytesData bd = new BytesData(); bd.setMessage(json); connector.write(bd); } @Override public void sessionClosed(IoSession session) throws Exception { } // byte[] tempData=null; // private byte[] get(byte[] data){ // if(null==tempData){ // tempData=data; // return data; // }else{ // int tl=tempData.length; // int l=data.length; // byte[] bytes=new byte[l]; // for(int i=0;i<l;i++){ // if(i<tl){ // if(tempData[i]!=data[i]){ // bytes[i]=data[i]; // }else{ // bytes[i]=tempData[i]; // } // }else{ // bytes[i]=data[i]; // } // } // tempData=bytes; // return bytes; // } // } @Override public void messageReceived(IoSession session, Object message) throws Exception { if (message instanceof BytesData) { BytesData bd = (BytesData) message; String json = bd.getMessage(); if (JSONUtils.mayBeJSON(json)) { JsonObject jo = jp.parse(json).getAsJsonObject(); boolean hasAction = jo.has("action"); if (hasAction) { String action = jo.get("action").getAsString(); if (action_auth.equals(action)) { } if (action_client.equals(action)) { // String receiveId = jo.has("receiveId") ? // jo.get("receiveId").getAsString() : ""; String sendId = jo.has("sendId") ? jo.get("sendId").getAsString() : ""; byte[] bytes = bd.getBytes(); bytes =OnlyZipUtil.unZip(bytes); //bytes= get(bytes); for (ScreenHandler sh : screenHandlerSet) { sh.handle(sendId, bytes); } } if (action_server.equals(action)) { EventData event = OnlyJsonUtil.getParameterValue("event", jo, EventData.class); handle(event); } } } } } }); imageThread.start(); }
Example #9
Source File: PortForwardingTest.java From termd with Apache License 2.0 | 4 votes |
@Before public void setUp() throws Exception { sshd = setupTestServer(); PropertyResolverUtils.updateProperty(sshd, FactoryManager.WINDOW_SIZE, 2048); PropertyResolverUtils.updateProperty(sshd, FactoryManager.MAX_PACKET_SIZE, 256); sshd.setTcpipForwardingFilter(AcceptAllForwardingFilter.INSTANCE); sshd.start(); if (!requestsQ.isEmpty()) { requestsQ.clear(); } final TcpipForwarderFactory factory = ValidateUtils.checkNotNull(sshd.getTcpipForwarderFactory(), "No TcpipForwarderFactory"); sshd.setTcpipForwarderFactory(new TcpipForwarderFactory() { private final Class<?>[] interfaces = {TcpipForwarder.class}; private final Map<String, String> method2req = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER) { private static final long serialVersionUID = 1L; // we're not serializing it... { put("localPortForwardingRequested", TcpipForwardHandler.REQUEST); put("localPortForwardingCancelled", CancelTcpipForwardHandler.REQUEST); } }; @Override public TcpipForwarder create(ConnectionService service) { Thread thread = Thread.currentThread(); ClassLoader cl = thread.getContextClassLoader(); final TcpipForwarder forwarder = factory.create(service); return (TcpipForwarder) Proxy.newProxyInstance(cl, interfaces, new InvocationHandler() { @SuppressWarnings("synthetic-access") @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Object result = method.invoke(forwarder, args); String name = method.getName(); String request = method2req.get(name); if (GenericUtils.length(request) > 0) { if (requestsQ.offer(request)) { log.info("Signal " + request); } else { log.error("Failed to offer request=" + request); } } return result; } }); } }); sshPort = sshd.getPort(); NioSocketAcceptor acceptor = new NioSocketAcceptor(); acceptor.setHandler(new IoHandlerAdapter() { @Override public void messageReceived(IoSession session, Object message) throws Exception { IoBuffer recv = (IoBuffer) message; IoBuffer sent = IoBuffer.allocate(recv.remaining()); sent.put(recv); sent.flip(); session.write(sent); } }); acceptor.setReuseAddress(true); acceptor.bind(new InetSocketAddress(0)); echoPort = acceptor.getLocalAddress().getPort(); this.acceptor = acceptor; }
Example #10
Source File: PortForwardingTest.java From termd with Apache License 2.0 | 4 votes |
@Before public void setUp() throws Exception { sshd = setupTestServer(); PropertyResolverUtils.updateProperty(sshd, FactoryManager.WINDOW_SIZE, 2048); PropertyResolverUtils.updateProperty(sshd, FactoryManager.MAX_PACKET_SIZE, 256); sshd.setTcpipForwardingFilter(AcceptAllForwardingFilter.INSTANCE); sshd.start(); if (!requestsQ.isEmpty()) { requestsQ.clear(); } final TcpipForwarderFactory factory = ValidateUtils.checkNotNull(sshd.getTcpipForwarderFactory(), "No TcpipForwarderFactory"); sshd.setTcpipForwarderFactory(new TcpipForwarderFactory() { private final Class<?>[] interfaces = {TcpipForwarder.class}; private final Map<String, String> method2req = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER) { private static final long serialVersionUID = 1L; // we're not serializing it... { put("localPortForwardingRequested", TcpipForwardHandler.REQUEST); put("localPortForwardingCancelled", CancelTcpipForwardHandler.REQUEST); } }; @Override public TcpipForwarder create(ConnectionService service) { Thread thread = Thread.currentThread(); ClassLoader cl = thread.getContextClassLoader(); final TcpipForwarder forwarder = factory.create(service); return (TcpipForwarder) Proxy.newProxyInstance(cl, interfaces, new InvocationHandler() { @SuppressWarnings("synthetic-access") @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Object result = method.invoke(forwarder, args); String name = method.getName(); String request = method2req.get(name); if (GenericUtils.length(request) > 0) { if (requestsQ.offer(request)) { log.info("Signal " + request); } else { log.error("Failed to offer request=" + request); } } return result; } }); } }); sshPort = sshd.getPort(); NioSocketAcceptor acceptor = new NioSocketAcceptor(); acceptor.setHandler(new IoHandlerAdapter() { @Override public void messageReceived(IoSession session, Object message) throws Exception { IoBuffer recv = (IoBuffer) message; IoBuffer sent = IoBuffer.allocate(recv.remaining()); sent.put(recv); sent.flip(); session.write(sent); } }); acceptor.setReuseAddress(true); acceptor.bind(new InetSocketAddress(0)); echoPort = acceptor.getLocalAddress().getPort(); this.acceptor = acceptor; }
Example #11
Source File: WebSocketTransport.java From red5-websocket with Apache License 2.0 | 4 votes |
public void setIoHandler(IoHandlerAdapter ioHandler) { this.ioHandler = ioHandler; }