Package org.apache.mina.transport.socket.nio

Examples of org.apache.mina.transport.socket.nio.NioSocketAcceptor


    public synchronized void start(FtpServerContext context) {
        try {

            this.context = context;

            acceptor = new NioSocketAcceptor(Runtime.getRuntime()
                    .availableProcessors());

            if (getServerAddress() != null) {
                address = new InetSocketAddress(getServerAddress(), getPort());
            } else {
View Full Code Here


      1000,
      60,
      TimeUnit.SECONDS,
      THREAD_FACTORY);

    acceptor = new NioSocketAcceptor(Runtime.getRuntime().availableProcessors() + 1);
    acceptor.setReuseAddress( true );
    acceptor.getSessionConfig().setReceiveBufferSize(BUFFER_SIZE);

    acceptor.getFilterChain().addLast("threadPool", new ExecutorFilter(executor));
    acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MyProtocolCodecFactory()));
View Full Code Here

  @Test
  public void testDispose() throws IOException, InterruptedException {

    List threadsBefore = getThreadNames();

    final IoAcceptor acceptor = new NioSocketAcceptor();

    acceptor.getFilterChain().addLast( "logger", new LoggingFilter() );
    acceptor.getFilterChain().addLast( "codec", new ProtocolCodecFilter( new TextLineCodecFactory( Charset.forName( "UTF-8" ))));

    acceptor.setHandlernew ServerHandler() );

    acceptor.getSessionConfig().setReadBufferSize( 2048 );
    acceptor.getSessionConfig().setIdleTime( IdleStatus.BOTH_IDLE, 10 );
    acceptor.bind( new InetSocketAddress(PORT) );
    System.out.println("Server running ...");

    final NioSocketConnector connector = new NioSocketConnector();

    // Set connect timeout.
    connector.setConnectTimeoutMillis(30 * 1000L);

    connector.setHandler(new ClientHandler());
    connector.getFilterChain().addLast( "logger", new LoggingFilter() );
    connector.getFilterChain().addLast( "codec", new ProtocolCodecFilter( new TextLineCodecFactory( Charset.forName( "UTF-8" ))));

    // Start communication.
    ConnectFuture cf = connector.connect(new InetSocketAddress("localhost", 9123));
    cf.awaitUninterruptibly();

    IoSession session = cf.getSession();

    // send a message
    session.write("Hello World!\r");

    // wait until response is received
    CountDownLatch latch = (CountDownLatch) session.getAttribute("latch");
    latch.await();

    // close the session
    CloseFuture closeFuture = session.close(false);

    System.out.println("session.close called");
    //Thread.sleep(5);

    // wait for session close and then dispose the connector
    closeFuture.addListener(new IoFutureListener<IoFuture>() {

      public void operationComplete(IoFuture future) {
        System.out.println("managed session count=" + connector.getManagedSessionCount());
        System.out.println("Disposing connector ...");
        connector.dispose(true);
        System.out.println("Disposing connector ... *finished*");

      }
    });

    closeFuture.awaitUninterruptibly();   
    acceptor.dispose(true);

    List threadsAfter = getThreadNames();

    System.out.println("threadsBefore = " + threadsBefore);
    System.out.println("threadsAfter  = " + threadsAfter);
View Full Code Here

    /**
     * Starts a Server with the SSL Filter and a simple text line
     * protocol codec filter
     */
    private static void startServer() throws Exception {
        NioSocketAcceptor acceptor = new NioSocketAcceptor();

        acceptor.setReuseAddress(true);
        DefaultIoFilterChainBuilder filters = acceptor.getFilterChain();

        // Inject the SSL filter
        SslFilter sslFilter = new SslFilter(createSSLContext());
        filters.addLast("sslFilter", sslFilter);
       
        // Inject the TestLine codec filter
        filters.addLast("text", new ProtocolCodecFilter(new TextLineCodecFactory()));
       
        acceptor.setHandler(new TestHandler());
        acceptor.bind(new InetSocketAddress(port));
    }
View Full Code Here

        // Disable SSL by default
        useSSL = false;

        boundAddress = null;
        datagramAcceptor = new NioDatagramAcceptor();
        socketAcceptor = new NioSocketAcceptor();

        ((DatagramSessionConfig) datagramAcceptor.getSessionConfig())
                .setReuseAddress(true);
        ((NioSocketAcceptor) socketAcceptor).setReuseAddress(true);
View Full Code Here

        // comment out next line if you want to see normal logging
        org.apache.log4j.Logger.getRootLogger().removeAllAppenders();
        previousLevelRootLogger = org.apache.log4j.Logger.getRootLogger().getLevel();
        org.apache.log4j.Logger.getRootLogger().setLevel(Level.DEBUG);
        org.apache.log4j.Logger.getRootLogger().addAppender(appender);
        acceptor = new NioSocketAcceptor();
    }
View Full Code Here

       
        try {
           
            this.context = context;
   
            acceptor = new NioSocketAcceptor(Runtime.getRuntime()
                    .availableProcessors());
   
            if (getServerAddress() != null) {
                address = new InetSocketAddress(getServerAddress(), getPort());
            } else {
View Full Code Here

    private int port;
    private NioSocketAcceptor acceptor;

    @Before
    public void setUp() throws Exception {
        acceptor = new NioSocketAcceptor();
        KeepAliveMessageFactory factory = new ServerFactory();
        KeepAliveFilter filter = new KeepAliveFilter(factory,
                IdleStatus.BOTH_IDLE);
        acceptor.getFilterChain().addLast("keep-alive", filter);
        acceptor.setHandler(new IoHandlerAdapter());
View Full Code Here

        assertEquals(1024, filter.getWriteBufferSize());
    }

    @Test
    public void testWriteUsingSocketTransport() throws Exception {
        NioSocketAcceptor acceptor = new NioSocketAcceptor();
        acceptor.setReuseAddress(true);
        SocketAddress address = new InetSocketAddress("localhost",
                AvailablePortFinder.getNextAvailable());

        NioSocketConnector connector = new NioSocketConnector();

        // Generate 4MB of random data
        byte[] data = new byte[4 * 1024 * 1024];
        new Random().nextBytes(data);

        byte[] expectedMd5 = MessageDigest.getInstance("MD5").digest(data);

        M message = createMessage(data);
       
        SenderHandler sender = new SenderHandler(message);
        ReceiverHandler receiver = new ReceiverHandler(data.length);

        acceptor.setHandler(sender);
        connector.setHandler(receiver);
       
        acceptor.bind(address);
        connector.connect(address);
        sender.latch.await();
        receiver.latch.await();

        acceptor.dispose();

        assertEquals(data.length, receiver.bytesRead);
        byte[] actualMd5 = receiver.digest.digest();
        assertEquals(expectedMd5.length, actualMd5.length);
        for (int i = 0; i < expectedMd5.length; i++) {
View Full Code Here

    public synchronized void start(FtpServerContext context) {
        try {
           
            this.context = context;
   
            acceptor = new NioSocketAcceptor(Runtime.getRuntime()
                    .availableProcessors());
   
            if (getServerAddress() != null) {
                address = new InetSocketAddress(getServerAddress(), getPort());
            } else {
View Full Code Here

TOP

Related Classes of org.apache.mina.transport.socket.nio.NioSocketAcceptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.