org.apache.tomcat.InstanceManager Java Examples

The following examples show how to use org.apache.tomcat.InstanceManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WsSession.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
private void fireEndpointOnClose(CloseReason closeReason) {

        // Fire the onClose event
        InstanceManager instanceManager = webSocketContainer.getInstanceManager();
        Thread t = Thread.currentThread();
        ClassLoader cl = t.getContextClassLoader();
        t.setContextClassLoader(applicationClassLoader);
        try {
            localEndpoint.onClose(this, closeReason);
            if (instanceManager != null) {
                instanceManager.destroyInstance(localEndpoint);
            }
        } catch (Throwable throwable) {
            ExceptionUtils.handleThrowable(throwable);
            localEndpoint.onError(this, throwable);
        } finally {
            t.setContextClassLoader(cl);
        }
    }
 
Example #2
Source File: HttpBindManager.java    From Openfire with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a Jetty context handler that can be used to expose the cross-domain functionality as implemented by
 * {@link FlashCrossDomainServlet}.
 *
 * Note that an invocation of this method will not register the handler (and thus make the related functionality
 * available to the end user). Instead, the created handler is returned by this method, and will need to be
 * registered with the embedded Jetty webserver by the caller.
 *
 * @return A Jetty context handler (never null).
 */
protected Handler createCrossDomainHandler()
{
    final ServletContextHandler context = new ServletContextHandler( null, "/crossdomain.xml", ServletContextHandler.SESSIONS );

    // Ensure the JSP engine is initialized correctly (in order to be able to cope with Tomcat/Jasper precompiled JSPs).
    final List<ContainerInitializer> initializers = new ArrayList<>();
    initializers.add( new ContainerInitializer( new JasperInitializer(), null ) );
    context.setAttribute( "org.eclipse.jetty.containerInitializers", initializers );
    context.setAttribute( InstanceManager.class.getName(), new SimpleInstanceManager() );

    // Generic configuration of the context.
    context.setAllowNullPathInfo( true );

    // Add the functionality-providers.
    context.addServlet( new ServletHolder( new FlashCrossDomainServlet() ), "" );

    return context;
}
 
Example #3
Source File: App.java    From mysql_perf_analyzer with Apache License 2.0 6 votes vote down vote up
private WebAppContext createDeployedApplicationInstance(File workDirectory,
		String deployedApplicationPath) {
	WebAppContext deployedApplication = new WebAppContext();
	deployedApplication.setContextPath(this.getContextPath());
	deployedApplication.setWar(deployedApplicationPath);
	deployedApplication.setAttribute("javax.servlet.context.tempdir",
			workDirectory.getAbsolutePath());
	deployedApplication
			.setAttribute(
					"org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
					".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/.*taglibs.*\\.jar$");
	deployedApplication.setAttribute(
			"org.eclipse.jetty.containerInitializers", jspInitializers());
	deployedApplication.setAttribute(InstanceManager.class.getName(),
			new SimpleInstanceManager());
	deployedApplication.addBean(new ServletContainerInitializersStarter(
			deployedApplication), true);
	// webapp.setClassLoader(new URLClassLoader(new
	// URL[0],App.class.getClassLoader()));
	deployedApplication.addServlet(jspServletHolder(), "*.jsp");
	return deployedApplication;
}
 
Example #4
Source File: JettyLauncher.java    From logsniffer with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Setups the web application context.
 * 
 * @throws IOException
 * @throws Exception
 */
protected void configureWebAppContext(final WebContextWithExtraConfigurations context) throws Exception {
	context.setAttribute("javax.servlet.context.tempdir", getScratchDir());
	// Set the ContainerIncludeJarPattern so that jetty examines these
	// container-path jars for tlds, web-fragments etc.
	// If you omit the jar that contains the jstl .tlds, the jsp engine will
	// scan for them instead.
	context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
			".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/[^/]*taglibs.*\\.jar$");
	context.setAttribute("org.eclipse.jetty.containerInitializers", jspInitializers());
	context.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());
	context.addBean(new ServletContainerInitializersStarter(context), true);
	// context.setClassLoader(getUrlClassLoader());

	context.addServlet(jspServletHolder(), "*.jsp");
	context.replaceConfiguration(WebInfConfiguration.class, WebInfConfigurationHomeUnpacked.class);
}
 
Example #5
Source File: TestDefaultInstanceManager.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private void doTestConcurrency(InstanceManager im, int threadCount) throws Exception {
    long start = System.nanoTime();

    Thread[] threads = new Thread[threadCount];

    for (int i = 0; i < threadCount; i++) {
        threads[i] = new Thread(new InstanceManagerRunnable(im));
    }

    for (int i = 0; i < threadCount; i++) {
        threads[i].start();
    }

    for (int i = 0; i < threadCount; i++) {
        threads[i].join();
    }

    long duration = System.nanoTime() - start;

    System.out.println(threadCount + " threads completed in " + duration + "ns");
}
 
Example #6
Source File: JspServletWrapper.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public void destroy() {
    if (theServlet != null) {
        theServlet.destroy();
        InstanceManager instanceManager = InstanceManagerFactory.getInstanceManager(config);
        try {
            instanceManager.destroyInstance(theServlet);
        } catch (Exception e) {
            Throwable t = ExceptionUtils.unwrapInvocationTargetException(e);
            ExceptionUtils.handleThrowable(t);
            // Log any exception, since it can't be passed along
            log.error(Localizer.getMessage("jsp.error.file.not.found",
                    e.getMessage()), t);
        }
    }
}
 
Example #7
Source File: InstanceManagerFactory.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public static InstanceManager getInstanceManager(ServletConfig config) {
    InstanceManager instanceManager = 
            (InstanceManager) config.getServletContext().getAttribute(InstanceManager.class.getName());
    if (instanceManager == null) {
        throw new IllegalStateException("No org.apache.tomcat.InstanceManager set in ServletContext");
    }
    return instanceManager;
}
 
Example #8
Source File: AsyncContextImpl.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
private InstanceManager getInstanceManager() {
    if (instanceManager == null) {
        if (context instanceof StandardContext) {
            instanceManager = ((StandardContext)context).getInstanceManager();
        } else {
            instanceManager = new DefaultInstanceManager(null,
                    new HashMap<String, Map<String, String>>(),
                    context,
                    getClass().getClassLoader());
        }
    }
    return instanceManager;
}
 
Example #9
Source File: ApplicationFilterConfig.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
private InstanceManager getInstanceManager() {
    if (instanceManager == null) {
        if (context instanceof StandardContext) {
            instanceManager = ((StandardContext)context).getInstanceManager();
        } else {
            instanceManager = new DefaultInstanceManager(null,
                    new HashMap<String, Map<String, String>>(),
                    context,
                    getClass().getClassLoader()); 
        }
    }
    return instanceManager;
}
 
Example #10
Source File: ApplicationFilterConfig.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
private InstanceManager getInstanceManager() {
    if (instanceManager == null) {
        if (context instanceof StandardContext) {
            instanceManager = ((StandardContext)context).getInstanceManager();
        } else {
            instanceManager = new DefaultInstanceManager(null,
                    new HashMap<String, Map<String, String>>(),
                    context,
                    getClass().getClassLoader()); 
        }
    }
    return instanceManager;
}
 
Example #11
Source File: AsyncContextImpl.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
private InstanceManager getInstanceManager() {
    if (instanceManager == null) {
        if (context instanceof StandardContext) {
            instanceManager = ((StandardContext)context).getInstanceManager();
        } else {
            instanceManager = new DefaultInstanceManager(null,
                    new HashMap<String, Map<String, String>>(),
                    context,
                    getClass().getClassLoader());
        }
    }
    return instanceManager;
}
 
Example #12
Source File: WsSession.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
private void fireEndpointOnClose(CloseReason closeReason) {

        // Fire the onClose event
        Throwable throwable = null;
        InstanceManager instanceManager = webSocketContainer.getInstanceManager();
        Thread t = Thread.currentThread();
        ClassLoader cl = t.getContextClassLoader();
        t.setContextClassLoader(applicationClassLoader);
        try {
            localEndpoint.onClose(this, closeReason);
        } catch (Throwable t1) {
            ExceptionUtils.handleThrowable(t1);
            throwable = t1;
        } finally {
            if (instanceManager != null) {
                try {
                    instanceManager.destroyInstance(localEndpoint);
                } catch (Throwable t2) {
                    ExceptionUtils.handleThrowable(t2);
                    if (throwable == null) {
                        throwable = t2;
                    }
                }
            }
            t.setContextClassLoader(cl);
        }

        if (throwable != null) {
            fireEndpointOnError(throwable);
        }
    }
 
Example #13
Source File: TestDefaultInstanceManager.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Ignore
@Test
public void testConcurrency() throws Exception {
    // Create a populated InstanceManager
    Tomcat tomcat = getTomcatInstance();
    Context ctx = tomcat.addContext(null, "", null);

    tomcat.start();

    InstanceManager im = ctx.getInstanceManager();

    for (int i = 1; i < 9; i++) {
        doTestConcurrency(im, i);
    }
}
 
Example #14
Source File: InstanceManagerFactory.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public static InstanceManager getInstanceManager(ServletConfig config) {
    InstanceManager instanceManager =
            (InstanceManager) config.getServletContext().getAttribute(InstanceManager.class.getName());
    if (instanceManager == null) {
        throw new IllegalStateException("No org.apache.tomcat.InstanceManager set in ServletContext");
    }
    return instanceManager;
}
 
Example #15
Source File: JasperInitializer.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public void onStartup(Set<Class<?>> types, ServletContext context) throws ServletException {
    if (log.isDebugEnabled()) {
        log.debug(Localizer.getMessage(MSG + ".onStartup", context.getServletContextName()));
    }

    // Setup a simple default Instance Manager
    if (context.getAttribute(InstanceManager.class.getName())==null) {
        context.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());
    }

    boolean validate = Boolean.parseBoolean(
            context.getInitParameter(Constants.XML_VALIDATION_TLD_INIT_PARAM));
    String blockExternalString = context.getInitParameter(
            Constants.XML_BLOCK_EXTERNAL_INIT_PARAM);
    boolean blockExternal;
    if (blockExternalString == null) {
        blockExternal = true;
    } else {
        blockExternal = Boolean.parseBoolean(blockExternalString);
    }

    // scan the application for TLDs
    TldScanner scanner = newTldScanner(context, true, validate, blockExternal);
    try {
        scanner.scan();
    } catch (IOException | SAXException e) {
        throw new ServletException(e);
    }

    // add any listeners defined in TLDs
    for (String listener : scanner.getListeners()) {
        context.addListener(listener);
    }

    context.setAttribute(TldCache.SERVLET_CONTEXT_ATTRIBUTE_NAME,
            new TldCache(context, scanner.getUriTldResourcePathMap(),
                    scanner.getTldResourcePathTaglibXmlMap()));
}
 
Example #16
Source File: Request.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @since Servlet 3.1
 */
@SuppressWarnings("unchecked")
@Override
public <T extends HttpUpgradeHandler> T upgrade(
        Class<T> httpUpgradeHandlerClass) throws java.io.IOException, ServletException {
    T handler;
    InstanceManager instanceManager = null;
    try {
        // Do not go through the instance manager for internal Tomcat classes since they don't
        // need injection
        if (InternalHttpUpgradeHandler.class.isAssignableFrom(httpUpgradeHandlerClass)) {
            handler = httpUpgradeHandlerClass.getConstructor().newInstance();
        } else {
            instanceManager = getContext().getInstanceManager();
            handler = (T) instanceManager.newInstance(httpUpgradeHandlerClass);
        }
    } catch (InstantiationException | IllegalAccessException | InvocationTargetException |
            NamingException | IllegalArgumentException | NoSuchMethodException |
            SecurityException e) {
        throw new ServletException(e);
    }
    UpgradeToken upgradeToken = new UpgradeToken(handler,
            getContext(), instanceManager);

    coyoteRequest.action(ActionCode.UPGRADE, upgradeToken);

    // Output required by RFC2616. Protocol specific headers should have
    // already been set.
    response.setStatus(HttpServletResponse.SC_SWITCHING_PROTOCOLS);

    return handler;
}
 
Example #17
Source File: JavaEEDefaultServerEnpointConfigurator.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public <T> T getEndpointInstance(final Class<T> clazz) throws InstantiationException {
    final ClassLoader classLoader = clazz.getClassLoader();
    InstanceManager instanceManager = instanceManagers.get(classLoader);

    if (instanceManager == null) {
        final ClassLoader tccl = Thread.currentThread().getContextClassLoader();
        if (tccl != null) {
            instanceManager = instanceManagers.get(tccl);
        }
    }
    // if we have a single app fallback otherwise we don't have enough contextual information here
    if (instanceManager == null && instanceManagers.size() == 1) {
        instanceManager = instanceManagers.values().iterator().next();
    }
    if (instanceManager == null) {
        return super.getEndpointInstance(clazz);
    }

    try {
        return clazz.cast(instanceManager.newInstance(clazz));
    } catch (final Exception e) {
        if (InstantiationException.class.isInstance(e)) {
            throw InstantiationException.class.cast(e);
        }
        throw new InstantiationException(e.getMessage());
    }
}
 
Example #18
Source File: ApplicationFilterConfig.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
private InstanceManager getInstanceManager() {
    if (instanceManager == null) {
        if (context instanceof StandardContext) {
            instanceManager = ((StandardContext)context).getInstanceManager();
        } else {
            instanceManager = new DefaultInstanceManager(null,
                    new HashMap<String, Map<String, String>>(),
                    context,
                    getClass().getClassLoader());
        }
    }
    return instanceManager;
}
 
Example #19
Source File: HttpBindManager.java    From Openfire with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a Jetty context handler that can be used to expose BOSH (HTTP-Bind) functionality.
 *
 * Note that an invocation of this method will not register the handler (and thus make the related functionality
 * available to the end user). Instead, the created handler is returned by this method, and will need to be
 * registered with the embedded Jetty webserver by the caller.
 *
 * @return A Jetty context handler (never null).
 */
protected Handler createBoshHandler()
{
    final int options;
    if(isHttpCompressionEnabled()) {
        options = ServletContextHandler.SESSIONS | ServletContextHandler.GZIP;
    } else {
        options = ServletContextHandler.SESSIONS;
    }
    final ServletContextHandler context = new ServletContextHandler( null, "/http-bind", options );

    // Ensure the JSP engine is initialized correctly (in order to be able to cope with Tomcat/Jasper precompiled JSPs).
    final List<ContainerInitializer> initializers = new ArrayList<>();
    initializers.add( new ContainerInitializer( new JasperInitializer(), null ) );
    context.setAttribute( "org.eclipse.jetty.containerInitializers", initializers );
    context.setAttribute( InstanceManager.class.getName(), new SimpleInstanceManager() );

    // Generic configuration of the context.
    context.setAllowNullPathInfo( true );

    // Add the functionality-providers.
    context.addServlet( new ServletHolder( new HttpBindServlet() ), "/*" );

    // Add compression filter when needed.
    if (isHttpCompressionEnabled()) {
        final GzipHandler gzipHandler = context.getGzipHandler();
        gzipHandler.addIncludedPaths("/*");
        gzipHandler.addIncludedMethods(HttpMethod.POST.asString());
    }

    return context;
}
 
Example #20
Source File: WsSession.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
private void fireEndpointOnClose(CloseReason closeReason) {

        // Fire the onClose event
        Throwable throwable = null;
        InstanceManager instanceManager = webSocketContainer.getInstanceManager();
        if (instanceManager == null) {
            instanceManager = InstanceManagerBindings.get(applicationClassLoader);
        }
        Thread t = Thread.currentThread();
        ClassLoader cl = t.getContextClassLoader();
        t.setContextClassLoader(applicationClassLoader);
        try {
            localEndpoint.onClose(this, closeReason);
        } catch (Throwable t1) {
            ExceptionUtils.handleThrowable(t1);
            throwable = t1;
        } finally {
            if (instanceManager != null) {
                try {
                    instanceManager.destroyInstance(localEndpoint);
                } catch (Throwable t2) {
                    ExceptionUtils.handleThrowable(t2);
                    if (throwable == null) {
                        throwable = t2;
                    }
                }
            }
            t.setContextClassLoader(cl);
        }

        if (throwable != null) {
            fireEndpointOnError(throwable);
        }
    }
 
Example #21
Source File: WsServerContainer.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
WsServerContainer(ServletContext servletContext) {

        this.servletContext = servletContext;
        setInstanceManager((InstanceManager) servletContext.getAttribute(InstanceManager.class.getName()));

        // Configure servlet context wide defaults
        String value = servletContext.getInitParameter(
                Constants.BINARY_BUFFER_SIZE_SERVLET_CONTEXT_INIT_PARAM);
        if (value != null) {
            setDefaultMaxBinaryMessageBufferSize(Integer.parseInt(value));
        }

        value = servletContext.getInitParameter(
                Constants.TEXT_BUFFER_SIZE_SERVLET_CONTEXT_INIT_PARAM);
        if (value != null) {
            setDefaultMaxTextMessageBufferSize(Integer.parseInt(value));
        }

        value = servletContext.getInitParameter(
                Constants.ENFORCE_NO_ADD_AFTER_HANDSHAKE_CONTEXT_INIT_PARAM);
        if (value != null) {
            setEnforceNoAddAfterHandshake(Boolean.parseBoolean(value));
        }

        FilterRegistration.Dynamic fr = servletContext.addFilter(
                "Tomcat WebSocket (JSR356) Filter", new WsFilter());
        fr.setAsyncSupported(true);

        EnumSet<DispatcherType> types = EnumSet.of(DispatcherType.REQUEST,
                DispatcherType.FORWARD);

        fr.addMappingForUrlPatterns(types, true, "/*");
    }
 
Example #22
Source File: InstanceManagerFactory.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public static InstanceManager getInstanceManager(ServletConfig config) {
    InstanceManager instanceManager = 
            (InstanceManager) config.getServletContext().getAttribute(InstanceManager.class.getName());
    if (instanceManager == null) {
        throw new IllegalStateException("No org.apache.tomcat.InstanceManager set in ServletContext");
    }
    return instanceManager;
}
 
Example #23
Source File: WsWebSocketContainer.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
InstanceManager getInstanceManager() {
    return instanceManager;
}
 
Example #24
Source File: TesterContext.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
public void setInstanceManager(InstanceManager instanceManager) {
    // NO-OP
}
 
Example #25
Source File: WsSession.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new WebSocket session for communication between the two
 * provided end points. The result of {@link Thread#getContextClassLoader()}
 * at the time this constructor is called will be used when calling
 * {@link Endpoint#onClose(Session, CloseReason)}.
 *
 * @param localEndpoint
 * @param wsRemoteEndpoint
 * @param negotiatedExtensions
 * @throws DeploymentException
 */
public WsSession(Endpoint localEndpoint,
        WsRemoteEndpointImplBase wsRemoteEndpoint,
        WsWebSocketContainer wsWebSocketContainer,
        URI requestUri, Map<String,List<String>> requestParameterMap,
        String queryString, Principal userPrincipal, String httpSessionId,
        List<Extension> negotiatedExtensions, String subProtocol, Map<String,String> pathParameters,
        boolean secure, EndpointConfig endpointConfig) throws DeploymentException {
    this.localEndpoint = localEndpoint;
    this.wsRemoteEndpoint = wsRemoteEndpoint;
    this.wsRemoteEndpoint.setSession(this);
    this.remoteEndpointAsync = new WsRemoteEndpointAsync(wsRemoteEndpoint);
    this.remoteEndpointBasic = new WsRemoteEndpointBasic(wsRemoteEndpoint);
    this.webSocketContainer = wsWebSocketContainer;
    applicationClassLoader = Thread.currentThread().getContextClassLoader();
    wsRemoteEndpoint.setSendTimeout(
            wsWebSocketContainer.getDefaultAsyncSendTimeout());
    this.maxBinaryMessageBufferSize =
            webSocketContainer.getDefaultMaxBinaryMessageBufferSize();
    this.maxTextMessageBufferSize =
            webSocketContainer.getDefaultMaxTextMessageBufferSize();
    this.maxIdleTimeout =
            webSocketContainer.getDefaultMaxSessionIdleTimeout();
    this.requestUri = requestUri;
    if (requestParameterMap == null) {
        this.requestParameterMap = Collections.emptyMap();
    } else {
        this.requestParameterMap = requestParameterMap;
    }
    this.queryString = queryString;
    this.userPrincipal = userPrincipal;
    this.httpSessionId = httpSessionId;
    this.negotiatedExtensions = negotiatedExtensions;
    if (subProtocol == null) {
        this.subProtocol = "";
    } else {
        this.subProtocol = subProtocol;
    }
    this.pathParameters = pathParameters;
    this.secure = secure;
    this.wsRemoteEndpoint.setEncoders(endpointConfig);
    this.endpointConfig = endpointConfig;

    this.userProperties.putAll(endpointConfig.getUserProperties());
    this.id = Long.toHexString(ids.getAndIncrement());

    InstanceManager instanceManager = webSocketContainer.getInstanceManager();
    if (instanceManager != null) {
        try {
            instanceManager.newInstance(localEndpoint);
        } catch (Exception e) {
            throw new DeploymentException(sm.getString("wsSession.instanceNew"), e);
        }
    }

    if (log.isDebugEnabled()) {
        log.debug(sm.getString("wsSession.created", id));
    }
}
 
Example #26
Source File: WsWebSocketContainer.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
protected void setInstanceManager(InstanceManager instanceManager) {
    this.instanceManager = instanceManager;
}
 
Example #27
Source File: WsServerContainer.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
WsServerContainer(ServletContext servletContext) {

        this.servletContext = servletContext;
        setInstanceManager((InstanceManager) servletContext.getAttribute(InstanceManager.class.getName()));

        // Configure servlet context wide defaults
        String value = servletContext.getInitParameter(
                Constants.BINARY_BUFFER_SIZE_SERVLET_CONTEXT_INIT_PARAM);
        if (value != null) {
            setDefaultMaxBinaryMessageBufferSize(Integer.parseInt(value));
        }

        value = servletContext.getInitParameter(
                Constants.TEXT_BUFFER_SIZE_SERVLET_CONTEXT_INIT_PARAM);
        if (value != null) {
            setDefaultMaxTextMessageBufferSize(Integer.parseInt(value));
        }

        value = servletContext.getInitParameter(
                Constants.ENFORCE_NO_ADD_AFTER_HANDSHAKE_CONTEXT_INIT_PARAM);
        if (value != null) {
            setEnforceNoAddAfterHandshake(Boolean.parseBoolean(value));
        }
        // Executor config
        int executorCoreSize = 0;
        long executorKeepAliveTimeSeconds = 60;
        value = servletContext.getInitParameter(
                Constants.EXECUTOR_CORE_SIZE_INIT_PARAM);
        if (value != null) {
            executorCoreSize = Integer.parseInt(value);
        }
        value = servletContext.getInitParameter(
                Constants.EXECUTOR_KEEPALIVETIME_SECONDS_INIT_PARAM);
        if (value != null) {
            executorKeepAliveTimeSeconds = Long.parseLong(value);
        }

        FilterRegistration.Dynamic fr = servletContext.addFilter(
                "Tomcat WebSocket (JSR356) Filter", new WsFilter());
        fr.setAsyncSupported(true);

        EnumSet<DispatcherType> types = EnumSet.of(DispatcherType.REQUEST,
                DispatcherType.FORWARD);

        fr.addMappingForUrlPatterns(types, true, "/*");

        // Use a per web application executor for any threads that the WebSocket
        // server code needs to create. Group all of the threads under a single
        // ThreadGroup.
        StringBuffer threadGroupName = new StringBuffer("WebSocketServer-");
        if ("".equals(servletContext.getContextPath())) {
            threadGroupName.append("ROOT");
        } else {
            threadGroupName.append(servletContext.getContextPath());
        }
        threadGroup = new ThreadGroup(threadGroupName.toString());
        WsThreadFactory wsThreadFactory = new WsThreadFactory(threadGroup);

        executorService = new ThreadPoolExecutor(executorCoreSize,
                Integer.MAX_VALUE, executorKeepAliveTimeSeconds, TimeUnit.SECONDS,
                new SynchronousQueue<Runnable>(), wsThreadFactory);
    }
 
Example #28
Source File: FailedContext.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
public void setInstanceManager(InstanceManager instanceManager) { /* NO-OP */ }
 
Example #29
Source File: TesterContext.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
public InstanceManager getInstanceManager() {
    return null;
}
 
Example #30
Source File: FailedContext.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
public InstanceManager getInstanceManager() { return null; }