| Method from org.jboss.ejb.EjbModule Detail: |
public void addLocalHome(Container con,
EJBLocalHome localHome) {
localHomes.put(con.getBeanMetaData().getEjbName(), localHome);
}
|
void createMissingPermissions(Container con,
BeanMetaData bean) throws ClassNotFoundException, PolicyContextException {
String contextID = con.getJaccContextID();
PolicyConfigurationFactory pcFactory = PolicyConfigurationFactory.getPolicyConfigurationFactory();
PolicyConfiguration pc = pcFactory.getPolicyConfiguration(contextID, false);
Class clazz = con.getHomeClass();
// If there is no security domain mark all methods as unchecked
boolean hasSecurityDomain = con.getSecurityManager() != null;
boolean exclude = hasSecurityDomain ? bean.isExcludeMissingMethods() : false;
if (clazz != null)
{
addMissingMethodPermissions(bean, exclude, clazz, InvocationType.HOME, pc);
}
clazz = con.getLocalHomeClass();
if (clazz != null)
{
addMissingMethodPermissions(bean, exclude, clazz, InvocationType.LOCALHOME, pc);
}
clazz = con.getLocalClass();
if (clazz != null)
{
addMissingMethodPermissions(bean, exclude, clazz, InvocationType.LOCAL, pc);
}
clazz = con.getRemoteClass();
if (clazz != null)
{
addMissingMethodPermissions(bean, exclude, clazz, InvocationType.REMOTE, pc);
}
if (pc.inService() == false)
pc.commit();
// Allow the policy to incorporate the policy configs
Policy.getPolicy().refresh();
}
Create any JACC permissions for the ejb methods that were not explicitly assigned method-permission or
exclude-list mappings. |
protected void createService() throws Exception {
serviceController = (ServiceControllerMBean) MBeanProxyExt.create(ServiceControllerMBean.class,
ServiceControllerMBean.OBJECT_NAME, server);
log.debug("createService, begin");
// Set up the beans in this module.
try
{
Iterator beans = appMetaData.getEnterpriseBeans();
String contextID = appMetaData.getJaccContextID();
if (contextID == null)
contextID = deploymentUnit.getSimpleName();
// appMetaData.gsetJaccContextID(contextID);
/* PolicyConfiguration pc = null; */
while (beans.hasNext())
{
BeanMetaData bean = (BeanMetaData) beans.next();
log.info("Deploying " + bean.getEjbName());
Container con = createContainer(bean, deploymentUnit);
addContainer(con);
// @todo support overriding the context id via metadata is needed
con.setJaccContextID(contextID);
}
// only one iteration should be necessary, but we won't sweat it.
// 2 iterations are needed by cmp...jdbc/bridge/JDBCCMRFieldBridge which
// assumes persistence managers are all set up for every
// bean in the relationship!
ListIterator iter = containerOrdering.listIterator();
while (iter.hasNext())
{
Container con = (Container) iter.next();
ObjectName jmxName = con.getJmxName();
/*
* Add the container mbean to the deployment mbeans so the state of the deployment can be tracked.
*/
server.registerMBean(con, jmxName);
// deploymentUnit.mbeans.add(jmxName);
BeanMetaData metaData = con.getBeanMetaData();
Collection< ObjectName > depends = new ArrayList< ObjectName >();
for (String dependsName : metaData.getDepends())
{
depends.add(ObjectName.getInstance(dependsName));
}
Iterator< String > invokerBindings = metaData.getInvokerBindings();
while (invokerBindings != null && invokerBindings.hasNext())
{
String invokerBindingName = invokerBindings.next();
InvokerProxyBindingMetaData ipbmd = appMetaData.getInvokerProxyBindingMetaDataByName(invokerBindingName);
if (ipbmd != null)
{
String invokerName = ipbmd.getInvokerMBean();
if (invokerName != null)
{
try
{
ObjectName invokerMBean = ObjectName.getInstance(invokerName);
if (depends.contains(invokerMBean) == false)
depends.add(invokerMBean);
}
catch (MalformedObjectNameException e)
{
log.trace("Ignored malformed invoker mbean '" + invokerName + "' " + e.toString());
}
}
}
}
serviceController.create(jmxName, depends);
// We keep the hashCode around for fast creation of proxies
int jmxHash = jmxName.hashCode();
Registry.bind(new Integer(jmxHash), jmxName);
log.debug("Bound jmxName=" + jmxName + ", hash=" + jmxHash + "into Registry");
}
}
catch (Exception e)
{
destroyService();
throw e;
} // end of try-catch
}
|
protected void destroyService() throws Exception {
WebServiceMBean webServer = null;
if (webServiceName != null)
{
webServer = (WebServiceMBean) MBeanProxyExt.create(WebServiceMBean.class, webServiceName);
}
ListIterator iter = containerOrdering.listIterator(containerOrdering.size());
while (iter.hasPrevious())
{
Container con = (Container) iter.previous();
ObjectName jmxName = con.getJmxName();
int conState = con.getState();
boolean destroyContainer = true;
log.debug("Looking to destroy container: " + jmxName + ", state: " + con.getStateString() + ", destroy: "
+ destroyContainer);
// always unregister from Registry
int jmxHash = jmxName.hashCode();
Registry.unbind(new Integer(jmxHash));
// Unregister the web classloader
// Removing the wcl should probably be done in stop of the container,
// but I don't want to look for errors today.
if (webServer != null)
{
ClassLoader wcl = con.getWebClassLoader();
if (wcl != null)
{
try
{
webServer.removeClassLoader(wcl);
}
catch (Throwable e)
{
log.warn("Failed to unregister webClassLoader", e);
}
}
}
// Only destroy containers that have been created or started
if (destroyContainer)
{
try
{
serviceController.destroy(jmxName);
serviceController.remove(jmxName);
log.info("Undeployed " + con.getBeanMetaData().getEjbName());
if (server.isRegistered(jmxName))
server.unregisterMBean(jmxName);
}
catch (Throwable e)
{
log.error("unexpected exception destroying Container: " + jmxName, e);
} // end of try-catch
}
// Destroy proxy factories
if (destroyContainer)
{
if (con.getBeanMetaData() != null && con.getBeanMetaData().getInvokerBindings() != null)
{
Iterator< String > invokerBindings = con.getBeanMetaData().getInvokerBindings();
while (invokerBindings.hasNext())
{
String invoker = invokerBindings.next();
EJBProxyFactory ci = con.lookupProxyFactory(invoker);
if (ci != null)
{
ci.setContainer(null);
ci.setInvokerBinding(null);
ci.setInvokerMetaData(null);
}
}
}
}
// cleanup container
con.setBeanMetaData(null);
con.setWebClassLoader(null);
con.setClassLoader(null);
con.setEjbModule(null);
con.setDeploymentInfo(null);
con.setTransactionManager(null);
con.setSecurityManager(null);
con.setRealmMapping(null);
con.setSecurityProxy(null);
con.setSecurityManagement(null);
con.setPolicyRegistration(null);
con.proxyFactories.clear();
}
this.containers.clear();
this.localHomes.clear();
this.containerOrdering.clear();
this.moduleData.clear();
this.serviceController = null;
}
|
public ClassLoader getClassLoader() {
return classLoader;
}
Get the class loader of this deployment unit. |
public Container getContainer(String name) {
return (Container) containers.get(name);
}
Get a container from this deployment unit that corresponds to a given name |
public Collection getContainers() {
return containerOrdering;
}
Get all containers in this deployment unit. |
public EJBLocalHome getLocalHome(Container con) {
return (EJBLocalHome) localHomes.get(con.getBeanMetaData().getEjbName());
}
|
public Object getModuleData(Object key) {
return moduleData.get(key);
}
|
public Map getModuleDataMap() {
return moduleData;
}
|
public EJBTimerService getTimerService() {
return timerService;
}
|
public URL getURL() {
return appMetaData.getUrl();
}
Get the URL from which this deployment unit was deployed |
public ObjectName getWebServiceName() {
return webServiceName;
}
|
public boolean isCallByValue() {
return callByValue;
}
Whether the container is call by value |
public void putModuleData(Object key,
Object value) {
moduleData.put(key, value);
}
|
public void removeContainer(Container con) {
containers.remove(con.getBeanMetaData().getEjbName());
containerOrdering.remove(con);
}
Remove a container from this deployment unit. |
public void removeLocalHome(Container con) {
localHomes.remove(con.getBeanMetaData().getEjbName());
}
|
public void removeModuleData(Object key) {
moduleData.remove(key);
}
|
public void setClassLoader(ClassLoader cl) {
this.classLoader = cl;
}
Set the class loader of this deployment unit |
public void setPolicyRegistration(PolicyRegistration policyRegistration) {
this.policyRegistration = policyRegistration;
}
|
public void setSecurityManagement(ISecurityManagement sm) {
this.securityManagement = sm;
}
|
public void setTimerService(EJBTimerService timerService) {
this.timerService = timerService;
}
|
public void setTransactionManagerFactory(TransactionManagerFactory tm) {
this.tmFactory = tm;
}
|
public void setWebServiceName(ObjectName webServiceName) {
this.webServiceName = webServiceName;
}
|
protected void startService() throws Exception {
// before EntityContainer returns from the startService, its PM should be usable
ListIterator iter = containerOrdering.listIterator();
while (iter.hasNext())
{
Container con = (Container) iter.next();
if (con.getBeanMetaData().isEntity())
{
ClassLoader oldCl = SecurityActions.getContextClassLoader();
SecurityActions.setContextClassLoader(con.getClassLoader());
con.pushENC();
try
{
((EntityContainer) con).getPersistenceManager().start();
}
finally
{
con.popENC();
// Reset classloader
SecurityActions.setContextClassLoader(oldCl);
}
}
}
iter = containerOrdering.listIterator();
while (iter.hasNext())
{
Container con = (Container) iter.next();
log.debug("startService, starting container: " + con.getBeanMetaData().getEjbName());
serviceController.start(con.getJmxName());
}
}
The mbean Service interface start method calls the start method on each contatiner, then the init
method on each container. Conversion to a different registration system with one-phase startup is conceivable. |
protected void stopService() throws Exception {
ListIterator iter = containerOrdering.listIterator(containerOrdering.size());
while (iter.hasPrevious())
{
Container con = (Container) iter.previous();
try
{
ObjectName jmxName = con.getJmxName();
// The container may already be destroyed so validate metaData
BeanMetaData metaData = con.getBeanMetaData();
String ejbName = metaData != null ? metaData.getEjbName() : "Unknown";
log.debug("stopService, stopping container: " + ejbName);
serviceController.stop(jmxName);
}
catch (Exception e)
{
log.error("unexpected exception stopping Container: " + con.getJmxName(), e);
} // end of try-catch
}
}
Stops all the containers of this application. |