Exemplo n.º 1
0
 protected Scheduler startScheduler() throws ServletException {
   try {
     Scheduler result = new ScheduledExecutorScheduler();
     result.start();
     return result;
   } catch (Exception x) {
     throw new ServletException(x);
   }
 }
 @Before
 public void startManager() throws Exception {
   _writeCount = 1;
   _lastEndPoint = null;
   _lastEndPointLatch = new CountDownLatch(1);
   _connector = ServerSocketChannel.open();
   _connector.socket().bind(null);
   _scheduler.start();
   _threadPool.start();
   _manager.start();
 }
  public void init(final Interested interested) throws Exception {
    threadPool = new QueuedThreadPool();
    threadPool.start();

    scheduler = new TimerScheduler();
    scheduler.start();

    connector = ServerSocketChannel.open();
    connector.bind(new InetSocketAddress("localhost", 0));

    selectorManager =
        new SelectorManager(threadPool, scheduler) {

          @Override
          protected EndPoint newEndPoint(
              SelectableChannel channel, ManagedSelector selector, SelectionKey key)
              throws IOException {
            SocketChannelEndPoint endp =
                new SocketChannelEndPoint(channel, selector, key, getScheduler()) {
                  @Override
                  protected void onIncompleteFlush() {
                    super.onIncompleteFlush();
                    interested.onIncompleteFlush();
                  }
                };

            endp.setIdleTimeout(60000);
            return endp;
          }

          @Override
          public Connection newConnection(
              SelectableChannel channel, final EndPoint endPoint, Object attachment) {
            return new AbstractConnection(endPoint, getExecutor()) {
              @Override
              public void onOpen() {
                super.onOpen();
                fillInterested();
              }

              @Override
              public void onFillable() {
                interested.onFillable(endPoint, this);
              }
            };
          }
        };
    selectorManager.start();
  }
 @BeforeClass
 public static void beforeClass() throws Exception {
   scheduler.start();
 }