public void init() {
    if (initialized) return;
    initialized = true;

    log = Logger.getLogger(ManagerBase.class);

    StandardContext ctx = (StandardContext) this.getContainer();
    distributable = ctx.getDistributable();
    if (org.apache.tomcat.util.Constants.ENABLE_MODELER) {
      if (oname == null) {
        try {
          Engine eng = (Engine) ctx.getParent().getParent();
          domain = ctx.getEngineName();
          StandardHost hst = (StandardHost) ctx.getParent();
          String path = ctx.getPath();
          if (path.equals("")) {
            path = "/";
          }
          oname = new ObjectName(domain + ":type=Manager,path=" + path + ",host=" + hst.getName());
          Registry.getRegistry(null, null).registerComponent(this, oname, null);
        } catch (Exception e) {
          log.error("Error registering ", e);
        }
      }
    }

    if (log.isDebugEnabled()) log.debug("Registering " + oname);
  }
Exemple #2
0
  public void init() {
    if (initialized) return;
    initialized = true;

    StandardContext ctx = (StandardContext) this.getContainer();
    distributable = ctx.getDistributable();
    if (org.apache.tomcat.util.Constants.ENABLE_MODELER) {
      if (oname == null) {
        try {
          Engine eng = (Engine) ctx.getParent().getParent();
          domain = ctx.getEngineName();
          StandardHost hst = (StandardHost) ctx.getParent();
          String path = ctx.getPath();
          if (path.equals("")) {
            path = "/";
          }
          oname = new ObjectName(domain + ":type=Manager,path=" + path + ",host=" + hst.getName());
          Registry.getRegistry(null, null).registerComponent(this, oname, null);
        } catch (Exception e) {
          CatalinaLogger.SESSION_LOGGER.failedSessionManagerJmxRegistration(oname, e);
        }
      }
    }

    if (CatalinaLogger.SESSION_LOGGER.isDebugEnabled())
      CatalinaLogger.SESSION_LOGGER.debug("Registering " + oname);
  }
 @Override
 public synchronized void stop() throws Exception {
   if (_serverContext != null) {
     // Destroy the web context unless if it is default
     if (!_serverContext.getPath().equals("/")) {
       try {
         Container container = _serverContext.getParent();
         container.removeChild(_serverContext);
         _serverContext.stop();
         _serverContext.destroy();
         _log.info("Destroyed HTTP context " + _serverContext.getPath());
       } catch (Exception e) {
         _log.error("Unable to destroy web context", e);
       }
     }
   }
 }
  @Override
  public synchronized void start() throws Exception {

    Host host = ServerUtil.getDefaultHost().getHost();
    _serverContext = (StandardContext) host.findChild("/" + _contextName);
    if (_serverContext == null) {
      _serverContext = new StandardContext();
      _serverContext.setPath("/" + _contextName);
      File docBase = new File(SERVER_TEMP_DIR, _contextName);
      if (!docBase.exists()) {
        if (!docBase.mkdirs()) {
          throw new RuntimeException("Unable to create temp directory " + docBase.getPath());
        }
      }
      _serverContext.setDocBase(docBase.getPath());
      _serverContext.addLifecycleListener(new ContextConfig());

      final Loader loader = new WebCtxLoader(Thread.currentThread().getContextClassLoader());
      loader.setContainer(host);
      _serverContext.setLoader(loader);
      _serverContext.setInstanceManager(new LocalInstanceManager());

      Wrapper wrapper = _serverContext.createWrapper();
      wrapper.setName(SERVLET_NAME);
      wrapper.setServletClass(SwitchYardRemotingServlet.class.getName());
      wrapper.setLoadOnStartup(1);
      _serverContext.addChild(wrapper);
      _serverContext.addServletMapping("/*", SERVLET_NAME);

      host.addChild(_serverContext);
      _serverContext.create();
      _serverContext.start();

      SwitchYardRemotingServlet remotingServlet = (SwitchYardRemotingServlet) wrapper.getServlet();
      remotingServlet.setEndpointPublisher(this);
      _log.info("Published Remote Service Endpoint " + _serverContext.getPath());
    } else {
      throw new RuntimeException("Context " + _contextName + " already exists!");
    }
  }