use of org.apache.catalina.Service in project tomcat by apache.
the class ServiceMBean method findConnectors.
/**
* Find and return the set of Connectors associated with this Service.
* @return an array of string representations of the connectors
* @throws MBeanException error accessing the associated service
*/
public String[] findConnectors() throws MBeanException {
Service service = doGetManagedResource();
Connector[] connectors = service.findConnectors();
String[] str = new String[connectors.length];
for (int i = 0; i < connectors.length; i++) {
str[i] = connectors[i].toString();
}
return str;
}
use of org.apache.catalina.Service in project tomcat by apache.
the class MBeanFactory method getParentContainerFromChild.
/**
* Get Parent ContainerBase to add its child component
* from child component's ObjectName as a String
*/
private Container getParentContainerFromChild(ObjectName oname) throws Exception {
String hostName = oname.getKeyProperty("host");
String path = oname.getKeyProperty("path");
Service service = getService(oname);
Container engine = service.getContainer();
if (hostName == null) {
// child's container is Engine
return engine;
} else if (path == null) {
// child's container is Host
Container host = engine.findChild(hostName);
return host;
} else {
// child's container is Context
Container host = engine.findChild(hostName);
path = getPathStr(path);
Container context = host.findChild(path);
return context;
}
}
use of org.apache.catalina.Service in project tomcat by apache.
the class MBeanFactory method removeService.
/**
* Remove an existing Service.
*
* @param name MBean Name of the component to remove
*
* @exception Exception if a component cannot be removed
*/
public void removeService(String name) throws Exception {
if (!(container instanceof Server)) {
throw new Exception();
}
// Acquire a reference to the component to be removed
ObjectName oname = new ObjectName(name);
Service service = getService(oname);
((Server) container).removeService(service);
}
use of org.apache.catalina.Service in project tomcat by apache.
the class MBeanFactory method createStandardContext.
/**
* Create a new StandardContext.
*
* @param parent MBean Name of the associated parent component
* @param path The context path for this Context
* @param docBase Document base directory (or WAR) for this Context
* @param xmlValidation if XML descriptors should be validated
* @param xmlNamespaceAware if the XML processor should namespace aware
* @return the object name of the created context
*
* @exception Exception if an MBean cannot be created or registered
*/
public String createStandardContext(String parent, String path, String docBase, boolean xmlValidation, boolean xmlNamespaceAware) throws Exception {
// Create a new StandardContext instance
StandardContext context = new StandardContext();
path = getPathStr(path);
context.setPath(path);
context.setDocBase(docBase);
context.setXmlValidation(xmlValidation);
context.setXmlNamespaceAware(xmlNamespaceAware);
ContextConfig contextConfig = new ContextConfig();
context.addLifecycleListener(contextConfig);
// Add the new instance to its parent component
ObjectName pname = new ObjectName(parent);
ObjectName deployer = new ObjectName(pname.getDomain() + ":type=Deployer,host=" + pname.getKeyProperty("host"));
if (mserver.isRegistered(deployer)) {
String contextName = context.getName();
Boolean result = (Boolean) mserver.invoke(deployer, "tryAddServiced", new Object[] { contextName }, new String[] { "java.lang.String" });
if (result.booleanValue()) {
try {
String configPath = (String) mserver.getAttribute(deployer, "configBaseName");
String baseName = context.getBaseName();
File configFile = new File(new File(configPath), baseName + ".xml");
if (configFile.isFile()) {
context.setConfigFile(configFile.toURI().toURL());
}
mserver.invoke(deployer, "manageApp", new Object[] { context }, new String[] { "org.apache.catalina.Context" });
} finally {
mserver.invoke(deployer, "removeServiced", new Object[] { contextName }, new String[] { "java.lang.String" });
}
} else {
throw new IllegalStateException(sm.getString("mBeanFactory.contextCreate.addServicedFail", contextName));
}
} else {
log.warn(sm.getString("mBeanFactory.noDeployer", pname.getKeyProperty("host")));
Service service = getService(pname);
Engine engine = service.getContainer();
Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
host.addChild(context);
}
// Return the corresponding MBean name
return context.getObjectName().toString();
}
use of org.apache.catalina.Service in project tomcat by apache.
the class MBeanFactory method createStandardServiceEngine.
/**
* Creates a new StandardService and StandardEngine.
*
* @param domain Domain name for the container instance
* @param defaultHost Name of the default host to be used in the Engine
* @param baseDir Base directory value for Engine
* @return the object name of the created service
*
* @exception Exception if an MBean cannot be created or registered
*/
public String createStandardServiceEngine(String domain, String defaultHost, String baseDir) throws Exception {
if (!(container instanceof Server)) {
throw new Exception(sm.getString("mBeanFactory.notServer"));
}
StandardEngine engine = new StandardEngine();
engine.setDomain(domain);
engine.setName(domain);
engine.setDefaultHost(defaultHost);
Service service = new StandardService();
service.setContainer(engine);
service.setName(domain);
((Server) container).addService(service);
return engine.getObjectName().toString();
}
Aggregations