本文整理汇总了Java中org.apache.catalina.LifecycleState类的典型用法代码示例。如果您正苦于以下问题:Java LifecycleState类的具体用法?Java LifecycleState怎么用?Java LifecycleState使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LifecycleState类属于org.apache.catalina包,在下文中一共展示了LifecycleState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: stopInternal
import org.apache.catalina.LifecycleState; //导入依赖的package包/类
/**
* 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();
}
示例2: testBug49132
import org.apache.catalina.LifecycleState; //导入依赖的package包/类
/**
* Test JNDI is available to ServletContextListeners.
*/
@Test
public void testBug49132() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
org.apache.catalina.Context ctx = tomcat.addContext("", null);
// Enable JNDI - it is disabled by default
tomcat.enableNaming();
ContextEnvironment environment = new ContextEnvironment();
environment.setType(BUG49132_VALUE.getClass().getName());
environment.setName(BUG49132_NAME);
environment.setValue(BUG49132_VALUE);
ctx.getNamingResources().addEnvironment(environment);
ctx.addApplicationListener(Bug49132Listener.class.getName());
tomcat.start();
assertEquals(LifecycleState.STARTED, ctx.getState());
}
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:26,代码来源:TestNamingContextListener.java
示例3: stopInternal
import org.apache.catalina.LifecycleState; //导入依赖的package包/类
/**
* 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();
}
示例4: declareRoles
import org.apache.catalina.LifecycleState; //导入依赖的package包/类
@Override
public void declareRoles(String... roleNames) {
if (!context.getState().equals(LifecycleState.STARTING_PREP)) {
// TODO Spec breaking enhancement to ignore this restriction
throw new IllegalStateException(sm.getString("applicationContext.addRole.ise", getContextPath()));
}
if (roleNames == null) {
throw new IllegalArgumentException(sm.getString("applicationContext.roles.iae", getContextPath()));
}
for (String role : roleNames) {
if (role == null || "".equals(role)) {
throw new IllegalArgumentException(sm.getString("applicationContext.role.iae", getContextPath()));
}
context.addSecurityRole(role);
}
}
示例5: startInternal
import org.apache.catalina.LifecycleState; //导入依赖的package包/类
/**
* 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 {
// Create a MessageDigest instance for credentials, if desired
if (digest != null) {
try {
md = MessageDigest.getInstance(digest);
} catch (NoSuchAlgorithmException e) {
throw new LifecycleException
(sm.getString("realmBase.algorithm", digest), e);
}
}
setState(LifecycleState.STARTING);
}
示例6: startInternal
import org.apache.catalina.LifecycleState; //导入依赖的package包/类
/**
* Start Cluster 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 {
if (log.isInfoEnabled())
log.info("Cluster is about to start");
try {
checkDefaults();
registerClusterValve();
channel.addMembershipListener(this);
channel.addChannelListener(this);
if (channel instanceof GroupChannel)
((GroupChannel) channel).setName(getClusterName() + "-Channel");
channel.start(channelStartOptions);
if (clusterDeployer != null)
clusterDeployer.start();
registerMember(channel.getLocalMember(false));
} catch (Exception x) {
log.error("Unable to start cluster.", x);
throw new LifecycleException(x);
}
setState(LifecycleState.STARTING);
}
示例7: addWelcomeFile
import org.apache.catalina.LifecycleState; //导入依赖的package包/类
/**
* Add a new welcome file to the set recognized by this Context.
*
* @param name
* New welcome file name
*/
@Override
public void addWelcomeFile(String name) {
synchronized (welcomeFilesLock) {
// Welcome files from the application deployment descriptor
// completely replace those from the default conf/web.xml file
if (replaceWelcomeFiles) {
fireContainerEvent(CLEAR_WELCOME_FILES_EVENT, null);
welcomeFiles = new String[0];
setReplaceWelcomeFiles(false);
}
String results[] = new String[welcomeFiles.length + 1];
for (int i = 0; i < welcomeFiles.length; i++)
results[i] = welcomeFiles[i];
results[welcomeFiles.length] = name;
welcomeFiles = results;
}
if (this.getState().equals(LifecycleState.STARTED))
fireContainerEvent(ADD_WELCOME_FILE_EVENT, name);
}
示例8: sendMsg
import org.apache.catalina.LifecycleState; //导入依赖的package包/类
/**
* Create a message and send it
*
* @param serverId
* the server instance id
* @param serverName
* the server name
* @param destAddr
* the JGroups destination address @return
* {@link JGroupsStateReporter} for chaining purposes
*/
private void sendMsg(final String serverId, final String serverName, final Address destAddr) {
messagingService.init();
try {
final Address channelAddress =
messagingService.getChannel().getAddress();
msgBuilder = new JGroupsServerInfoMessageBuilder().setServerId(serverId).setServerName(serverName)
.setState(state).setSrcAddress(channelAddress).setDestAddress(destAddr);
} catch (final Exception e) {
throw new JGroupsStateReporterException("Failed to create message!", e);
}
messagingService.send(msgBuilder.build()); // send the
// state
// details
// immediately
if (LifecycleState.STOPPED.equals(state) || LifecycleState.DESTROYED.equals(state)) {
LOGGER.info("State {} received, destroying messaging service...", state);
messagingService.destroy();
}
}
示例9: stopInternal
import org.apache.catalina.LifecycleState; //导入依赖的package包/类
/**
* Stop nested components ({@link Service}s) and implement the requirements
* of {@link org.apache.catalina.util.LifecycleBase#stopInternal()}.
*
* @exception LifecycleException
* if this component detects a fatal error that needs to be
* reported
*/
@Override
protected void stopInternal() throws LifecycleException {
setState(LifecycleState.STOPPING);
fireLifecycleEvent(CONFIGURE_STOP_EVENT, null);
// Stop our defined Services
for (int i = 0; i < services.length; i++) {
services[i].stop();
}
globalNamingResources.stop();
stopAwait();
}
示例10: testWebappLoaderStartFail
import org.apache.catalina.LifecycleState; //导入依赖的package包/类
@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());
}
示例11: testWebappListenerConfigureFail
import org.apache.catalina.LifecycleState; //导入依赖的package包/类
@Test
public void testWebappListenerConfigureFail() throws Exception {
// Test that if LifecycleListener on webapp fails during
// configure_start event 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);
FailingLifecycleListener listener = new FailingLifecycleListener();
File root = new File("test/webapp-3.0");
Context context = tomcat.addWebapp("", root.getAbsolutePath());
context.addLifecycleListener(listener);
try {
context.start();
fail();
} catch (LifecycleException ex) {
// As expected
}
assertEquals(LifecycleState.FAILED, context.getState());
// The second attempt
listener.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());
}
示例12: testDeploymentXmlExternalDirXmlFTT
import org.apache.catalina.LifecycleState; //导入依赖的package包/类
@Test
public void testDeploymentXmlExternalDirXmlFTT() throws Exception {
File dir = createDirInExternal(true);
createXmlInConfigBaseForExternal(dir);
doTestDeployment(false, true, true,
LifecycleState.STARTED, XML_COOKIE_NAME, true, false, false);
}
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:8,代码来源:TestHostConfigAutomaticDeployment.java
示例13: lifecycleEvent
import org.apache.catalina.LifecycleState; //导入依赖的package包/类
@Override
public synchronized void lifecycleEvent(final LifecycleEvent event) {
final LifecycleState lifecycleState = event.getLifecycle().getState();
// h2 tcp server
if (h2TcpServerService == null) {
h2TcpServerService = new H2TcpServerServiceImpl(tcpServerParam);
}
if (LifecycleState.STARTING_PREP.equals(lifecycleState) && !h2TcpServerService.isServerRunning()) {
LOGGER.info("Initializing H2 tcp server on Tomcat lifecycle: " + lifecycleState);
h2TcpServerService.startServer();
} else if (LifecycleState.DESTROYING.equals(lifecycleState) && h2TcpServerService.isServerRunning()) {
LOGGER.info("Destroying H2 tcp server on Tomcat lifecycle: " + lifecycleState);
h2TcpServerService.stopServer();
}
// h2 web server
try {
if (h2WebServerService == null) {
h2WebServerService = new H2WebServerServiceImpl(webServerParam);
}
if (LifecycleState.STARTING_PREP.equals(lifecycleState) && !h2WebServerService.isServerRunning()) {
LOGGER.info("Initializing H2 web server on Tomcat lifecycle: " + lifecycleState);
h2WebServerService.startServer();
} else if (LifecycleState.DESTROYING.equals(lifecycleState) && h2WebServerService.isServerRunning()) {
LOGGER.info("Destroying H2 web server on Tomcat lifecycle: " + lifecycleState);
h2WebServerService.stopServer();
}
} catch (final DbServerServiceException e) {
LOGGER.log(Level.SEVERE, "Failed to start H2 Web Server! Continuing without it.", e);
}
}
示例14: stop
import org.apache.catalina.LifecycleState; //导入依赖的package包/类
/**
* Stop an existing server instance.
*/
public void stop() {
try {
// Remove the ShutdownHook first so that server.stop()
// doesn't get invoked twice
if (useShutdownHook) {
Runtime.getRuntime().removeShutdownHook(shutdownHook);
// If JULI is being used, re-enable JULI's shutdown to ensure
// log messages are not lost
LogManager logManager = LogManager.getLogManager();
if (logManager instanceof ClassLoaderLogManager) {
((ClassLoaderLogManager) logManager).setUseShutdownHook(
true);
}
}
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
// This will fail on JDK 1.2. Ignoring, as Tomcat can run
// fine without the shutdown hook.
}
// Shut down the server
try {
Server s = getServer();
LifecycleState state = s.getState();
if (LifecycleState.STOPPING_PREP.compareTo(state) <= 0
&& LifecycleState.DESTROYED.compareTo(state) >= 0) {
// Nothing to do. stop() was already called
} else {
s.stop();
s.destroy();
}
} catch (LifecycleException e) {
log.error("Catalina.stop", e);
}
}
示例15: startInternal
import org.apache.catalina.LifecycleState; //导入依赖的package包/类
/**
* 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 {
// Create a MessageDigest instance for credentials, if desired
if (digest != null) {
try {
md = MessageDigest.getInstance(digest);
} catch (NoSuchAlgorithmException e) {
throw new LifecycleException(sm.getString("realmBase.algorithm", digest), e);
}
}
setState(LifecycleState.STARTING);
}