org.apache.catalina.Server类的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(10.1k)|赞(0)|评价(0)|浏览(147)

本文整理了Java中org.apache.catalina.Server类的一些代码示例,展示了Server类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Server类的具体详情如下:
包路径:org.apache.catalina.Server
类名称:Server

Server介绍

[英]A Server element represents the entire Catalina servlet container. Its attributes represent the characteristics of the servlet container as a whole. A Server may contain one or more Services, and the top level set of naming resources.

Normally, an implementation of this interface will also implement Lifecycle, such that when the start() and stop() methods are called, all of the defined Services are also started or stopped.

In between, the implementation must open a server socket on the port number specified by the port property. When a connection is accepted, the first line is read and compared with the specified shutdown command. If the command matches, shutdown of the server is initiated.

NOTE - The concrete implementation of this class should register the (singleton) instance with the ServerFactory class in its constructor(s).
[中]

代码示例

代码示例来源:origin: SonarSource/sonarqube

void awaitTermination() {
  tomcat.getServer().await();
 }
}

代码示例来源:origin: org.springframework.boot/spring-boot

private void removeServiceConnectors() {
  for (Service service : this.tomcat.getServer().findServices()) {
    Connector[] connectors = service.findConnectors().clone();
    this.serviceConnectors.put(service, connectors);
    for (Connector connector : connectors) {
      service.removeConnector(connector);
    }
  }
}

代码示例来源:origin: OryxProject/oryx

private static void configureServer(Server server) {
 server.addLifecycleListener(new JreMemoryLeakPreventionListener());
 server.addLifecycleListener(new ThreadLocalLeakPreventionListener());
}

代码示例来源:origin: line/armeria

static String toString(org.apache.catalina.Server server) {
  requireNonNull(server, "server");
  final Service[] services = server.findServices();
  final String serviceName;
  if (services.length == 0) {
    serviceName = "<unknown>";
  } else {
    serviceName = services[0].getName();
  }
  final StringBuilder buf = new StringBuilder(128);
  buf.append("(serviceName: ");
  buf.append(serviceName);
  if (TomcatVersion.major() >= 8) {
    buf.append(", catalinaBase: ");
    buf.append(server.getCatalinaBase());
  }
  buf.append(')');
  return buf.toString();
}

代码示例来源:origin: line/armeria

static TomcatService forConfig(TomcatServiceConfig config) {
  final Consumer<Connector> postStopTask = connector -> {
    final org.apache.catalina.Server server = connector.getService().getServer();
    if (server.getState() == LifecycleState.STOPPED) {
      try {
        logger.info("Destroying an embedded Tomcat: {}", toString(server));
        server.destroy();
      } catch (Exception e) {
        logger.warn("Failed to destroy an embedded Tomcat: {}", toString(server), e);
      }
    }
  };
  return new ManagedTomcatService(null, new ManagedConnectorFactory(config), postStopTask);
}

代码示例来源:origin: line/armeria

void start() throws Exception {
  assert hostName() != null;
  started = false;
  connector = connectorFactory.apply(hostName());
  final Service service = connector.getService();
  final Engine engine = TomcatUtil.engine(service, hostName());
  final String engineName = engine.getName();
  if (activeEngines.contains(engineName)) {
    throw new TomcatServiceException("duplicate engine name: " + engineName);
  }
  server = service.getServer();
  if (!TOMCAT_START_STATES.contains(server.getState())) {
    logger.info("Starting an embedded Tomcat: {}", toString(server));
    server.start();
    started = true;
  } else {
    throw new TomcatServiceException("Cannot manage already running server: " + engineName);
  }
  activeEngines.add(engineName);
  this.engineName = engineName;
}

代码示例来源:origin: ch.rasc/embeddedtc

log.error("PORT " + this.httpPort + " ALREADY IN USE");
  return;
    this.skipJarsTldConfig);
this.tomcat = new Tomcat();
this.tomcat.setBaseDir(this.tempDirectory);
  this.tomcat.setSilent(true);
  this.tomcat.getServer().addLifecycleListener(new AprLifecycleListener());
  this.tomcat.getEngine().setDefaultHost("localhost");
  this.tomcat.getService().addConnector(httpsConnector);
  this.tomcat.getServer().setPort(this.shutdownPort);
    this.tomcat.getServer()
        .addLifecycleListener(new GlobalResourcesLifecycleListener());
  Server server = this.tomcat.getServer();
  server.addLifecycleListener(new JreMemoryLeakPreventionListener());
  server.addLifecycleListener(new ThreadLocalLeakPreventionListener());
  this.tomcat.getServer().await();
  stop();

代码示例来源:origin: com.ovea.tajin.servers/tajin-server-jetty9

if (log.isDebugEnabled())
  log.debug("Creating MBean for Server " + server);
NamingResources resources = server.getGlobalNamingResources();
if (resources != null) {
  createMBeans(resources);
Service services[] = server.findServices();
for (int i = 0; i < services.length; i++) {
  if (services[i].getContainer().getClass().getName().equals
    ("org.apache.catalina.connector.warp.WarpEngine")) {
    if (log.isDebugEnabled()) {
      log.debug("Skipping MBean for Service " + services[i]);

代码示例来源:origin: org.apache.catalina/com.springsource.org.apache.catalina

/**
 * Process a "destroy" event for this Context.
 */
protected synchronized void destroy() {
  // Called from StandardContext.destroy()
  if (log.isDebugEnabled())
    log.debug(sm.getString("contextConfig.destroy"));
  // Skip clearing the work directory if Tomcat is being shutdown
  Server s = getServer();
  if (s != null && !s.getState().isAvailable()) {
    return;
  }
  
  // Changed to getWorkPath per Bugzilla 35819.
  String workDir = ((StandardContext) context).getWorkPath();
  if (workDir != null)
    ExpandWar.delete(new File(workDir));
}

代码示例来源:origin: org.ops4j.pax.tipi/org.ops4j.pax.tipi.tomcat-embed-core

digester.parse(is);
  } catch (Exception e) {
    log.error("Catalina.stop: ", e);
    System.exit(1);
    s.stop();
  } catch (LifecycleException e) {
    log.error("Catalina.stop: ", e);
if (s.getPort()>0) {
  try (Socket socket = new Socket(s.getAddress(), s.getPort());
      OutputStream stream = socket.getOutputStream()) {
    String shutdown = s.getShutdown();
    for (int i = 0; i < shutdown.length(); i++) {
      stream.write(shutdown.charAt(i));
    log.error(sm.getString("catalina.stopServer.connectException",
                s.getAddress(),
                String.valueOf(s.getPort())));
    log.error("Catalina.stop: ", ce);
    System.exit(1);
  log.error(sm.getString("catalina.stopServer"));
  System.exit(1);

代码示例来源:origin: org.crazyyak.embedded/yak-embedded-tomcat

tomcat.setBaseDir(args.getWorkingDirectory());
StandardHost host = (StandardHost)tomcat.getHost();
host.setAutoDeploy(false);
host.setDeployOnStartup(true);
tomcat.getServer().setPort(args.getShutdownPort());
 tomcat.getService().addConnector(connector);
 tomcat.getService().addConnector(connector);
 tomcat.getService().addConnector(connector);

代码示例来源:origin: SonarSource/sonarqube

void terminate() {
 if (tomcat.getServer().getState().isAvailable()) {
  try {
   tomcat.stop();
   tomcat.destroy();
  } catch (Exception e) {
   Loggers.get(EmbeddedTomcat.class).error("Fail to stop web server", e);
  }
 }
 deleteQuietly(tomcatBasedir());
}

代码示例来源:origin: pippo-java/pippo

tomcat.setBaseDir(getSettings().getBaseFolder());
Context context = tomcat.addContext(getSettings().getContextPath(), docBase.getAbsolutePath());
context.setAllowCasualMultipartParsing(true);
PippoServlet pippoServlet = new PippoServlet();
  tomcat.start();
} catch (LifecycleException e) {
  log.error("Unable to launch Tomcat", e);
  tomcat.getServer().await();

代码示例来源:origin: com.bsb.common.vaadin/com.bsb.common.vaadin7.embed

/**
 * Fires the embedded tomcat that is assumed to be fully configured.
 *
 * @throws LifecycleException if tomcat failed to start
 */
private void doStart() throws LifecycleException {
  tomcat.getServer().addLifecycleListener(new TomcatLifecycleListener());
  logger.info("Deploying application to [" + getConfig().getDeployUrl() + "]");
  tomcat.start();
  // Let's set the port that was used to actually start the application if necessary
  if (getConfig().getPort() == EmbedVaadinConfig.DEFAULT_PORT) {
    getConfig().setPort(getTomcat().getConnector().getLocalPort());
  }
  logger.info("Application has been deployed to [" + getConfig().getDeployUrl() + "]");
  if (config.shouldOpenBrowser()) {
    BrowserUtils.openBrowser(getConfig().getOpenBrowserUrl());
  }
  if (isWaiting()) {
    tomcat.getServer().await();
  }
}

代码示例来源:origin: org.talend.sdk.component/component-server

@Override
public void accept(final Tomcat tomcat) {
  tomcat.getServer().addLifecycleListener(this);
}

代码示例来源:origin: com.github.skjolber.mockito-rest-spring/tomcat

private void stop(Tomcat tomcat) throws LifecycleException, InterruptedException {
  tomcat.stop();
  
  long deadline = System.currentTimeMillis() + 10000;
  do {
    switch(tomcat.getServer().getState()) {
    case STOPPED:
    case DESTROYING:
    case DESTROYED:
    case FAILED:
      return;
    default : {
    }
    }
    Thread.sleep(10);
  } while(deadline > System.currentTimeMillis());		
}

代码示例来源:origin: org.apache.geronimo.modules/geronimo-tomcat6

public void doStart() throws Exception {        
  //Find all the access log valves and add them to the list
  //Valve could be added on Engine/Host/Context
  Server server = tomcatServer.getServer();
  accessLogValves = new LinkedList<AccessLogValve>();
  for(Service service : server.findServices()) {
    Container container = service.getContainer();
    searchAccessLogValves(container);
  }
}

代码示例来源:origin: org.springframework.boot/spring-boot

private void addPreviouslyRemovedConnectors() {
  Service[] services = this.tomcat.getServer().findServices();
  for (Service service : services) {
    Connector[] connectors = this.serviceConnectors.get(service);
    if (connectors != null) {
      for (Connector connector : connectors) {
        service.addConnector(connector);
        if (!this.autoStart) {
          stopProtocolHandler(connector);
        }
      }
      this.serviceConnectors.remove(service);
    }
  }
}

代码示例来源:origin: org.apache.tomcat/tomcat-catalina

digester.parse(is);
  } catch (Exception e) {
    log.error(sm.getString("catalina.stopError"), e);
    System.exit(1);
    s.stop();
  } catch (LifecycleException e) {
    log.error(sm.getString("catalina.stopError"), e);
if (s.getPortWithOffset() > 0) {
  try (Socket socket = new Socket(s.getAddress(), s.getPortWithOffset());
      OutputStream stream = socket.getOutputStream()) {
    String shutdown = s.getShutdown();
    for (int i = 0; i < shutdown.length(); i++) {
      stream.write(shutdown.charAt(i));
    log.error(sm.getString("catalina.stopServer.connectException", s.getAddress(),
        String.valueOf(s.getPortWithOffset()), String.valueOf(s.getPort()),
        String.valueOf(s.getPortOffset())));
    log.error(sm.getString("catalina.stopError"), ce);
    System.exit(1);

代码示例来源:origin: org.apache.tomcat/tomcat-catalina

LifecycleState state = s.getState();
if (LifecycleState.STOPPING_PREP.compareTo(state) <= 0
    && LifecycleState.DESTROYED.compareTo(state) >= 0) {
  s.stop();
  s.destroy();
log.error(sm.getString("catalina.stopError"), e);

相关文章