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

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


        sb.append("HTTP/1.1 200 OK").append('\n');
        sb.append("Content-Type: text/HTML").append('\n');
        sb.append("Content-Length: ").append(resp.length()).append('\n');
        sb.append('\n');
        sb.append(resp);
        NioSocketAcceptor acceptor = new NioSocketAcceptor();
        acceptor.setHandler(new IoHandlerAdapter() {
            @Override
            public void messageReceived(IoSession session, Object message) throws Exception {
                session.write(IoBuffer.wrap(sb.toString().getBytes()));
            }
        });
        acceptor.setReuseAddress(true);
        acceptor.bind(new InetSocketAddress(port));


        Session session = createSession();

        final int forwardedPort1 = getFreePort();
View Full Code Here


        acceptor.dispose();
        acceptor = null;
    }

    protected IoAcceptor createAcceptor() {
        return new NioSocketAcceptor();
    }
View Full Code Here

        return new NioSocketAcceptor();
    }

    protected void configure(IoAcceptor acceptor) {
        if (acceptor instanceof NioSocketAcceptor) {
            final NioSocketAcceptor nio = (NioSocketAcceptor) acceptor;
            nio.setReuseAddress(reuseAddress);
            nio.setBacklog(backlog);

            // MINA itself forces our socket receive buffer to 1024 bytes
            // by default, despite what the operating system defaults to.
            // This limits us to about 3 MB/s incoming data transfer.  By
            // forcing back to the operating system default we can get a
            // decent transfer rate again.
            //
            final Socket s = new Socket();
            try {
              try {
                  nio.getSessionConfig().setReceiveBufferSize(s.getReceiveBufferSize());
              } finally {
                  s.close();
              }
            } catch (IOException e) {
                log.warn("cannot adjust SO_RCVBUF back to system default", e);
View Full Code Here

        this.session = session;
    }

    public synchronized void initialize() {
        if (this.acceptor == null) {
            NioSocketAcceptor acceptor = new NioSocketAcceptor();
            acceptor.setHandler(this);
            acceptor.setReuseAddress(true);
            acceptor.getFilterChain().addLast(
                    "executor",
                    new ExecutorFilter(EnumSet.complementOf(
                            EnumSet.of(IoEventType.SESSION_CREATED)).toArray(
                            new IoEventType[0])));
            this.acceptor = acceptor;
View Full Code Here

        this.session = session;
    }

    public synchronized void initialize() {
        if (this.acceptor == null) {
            NioSocketAcceptor acceptor = new NioSocketAcceptor();
            acceptor.setHandler(this);
            acceptor.setReuseAddress(true);
            acceptor.getFilterChain().addLast("executor", new ExecutorFilter(EnumSet.complementOf(EnumSet.of(IoEventType.SESSION_CREATED)).toArray(new IoEventType[0])));
            this.acceptor = acceptor;
        }
    }
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

     *
     * @throws IOException
     */
    public void start() throws IOException {
        checkConfig();
        acceptor = new NioSocketAcceptor();

        SessionFactory handler = sessionFactory;
        if (handler == null) {
            handler = new SessionFactory();
        }
View Full Code Here

  /**
   * @param args
   * @throws IOException
   */
  public static void main(String[] args) throws IOException {
    IoAcceptor acceptor=new NioSocketAcceptor();
    acceptor.getFilterChain().addLast("logger", new LoggingFilter());
    acceptor.getFilterChain().addLast("httpfilter", new ProtocolCodecFilter(new HttpCodecFactory(charset)));
   
    acceptor.setHandler(new ServerHandler());
    //acceptor.getSessionConfig().setMaxReadBufferSize(1024);
    acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 5);
    acceptor.bind(new InetSocketAddress(port));
    //acceptor.dispose();
  }
View Full Code Here

  public void start() {
    logger.info("Starting {}...", this);

    // allow user to specify number of processors to use for thread pool
    if (numProcessors != null) {
      acceptor = new NioSocketAcceptor(numProcessors);
    } else {
      acceptor = new NioSocketAcceptor();
    }
    acceptor.setReuseAddress(true);
    acceptor.getSessionConfig().setReadBufferSize(readBufferSize);
    acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
View Full Code Here

        List<IoFilter> filters = configuration.getFilters();

        address = new InetSocketAddress(configuration.getHost(), configuration.getPort());

        final int processorCount = Runtime.getRuntime().availableProcessors() + 1;
        acceptor = new NioSocketAcceptor(processorCount);

        // acceptor connectorConfig
        configureCodecFactory("Mina2Consumer", acceptor, configuration);
        ((NioSocketAcceptor) acceptor).setReuseAddress(true);
        acceptor.setCloseOnDeactivation(true);
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.