Search in sources :

Example 6 with ScheduledExecutorScheduler

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

the class HouseKeeper method findScheduler.

/**
     * Get a scheduler. First try a common scheduler, failing that
     * create our own.
     * 
     * @throws Exception
     */
protected void findScheduler() throws Exception {
    if (_scheduler == null) {
        if (_sessionIdManager instanceof DefaultSessionIdManager) {
            //try and use a common scheduler, fallback to own
            _scheduler = ((DefaultSessionIdManager) _sessionIdManager).getServer().getBean(Scheduler.class);
        }
        if (_scheduler == null) {
            _scheduler = new ScheduledExecutorScheduler();
            _ownScheduler = true;
            _scheduler.start();
            if (LOG.isDebugEnabled())
                LOG.debug("Using own scheduler for scavenging");
        } else if (!_scheduler.isStarted())
            throw new IllegalStateException("Shared scheduler not started");
    }
}
Also used : Scheduler(org.eclipse.jetty.util.thread.Scheduler) ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler) ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler)

Example 7 with ScheduledExecutorScheduler

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

the class IteratingCallbackTest method prepare.

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

Example 8 with ScheduledExecutorScheduler

use of org.eclipse.jetty.util.thread.ScheduledExecutorScheduler in project steve by RWTH-i5-IDSG.

the class JettyServer method prepare.

/**
 * A fully configured Jetty Server instance
 */
private void prepare() {
    // === jetty.xml ===
    // Setup Threadpool
    QueuedThreadPool threadPool = new QueuedThreadPool();
    threadPool.setMinThreads(MIN_THREADS);
    threadPool.setMaxThreads(MAX_THREADS);
    // Server
    server = new Server(threadPool);
    // Scheduler
    server.addBean(new ScheduledExecutorScheduler());
    // HTTP Configuration
    HttpConfiguration httpConfig = new HttpConfiguration();
    httpConfig.setSecureScheme(HttpScheme.HTTPS.asString());
    httpConfig.setSecurePort(CONFIG.getJetty().getHttpsPort());
    httpConfig.setOutputBufferSize(32768);
    httpConfig.setRequestHeaderSize(8192);
    httpConfig.setResponseHeaderSize(8192);
    httpConfig.setSendServerVersion(false);
    httpConfig.setSendDateHeader(false);
    httpConfig.setSendXPoweredBy(false);
    // Extra options
    server.setDumpAfterStart(false);
    server.setDumpBeforeStop(false);
    server.setStopAtShutdown(true);
    server.setStopTimeout(STOP_TIMEOUT);
    if (CONFIG.getJetty().isHttpEnabled()) {
        server.addConnector(httpConnector(httpConfig));
    }
    if (CONFIG.getJetty().isHttpsEnabled()) {
        server.addConnector(httpsConnector(httpConfig));
    }
    SteveAppContext steveAppContext = new SteveAppContext();
    server.setHandler(steveAppContext.getHandlers());
}
Also used : Server(org.eclipse.jetty.server.Server) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration)

Example 9 with ScheduledExecutorScheduler

use of org.eclipse.jetty.util.thread.ScheduledExecutorScheduler in project i2p.i2p by i2p.

the class RouterConsoleRunner method initialize.

/**
 *  Set up basic security constraints for the webapp.
 *  Add all users and passwords.
 */
static void initialize(RouterContext ctx, WebAppContext context) {
    ConstraintSecurityHandler sec = new ConstraintSecurityHandler();
    List<ConstraintMapping> constraints = new ArrayList<ConstraintMapping>(4);
    ConsolePasswordManager mgr = new ConsolePasswordManager(ctx);
    boolean enable = ctx.getBooleanProperty(PROP_PW_ENABLE);
    if (enable) {
        Map<String, String> userpw = mgr.getMD5(PROP_CONSOLE_PW);
        if (userpw.isEmpty()) {
            enable = false;
            ctx.router().saveConfig(PROP_PW_ENABLE, "false");
        } else {
            HashLoginService realm = new CustomHashLoginService(JETTY_REALM, context.getContextPath(), ctx.logManager().getLog(RouterConsoleRunner.class));
            sec.setLoginService(realm);
            sec.setAuthenticator(authenticator);
            String[] role = new String[] { JETTY_ROLE };
            for (Map.Entry<String, String> e : userpw.entrySet()) {
                String user = e.getKey();
                String pw = e.getValue();
                Credential cred = Credential.getCredential(MD5_CREDENTIAL_TYPE + pw);
                realm.putUser(user, cred, role);
                Constraint constraint = new Constraint(user, JETTY_ROLE);
                constraint.setAuthenticate(true);
                ConstraintMapping cm = new ConstraintMapping();
                cm.setConstraint(constraint);
                cm.setPathSpec("/");
                constraints.add(cm);
                // Jetty does auth checking only with ISO-8859-1,
                // so register a 2nd and 3rd user with different encodings if necessary.
                // Might work, might not...
                // There's no standard and browser behavior varies.
                // Chrome sends UTF-8. Firefox doesn't send anything.
                // https://bugzilla.mozilla.org/show_bug.cgi?id=41489
                // see also RFC 7616/7617 (late 2015) and PasswordManager.md5Hex()
                byte[] b1 = DataHelper.getUTF8(user);
                byte[] b2 = DataHelper.getASCII(user);
                if (!DataHelper.eq(b1, b2)) {
                    try {
                        // each char truncated to 8 bytes
                        String user2 = new String(b2, "ISO-8859-1");
                        realm.putUser(user2, cred, role);
                        constraint = new Constraint(user2, JETTY_ROLE);
                        constraint.setAuthenticate(true);
                        cm = new ConstraintMapping();
                        cm.setConstraint(constraint);
                        cm.setPathSpec("/");
                        constraints.add(cm);
                        // each UTF-8 byte as a char
                        // this is what chrome does
                        String user3 = new String(b1, "ISO-8859-1");
                        realm.putUser(user3, cred, role);
                        constraint = new Constraint(user3, JETTY_ROLE);
                        constraint.setAuthenticate(true);
                        cm = new ConstraintMapping();
                        cm.setConstraint(constraint);
                        cm.setPathSpec("/");
                        constraints.add(cm);
                    } catch (UnsupportedEncodingException uee) {
                    }
                }
            }
        }
    }
    // This forces a '403 Forbidden' response for TRACE and OPTIONS unless the
    // WAC handler handles it.
    // (LocaleWebAppHandler returns a '405 Method Not Allowed')
    // TRACE and OPTIONS aren't really security issues...
    // TRACE doesn't echo stuff unless you call setTrace(true)
    // But it might bug some people
    // The other strange methods - PUT, DELETE, MOVE - are disabled by default
    // See also:
    // http://old.nabble.com/Disable-HTTP-TRACE-in-Jetty-5.x-td12412607.html
    Constraint sc = new Constraint();
    sc.setName("No trace");
    ConstraintMapping cm = new ConstraintMapping();
    cm.setMethod("TRACE");
    cm.setConstraint(sc);
    cm.setPathSpec("/");
    constraints.add(cm);
    sc = new Constraint();
    sc.setName("No options");
    cm = new ConstraintMapping();
    cm.setMethod("OPTIONS");
    cm.setConstraint(sc);
    cm.setPathSpec("/");
    constraints.add(cm);
    ConstraintMapping[] cmarr = constraints.toArray(new ConstraintMapping[constraints.size()]);
    sec.setConstraintMappings(cmarr);
    context.setSecurityHandler(sec);
    // see HashSessionManager javadoc
    synchronized (RouterConsoleRunner.class) {
        if (_jettyTimer == null) {
            _jettyTimer = new ScheduledExecutorScheduler("Console HashSessionScavenger", true);
            try {
                _jettyTimer.start();
            } catch (Exception e) {
                System.err.println("Warning: ScheduledExecutorScheduler start failed: " + e);
            }
        }
        context.getServletContext().setAttribute("org.eclipse.jetty.server.session.timer", _jettyTimer);
    }
}
Also used : ConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) Credential(org.eclipse.jetty.util.security.Credential) Constraint(org.eclipse.jetty.util.security.Constraint) ArrayList(java.util.ArrayList) ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler) UnsupportedEncodingException(java.io.UnsupportedEncodingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) HashLoginService(org.eclipse.jetty.security.HashLoginService) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) Map(java.util.Map) HashMap(java.util.HashMap)

Example 10 with ScheduledExecutorScheduler

use of org.eclipse.jetty.util.thread.ScheduledExecutorScheduler in project spring-framework by spring-projects.

the class JettyResourceFactory method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    String name = this.threadPrefix + "@" + Integer.toHexString(hashCode());
    if (this.executor == null) {
        QueuedThreadPool threadPool = new QueuedThreadPool();
        threadPool.setName(name);
        this.executor = threadPool;
    }
    if (this.byteBufferPool == null) {
        this.byteBufferPool = new MappedByteBufferPool(2048, this.executor instanceof ThreadPool.SizedThreadPool ? ((ThreadPool.SizedThreadPool) this.executor).getMaxThreads() / 2 : ProcessorUtils.availableProcessors() * 2);
    }
    if (this.scheduler == null) {
        this.scheduler = new ScheduledExecutorScheduler(name + "-scheduler", false);
    }
    if (this.executor instanceof LifeCycle) {
        ((LifeCycle) this.executor).start();
    }
    this.scheduler.start();
}
Also used : MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) LifeCycle(org.eclipse.jetty.util.component.LifeCycle) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ThreadPool(org.eclipse.jetty.util.thread.ThreadPool) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler)

Aggregations

ScheduledExecutorScheduler (org.eclipse.jetty.util.thread.ScheduledExecutorScheduler)20 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)9 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)8 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)7 Server (org.eclipse.jetty.server.Server)7 Scheduler (org.eclipse.jetty.util.thread.Scheduler)7 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)6 IOException (java.io.IOException)5 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)5 InstrumentedConnectionFactory (com.codahale.metrics.jetty9.InstrumentedConnectionFactory)4 MappedByteBufferPool (org.eclipse.jetty.io.MappedByteBufferPool)4 ServerConnector (org.eclipse.jetty.server.ServerConnector)4 ArrayList (java.util.ArrayList)3 ServletException (javax.servlet.ServletException)3 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 HTTP2ServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory)2 ForwardedRequestCustomizer (org.eclipse.jetty.server.ForwardedRequestCustomizer)2 Request (org.eclipse.jetty.server.Request)2