Example usage for javax.enterprise.deploy.spi DeploymentManager getRunningModules

List of usage examples for javax.enterprise.deploy.spi DeploymentManager getRunningModules

Introduction

In this page you can find the example usage for javax.enterprise.deploy.spi DeploymentManager getRunningModules.

Prototype

public TargetModuleID[] getRunningModules(ModuleType moduleType, Target[] targetList)
        throws TargetException, IllegalStateException;

Source Link

Document

Retrieve the list of Java EE application modules distributed to the identified targets and that are currently running on the associated server or servers.

Usage

From source file:org.apache.geronimo.console.databasemanager.wizard.DatabasePoolPortlet.java

private void delete(PortletRequest request, ActionResponse response, PoolData data) {
    // check to make sure the abstract name does not begin with 'org.apache.geronimo.configs'
    // if it does not - then delete it -- otherwise it is a system database
    if (data.getAbstractName() != null) {
        boolean isSystemDatabasePool = (data.getAbstractName().indexOf("org.apache.geronimo.configs") == 0);

        if (!isSystemDatabasePool) {
            DeploymentManager mgr = ManagementHelper.getManagementHelper(request).getDeploymentManager();
            try {
                // retrieve all running modules
                TargetModuleID[] runningIds = mgr.getRunningModules(ModuleType.RAR, mgr.getTargets());

                // index of module to keep
                int index = -1;

                // only keep module id that is associated with selected DB pool
                for (int i = 0; i < runningIds.length; i++) {
                    if (data.getAbstractName().contains(runningIds[i].getModuleID())) {
                        index = i;/*from ww  w .  j  av a 2s  .c o m*/
                        break;
                    }
                }
                TargetModuleID[] ids = { runningIds[index] };

                // undeploy the db pool
                ProgressObject po = mgr.undeploy(ids);
                waitForProgress(po);

                if (po.getDeploymentStatus().isCompleted()) {
                    log.info("Undeployment completed successfully!");
                }
            } catch (Exception e) {
                log.error("Undeployment unsuccessful!");
            } finally {
                if (mgr != null)
                    mgr.release();
            }
        }
    }
}