A simple subdeployer that deploys a managed object after parsing the
deployment's xml file.
| Method from org.jboss.deployment.SimpleSubDeployerSupport Detail: |
public boolean accepts(DeploymentInfo di) {
String urlStr = di.url.toString();
String extension = getExtension();
return urlStr.endsWith(extension) || urlStr.endsWith(extension + '/");
}
|
public void create(DeploymentInfo di) throws DeploymentException {
determineObjectName(di);
ObjectName uclName = registerClassLoader(di);
try
{
registerDeployment(di, uclName);
try
{
createService(di);
try
{
super.create(di);
}
catch (Throwable t)
{
destroyService(di);
}
}
catch (Throwable t)
{
unregisterDeployment(di);
throw t;
}
}
catch (Throwable t)
{
unregisterClassLoader(di);
DeploymentException.rethrowAsDeploymentException("Error creating deployment " + di.url, t);
}
}
|
protected void createService(DeploymentInfo di) throws DeploymentException {
try
{
serviceController.create(di.deployedObject);
}
catch (Throwable t)
{
DeploymentException.rethrowAsDeploymentException("Error in create for deployment " + di.url, t);
}
}
Do the create lifecyle for the deployment |
public void destroy(DeploymentInfo di) throws DeploymentException {
try
{
destroyService(di);
super.destroy(di);
}
finally
{
unregisterDeployment(di);
unregisterClassLoader(di);
}
}
|
protected void destroyService(DeploymentInfo di) throws DeploymentException {
try
{
if (di.deployedObject != null)
serviceController.destroy(di.deployedObject);
}
catch (Throwable t)
{
log.warn("Error in destroy for deployment " + di.url, t);
}
try
{
if (di.deployedObject != null)
serviceController.remove(di.deployedObject);
}
catch (Throwable t)
{
log.warn("Error in remove for deployment " + di.url, t);
}
}
Do the destroy lifecyle for the deployment |
protected void determineObjectName(DeploymentInfo di) throws DeploymentException {
String objectName = getObjectName(di);
try
{
di.deployedObject = new ObjectName(objectName);
}
catch (MalformedObjectNameException e)
{
throw new DeploymentException("INTERNAL ERROR: Bad object name. " + objectName);
}
}
Determine the object name |
abstract public String getDeploymentClass()
|
abstract public String getExtension()
Get the package extension for this deployment |
protected URL getMetaDataResource(DeploymentInfo di) throws DeploymentException {
URL url = di.localCl.findResource(getMetaDataURL());
if (url == null)
throw new DeploymentException("Could not find meta data " + getMetaDataURL() + " for deployment " + di.url);
return url;
}
Get the url of the meta data resource |
abstract public String getMetaDataURL()
|
abstract public String getObjectName(DeploymentInfo di) throws DeploymentException
Get the object name for this deployment |
public void init(DeploymentInfo di) throws DeploymentException {
URL url = getMetaDataResource(di);
parseMetaData(di, url);
resolveWatch(di, url);
super.init(di);
}
|
abstract protected void parseMetaData(DeploymentInfo di,
URL url) throws DeploymentException
|
public void postRegister(Boolean done) {
super.postRegister(done);
if (done.booleanValue())
{
serviceController = (ServiceControllerMBean)
MBeanProxyExt.create(ServiceControllerMBean.class,
ServiceControllerMBean.OBJECT_NAME,
server);
}
}
|
protected ObjectName registerClassLoader(DeploymentInfo di) throws DeploymentException {
ObjectName uclName = null;
try
{
RepositoryClassLoader ucl = di.ucl;
uclName = ucl.getObjectName();
if (server.isRegistered(uclName) == false)
{
server.registerMBean(di.ucl, uclName);
registeredClassLoader = true;
}
}
catch (Throwable t)
{
DeploymentException.rethrowAsDeploymentException("Error registering classloader " + uclName, t);
}
return uclName;
}
Register the UCL classloader |
protected void registerDeployment(DeploymentInfo di,
ObjectName uclName) throws DeploymentException {
try
{
String deploymentClass = getDeploymentClass();
server.createMBean(deploymentClass, di.deployedObject, uclName, new Object[] { di }, new String[] { DeploymentInfo.class.getName() });
}
catch (Throwable t)
{
DeploymentException.rethrowAsDeploymentException("Error registering deployment " + di.url, t);
}
}
|
protected void resolveWatch(DeploymentInfo di,
URL url) throws DeploymentException {
// Assume we watch the main deployment
di.watch = di.url;
// Unless it is an unpacked directory
if (di.url.getProtocol().equals("file"))
{
File file = new File(di.url.getFile());
if (file.isDirectory())
di.watch = url;
}
}
|
public void start(DeploymentInfo di) throws DeploymentException {
startService(di);
try
{
super.start(di);
}
catch (Throwable t)
{
stopService(di);
DeploymentException.rethrowAsDeploymentException("Error in start for deployment " + di.url, t);
}
}
|
protected void startService(DeploymentInfo di) throws DeploymentException {
try
{
serviceController.start(di.deployedObject);
}
catch (Throwable t)
{
DeploymentException.rethrowAsDeploymentException("Error in start for deployment " + di.url, t);
}
}
Do the start lifecyle for the deployment |
public void stop(DeploymentInfo di) throws DeploymentException {
stopService(di);
super.stop(di);
}
|
protected void stopService(DeploymentInfo di) {
try
{
if (di.deployedObject != null)
serviceController.stop(di.deployedObject);
}
catch (Throwable t)
{
log.warn("Error in stop for deployment " + di.url, t);
}
}
Do the stop lifecyle for the deployment |
protected void unregisterClassLoader(DeploymentInfo di) {
ObjectName uclName = null;
try
{
RepositoryClassLoader ucl = di.ucl;
if (ucl != null)
{
uclName = ucl.getObjectName();
if (registeredClassLoader && server.isRegistered(uclName))
{
server.unregisterMBean(uclName);
registeredClassLoader = false;
}
}
}
catch (Throwable t)
{
log.warn("Error unregistering classloader " + uclName, t);
}
}
Unregister the UCL classloader |
protected void unregisterDeployment(DeploymentInfo di) {
try
{
if (server.isRegistered(di.deployedObject))
server.unregisterMBean(di.deployedObject);
}
catch (Throwable t)
{
log.warn("Error unregistering deployment " + di.deployedObject, t);
}
}
Unregister the deployment |