Search in sources :

Example 1 with TimerScheduler

use of org.eclipse.jetty.util.thread.TimerScheduler in project jetty.project by eclipse.

the class IdleTimeoutTest method setUp.

@Before
public void setUp() throws Exception {
    _open = true;
    _expired = null;
    _timer = new TimerScheduler();
    _timer.start();
    _timeout = new IdleTimeout(_timer) {

        @Override
        protected void onIdleExpired(TimeoutException timeout) {
            _expired = timeout;
        }

        @Override
        public boolean isOpen() {
            return _open;
        }
    };
    _timeout.setIdleTimeout(1000);
}
Also used : TimerScheduler(org.eclipse.jetty.util.thread.TimerScheduler) TimeoutException(java.util.concurrent.TimeoutException) Before(org.junit.Before)

Example 2 with TimerScheduler

use of org.eclipse.jetty.util.thread.TimerScheduler in project jetty.project by eclipse.

the class LowResourcesMonitorTest method before.

@Before
public void before() throws Exception {
    _threadPool = new QueuedThreadPool();
    _threadPool.setMaxThreads(50);
    _server = new Server(_threadPool);
    _server.manage(_threadPool);
    _server.addBean(new TimerScheduler());
    _connector = new ServerConnector(_server);
    _connector.setPort(0);
    _connector.setIdleTimeout(35000);
    _server.addConnector(_connector);
    _server.setHandler(new DumpHandler());
    _lowResourcesMonitor = new LowResourceMonitor(_server);
    _lowResourcesMonitor.setLowResourcesIdleTimeout(200);
    _lowResourcesMonitor.setMaxConnections(20);
    _lowResourcesMonitor.setPeriod(900);
    _server.addBean(_lowResourcesMonitor);
    _server.start();
}
Also used : TimerScheduler(org.eclipse.jetty.util.thread.TimerScheduler) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) Before(org.junit.Before)

Example 3 with TimerScheduler

use of org.eclipse.jetty.util.thread.TimerScheduler in project jetty.project by eclipse.

the class ResponseTest method init.

@Before
public void init() throws Exception {
    _server = new Server();
    Scheduler _scheduler = new TimerScheduler();
    HttpConfiguration config = new HttpConfiguration();
    LocalConnector connector = new LocalConnector(_server, null, _scheduler, null, 1, new HttpConnectionFactory(config));
    _server.addConnector(connector);
    _server.setHandler(new DumpHandler());
    _server.start();
    AbstractEndPoint endp = new ByteArrayEndPoint(_scheduler, 5000) {

        @Override
        public InetSocketAddress getLocalAddress() {
            return LOCALADDRESS;
        }
    };
    _channel = new HttpChannel(connector, new HttpConfiguration(), endp, new HttpTransport() {

        private Throwable _channelError;

        @Override
        public void send(MetaData.Response info, boolean head, ByteBuffer content, boolean lastContent, Callback callback) {
            if (_channelError == null)
                callback.succeeded();
            else
                callback.failed(_channelError);
        }

        @Override
        public boolean isPushSupported() {
            return false;
        }

        @Override
        public void push(org.eclipse.jetty.http.MetaData.Request request) {
        }

        @Override
        public void onCompleted() {
        }

        @Override
        public void abort(Throwable failure) {
            _channelError = failure;
        }

        @Override
        public boolean isOptimizedForDirectBuffers() {
            return false;
        }
    });
}
Also used : TimerScheduler(org.eclipse.jetty.util.thread.TimerScheduler) AbstractEndPoint(org.eclipse.jetty.io.AbstractEndPoint) Scheduler(org.eclipse.jetty.util.thread.Scheduler) TimerScheduler(org.eclipse.jetty.util.thread.TimerScheduler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ByteArrayEndPoint(org.eclipse.jetty.io.ByteArrayEndPoint) ByteBuffer(java.nio.ByteBuffer) HttpServletResponse(javax.servlet.http.HttpServletResponse) Callback(org.eclipse.jetty.util.Callback) Before(org.junit.Before)

Example 4 with TimerScheduler

use of org.eclipse.jetty.util.thread.TimerScheduler in project jetty.project by eclipse.

the class SelectChannelEndPointInterestsTest method init.

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();
}
Also used : SelectionKey(java.nio.channels.SelectionKey) TimerScheduler(org.eclipse.jetty.util.thread.TimerScheduler) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) SelectableChannel(java.nio.channels.SelectableChannel) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool)

Example 5 with TimerScheduler

use of org.eclipse.jetty.util.thread.TimerScheduler in project jetty.project by eclipse.

the class ByteArrayEndPointTest method before.

@Before
public void before() throws Exception {
    _scheduler = new TimerScheduler();
    _scheduler.start();
}
Also used : TimerScheduler(org.eclipse.jetty.util.thread.TimerScheduler) Before(org.junit.Before)

Aggregations

TimerScheduler (org.eclipse.jetty.util.thread.TimerScheduler)5 Before (org.junit.Before)4 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)2 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 ByteBuffer (java.nio.ByteBuffer)1 SelectableChannel (java.nio.channels.SelectableChannel)1 SelectionKey (java.nio.channels.SelectionKey)1 TimeoutException (java.util.concurrent.TimeoutException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 AbstractEndPoint (org.eclipse.jetty.io.AbstractEndPoint)1 ByteArrayEndPoint (org.eclipse.jetty.io.ByteArrayEndPoint)1 Callback (org.eclipse.jetty.util.Callback)1 Scheduler (org.eclipse.jetty.util.thread.Scheduler)1