Java Code Examples for org.apache.catalina.LifecycleException

The following examples show how to use org.apache.catalina.LifecycleException. These examples are extracted from open source projects. 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 Project: rock-paper-scissors-in-java   Source File: RpsMain.java    License: MIT License 6 votes vote down vote up
public static void main(String[] args) throws Exception, LifecycleException {
    // Define a folder to hold web application contents.
    String webappDirLocation = "src/main/webapp/";
    Tomcat tomcat = new Tomcat();

    // Define port number for the web application
    String webPort = System.getenv("PORT");
    if (webPort == null || webPort.isEmpty()) {
        webPort = "8080";
    }
    // Bind the port to Tomcat server
    tomcat.setPort(Integer.valueOf(webPort));

    // Define a web application context.
    Context context = tomcat.addWebapp("", new File(webappDirLocation).getAbsolutePath());

    // Define and bind web.xml file location.
    File configFile = new File(webappDirLocation + "WEB-INF/web.xml");
    context.setConfigFile(configFile.toURI().toURL());

    tomcat.start();
    logger.info("Server started at http://localhost:{}", webPort);
    tomcat.getServer().await();
}
 
Example 2
Source Project: api-layer   Source File: TomcatServerFactory.java    License: Eclipse Public License 2.0 6 votes vote down vote up
public static void main(String[] args) throws LifecycleException, ClientProtocolException, IOException {
    log.debug("Cwd: {}", System.getProperty("user.dir"));

    HttpsConfig httpsConfig = HttpsConfig.builder()
            .keyStore(new File("keystore/localhost/localhost.keystore.p12").getCanonicalPath())
            .keyStorePassword(STORE_PASSWORD).keyPassword(STORE_PASSWORD)
            .trustStore(new File("keystore/localhost/localhost.truststore.p12").getCanonicalPath())
            .trustStorePassword(STORE_PASSWORD).protocol("TLSv1.2").build();
    HttpsFactory httpsFactory = new HttpsFactory(httpsConfig);

    Tomcat tomcat = new TomcatServerFactory().startTomcat(httpsConfig);
    try {
        HttpClient client = httpsFactory.createSecureHttpClient();

        int port = getLocalPort(tomcat);
        HttpGet get = new HttpGet(String.format("https://localhost:%d", port));
        HttpResponse response = client.execute(get);

        String responseBody = EntityUtils.toString(response.getEntity());

        assertEquals(200, response.getStatusLine().getStatusCode());
        assertEquals("OK", responseBody);
    } finally {
        tomcat.stop();
    }
}
 
Example 3
Source Project: tomcatsrc   Source File: TestReplicatedContext.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testBug57425() throws LifecycleException, IOException {
    Tomcat tomcat = getTomcatInstance();
    Host host = tomcat.getHost();
    if (host instanceof StandardHost) {
        ((StandardHost) host).setContextClass(ReplicatedContext.class.getName());
    }

    File root = new File("test/webapp-3.0");
    Context context = tomcat.addWebapp(host, "", root.getAbsolutePath());

    Tomcat.addServlet(context, "test", new AccessContextServlet());
    context.addServletMapping("/access", "test");

    tomcat.start();

    ByteChunk result = getUrl("http://localhost:" + getPort() + "/access");

    Assert.assertEquals("OK", result.toString());

}
 
Example 4
Source Project: tomcatsrc   Source File: BackupManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Stop this component and implement the requirements
 * of {@link org.apache.catalina.util.LifecycleBase#stopInternal()}.
 *
 * This will disconnect the cluster communication channel and stop the
 * listener thread.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected synchronized void stopInternal() throws LifecycleException {

    if (log.isDebugEnabled())
        log.debug(sm.getString("backupManager.stopped", getName()));

    setState(LifecycleState.STOPPING);

    if (sessions instanceof LazyReplicatedMap) {
        LazyReplicatedMap<String,Session> map =
                (LazyReplicatedMap<String,Session>)sessions;
        map.breakdown();
    }

    super.stopInternal();
}
 
Example 5
Source Project: Tomcat7.0.67   Source File: Connector.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void destroyInternal() throws LifecycleException {
    mapperListener.destroy();

    try {
        protocolHandler.destroy();
    } catch (Exception e) {
        throw new LifecycleException
            (sm.getString
             ("coyoteConnector.protocolHandlerDestroyFailed"), e);
    }

    if (getService() != null) {
        getService().removeConnector(this);
    }

    super.destroyInternal();
}
 
Example 6
Source Project: Tomcat8-Source-Read   Source File: CombinedRealm.java    License: MIT License 6 votes vote down vote up
/**
 * Prepare for the beginning of active use of the public methods of this
 * component and implement the requirements of
 * {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected void startInternal() throws LifecycleException {
    // Start 'sub-realms' then this one
    Iterator<Realm> iter = realms.iterator();

    while (iter.hasNext()) {
        Realm realm = iter.next();
        if (realm instanceof Lifecycle) {
            try {
                ((Lifecycle) realm).start();
            } catch (LifecycleException e) {
                // If realm doesn't start can't authenticate against it
                iter.remove();
                log.error(sm.getString("combinedRealm.realmStartFail",
                        realm.getClass().getName()), e);
            }
        }
    }
    super.startInternal();
}
 
Example 7
Source Project: Tomcat8-Source-Read   Source File: StandardService.java    License: MIT License 6 votes vote down vote up
/**
 * Add a new Connector to the set of defined Connectors, and associate it
 * with this Service's Container.
 *
 * @param connector The Connector to be added
 */
@Override
public void addConnector(Connector connector) {

    synchronized (connectorsLock) {
        connector.setService(this);
        Connector results[] = new Connector[connectors.length + 1];
        System.arraycopy(connectors, 0, results, 0, connectors.length);
        results[connectors.length] = connector;
        connectors = results;

        if (getState().isAvailable()) {
            try {
                connector.start();
            } catch (LifecycleException e) {
                log.error(sm.getString(
                        "standardService.connector.startFailed",
                        connector), e);
            }
        }

        // Report this property change to interested listeners
        support.firePropertyChange("connector", null, connector);
    }

}
 
Example 8
Source Project: tomcatsrc   Source File: JNDIRealm.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Prepare for the beginning of active use of the public methods of this
 * component and implement the requirements of
 * {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected void startInternal() throws LifecycleException {

    // Check to see if the connection to the directory can be opened
    try {
        open();
    } catch (NamingException e) {
        // A failure here is not fatal as the directory may be unavailable
        // now but available later. Unavailability of the directory is not
        // fatal once the Realm has started so there is no reason for it to
        // be fatal when the Realm starts.
        containerLog.error(sm.getString("jndiRealm.open"), e);
    }

    super.startInternal();
}
 
Example 9
Source Project: Tomcat7.0.67   Source File: DeltaManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Stop this component and implement the requirements
 * of {@link org.apache.catalina.util.LifecycleBase#stopInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected synchronized void stopInternal() throws LifecycleException {

    if (log.isDebugEnabled())
        log.debug(sm.getString("deltaManager.stopped", getName()));

    setState(LifecycleState.STOPPING);
    
    // Expire all active sessions
    if (log.isInfoEnabled()) log.info(sm.getString("deltaManager.expireSessions", getName()));
    Session sessions[] = findSessions();
    for (int i = 0; i < sessions.length; i++) {
        DeltaSession session = (DeltaSession) sessions[i];
        if (!session.isValid())
            continue;
        try {
            session.expire(true, isExpireSessionsOnShutdown());
        } catch (Throwable t) {
            ExceptionUtils.handleThrowable(t);
        } 
    }

    // Require a new random number generator if we are restarted
    super.stopInternal();
}
 
Example 10
Source Project: Tomcat7.0.67   Source File: UserDatabaseRealm.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Prepare for the beginning of active use of the public methods of this
 * component and implement the requirements of
 * {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected void startInternal() throws LifecycleException {

    try {
        Context context = getServer().getGlobalNamingContext();
        database = (UserDatabase) context.lookup(resourceName);
    } catch (Throwable e) {
        ExceptionUtils.handleThrowable(e);
        containerLog.error(sm.getString("userDatabaseRealm.lookup",
                                        resourceName),
                           e);
        database = null;
    }
    if (database == null) {
        throw new LifecycleException
            (sm.getString("userDatabaseRealm.noDatabase", resourceName));
    }

    super.startInternal();
}
 
Example 11
Source Project: Tomcat8-Source-Read   Source File: TomcatBaseTest.java    License: MIT License 6 votes vote down vote up
/**
 * Make the Tomcat instance preconfigured with test/webapp available to
 * sub-classes.
 * @param addJstl Should JSTL support be added to the test webapp
 * @param start   Should the Tomcat instance be started
 *
 * @return A Tomcat instance pre-configured with the web application located
 *         at test/webapp
 *
 * @throws LifecycleException If a problem occurs while starting the
 *                            instance
 */
public Tomcat getTomcatInstanceTestWebapp(boolean addJstl, boolean start)
        throws LifecycleException {
    File appDir = new File("test/webapp");
    Context ctx = tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    StandardJarScanner scanner = (StandardJarScanner) ctx.getJarScanner();
    StandardJarScanFilter filter = (StandardJarScanFilter) scanner.getJarScanFilter();
    filter.setTldSkip(filter.getTldSkip() + ",testclasses");
    filter.setPluggabilitySkip(filter.getPluggabilitySkip() + ",testclasses");

    if (addJstl) {
        File lib = new File("webapps/examples/WEB-INF/lib");
        ctx.setResources(new StandardRoot(ctx));
        ctx.getResources().createWebResourceSet(
                WebResourceRoot.ResourceSetType.POST, "/WEB-INF/lib",
                lib.getAbsolutePath(), null, "/");
    }

    if (start) {
        tomcat.start();
    }
    return tomcat;
}
 
Example 12
Source Project: joinfaces   Source File: JsfTomcatApplicationListenerIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void embeddedJarWithoutAppResources2() throws LifecycleException {
	ContextMock contextMock = new ContextMock();

	File file = new File(TARGET + File.separator + TEST_CLASSES + File.separator + "test.jar");
	JarWarResourceSet jarWarResourceSet = new JarWarResourceSet(contextMock.getWebResourceRoot(),
		"/", file.getAbsolutePath(), INTERNAL_JAR, METAINF_RESOURCES);
	jarWarResourceSet.init();

	DirResourceSet dirResourceSet = new DirResourceSet(contextMock.getWebResourceRoot(),
		TEST, TEST, TEST);

	contextMock.init(dirResourceSet, jarWarResourceSet);

	callApplicationEvent(contextMock);

	assertThat(contextMock.getWebResourceRoot().getCreateWebResourceSetCalls())
		.isEqualTo(2);
}
 
Example 13
Source Project: tomcatsrc   Source File: TestRemoteIpFilter.java    License: Apache License 2.0 6 votes vote down vote up
private MockFilterChain testRemoteIpFilter(FilterDef filterDef, Request request)
        throws LifecycleException, IOException, ServletException {
    Tomcat tomcat = getTomcatInstance();
    Context root = tomcat.addContext("", TEMP_DIR);

    RemoteIpFilter remoteIpFilter = new RemoteIpFilter();
    filterDef.setFilterClass(RemoteIpFilter.class.getName());
    filterDef.setFilter(remoteIpFilter);
    filterDef.setFilterName(RemoteIpFilter.class.getName());
    root.addFilterDef(filterDef);

    FilterMap filterMap = new FilterMap();
    filterMap.setFilterName(RemoteIpFilter.class.getName());
    filterMap.addURLPattern("*");
    root.addFilterMap(filterMap);

    getTomcatInstance().start();

    MockFilterChain filterChain = new MockFilterChain();

    // TEST
    TesterResponse response = new TesterResponse();
    response.setRequest(request);
    remoteIpFilter.doFilter(request, response, filterChain);
    return filterChain;
}
 
Example 14
Source Project: tomee   Source File: TomcatWebAppBuilder.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void destroy(final StandardContext standardContext) {
    final Loader standardContextLoader = standardContext.getLoader();
    if (LazyStopLoader.class.isInstance(standardContextLoader)) {
        final Loader delegate = LazyStopLoader.class.cast(standardContextLoader).getDelegateLoader();
        if (TomEEWebappLoader.class.isInstance(delegate)) {
            final TomEEWebappLoader webappLoader = TomEEWebappLoader.class.cast(delegate);
            final ClassLoader loader = webappLoader.internalLoader();
            webappLoader.clearLoader();
            if (TomEEWebappClassLoader.class.isInstance(loader)) {
                TomEEWebappClassLoader.class.cast(loader).internalDestroy();
            }
        }
    }

    final WebResourceRoot root = standardContext.getResources();
    if (LazyStopStandardRoot.class.isInstance(root)) {
        try {
            LazyStopStandardRoot.class.cast(root).internalDestroy();
        } catch (final LifecycleException e) {
            throw new IllegalStateException(e);
        }
    }
}
 
Example 15
Source Project: tomcatsrc   Source File: PersistentManagerBase.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Start this component and implement the requirements
 * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected synchronized void startInternal() throws LifecycleException {

    super.startInternal();

    if (store == null)
        log.error("No Store configured, persistence disabled");
    else if (store instanceof Lifecycle)
        ((Lifecycle)store).start();

    setState(LifecycleState.STARTING);
}
 
Example 16
Source Project: tomcatsrc   Source File: JvmRouteSessionIDBinderListener.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Add this Mover as Cluster Listener ( receiver)
 * 
 * @throws LifecycleException
 */
public void start() throws LifecycleException {
    if (started)
        return;
    getCluster().addClusterListener(this);
    started = true;
    if (log.isInfoEnabled())
        log.info(sm.getString("jvmRoute.clusterListener.started"));
}
 
Example 17
Source Project: Tomcat8-Source-Read   Source File: ClusterManagerBase.java    License: MIT License 5 votes vote down vote up
@Override
protected void startInternal() throws LifecycleException {
    super.startInternal();
    if (getCluster() == null) {
        Cluster cluster = getContext().getCluster();
        if (cluster instanceof CatalinaCluster) {
            setCluster((CatalinaCluster)cluster);
        }
    }
    if (cluster != null) cluster.registerManager(this);
}
 
Example 18
Source Project: Tomcat7.0.67   Source File: TestPersistentManager.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void noSessionCreate_57637() throws IOException, LifecycleException {

    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0-fragments-empty-absolute-ordering");
    StandardContext ctx = (StandardContext) tomcat.addContext("", appDir.getAbsolutePath());

    Tomcat.addServlet(ctx, "DummyServlet", new DummyServlet());
    ctx.addServletMapping("/dummy", "DummyServlet");

    PersistentManager manager = new PersistentManager();
    DummyStore store = new DummyStore();

    manager.setStore(store);
    manager.setMaxIdleBackup(0);
    manager.setDistributable(true);
    ctx.setManager(manager);
    ctx.addValve(new PersistentValve());
    tomcat.start();
    Assert.assertEquals(manager.getActiveSessions(), 0);
    Assert.assertTrue("No sessions managed", manager.getSessionIdsFull().isEmpty());
    Assert.assertEquals(
            "NO_SESSION",
            getUrl(
                    "http://localhost:" + getPort()
                            + "/dummy?no_create_session=true").toString());
    Assert.assertEquals(manager.getActiveSessions(), 0);
    Assert.assertTrue("No sessions where created", manager.getSessionIdsFull().isEmpty());
}
 
Example 19
Source Project: Tomcat8-Source-Read   Source File: ClusterSingleSignOn.java    License: MIT License 5 votes vote down vote up
/**
 * Start this component and implement the requirements
 * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected synchronized void startInternal() throws LifecycleException {

    // Load the cluster component, if any
    try {
        if(cluster == null) {
            Container host = getContainer();
            if(host instanceof Host) {
                if(host.getCluster() instanceof CatalinaCluster) {
                    setCluster((CatalinaCluster) host.getCluster());
                }
            }
        }
        if (cluster == null) {
            throw new LifecycleException(sm.getString("clusterSingleSignOn.nocluster"));
        }

        ClassLoader[] cls = new ClassLoader[] { this.getClass().getClassLoader() };

        ReplicatedMap<String,SingleSignOnEntry> cache = new ReplicatedMap<>(
                this, cluster.getChannel(), rpcTimeout, cluster.getClusterName() + "-SSO-cache",
                cls, terminateOnStartFailure);
        cache.setChannelSendOptions(mapSendOptions);
        cache.setAccessTimeout(accessTimeout);
        this.cache = cache;
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        throw new LifecycleException(sm.getString("clusterSingleSignOn.clusterLoad.fail"), t);
    }

    super.startInternal();
}
 
Example 20
Source Project: redisson   Source File: RedissonSessionManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void stopInternal() throws LifecycleException {
    super.stopInternal();
    
    setState(LifecycleState.STOPPING);
    
    Pipeline pipeline = getEngine().getPipeline();
    synchronized (pipeline) {
        contextInUse.remove(getContext().getName());
        //remove valves when all of the RedissonSessionManagers (web apps) are not in use anymore
        if (contextInUse.isEmpty()) {
            if (updateValve != null) {
                pipeline.removeValve(updateValve);
                updateValve = null;
            }
        }
    }
    
    if (messageListener != null) {
         RTopic updatesTopic = getTopic();
         updatesTopic.removeListener(messageListener);
    }

    codecToUse = null;

    try {
        shutdownRedisson();
    } catch (Exception e) {
        throw new LifecycleException(e);
    }
    
}
 
Example 21
Source Project: tomcatsrc   Source File: TestStandardContext.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testWebappLoaderStartFail() throws Exception {
    // Test that if WebappLoader start() fails and if the cause of
    // the failure is gone, the context can be started without
    // a need to redeploy it.

    // Set up a container
    Tomcat tomcat = getTomcatInstance();
    tomcat.start();
    // To not start Context automatically, as we have to configure it first
    ((ContainerBase) tomcat.getHost()).setStartChildren(false);

    FailingWebappLoader loader = new FailingWebappLoader();
    File root = new File("test/webapp-3.0");
    Context context = tomcat.addWebapp("", root.getAbsolutePath());
    context.setLoader(loader);

    try {
        context.start();
        fail();
    } catch (LifecycleException ex) {
        // As expected
    }
    assertEquals(LifecycleState.FAILED, context.getState());

    // The second attempt
    loader.setFail(false);
    context.start();
    assertEquals(LifecycleState.STARTED, context.getState());

    // Using a test from testBug49922() to check that the webapp is running
    ByteChunk result = getUrl("http://localhost:" + getPort() +
            "/bug49922/target");
    assertEquals("Target", result.toString());
}
 
Example 22
Source Project: tomcat-runtime   Source File: TraceValveTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = LifecycleException.class)
public void testServiceInitializationError() throws Exception {
  valve.setTraceScheduledDelay(60);
  TraceValve spiedValve = spy(valve);
  Builder builder = spy(TraceGrpcApiService.builder());
  when(builder.build()).thenThrow(new IOException());
  when(spiedValve.getTraceService()).thenReturn(builder);
  spiedValve.initTraceService();
}
 
Example 23
@Test
public void transitionStoppingPrepStopping() throws LifecycleException {
    this.lifecycleStateMachine.transition(INITIALIZING);
    this.lifecycleStateMachine.transition(INITIALIZED);
    this.lifecycleStateMachine.transition(STARTING_PREP);
    this.lifecycleStateMachine.transition(STARTING);
    this.lifecycleStateMachine.transition(STARTED);
    this.lifecycleStateMachine.transition(STOPPING_PREP);
    assertTransition(STOPPING);
}
 
Example 24
Source Project: Tomcat7.0.67   Source File: ContainerBase.java    License: Apache License 2.0 5 votes vote down vote up
private void addChildInternal(Container child) {

        if( log.isDebugEnabled() )
            log.debug("Add child " + child + " " + this);
        synchronized(children) {
            if (children.get(child.getName()) != null)
                throw new IllegalArgumentException("addChild:  Child name '" +
                                                   child.getName() +
                                                   "' is not unique");
            child.setParent(this);  // May throw IAE
            children.put(child.getName(), child);
        }

        // Start child
        // Don't do this inside sync block - start can be a slow process and
        // locking the children object can cause problems elsewhere
        try {
            if ((getState().isAvailable() ||
                    LifecycleState.STARTING_PREP.equals(getState())) &&
                    startChildren) {
                child.start();
            }
        } catch (LifecycleException e) {
            log.error("ContainerBase.addChild: start: ", e);
            throw new IllegalStateException("ContainerBase.addChild: start: " + e);
        } finally {
            fireContainerEvent(ADD_CHILD_EVENT, child);
        }
    }
 
Example 25
Source Project: Tomcat8-Source-Read   Source File: ContainerBase.java    License: MIT License 5 votes vote down vote up
@Override
public Void call() throws LifecycleException {
    if (child.getState().isAvailable()) {
        child.stop();
    }
    return null;
}
 
Example 26
Source Project: TeaStore   Source File: HeartbeatTest.java    License: Apache License 2.0 5 votes vote down vote up
private Tomcat createClientTomcat(Service service, Tomcat tomcat) throws ServletException, LifecycleException {
		int clientPort = getNextClientPort();
		tomcat.getEngine().setName("Catalina" + clientPort);
		tomcat.setPort(clientPort);
		tomcat.setBaseDir(testWorkingDir);
		tomcat.enableNaming();
		Context context = tomcat.addWebapp("/" + service.getServiceName(), testWorkingDir);
		ContextEnvironment registryURL = new ContextEnvironment();
		registryURL.setDescription("");
		registryURL.setOverride(false);
		registryURL.setType("java.lang.String");
		registryURL.setName("registryURL");
		registryURL.setValue("http://localhost:" + getRegistryPort() + "/test/rest/services/");
		context.getNamingResources().addEnvironment(registryURL);
		ContextEnvironment servicePort = new ContextEnvironment();
		servicePort.setDescription("");
		servicePort.setOverride(false);
		servicePort.setType("java.lang.String");
	    servicePort.setName("servicePort");
	    servicePort.setValue("" + clientPort);
		context.getNamingResources().addEnvironment(servicePort);		
		context.addApplicationListener(TestRegistryClientStartup.class.getName());
//		HeartbeatServlet heartbeatServlet = new HeartbeatServlet();
//		tomcat.addServlet("/" + service.getServiceName(), "heartbeatServlet", heartbeatServlet);
//		context.addServletMappingDecoded("/heartbeat", "heartbeatServlet");
		tomcat.start();
		return tomcat;
	}
 
Example 27
Source Project: tomee   Source File: LazyRealm.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void stopInternal() throws LifecycleException {
    final Class<?> r = loadClass();
    if (r != null && Lifecycle.class.isAssignableFrom(r) && instance() != null) {
        Lifecycle.class.cast(instance()).stop();
    }
    setState(LifecycleState.STOPPING);
}
 
Example 28
Source Project: tomcatsrc   Source File: LockOutRealm.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Prepare for the beginning of active use of the public methods of this
 * component and implement the requirements of
 * {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected void startInternal() throws LifecycleException {
    // Configure the list of failed users to delete the oldest entry once it
    // exceeds the specified size
    failedUsers = new LinkedHashMap<String, LockRecord>(cacheSize, 0.75f,
            true) {
        private static final long serialVersionUID = 1L;
        @Override
        protected boolean removeEldestEntry(
                Map.Entry<String, LockRecord> eldest) {
            if (size() > cacheSize) {
                // Check to see if this element has been removed too quickly
                long timeInCache = (System.currentTimeMillis() -
                        eldest.getValue().getLastFailureTime())/1000;
                
                if (timeInCache < cacheRemovalWarningTime) {
                    log.warn(sm.getString("lockOutRealm.removeWarning",
                            eldest.getKey(), Long.valueOf(timeInCache)));
                }
                return true;
            }
            return false;
        }
    };

    super.startInternal();
}
 
Example 29
Source Project: Tomcat8-Source-Read   Source File: Benchmarks.java    License: MIT License 5 votes vote down vote up
@Test
public void testManagerBaseCreateSession() throws LifecycleException {
    doTestManagerBaseCreateSession(1, 100000);
    doTestManagerBaseCreateSession(2, 1000000);
    doTestManagerBaseCreateSession(4, 1000000);
    doTestManagerBaseCreateSession(16, 1000000);
    // Reduce iterations as context switching will slow things down
    doTestManagerBaseCreateSession(100, 100000);
    doTestManagerBaseCreateSession(400, 10000);
}
 
Example 30
Source Project: tomee   Source File: LazyValve.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void stop() throws LifecycleException {
    if (instance() != null && Lifecycle.class.isInstance(delegate)) {
        Lifecycle.class.cast(delegate).stop();
    }
    state = LifecycleState.STOPPED;
}