📄 mbeanfactory.java
字号:
/**
* Create a new System Error Logger.
*
* @param parent MBean Name of the associated parent component
*
* @exception Exception if an MBean cannot be created or registered
*/
public String createSystemErrLogger(String parent)
throws Exception {
// Create a new SystemErrLogger instance
SystemErrLogger logger = new SystemErrLogger();
// Add the new instance to its parent component
ObjectName pname = new ObjectName(parent);
ContainerBase containerBase = getParentContainerFromParent(pname);
containerBase.setLogger(logger);
ObjectName oname = logger.getObjectName();
return (oname.toString());
}
/**
* Create a new System Output Logger.
*
* @param parent MBean Name of the associated parent component
*
* @exception Exception if an MBean cannot be created or registered
*/
public String createSystemOutLogger(String parent)
throws Exception {
// Create a new SystemOutLogger instance
SystemOutLogger logger = new SystemOutLogger();
// Add the new instance to its parent component
ObjectName pname = new ObjectName(parent);
ContainerBase containerBase = getParentContainerFromParent(pname);
containerBase.setLogger(logger);
ObjectName oname = logger.getObjectName();
return (oname.toString());
}
/**
* Create a new UserDatabaseRealm.
*
* @param parent MBean Name of the associated parent component
* @param resourceName Global JNDI resource name of the associated
* UserDatabase
*
* @exception Exception if an MBean cannot be created or registered
*/
public String createUserDatabaseRealm(String parent, String resourceName)
throws Exception {
// Create a new UserDatabaseRealm instance
UserDatabaseRealm realm = new UserDatabaseRealm();
realm.setResourceName(resourceName);
// Add the new instance to its parent component
ObjectName pname = new ObjectName(parent);
ContainerBase containerBase = getParentContainerFromParent(pname);
// Add the new instance to its parent component
containerBase.setRealm(realm);
// Return the corresponding MBean name
ObjectName oname = realm.getObjectName();
// FIXME getObjectName() returns null
//ObjectName oname =
// MBeanUtils.createObjectName(pname.getDomain(), realm);
if (oname != null) {
return (oname.toString());
} else {
return null;
}
}
/**
* Create a new Web Application Loader.
*
* @param parent MBean Name of the associated parent component
*
* @exception Exception if an MBean cannot be created or registered
*/
public String createWebappLoader(String parent)
throws Exception {
// Create a new WebappLoader instance
WebappLoader loader = new WebappLoader();
// Add the new instance to its parent component
ObjectName pname = new ObjectName(parent);
ContainerBase containerBase = getParentContainerFromParent(pname);
if (containerBase != null) {
containerBase.setLoader(loader);
}
// FIXME add Loader.getObjectName
//ObjectName oname = loader.getObjectName();
ObjectName oname =
MBeanUtils.createObjectName(pname.getDomain(), loader);
return (oname.toString());
}
/**
* Remove an existing Connector.
*
* @param name MBean Name of the comonent to remove
*
* @param serviceName Service name of the connector to remove
*
* @exception Exception if a component cannot be removed
*/
public void removeConnector(String name) throws Exception {
// Acquire a reference to the component to be removed
ObjectName oname = new ObjectName(name);
Server server = ServerFactory.getServer();
Service service = getService(oname);
String port = oname.getKeyProperty("port");
//String address = oname.getKeyProperty("address");
Connector conns[] = (Connector[]) service.findConnectors();
for (int i = 0; i < conns.length; i++) {
Class cls = conns[i].getClass();
Method getAddrMeth = cls.getMethod("getAddress", null);
Object addrObj = getAddrMeth.invoke(conns[i], null);
String connAddress = null;
if (addrObj != null) {
connAddress = addrObj.toString();
}
Method getPortMeth = cls.getMethod("getPort", null);
Object portObj = getPortMeth.invoke(conns[i], null);
String connPort = new String();
if (portObj != null) {
connPort = portObj.toString();
}
// if (((address.equals("null")) &&
if ((connAddress==null) && port.equals(connPort)) {
service.removeConnector(conns[i]);
((CoyoteConnector)conns[i]).destroy();
break;
}
// } else if (address.equals(connAddress))
if (port.equals(connPort)) {
// Remove this component from its parent component
service.removeConnector(conns[i]);
((CoyoteConnector)conns[i]).destroy();
break;
}
}
}
/**
* Remove an existing Context.
*
* @param name MBean Name of the comonent to remove
*
* @exception Exception if a component cannot be removed
*/
public void removeContext(String contextName) throws Exception {
// Acquire a reference to the component to be removed
ObjectName oname = new ObjectName(contextName);
String domain = oname.getDomain();
StandardService service = (StandardService) getService(oname);
if (!service.getObjectName().getDomain().equals(domain)) {
throw new Exception("Service with the domain is not found");
}
Engine engine = (Engine) service.getContainer();
String name = oname.getKeyProperty("name");
name = name.substring(2);
int i = name.indexOf("/");
String hostName = name.substring(0,i);
String path = name.substring(i);
Host host = (Host) engine.findChild(hostName);
String pathStr = getPathStr(path);
Context context = (Context) host.findChild(pathStr);
// Remove this component from its parent component
host.removeChild(context);
}
/**
* Remove an existing Host.
*
* @param name MBean Name of the comonent to remove
*
* @exception Exception if a component cannot be removed
*/
public void removeHost(String name) throws Exception {
// Acquire a reference to the component to be removed
ObjectName oname = new ObjectName(name);
String hostName = oname.getKeyProperty("host");
Service service = getService(oname);
Engine engine = (Engine) service.getContainer();
Host host = (Host) engine.findChild(hostName);
// Remove this component from its parent component
engine.removeChild(host);
}
/**
* Remove an existing Logger.
*
* @param name MBean Name of the comonent to remove
*
* @exception Exception if a component cannot be removed
*/
public void removeLogger(String name) throws Exception {
ObjectName oname = new ObjectName(name);
// Acquire a reference to the component to be removed
ContainerBase container = getParentContainerFromChild(oname);
container.setLogger(null);
}
/**
* Remove an existing Loader.
*
* @param name MBean Name of the comonent to remove
*
* @exception Exception if a component cannot be removed
*/
public void removeLoader(String name) throws Exception {
ObjectName oname = new ObjectName(name);
// Acquire a reference to the component to be removed
ContainerBase container = getParentContainerFromChild(oname);
container.setLoader(null);
}
/**
* Remove an existing Manager.
*
* @param name MBean Name of the comonent to remove
*
* @exception Exception if a component cannot be removed
*/
public void removeManager(String name) throws Exception {
ObjectName oname = new ObjectName(name);
// Acquire a reference to the component to be removed
ContainerBase container = getParentContainerFromChild(oname);
container.setManager(null);
}
/**
* Remove an existing Realm.
*
* @param name MBean Name of the comonent to remove
*
* @exception Exception if a component cannot be removed
*/
public void removeRealm(String name) throws Exception {
ObjectName oname = new ObjectName(name);
// Acquire a reference to the component to be removed
ContainerBase container = getParentContainerFromChild(oname);
container.setRealm(null);
}
/**
* 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 {
// Acquire a reference to the component to be removed
ObjectName oname = new ObjectName(name);
String serviceName = oname.getKeyProperty("serviceName");
Server server = ServerFactory.getServer();
Service service = server.findService(serviceName);
// Remove this component from its parent component
server.removeService(service);
}
/**
* Remove an existing Valve.
*
* @param name MBean Name of the comonent to remove
*
* @exception Exception if a component cannot be removed
*/
public void removeValve(String name) throws Exception {
// Acquire a reference to the component to be removed
ObjectName oname = new ObjectName(name);
ContainerBase container = getParentContainerFromChild(oname);
String sequence = oname.getKeyProperty("seq");
Valve[] valves = (Valve[])container.getValves();
for (int i = 0; i < valves.length; i++) {
ObjectName voname = ((ValveBase) valves[i]).getObjectName();
if (voname.equals(oname)) {
container.removeValve(valves[i]);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -