FileDocCategorySizeDatePackage
PluginManager.javaAPI DocJBoss 4.2.115637Fri Jul 13 21:02:16 BST 2007org.jboss.console.manager

PluginManager

public class PluginManager extends org.jboss.system.ServiceMBeanSupport implements PluginManagerMBean, NotificationListener
jmx:mbean
extends="org.jboss.system.ServiceMBean"

Fields Summary
public static String
PLUGIN_MANAGER_NAME
protected ArrayList
plugins
protected org.jboss.console.manager.interfaces.ManageableResource
bootstrapResource
public String
jndiName
protected long
treeVersion
protected HashMap
currentTrees
protected String
mainLogoUrl
protected String
mainLinkUrl
protected boolean
enableShutdown
Constructors Summary
public PluginManager()

   
   // Static --------------------------------------------------------
   
   // Constructors --------------------------------------------------
   
     
   
   
Methods Summary
protected voidbindProxyInJndi()

      InitialContext ctx = new InitialContext ();      
      Object proxy = RMIRemoteMBeanProxy.create (PluginManagerMBean.class, this.getServiceName (), this.getServer ());         
      Util.rebind (ctx, this.jndiName, proxy);
   
public voidcreateService()

      this.bootstrapResource = new MBeanResource (this.getServiceName (), this.getClass ().toString ());      
   
protected java.util.HashSetfindSubResources(org.jboss.console.manager.interfaces.TreeNode tree)

      HashSet result = new HashSet ();
      
      // first add the tree node itself if it is an instance
      // of an ResourceTreeNode
      //
      if (tree instanceof ResourceTreeNode)
      {
         result.add (((ResourceTreeNode)tree).getResource ());
      }
      
      // then add local resources
      //
      ResourceTreeNode[] rns = tree.getNodeManagableResources ();
      if (rns != null && rns.length > 0)
      {      
         // Then travel to sub-nodes resources...
         //
         for (int i=0; i<rns.length; i++)
         {
            result.add (rns[i].getResource ());
            HashSet subResult = findSubResources (rns[i]);
            if (subResult != null && subResult.size () > 0)
               result.addAll (subResult);            
         }
      }
      
      // ..and to other sub-nodes (which are not resources)
      //
      TreeNode[] ns = tree.getSubNodes ();
      if (ns != null && ns.length > 0)
      {
         for (int i=0; i<ns.length; i++)
         {
            HashSet subResult = findSubResources (ns[i]);
            if (subResult != null && subResult.size () > 0)
               result.addAll (subResult);            
         }
      }
      
      return result;      
   
public org.jboss.console.manager.interfaces.ManageableResourcegetBootstrapResource()

jmx:managed-attribute

      return this.bootstrapResource;
   
public java.lang.StringgetJndiName()

jmx:managed-attribute

      return jndiName;
   
public javax.management.MBeanServergetMBeanServer()

jmx:managed-attribute

      return this.server;
   
public java.lang.StringgetMainLinkUrl()

jmx:managed-attribute

      return mainLinkUrl;      
   
public java.lang.StringgetMainLogoUrl()

jmx:managed-attribute

      return mainLogoUrl;
   
protected java.util.ArrayListgetPluginsSubsetForProfile(java.lang.String profile)

      ArrayList result = new ArrayList ();
      
      for (int i = 0; i < plugins.size(); i++)
      {
         ConsolePlugin cp = (ConsolePlugin)plugins.get(i);
         String [] set = cp.getSupportedProfiles ();
         if (java.util.Arrays.asList (set).contains (profile))
            result.add (cp);
      }
      
      return result;
   
public synchronized org.jboss.console.manager.interfaces.TreeInfogetTreeForProfile(java.lang.String profile)

jmx:managed-operation

      TreeInfo currentTree = (TreeInfo)currentTrees.get(profile);
      
      if (currentTree == null)
      {      
         HashSet resourcesToManage = new HashSet ();      
         TreeInfo result = new DefaultTreeInfo ();      
         ArrayList pluginsSubset = getPluginsSubsetForProfile (profile);
         HashSet resourcesAlreadyScanned = new HashSet ();
         
         result.setRootResources (new ManageableResource[] {bootstrapResource});
         
         // Bootstrap tree creation
         //
         resourcesToManage.add (bootstrapResource);
         
         while (resourcesToManage.size () > 0)
         {
            ManageableResource currentResource = (ManageableResource)resourcesToManage.iterator ().next ();
            
            // pre-clean resources environment
            //
            resourcesToManage.remove (currentResource);
            resourcesAlreadyScanned.add (currentResource);
            
            Iterator iter = getTreesForResource(currentResource, profile, pluginsSubset);
            while (iter.hasNext ())
            {
               TreeNode subTree = (TreeNode)iter.next ();
               result.addTreeToResource (currentResource, subTree);
               HashSet subResources = findSubResources (subTree);
               if (subResources != null && subResources.size () > 0)
               {
                  Iterator subsRes = subResources.iterator ();
                  while (subsRes.hasNext ())
                  {
                     ManageableResource subRes = (ManageableResource)subsRes.next ();
                     if (!resourcesAlreadyScanned.contains (subRes))
                        resourcesToManage.add (subRes);                  
                  }
               }
               
   
            }
         }
         
         this.treeVersion++;
         result.setTreeVersion (this.treeVersion);
         try
         {            
            TreeNodeMenuEntry[] base = new TreeNodeMenuEntry[]
            {
               new SimpleTreeNodeMenuEntryImpl ("Update tree", new RefreshTreeAction (false)),
               new SimpleTreeNodeMenuEntryImpl ("Force update tree", new RefreshTreeAction (true)),
            };
            
            if (enableShutdown)
            {
               result.setRootMenus (new TreeNodeMenuEntry[]
                  {
                     base[0],
                     base[1],
                     new SeparatorTreeNodeMenuEntry (),
                     new SimpleTreeNodeMenuEntryImpl ("Shutdown JBoss instance", 
                        new MBeanAction (new ObjectName("jboss.system:type=Server"),
                                          "shutdown", new Object[0], new String[0])
                     ),
                     new SimpleTreeNodeMenuEntryImpl ("Shutdown and Restart JBoss instance", 
                        new MBeanAction (new ObjectName("jboss.system:type=Server"),
                                          "exit", new Object[] {new Integer (10)}, 
                                          new String[] {"int"})                                       
                     ),
                     new SimpleTreeNodeMenuEntryImpl ("HALT and Restart JBoss instance", 
                        new MBeanAction (new ObjectName("jboss.system:type=Server"),
                                          "halt", new Object[] {new Integer (10)}, 
                                          new String[] {"int"})                                       
                     )
                  }
               );
            }
            else
            {
               result.setRootMenus (base);
            }
            
            result.setHomeAction(new HttpLinkTreeAction (this.mainLinkUrl));
            result.setIconUrl (this.mainLogoUrl);
         }
         catch (Exception bla) {}
         
         currentTree = result;
         
         currentTrees.put(profile, currentTree);
         
      }
      
      return currentTree;
   
protected java.util.IteratorgetTreesForResource(org.jboss.console.manager.interfaces.ManageableResource res, java.lang.String profile, java.util.ArrayList pluginsSubset)

      ArrayList result = new ArrayList ();
      

      for (int i = 0; i < pluginsSubset.size(); i++)
      {
         ConsolePlugin cp = (ConsolePlugin)pluginsSubset.get(i);
         TreeNode node = null;
         try
         {
            node = cp.getSubTreeForResource (this, profile, res);
         }
         catch (Throwable t) 
         { 
            t.printStackTrace(); 
         }
         
         if (node != null)
            result.add (node);
      }
      
      return result.iterator ();
   
public synchronized org.jboss.console.manager.interfaces.TreeInfogetUpdateTreeForProfile(java.lang.String profile, long knownVersion)
Only return the tree if the actual version is bigger than the known version

jmx:managed-operation

      TreeInfo currentTree = (TreeInfo)currentTrees.get(profile);
            
      if (this.treeVersion > knownVersion || currentTree==null)
         return getTreeForProfile (profile);
      else
         return null;
   
public voidhandleNotification(javax.management.Notification notif, java.lang.Object handback)

      // Very simple implementation: could be optimized to minimize tree regeneration 
      // (local invalidation for example)//
      //
      regenerateAdminTree ();
   
protected voidinitNotificationReception()

     
      ObjectName mbsDelegate = 
         new ObjectName ("JMImplementation:type=MBeanServerDelegate");
      
      NotificationFilter filter = new NotificationFilter ()
      {
         public boolean isNotificationEnabled (Notification n)
         {
            return ( n.getType().equals("JMX.mbean.registered") ||
                      n.getType().equals("JMX.mbean.unregistered") );
         }         
      };
      
      this.getServer().addNotificationListener(mbsDelegate, this, filter, null);
   
public booleanisEnableShutdown()

jmx:managed-attribute

      return enableShutdown;
   
public synchronized voidregenerateAdminTree()

jmx:managed-operation

      // remove all cached trees
      //
      currentTrees.clear();
   
public synchronized voidregenerateAdminTreeForProfile(java.lang.String profile)

jmx:managed-operation

      // remove cached tree for profile (if any)
      //
      currentTrees.remove(profile);
   
public voidregisterPlugin(java.lang.String consolePluginClassName)
send a message

jmx:managed-operation

      Class pluginClass = Thread.currentThread ().getContextClassLoader ().
                           loadClass (consolePluginClassName);
      ConsolePlugin plugin = (ConsolePlugin)pluginClass.newInstance ();
      this.registerPlugin (plugin);
   
public synchronized voidregisterPlugin(org.jboss.console.manager.interfaces.ConsolePlugin plugin)
send a message

jmx:managed-operation

      plugins.add (plugin);
      regenerateAdminTree();
   
public voidsetEnableShutdown(boolean enableShutdown)

jmx:managed-attribute

      this.enableShutdown = enableShutdown;
      treeVersion++;
   
public voidsetJndiName(java.lang.String jndiName)

jmx:managed-attribute

      this.jndiName = jndiName;
   
public voidsetMainLinkUrl(java.lang.String mainLinkUrl)

jmx:managed-attribute

      this.mainLinkUrl = mainLinkUrl;
      treeVersion++;
   
public voidsetMainLogoUrl(java.lang.String mainLogoUrl)

jmx:managed-attribute

      this.mainLogoUrl = mainLogoUrl;
      treeVersion++;
   
public voidstartService()

      bindProxyInJndi ();
      PLUGIN_MANAGER_NAME = this.getServiceName().toString();
      Registry.bind(PLUGIN_MANAGER_NAME, this);
      
      initNotificationReception ();      
   
public voidstopService()

      Registry.unbind(this.getServiceName().toString());
   
public synchronized voidunregisterPlugin(org.jboss.console.manager.interfaces.ConsolePlugin plugin)
send a message

jmx:managed-operation

      plugins.remove (plugin);
      regenerateAdminTree();