Home » geronimo-2.2-source-release » org.apache.geronimo.j2ee.management.impl » [javadoc | source]

    1   /**
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   
   18   package org.apache.geronimo.j2ee.management.impl;
   19   
   20   import java.util.ArrayList;
   21   import java.util.Collection;
   22   import java.util.Hashtable;
   23   import javax.management.ObjectName;
   24   
   25   import org.apache.geronimo.gbean.GBeanInfo;
   26   import org.apache.geronimo.gbean.GBeanInfoBuilder;
   27   import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
   28   import org.apache.geronimo.kernel.ObjectNameUtil;
   29   import org.apache.geronimo.kernel.config.ConfigurationManager;
   30   import org.apache.geronimo.kernel.repository.ListableRepository;
   31   import org.apache.geronimo.kernel.repository.WritableListableRepository;
   32   import org.apache.geronimo.management.AppClientModule;
   33   import org.apache.geronimo.management.EJBModule;
   34   import org.apache.geronimo.management.J2EEDeployedObject;
   35   import org.apache.geronimo.management.J2EEResource;
   36   import org.apache.geronimo.management.geronimo.EJBManager;
   37   import org.apache.geronimo.management.geronimo.J2EEApplication;
   38   import org.apache.geronimo.management.geronimo.J2EEServer;
   39   import org.apache.geronimo.management.geronimo.JMSManager;
   40   import org.apache.geronimo.management.geronimo.JVM;
   41   import org.apache.geronimo.management.geronimo.KeystoreManager;
   42   import org.apache.geronimo.management.geronimo.ResourceAdapterModule;
   43   import org.apache.geronimo.management.geronimo.SecurityRealm;
   44   import org.apache.geronimo.management.geronimo.WebManager;
   45   import org.apache.geronimo.management.geronimo.WebModule;
   46   import org.apache.geronimo.system.serverinfo.ServerInfo;
   47   import org.apache.geronimo.system.threads.ThreadPool;
   48   
   49   /**
   50    * @version $Rev: 698441 $ $Date: 2008-09-24 00:10:08 -0700 (Wed, 24 Sep 2008) $
   51    */
   52   public class J2EEServerImpl implements J2EEServer {
   53       private static final String SERVER_VENDOR = "The Apache Software Foundation";
   54       private final String objectName;
   55       private final ServerInfo serverInfo;
   56       private final Collection jvms;
   57       private final Collection resources;
   58       private final Collection j2eeApplications;
   59       private final Collection appClientModules;
   60       private final Collection webModules;
   61       private final Collection ejbModules;
   62       private final Collection resourceAdapterModules;
   63       private final Collection webManagers;
   64       private final Collection ejbManagers;
   65       private final Collection jmsManagers;
   66       private final Collection threadPools;
   67       private final Collection repositories;
   68       private final Collection writableRepos;
   69       private final Collection securityRealms;
   70       private final Collection keystoreManagers;
   71       private final ConfigurationManager configurationManager;
   72   
   73       public J2EEServerImpl(String objectName,
   74                             ServerInfo serverInfo,
   75                             Collection jvms,
   76                             Collection resources,
   77                             Collection applications,
   78                             Collection appClientModules,
   79                             Collection webModules,
   80                             Collection ejbModules,
   81                             Collection resourceAdapterModules,
   82                             Collection webManagers,
   83                             Collection ejbManagers,
   84                             Collection jmsManagers,
   85                             Collection threadPools,
   86                             Collection repositories,
   87                             Collection writableRepos,
   88                             Collection securityRealms,
   89                             Collection keystoreManagers,
   90                             ConfigurationManager configurationManager) {
   91   
   92           this.objectName = objectName;
   93           ObjectName myObjectName = ObjectNameUtil.getObjectName(this.objectName);
   94           verifyObjectName(myObjectName);
   95   
   96           this.serverInfo = serverInfo;
   97           this.jvms = jvms;
   98           this.resources = resources;
   99   
  100           this.j2eeApplications = applications;
  101           this.appClientModules = appClientModules;
  102           this.webModules = webModules;
  103           this.ejbModules = ejbModules;
  104           this.resourceAdapterModules = resourceAdapterModules;
  105   
  106           this.webManagers = webManagers;
  107           this.ejbManagers = ejbManagers;
  108           this.jmsManagers = jmsManagers;
  109   
  110           this.threadPools = threadPools;
  111           this.repositories = repositories;
  112           this.writableRepos = writableRepos;
  113           this.securityRealms = securityRealms;
  114           this.keystoreManagers = keystoreManagers;
  115           this.configurationManager = configurationManager;
  116       }
  117   
  118       public String getObjectName() {
  119           return objectName;
  120       }
  121   
  122       public boolean isStateManageable() {
  123           return true;
  124       }
  125   
  126       public boolean isStatisticsProvider() {
  127           return false;
  128       }
  129   
  130       public boolean isEventProvider() {
  131           return true;
  132       }
  133   
  134       /**
  135        * ObjectName must match this pattern:
  136        * <p/>
  137        * domain:j2eeType=J2EEServer,name=MyName
  138        * @param objectName object name to verify pattern
  139        */
  140       private void verifyObjectName(ObjectName objectName) {
  141           if (objectName.isPattern()) {
  142               throw new InvalidObjectNameException("ObjectName can not be a pattern", objectName);
  143           }
  144           Hashtable keyPropertyList = objectName.getKeyPropertyList();
  145           if (!"J2EEServer".equals(keyPropertyList.get("j2eeType"))) {
  146               throw new InvalidObjectNameException("J2EEServer object name j2eeType property must be 'J2EEServer'", objectName);
  147           }
  148           if (!keyPropertyList.containsKey("name")) {
  149               throw new InvalidObjectNameException("J2EEServer object must contain a name property", objectName);
  150           }
  151           if (keyPropertyList.size() != 2) {
  152               throw new InvalidObjectNameException("J2EEServer object name can only have j2eeType, and name", objectName);
  153           }
  154       }
  155   
  156   
  157       public String[] getDeployedObjects() {
  158           return Util.getObjectNames(getDeployedObjectInstances());
  159       }
  160   
  161       public J2EEDeployedObject[] getDeployedObjectInstances() {
  162           ArrayList objects = new ArrayList();
  163           if (j2eeApplications != null) {
  164               objects.addAll(j2eeApplications);
  165           }
  166           if (appClientModules  != null) {
  167               objects.addAll(appClientModules);
  168           }
  169           if (ejbModules  != null) {
  170               objects.addAll(ejbModules);
  171           }
  172           if (webModules  != null) {
  173               objects.addAll(webModules);
  174           }
  175           if (resourceAdapterModules != null) {
  176               objects.addAll(resourceAdapterModules);
  177           }
  178   
  179           return (J2EEDeployedObject[]) objects.toArray(new J2EEDeployedObject[objects.size()]);
  180       }
  181   
  182       public String[] getResources() {
  183           return Util.getObjectNames(getResourceInstances());
  184       }
  185   
  186       public J2EEResource[] getResourceInstances() {
  187           if (resources == null) return new J2EEResource[0];
  188           return (J2EEResource[]) resources.toArray(new J2EEResource[resources.size()]);
  189       }
  190   
  191       public String[] getJavaVMs() {
  192           return Util.getObjectNames(getJavaVMInstances());
  193       }
  194   
  195       public JVM[] getJavaVMInstances() {
  196           if (jvms == null) return new JVM[0];
  197           return (JVM[]) jvms.toArray(new JVM[jvms.size()]);
  198       }
  199   
  200       public J2EEApplication[] getApplications() {
  201           if (j2eeApplications == null) return new J2EEApplication[0];
  202           return (J2EEApplication[]) j2eeApplications.toArray(new J2EEApplication[j2eeApplications.size()]);
  203       }
  204   
  205       public AppClientModule[] getAppClients() {
  206           if (appClientModules == null) return new AppClientModule[0];
  207           return (AppClientModule[]) appClientModules.toArray(new AppClientModule[appClientModules.size()]);
  208       }
  209   
  210       public WebModule[] getWebModules() {
  211           if (webModules == null) return new WebModule[0];
  212           return (WebModule[]) webModules.toArray(new WebModule[webModules.size()]);
  213       }
  214   
  215       public EJBModule[] getEJBModules() {
  216           if (ejbModules == null) return new EJBModule[0];
  217           return (EJBModule[]) ejbModules.toArray(new EJBModule[ejbModules.size()]);
  218       }
  219   
  220       public ResourceAdapterModule[] getResourceAdapterModules() {
  221           if (resourceAdapterModules == null) return new ResourceAdapterModule[0];
  222           return (ResourceAdapterModule[]) resourceAdapterModules.toArray(new ResourceAdapterModule[resourceAdapterModules.size()]);
  223       }
  224   
  225   
  226       public WebManager[] getWebManagers() {
  227           if (webManagers == null) return new WebManager[0];
  228           return (WebManager[]) webManagers.toArray(new WebManager[webManagers.size()]);
  229       }
  230   
  231       public EJBManager[] getEJBManagers() {
  232           if (ejbManagers == null) return new EJBManager[0];
  233           return (EJBManager[]) ejbManagers.toArray(new EJBManager[ejbManagers.size()]);
  234       }
  235   
  236       public JMSManager[] getJMSManagers() {
  237           if (jmsManagers == null) return new JMSManager[0];
  238           return (JMSManager[]) jmsManagers.toArray(new JMSManager[jmsManagers.size()]);
  239       }
  240   
  241       public ThreadPool[] getThreadPools() {
  242           if (threadPools == null) return new ThreadPool[0];
  243           return (ThreadPool[]) threadPools.toArray(new ThreadPool[threadPools.size()]);
  244       }
  245   
  246       public ListableRepository[] getRepositories() {
  247           if (repositories == null) return new ListableRepository[0];
  248           return (ListableRepository[]) repositories.toArray(new ListableRepository[repositories.size()]);
  249       }
  250   
  251       public WritableListableRepository[] getWritableRepositories() {
  252           if (writableRepos == null) return new WritableListableRepository[0];
  253           return (WritableListableRepository[]) writableRepos.toArray(new WritableListableRepository[writableRepos.size()]);
  254       }
  255   
  256       public SecurityRealm[] getSecurityRealms() {
  257           if (securityRealms == null) return new SecurityRealm[0];
  258           return (SecurityRealm[]) securityRealms.toArray(new SecurityRealm[securityRealms.size()]);
  259       }
  260   
  261       public ServerInfo getServerInfo() {
  262           return serverInfo;
  263       }
  264   
  265       public KeystoreManager getKeystoreManager() {
  266           if (keystoreManagers == null) return null;
  267           return (KeystoreManager) keystoreManagers.iterator().next();
  268       }
  269   
  270       public ConfigurationManager getConfigurationManager() {
  271           return configurationManager;
  272       }
  273   
  274       public String getServerVendor() {
  275           return SERVER_VENDOR;
  276       }
  277   
  278       public String getServerVersion() {
  279           return serverInfo.getVersion();
  280       }
  281   
  282       public static final GBeanInfo GBEAN_INFO;
  283   
  284       static {
  285           GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(J2EEServerImpl.class, NameFactory.J2EE_SERVER);
  286   
  287           infoFactory.addReference("ServerInfo", ServerInfo.class, GBeanInfoBuilder.DEFAULT_J2EE_TYPE);
  288           infoFactory.addReference("JVMs", JVM.class, NameFactory.JVM);
  289           infoFactory.addReference("Resources", J2EEResource.class); // several types match this
  290           infoFactory.addReference("Applications", J2EEApplication.class, NameFactory.J2EE_APPLICATION);
  291           infoFactory.addReference("AppClientModules", AppClientModule.class, NameFactory.APP_CLIENT_MODULE);
  292           infoFactory.addReference("WebModules", WebModule.class, NameFactory.WEB_MODULE);
  293           infoFactory.addReference("EJBModules", EJBModule.class, NameFactory.EJB_MODULE);
  294           infoFactory.addReference("ResourceAdapterModules", ResourceAdapterModule.class, NameFactory.RESOURCE_ADAPTER_MODULE);
  295           infoFactory.addReference("WebManagers", WebManager.class);
  296           infoFactory.addReference("EJBManagers", EJBManager.class);
  297           infoFactory.addReference("JMSManagers", JMSManager.class);
  298           infoFactory.addReference("ThreadPools", ThreadPool.class);
  299           infoFactory.addReference("Repositories", ListableRepository.class);
  300           infoFactory.addReference("WritableRepos", WritableListableRepository.class);
  301           infoFactory.addReference("SecurityRealms", SecurityRealm.class);
  302           infoFactory.addReference("KeystoreManagers", KeystoreManager.class);
  303           infoFactory.addReference("ConfigurationManager", ConfigurationManager.class);
  304   
  305           infoFactory.setConstructor(new String[]{
  306                   "objectName",
  307                   "ServerInfo",
  308                   "JVMs",
  309                   "Resources",
  310                   "Applications",
  311                   "AppClientModules",
  312                   "WebModules",
  313                   "EJBModules",
  314                   "ResourceAdapterModules",
  315                   "WebManagers",
  316                   "EJBManagers",
  317                   "JMSManagers",
  318                   "ThreadPools",
  319                   "Repositories",
  320                   "WritableRepos",
  321                   "SecurityRealms",
  322                   "KeystoreManagers",
  323                   "ConfigurationManager",
  324           });
  325   
  326           GBEAN_INFO = infoFactory.getBeanInfo();
  327       }
  328   
  329       public static GBeanInfo getGBeanInfo() {
  330           return GBEAN_INFO;
  331       }
  332   }

Home » geronimo-2.2-source-release » org.apache.geronimo.j2ee.management.impl » [javadoc | source]