org.apache.catalina.Service.getServer()方法的使用及代码示例

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

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

Service.getServer介绍

[英]Return the Server with which we are associated (if any).
[中]返回与我们相关联的Server(如果有)。

代码示例

代码示例来源: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: line/armeria

@Override
public Connector apply(String hostname) {
  // Create the connector with our protocol handler. Tomcat will call ProtocolHandler.setAdapter()
  // on its startup with the Coyote Adapter which gives an access to Tomcat's HTTP service pipeline.
  final Class<?> protocolType = TomcatService.PROTOCOL_HANDLER_CLASS;
  final Connector connector = new Connector(protocolType.getName());
  // We do not really open a port - just trying to stop the Connector from complaining.
  connector.setPort(0);
  final StandardServer server = newServer(hostname, connector, config);
  // Retrieve the components configured by newServer(), so we can use it in checkConfiguration().
  final Service service = server.findServices()[0];
  final Engine engine = TomcatUtil.engine(service, hostname);
  final StandardHost host = (StandardHost) engine.findChildren()[0];
  final Context context = (Context) host.findChildren()[0];
  // Apply custom configurators set via TomcatServiceBuilder.configurator()
  try {
    config.configurators().forEach(c -> c.accept(server));
  } catch (Throwable t) {
    throw new TomcatServiceException("failed to configure an embedded Tomcat", t);
  }
  // Make sure the configurators did not ruin what we have configured in this method.
  checkConfiguration(server, service, connector, engine, host, context);
  assert connector.getService().getServer() != null;
  return connector;
}

代码示例来源:origin: modcluster/mod_cluster

private Server findServer() {
    try {
      Service[] services = (Service[]) this.mbeanServer.invoke(this.name, "findServices", null, null);
      return (services.length > 0) ? services[0].getServer() : null;
    } catch (JMException e) {
      throw new IllegalStateException(e);
    }
  }
}

代码示例来源:origin: org.jboss.mod_cluster/mod_cluster

/**
* Constructs a new CatalinaEngine that wraps the specified catalina engine
* @param engine a catalina engine
*/
public CatalinaEngine(org.apache.catalina.Engine engine, MBeanServer mbeanServer)
{
 this(engine, new CatalinaServer(engine.getService().getServer(), mbeanServer));
}

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

private Server getServer() {
  Container c = context;
  while (c != null && !(c instanceof Engine)) {
    c = c.getParent();
  }
  if (c == null) {
    return null;
  }
  Service s = ((Engine)c).getService();
  if (s == null) {
    return null;
  }
  return s.getServer();
}

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

@Override
public File getCatalinaHome() {
  if (service != null) {
    Server s = service.getServer();
    if (s != null) {
      File base = s.getCatalinaHome();
      if (base != null) {
        return base;
      }
    }
  }
  // Fall-back
  return super.getCatalinaHome();
}

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

@Override
public File getCatalinaBase() {
  if (service != null) {
    Server s = service.getServer();
    if (s != null) {
      File base = s.getCatalinaBase();
      if (base != null) {
        return base;
      }
    }
  }
  // Fall-back
  return super.getCatalinaBase();
}

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

private Server getServer() {
  if (container instanceof Server) {
    return (Server) container;
  }
  if (container instanceof Context) {
    // Could do this in one go. Lots of casts so split out for clarity
    Engine engine =
      (Engine) ((Context) container).getParent().getParent();
    return engine.getService().getServer();
  }
  return null;
}

代码示例来源:origin: codefollower/Tomcat-Research

private Server getServer() {
  if (container instanceof Server) {
    return (Server) container;
  }
  if (container instanceof Context) {
    // Could do this in one go. Lots of casts so split out for clarity
    Engine engine =
      (Engine) ((Context) container).getParent().getParent();
    return engine.getService().getServer();
  }
  return null;
}

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

private Server getServer() {
  if (container instanceof Server) {
    return (Server) container;
  }
  if (container instanceof Context) {
    // Could do this in one go. Lots of casts so split out for clarity
    Engine engine =
      (Engine) ((Context) container).getParent().getParent();
    return engine.getService().getServer();
  }
  return null;
}

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

private Server getServer() {
  if (container instanceof Server) {
    return (Server) container;
  }
  if (container instanceof Context) {
    // Could do this in one go. Lots of casts so split out for clarity
    Engine engine =
      (Engine) ((Context) container).getParent().getParent();
    return engine.getService().getServer();
  }
  return null;
}

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

private Server getServer() {
  if (container instanceof Server) {
    return (Server) container;
  }
  if (container instanceof Context) {
    // Could do this in one go. Lots of casts so split out for clarity
    Engine engine =
      (Engine) ((Context) container).getParent().getParent();
    return engine.getService().getServer();
  }
  return null;
}

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

private Server getServer() {
  if (container instanceof Server) {
    return (Server) container;
  }
  if (container instanceof Context) {
    // Could do this in one go. Lots of casts so split out for clarity
    Engine engine =
      (Engine) ((Context) container).getParent().getParent();
    return engine.getService().getServer();
  }
  return null;
}

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

private Server getServer() {
  if (container instanceof Server) {
    return (Server) container;
  }
  if (container instanceof Context) {
    // Could do this in one go. Lots of casts so split out for clarity
    Engine engine =
      (Engine) ((Context) container).getParent().getParent();
    return engine.getService().getServer();
  }
  return null;
}

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

private Server getServer() {
  if (container instanceof Server) {
    return (Server) container;
  }
  if (container instanceof Context) {
    // Could do this in one go. Lots of casts so split out for clarity
    Engine engine =
      (Engine) ((Context) container).getParent().getParent();
    return engine.getService().getServer();
  }
  return null;
}

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

private javax.naming.Context getGlobalNamingContext() {
  if (container instanceof Context) {
    Engine e = (Engine) ((Context) container).getParent().getParent();
    return e.getService().getServer().getGlobalNamingContext();
  }
  return null;
}

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

private javax.naming.Context getGlobalNamingContext() {
  if (container instanceof Context) {
    Engine e = (Engine) ((Context) container).getParent().getParent();
    return e.getService().getServer().getGlobalNamingContext();
  }
  return null;
}

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

private void reconfigureStartStopExecutor(int threads) {
  if (threads == 1) {
    // Use a fake executor
    if (!(startStopExecutor instanceof InlineExecutorService)) {
      startStopExecutor = new InlineExecutorService();
    }
  } else {
    // Delegate utility execution to the Service
    Server server = Container.getService(this).getServer();
    server.setUtilityThreads(threads);
    startStopExecutor = server.getUtilityExecutor();
  }
}

代码示例来源:origin: modcluster/mod_cluster

@Test
public void test() throws Exception {
  MBeanServer mbeanServer = mock(MBeanServer.class);
  ObjectName name = ObjectName.getInstance("Catalina:type=Server");
  Server expected = mock(Server.class);
  Service service = mock(Service.class);
  when(mbeanServer.invoke(same(name), eq("findServices"), (Object[]) isNull(), (String[]) isNull())).thenReturn(new Service[] { service });
  when(service.getServer()).thenReturn(expected);
  ServerProvider provider = new JMXServerProvider(mbeanServer, name);
  Server result = provider.getServer();
  assertSame(expected, result);
}

相关文章