org.rhq.enterprise.communications.command.server
Class CommandServiceDirectory

java.lang.Object
  extended by org.rhq.enterprise.communications.command.server.CommandMBean
      extended by org.rhq.enterprise.communications.command.server.CommandServiceDirectory
All Implemented Interfaces:
EventListener, MBeanRegistration, NotificationListener, CommandServiceDirectoryMBean

public class CommandServiceDirectory
extends CommandMBean
implements CommandServiceDirectoryMBean, NotificationListener

An MBean that maintains a directory of all currently deployed CommandService MBean services for all subsystems. In effect, it provides a service that allows a client to determine what MBean service provides support and can execute a particular type of command.

Each set of command services are organized into separate subsystems. A command service belongs to a subsystem if, in its ObjectName, it has the subsystem key property specified. If it does not specify that key property in its name, it is considered in the unnamed, anonymous subsystem.

This directory service is used by the CommandProcessor invocation handler to help determine where to direct a command request for processing.

This directory is part of the mechanism by which command services can be dynamically added/updated/removed. This service will listen for command services getting deployed and undeployed to/from the MBeanServer and will dynamically update itself accordingly.

Author:
John Mazzitelli

Constructor Summary
CommandServiceDirectory()
          Creates a new CommandServiceDirectory object.
 
Method Summary
 CommandServiceDirectoryEntry[] getAllEntries()
          This will return all the entries for all subsystems - in other words, all the supported command types and the command services that provide them in all subsystems.
 boolean getAllowDynamicDiscovery()
          This attribute will indicate if new commands are allowed to be added dynamically at runtime.
 CommandServiceDirectoryEntry getCommandTypeProvider(String subsystem, CommandType commandType)
          Finds the provider of the given command type by looking it up in the directory in a thread-safe way.
 CommandServiceDirectoryEntry[] getSubsystemEntries(String subsystem)
          Given a subsystem, this will return all the entries for that subsystem - in other words, all the supported command types and the command services that provide them.
 void handleNotification(Notification notification, Object handback)
          As command services are deployed and undeployed, this notification handler will detect this and update the directory accordingly.
 ObjectName preRegister(MBeanServer mbs, ObjectName name)
          Verifies that the ObjectName of this directory MBean has the appropriate key properties and initializes the directory with an inventory of the current set of supported command types/command services.
 void setAllowDynamicDiscovery(boolean flag)
          This attribute will indicate if new commands are allowed to be added dynamically at runtime.
 void startService()
          Clears the directory of all entries then takes an inventory of existing command services and adds them to the directory.
 void stopService()
          Clean up any resources that were initialized during start.
 
Methods inherited from class org.rhq.enterprise.communications.command.server.CommandMBean
getLog, getMBeanServer, getObjectName, postDeregister, postRegister, preDeregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommandServiceDirectory

public CommandServiceDirectory()
Creates a new CommandServiceDirectory object.

Method Detail

preRegister

public ObjectName preRegister(MBeanServer mbs,
                              ObjectName name)
                       throws Exception
Verifies that the ObjectName of this directory MBean has the appropriate key properties and initializes the directory with an inventory of the current set of supported command types/command services.

Specified by:
preRegister in interface MBeanRegistration
Overrides:
preRegister in class CommandMBean
Throws:
Exception
See Also:
MBeanRegistration.preRegister(MBeanServer, ObjectName)

startService

public void startService()
Clears the directory of all entries then takes an inventory of existing command services and adds them to the directory.

Overrides:
startService in class CommandMBean
Throws:
RuntimeException

stopService

public void stopService()
Clean up any resources that were initialized during start.

Overrides:
stopService in class CommandMBean

handleNotification

public void handleNotification(Notification notification,
                               Object handback)
As command services are deployed and undeployed, this notification handler will detect this and update the directory accordingly.

This method ensures thread-safety during its modifications to the directory data structures.

If the directory is not allowed to perform dynamic discovery, this method does nothing; the notification is ignored.

Specified by:
handleNotification in interface NotificationListener
See Also:
NotificationListener.handleNotification(Notification, Object)

getCommandTypeProvider

public CommandServiceDirectoryEntry getCommandTypeProvider(String subsystem,
                                                           CommandType commandType)
Finds the provider of the given command type by looking it up in the directory in a thread-safe way.

Specified by:
getCommandTypeProvider in interface CommandServiceDirectoryMBean
Parameters:
subsystem - the subsystem to look in (may be null)
commandType - find a provider for this command type
Returns:
the entry that indicates the name of the subsystem's command service that provides support for the given command type, or null if no provider exists
See Also:
CommandServiceDirectoryMBean.getCommandTypeProvider(String, CommandType)

getSubsystemEntries

public CommandServiceDirectoryEntry[] getSubsystemEntries(String subsystem)
Description copied from interface: CommandServiceDirectoryMBean
Given a subsystem, this will return all the entries for that subsystem - in other words, all the supported command types and the command services that provide them.

If no command service providers exists for the given subsystem, an empty array is returned.

subsystem may be null to denote the unnamed, anonymous subsystem.

Specified by:
getSubsystemEntries in interface CommandServiceDirectoryMBean
Parameters:
subsystem - the subsystem to look in (may be null)
Returns:
array of all entries for the given subsystem
See Also:
CommandServiceDirectoryMBean.getSubsystemEntries(String)

getAllEntries

public CommandServiceDirectoryEntry[] getAllEntries()
Description copied from interface: CommandServiceDirectoryMBean
This will return all the entries for all subsystems - in other words, all the supported command types and the command services that provide them in all subsystems.

If no command service providers exists, an empty array is returned.

Specified by:
getAllEntries in interface CommandServiceDirectoryMBean
Returns:
array of all entries in the directory
See Also:
CommandServiceDirectoryMBean.getAllEntries()

setAllowDynamicDiscovery

public void setAllowDynamicDiscovery(boolean flag)
Description copied from interface: CommandServiceDirectoryMBean
This attribute will indicate if new commands are allowed to be added dynamically at runtime. If false, only those command services currently installed at the time of this directory's registration will be found in the directory. If true, the directory will add new command services to the directory as they come online.

Note that this has no effect on dynamically discovering the removal of command services. The directory will always detect the removal of commands and remove their entries from the directory.

Specified by:
setAllowDynamicDiscovery in interface CommandServiceDirectoryMBean
Parameters:
flag - true will allow the directory to discovery changes during runtime. false means only those command services already in existence at the time the directory service is registered will be stored in the directory.
See Also:
CommandServiceDirectoryMBean.setAllowDynamicDiscovery(boolean)

getAllowDynamicDiscovery

public boolean getAllowDynamicDiscovery()
Description copied from interface: CommandServiceDirectoryMBean
This attribute will indicate if new commands are allowed to be added dynamically at runtime. If false, only those command services currently installed at the time of this directory's registration will be found in the directory. If true, the directory will add new command services to the directory as they come online.

Note that this has no effect on dynamically discovering the removal of command services. The directory will always detect the removal of commands and remove their entries from the directory.

Specified by:
getAllowDynamicDiscovery in interface CommandServiceDirectoryMBean
Returns:
true will allow the directory to discovery changes during runtime. false means only those command services already in existence at the time the directory service is registered will be stored in the directory.
See Also:
CommandServiceDirectoryMBean.getAllowDynamicDiscovery()


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.