| Method from org.jboss.console.manager.PluginManager Detail: |
protected void bindProxyInJndi() throws Exception {
InitialContext ctx = new InitialContext ();
Object proxy = RMIRemoteMBeanProxy.create (PluginManagerMBean.class, this.getServiceName (), this.getServer ());
Util.rebind (ctx, this.jndiName, proxy);
}
|
public void createService() throws Exception {
this.bootstrapResource = new MBeanResource (this.getServiceName (), this.getClass ().toString ());
}
|
protected HashSet findSubResources(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 ManageableResource getBootstrapResource() {
return this.bootstrapResource;
}
|
public String getJndiName() {
return jndiName;
}
|
public MBeanServer getMBeanServer() {
return this.server;
}
|
public String getMainLinkUrl() {
return mainLinkUrl;
}
|
public String getMainLogoUrl() {
return mainLogoUrl;
}
|
protected ArrayList getPluginsSubsetForProfile(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 TreeInfo getTreeForProfile(String profile) {
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 Iterator getTreesForResource(ManageableResource res,
String profile,
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 TreeInfo getUpdateTreeForProfile(String profile,
long knownVersion) {
TreeInfo currentTree = (TreeInfo)currentTrees.get(profile);
if (this.treeVersion > knownVersion || currentTree==null)
return getTreeForProfile (profile);
else
return null;
}
Only return the tree if the actual version is bigger than the known version |
public void handleNotification(Notification notif,
Object handback) {
// Very simple implementation: could be optimized to minimize tree regeneration
// (local invalidation for example)//
//
regenerateAdminTree ();
}
|
protected void initNotificationReception() throws Exception {
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 boolean isEnableShutdown() {
return enableShutdown;
}
|
public synchronized void regenerateAdminTree() {
// remove all cached trees
//
currentTrees.clear();
}
|
public synchronized void regenerateAdminTreeForProfile(String profile) {
// remove cached tree for profile (if any)
//
currentTrees.remove(profile);
}
|
public void registerPlugin(String consolePluginClassName) throws Exception {
Class pluginClass = Thread.currentThread ().getContextClassLoader ().
loadClass (consolePluginClassName);
ConsolePlugin plugin = (ConsolePlugin)pluginClass.newInstance ();
this.registerPlugin (plugin);
}
|
public synchronized void registerPlugin(ConsolePlugin plugin) {
plugins.add (plugin);
regenerateAdminTree();
}
|
public void setEnableShutdown(boolean enableShutdown) {
this.enableShutdown = enableShutdown;
treeVersion++;
}
|
public void setJndiName(String jndiName) {
this.jndiName = jndiName;
}
|
public void setMainLinkUrl(String mainLinkUrl) {
this.mainLinkUrl = mainLinkUrl;
treeVersion++;
}
|
public void setMainLogoUrl(String mainLogoUrl) {
this.mainLogoUrl = mainLogoUrl;
treeVersion++;
}
|
public void startService() throws Exception {
bindProxyInJndi ();
PLUGIN_MANAGER_NAME = this.getServiceName().toString();
Registry.bind(PLUGIN_MANAGER_NAME, this);
initNotificationReception ();
}
|
public void stopService() {
Registry.unbind(this.getServiceName().toString());
}
|
public synchronized void unregisterPlugin(ConsolePlugin plugin) {
plugins.remove (plugin);
regenerateAdminTree();
}
|