Java Code Examples for org.apache.mina.transport.socket.SocketConnector#connect()

The following examples show how to use org.apache.mina.transport.socket.SocketConnector#connect() . 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: ReqSession.java    From sumk with Apache License 2.0 6 votes vote down vote up
private void connect(SocketConnector connector) throws InterruptedException {

		if (session == null || session.isClosing()) {
			Logs.rpc().debug("create session for {}", addr);
			ConnectFuture cf = connector.connect(addr.toInetSocketAddress());

			cf.await(connector.getConnectTimeoutMillis() + 1);
			IoSession se = cf.getSession();
			if (se != null) {
				this.session = se;
				return;
			}
			cf.cancel();

		}
	}
 
Example 2
Source File: TestReloadClassLoader.java    From gameserver with Apache License 2.0 5 votes vote down vote up
@Test
	public void testClassLoaderLeak2() throws Exception {
		int max = 10000;
		File sourceFile = new File(reloadSourceDir);
		URL[] urls = new URL[]{sourceFile.toURL()};
//		ReloadProtocolCodecFilter filter = ReloadProtocolCodecFilter.getInstance(
//				GameServer.PROTOCOL_CODEC, GameServer.PROTOCOL_HANDLER, urls);
		SocketConnector connector = new NioSocketConnector();
//		connector.getFilterChain().addLast("codec", filter);
		connector.setHandler(new ClientHandler());
    //Send 1000 connections.
    try {
			for ( int i=0; i<Integer.MAX_VALUE; i++ ) {
				ConnectFuture future = connector.connect(new InetSocketAddress("localhost", 3443));
				future.awaitUninterruptibly();
				IoSession session = future.getSession();
				IoBuffer buffer = IoBuffer.allocate(8);
				buffer.putShort((short)8);
				buffer.putShort((short)0);
				buffer.putInt(i);
				WriteFuture wfuture = session.write(buffer);
				wfuture.awaitUninterruptibly();
			}
		} catch (Exception e) {
			e.printStackTrace();
			fail();
		}
	}