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");
}
}
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();
}
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());
}
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);
}
}
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();
}
Aggregations