Information

4
Story Points

Technologies

Decompiled Java File
package com.googlecode.arit.websphere;

import com.github.veithen.rbeans.RBeanFactory;
import com.github.veithen.rbeans.RBeanFactoryException;
import com.googlecode.arit.mbeans.MBeanAccessor;
import com.googlecode.arit.mbeans.MBeanServerInspector;
import com.googlecode.arit.module.ModuleDescription;
import com.googlecode.arit.module.ModuleInspector;
import com.googlecode.arit.module.ModuleInspectorPlugin;
import com.googlecode.arit.module.ModuleStatus;
import com.googlecode.arit.module.ModuleType;
import com.googlecode.arit.websphere.AdminServiceFactoryRBean;
import com.googlecode.arit.websphere.CompoundClassLoaderRBean;
import com.googlecode.arit.websphere.DeployedApplicationRBean;
import com.googlecode.arit.websphere.DeployedObjectCollaboratorRBean;
import com.googlecode.arit.websphere.DeployedObjectRBean;
import com.googlecode.arit.websphere.Utils;
import com.googlecode.arit.websphere.WASModuleInspector;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.QueryExp;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

public class WASModuleInspectorPlugin implements ModuleInspectorPlugin, InitializingBean {
   @Autowired
   private MBeanServerInspector mbsInspector;
   @Autowired
   @Qualifier("ear")
   private ModuleType earModuleType;
   @Autowired
   @Qualifier("appwar")
   private ModuleType appWarModuleType;
   @Autowired
   @Qualifier("war")
   private ModuleType warModuleType;
   private RBeanFactory rbf;
   private MBeanServer mbs;
   private MBeanAccessor mbeanAccessor;
   private Map jmxNameMap = new HashMap();

   public void afterPropertiesSet() throws Exception {
      try {
         this.rbf = new RBeanFactory(new Class[]{AdminServiceFactoryRBean.class, DeployedObjectCollaboratorRBean.class, CompoundClassLoaderRBean.class});
      } catch (RBeanFactoryException var2) {
         return;
      }

      this.mbs = ((AdminServiceFactoryRBean)this.rbf.createRBean(AdminServiceFactoryRBean.class)).getMBeanFactory().getMBeanServer();
      this.mbeanAccessor = this.mbsInspector.inspect(this.mbs);
      if(this.mbeanAccessor == null) {
         throw new Error("Unable to inspect WebSphere\'s MBean server; this is unexpected because we are in a WebSphere specific plugin");
      } else {
         this.jmxNameMap.put(this.earModuleType, new ObjectName("WebSphere:type=Application,*"));
         this.jmxNameMap.put(this.warModuleType, new ObjectName("WebSphere:type=WebModule,*"));
      }
   }

   public boolean isAvailable() {
      return this.rbf != null && this.mbeanAccessor != null;
   }

   private List getCollaborators(ObjectName query) {
      Set names = this.mbs.queryNames(query, (QueryExp)null);
      ArrayList collaborators = new ArrayList(names.size());
      Iterator var4 = names.iterator();

      while(var4.hasNext()) {
         ObjectName name = (ObjectName)var4.next();
         collaborators.add(this.rbf.createRBean(DeployedObjectCollaboratorRBean.class, this.mbeanAccessor.retrieve(name)));
      }

      return collaborators;
   }

   public ModuleInspector createModuleInspector() {
      List earCollaborators;
      List warCollaborators;
      try {
         earCollaborators = this.getCollaborators(new ObjectName("WebSphere:type=Application,*"));
         warCollaborators = this.getCollaborators(new ObjectName("WebSphere:type=WebModule,*"));
      } catch (MalformedObjectNameException var13) {
         throw new Error("Failed to create object name", var13);
      }

      HashSet earClassLoaders = new HashSet();
      Iterator appWarClassLoaders = earCollaborators.iterator();

      while(appWarClassLoaders.hasNext()) {
         DeployedObjectCollaboratorRBean moduleMap = (DeployedObjectCollaboratorRBean)appWarClassLoaders.next();
         earClassLoaders.add(moduleMap.getDeployedObject().getClassLoader());
      }

      HashSet appWarClassLoaders1 = new HashSet();
      Iterator moduleMap1 = warCollaborators.iterator();

      while(moduleMap1.hasNext()) {
         DeployedObjectCollaboratorRBean collaborator = (DeployedObjectCollaboratorRBean)moduleMap1.next();
         ClassLoader collaborator1 = collaborator.getDeployedObject().getClassLoader();
         if(earClassLoaders.contains(collaborator1)) {
            appWarClassLoaders1.add(collaborator1);
         }
      }

      HashMap moduleMap2 = new HashMap();
      Iterator collaborator2 = earCollaborators.iterator();

      while(true) {
         ClassLoader classLoader1;
         URL url;
         DeployedObjectCollaboratorRBean collaborator3;
         while(true) {
            if(!collaborator2.hasNext()) {
               collaborator2 = warCollaborators.iterator();

               while(collaborator2.hasNext()) {
                  collaborator3 = (DeployedObjectCollaboratorRBean)collaborator2.next();
                  ClassLoader classLoader2 = collaborator3.getDeployedObject().getClassLoader();
                  if(!appWarClassLoaders1.contains(classLoader2)) {
                     moduleMap2.put(classLoader2, new ModuleDescription(this.warModuleType, collaborator3.getName(), classLoader2, Utils.dirToURL(Utils.getWebAppRoot((CompoundClassLoaderRBean)this.rbf.createRBean(CompoundClassLoaderRBean.class, classLoader2))), ModuleStatus.STARTED));
                  }
               }

               return new WASModuleInspector(this.rbf, moduleMap2, this.earModuleType, this.appWarModuleType, this.warModuleType);
            }

            collaborator3 = (DeployedObjectCollaboratorRBean)collaborator2.next();
            DeployedObjectRBean classLoader = collaborator3.getDeployedObject();
            classLoader1 = classLoader.getClassLoader();
            if(classLoader instanceof DeployedApplicationRBean) {
               String binariesURL = ((DeployedApplicationRBean)classLoader).getBinariesURL();
               if(binariesURL != null) {
                  url = Utils.dirToURL(new File(binariesURL));
                  break;
               }

               CompoundClassLoaderRBean ccl = (CompoundClassLoaderRBean)this.rbf.createRBean(CompoundClassLoaderRBean.class, classLoader1);
               if(!ccl.getProviders().iterator().hasNext()) {
                  continue;
               }

               url = Utils.dirToURL(Utils.getEARRoot(ccl));
               break;
            }

            url = null;
            break;
         }

         moduleMap2.put(classLoader1, new ModuleDescription(appWarClassLoaders1.contains(classLoader1)?this.appWarModuleType:this.earModuleType, collaborator3.getName(), classLoader1, url, ModuleStatus.STARTED));
      }
   }
}
Page generated: Oct 19, 2017 2:35:19 PM