Search in sources :

Example 6 with InstanceManager

use of org.apache.tomcat.InstanceManager in project tomcat by apache.

the class JspServletWrapper method getServlet.

public Servlet getServlet() throws ServletException {
    // new servlet object is read consistently)
    if (reload) {
        synchronized (this) {
            // of different pages, but not the same page.
            if (reload) {
                // This is to maintain the original protocol.
                destroy();
                final Servlet servlet;
                try {
                    InstanceManager instanceManager = InstanceManagerFactory.getInstanceManager(config);
                    servlet = (Servlet) instanceManager.newInstance(ctxt.getFQCN(), ctxt.getJspLoader());
                } catch (Exception e) {
                    Throwable t = ExceptionUtils.unwrapInvocationTargetException(e);
                    ExceptionUtils.handleThrowable(t);
                    throw new JasperException(t);
                }
                servlet.init(config);
                if (!firstTime) {
                    ctxt.getRuntimeContext().incrementJspReloadCount();
                }
                theServlet = servlet;
                reload = false;
            // Volatile 'reload' forces in order write of 'theServlet' and new servlet object
            }
        }
    }
    return theServlet;
}
Also used : JasperException(org.apache.jasper.JasperException) InstanceManager(org.apache.tomcat.InstanceManager) Servlet(javax.servlet.Servlet) ServletException(javax.servlet.ServletException) JasperException(org.apache.jasper.JasperException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UnavailableException(javax.servlet.UnavailableException)

Example 7 with InstanceManager

use of org.apache.tomcat.InstanceManager in project tomcat by apache.

the class TestDefaultInstanceManager method testConcurrency.

/*
     * Performance test. Comment out @Ignore to run the test.
     */
@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);
    }
}
Also used : Context(org.apache.catalina.Context) Tomcat(org.apache.catalina.startup.Tomcat) InstanceManager(org.apache.tomcat.InstanceManager) Ignore(org.junit.Ignore) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 8 with InstanceManager

use of org.apache.tomcat.InstanceManager in project tomee by apache.

the class JavaEEDefaultServerEnpointConfigurator method getEndpointInstance.

@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());
    }
}
Also used : InstanceManager(org.apache.tomcat.InstanceManager)

Aggregations

InstanceManager (org.apache.tomcat.InstanceManager)8 ServletException (javax.servlet.ServletException)4 IOException (java.io.IOException)3 NamingException (javax.naming.NamingException)3 Servlet (javax.servlet.Servlet)2 LifecycleException (org.apache.catalina.LifecycleException)2 FileNotFoundException (java.io.FileNotFoundException)1 PrintStream (java.io.PrintStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ListenerNotFoundException (javax.management.ListenerNotFoundException)1 Context (javax.naming.Context)1