Class InternalComponentManager
- java.lang.Object
-
- org.jivesoftware.openfire.container.BasicModule
-
- org.jivesoftware.openfire.component.InternalComponentManager
-
- All Implemented Interfaces:
ChannelHandler<org.xmpp.packet.Packet>
,ClusterEventListener
,Module
,RoutableChannelHandler
,org.xmpp.component.ComponentManager
public class InternalComponentManager extends BasicModule implements ClusterEventListener, org.xmpp.component.ComponentManager, RoutableChannelHandler
Manages the registration and delegation of Components, which includes External Components as well as components that run in the Openfire JVM. The ComponentManager is responsible for managing registration and delegation ofComponents
, as well as offering a facade around basic server functionality such as sending and receiving of packets. This component manager will be an internal service whose JID will be component.[domain]. So the component manager will be able to send packets to other internal or external components and also receive packets from other components or even from trusted clients (e.g. ad-hoc commands).- Author:
- Derek DeMoro
-
-
Field Summary
Fields Modifier and Type Field Description static String
COMPONENT_CACHE_NAME
-
Constructor Summary
Constructors Constructor Description InternalComponentManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addComponent(String subdomain, org.xmpp.component.Component component)
void
addListener(ComponentEventListener listener)
Adds a new listener that will be notified of component events.void
addPresenceRequest(org.xmpp.packet.JID prober, org.xmpp.packet.JID probee)
Registers Probers who have not yet been serviced.void
destroy()
Destroys the module.org.xmpp.packet.JID
getAddress()
Returns the XMPP address.String
getHomeDirectory()
static InternalComponentManager
getInstance()
String
getProperty(String name)
String
getServerName()
boolean
hasComponent(org.xmpp.packet.JID componentJID)
Returns true if a component is associated to the specified address.void
initialize(XMPPServer server)
Initializes the basic module.boolean
isExternalMode()
void
joinedCluster()
Notification event indicating that this JVM is now part of a cluster.void
joinedCluster(byte[] nodeID)
Notification event indicating that another JVM is now part of a cluster.void
leftCluster()
Notification event indicating that this JVM is no longer part of the cluster.void
leftCluster(byte[] nodeID)
Notification event indicating that another JVM is no longer part of the cluster.void
markedAsSeniorClusterMember()
Notification event indicating that this JVM is now the senior cluster member.void
process(org.xmpp.packet.Packet packet)
Processes packets that were sent to this service.org.xmpp.packet.IQ
query(org.xmpp.component.Component component, org.xmpp.packet.IQ packet, long timeout)
void
query(org.xmpp.component.Component component, org.xmpp.packet.IQ packet, org.xmpp.component.IQResultListener listener)
void
removeComponent(String subdomain)
Removes a component.void
removeComponent(String subdomain, org.xmpp.component.Component component)
Removes a given component.void
removeListener(ComponentEventListener listener)
Removes the specified listener from the listeners being notified of component events.void
sendPacket(org.xmpp.component.Component component, org.xmpp.packet.Packet packet)
void
setProperty(String name, String value)
void
start()
Starts the basic module.void
stop()
Stops the basic module.-
Methods inherited from class org.jivesoftware.openfire.container.BasicModule
getName
-
-
-
-
Field Detail
-
COMPONENT_CACHE_NAME
public static final String COMPONENT_CACHE_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstance
public static InternalComponentManager getInstance()
-
initialize
public void initialize(XMPPServer server)
Description copied from class:BasicModule
Initializes the basic module.
Inheriting classes that choose to override this method MUST call this initialize() method before accessing BasicModule resources.
- Specified by:
initialize
in interfaceModule
- Overrides:
initialize
in classBasicModule
- Parameters:
server
- the server hosting this module.
-
start
public void start()
Description copied from class:BasicModule
Starts the basic module.
Inheriting classes that choose to override this method MUST call this start() method before accessing BasicModule resources.
- Specified by:
start
in interfaceModule
- Overrides:
start
in classBasicModule
-
stop
public void stop()
Description copied from class:BasicModule
Stops the basic module.
Inheriting classes that choose to override this method MUST call this stop() method before accessing BasicModule resources.
- Specified by:
stop
in interfaceModule
- Overrides:
stop
in classBasicModule
-
destroy
public void destroy()
Description copied from class:BasicModule
Destroys the module.
Does nothing in the basic module.
- Specified by:
destroy
in interfaceModule
- Overrides:
destroy
in classBasicModule
-
addComponent
public void addComponent(String subdomain, org.xmpp.component.Component component) throws org.xmpp.component.ComponentException
- Specified by:
addComponent
in interfaceorg.xmpp.component.ComponentManager
- Throws:
org.xmpp.component.ComponentException
-
removeComponent
public void removeComponent(String subdomain)
Removes a component. TheComponent.shutdown()
method will be called on the component. Note that if the component was an external component that was connected several times then all its connections will be terminated.- Specified by:
removeComponent
in interfaceorg.xmpp.component.ComponentManager
- Parameters:
subdomain
- the subdomain of the component's address.
-
removeComponent
public void removeComponent(String subdomain, org.xmpp.component.Component component)
Removes a given component. UnlikeremoveComponent(String)
this method will just remove a single component instead of all components associated to the subdomain. External components may connect several times and register for the same subdomain. This method just removes a singled connection not all of them.- Parameters:
subdomain
- the subdomain of the component's address.component
- specific component to remove.
-
sendPacket
public void sendPacket(org.xmpp.component.Component component, org.xmpp.packet.Packet packet)
- Specified by:
sendPacket
in interfaceorg.xmpp.component.ComponentManager
-
query
public org.xmpp.packet.IQ query(org.xmpp.component.Component component, org.xmpp.packet.IQ packet, long timeout) throws org.xmpp.component.ComponentException
- Specified by:
query
in interfaceorg.xmpp.component.ComponentManager
- Throws:
org.xmpp.component.ComponentException
-
query
public void query(org.xmpp.component.Component component, org.xmpp.packet.IQ packet, org.xmpp.component.IQResultListener listener) throws org.xmpp.component.ComponentException
- Specified by:
query
in interfaceorg.xmpp.component.ComponentManager
- Throws:
org.xmpp.component.ComponentException
-
addListener
public void addListener(ComponentEventListener listener)
Adds a new listener that will be notified of component events. Events being notified are: 1) when a component is added to the component manager, 2) when a component is deleted and 3) when disco#info is received from a component.- Parameters:
listener
- the new listener to notify of component events.
-
removeListener
public void removeListener(ComponentEventListener listener)
Removes the specified listener from the listeners being notified of component events.- Parameters:
listener
- the listener to remove.
-
getProperty
public String getProperty(String name)
- Specified by:
getProperty
in interfaceorg.xmpp.component.ComponentManager
-
setProperty
public void setProperty(String name, String value)
- Specified by:
setProperty
in interfaceorg.xmpp.component.ComponentManager
-
getServerName
public String getServerName()
- Specified by:
getServerName
in interfaceorg.xmpp.component.ComponentManager
-
getHomeDirectory
public String getHomeDirectory()
-
isExternalMode
public boolean isExternalMode()
- Specified by:
isExternalMode
in interfaceorg.xmpp.component.ComponentManager
-
hasComponent
public boolean hasComponent(org.xmpp.packet.JID componentJID)
Returns true if a component is associated to the specified address. Components registered with this JVM or other cluster nodes are going to be considered.- Parameters:
componentJID
- the address of the component. This is the complete domain.- Returns:
- true if a component is associated to the specified address.
-
addPresenceRequest
public void addPresenceRequest(org.xmpp.packet.JID prober, org.xmpp.packet.JID probee)
Registers Probers who have not yet been serviced.- Parameters:
prober
- the jid probing.probee
- the presence being probed.
-
getAddress
public org.xmpp.packet.JID getAddress()
Description copied from interface:RoutableChannelHandler
Returns the XMPP address. The address is used by services like the core server packet router to determine if a packet should be sent to the handler. Handlers that are working on behalf of the server should use the generic server hostname address (e.g. server.com).- Specified by:
getAddress
in interfaceRoutableChannelHandler
- Returns:
- the XMPP address.
-
process
public void process(org.xmpp.packet.Packet packet) throws PacketException
Processes packets that were sent to this service. Currently only packets that were sent from registered components are being processed. In the future, we may also process packet of trusted clients. Trusted clients may be able to execute ad-hoc commands such as adding or removing components.- Specified by:
process
in interfaceChannelHandler<org.xmpp.packet.Packet>
- Parameters:
packet
- the packet to process.- Throws:
PacketException
- thrown if the packet is malformed (results in the sender's session being shutdown).
-
joinedCluster
public void joinedCluster()
Description copied from interface:ClusterEventListener
Notification event indicating that this JVM is now part of a cluster. At this point theXMPPServer.getNodeID()
holds the new nodeID value.When joining the cluster as the senior cluster member the
ClusterEventListener.markedAsSeniorClusterMember()
event will be sent right after this event.At this point the CacheFactory holds clustered caches. That means that modifications to the caches will be reflected in the cluster. The clustered caches were just obtained from the cluster and no local cached data was automatically moved.
It is generally advisable that implementations of this method:- enrich clustered cache data, by (re)adding data from this JVM/cluster node to relevant caches
- invoke applicable event listeners, to reflect changes in availability of data on other cluster nodes.
- Specified by:
joinedCluster
in interfaceClusterEventListener
-
joinedCluster
public void joinedCluster(byte[] nodeID)
Description copied from interface:ClusterEventListener
Notification event indicating that another JVM is now part of a cluster.At this point the CacheFactory of the new node holds clustered caches. That means that modifications to the caches of this JVM will be reflected in the cluster and in particular in the new node.
- Specified by:
joinedCluster
in interfaceClusterEventListener
- Parameters:
nodeID
- ID of the node that joined the cluster.
-
leftCluster
public void leftCluster()
Description copied from interface:ClusterEventListener
Notification event indicating that this JVM is no longer part of the cluster. This could happen when disabling clustering support, removing the enterprise plugin that provides clustering support or connection to cluster got lost.Moreover, if we were in a "split brain" scenario (ie. separated cluster islands) and the island were this JVM belonged was marked as "old" then all nodes of that island will get the
left cluster event
andjoined cluster events
. That means that caches will be reset and thus will need to be repopulated again with fresh data from this JVM. This also includes the case where this JVM was the senior cluster member and when the islands met again then this JVM stopped being the senior member.At this point the CacheFactory holds local caches. That means that modifications to the caches will only affect this JVM. It is generally advisable that implementations of this method:
- restore relevant caches content, by repopulating the caches with data from this JVM/cluster node
- invoke applicable event listeners, to reflect changes in availability of data on other cluster nodes.
- Specified by:
leftCluster
in interfaceClusterEventListener
-
leftCluster
public void leftCluster(byte[] nodeID)
Description copied from interface:ClusterEventListener
Notification event indicating that another JVM is no longer part of the cluster. This could happen when disabling clustering support, removing the enterprise plugin that provides clustering support or connection to cluster got lost.Moreover, if we were in a "split brain" scenario (ie. separated cluster islands) and the island were the other JVM belonged was marked as "old" then all nodes of that island will get the
left cluster event
andjoined cluster events
. That means that caches will be reset and thus will need to be repopulated again with fresh data from this JVM. This also includes the case where the other JVM was the senior cluster member and when the islands met again then the other JVM stopped being the senior member.At this point the CacheFactory of the leaving node holds local caches. That means that modifications to the caches of this JVM will not affect the leaving node but other cluster members. It is generally advisable that implementations of this method invoke applicable event listeners, to reflect changes in availability of data (related to the node that left). Often, this action is orchestrated by only one of the remaining cluster nodes: the senior member.
- Specified by:
leftCluster
in interfaceClusterEventListener
- Parameters:
nodeID
- ID of the node that is left the cluster.
-
markedAsSeniorClusterMember
public void markedAsSeniorClusterMember()
Description copied from interface:ClusterEventListener
Notification event indicating that this JVM is now the senior cluster member. This could either happen when initially joining the cluster or when the senior cluster member node left the cluster and this JVM was marked as the new senior cluster member.Moreover, in the case of a "split brain" scenario (ie. separated cluster islands) each island will have its own senior cluster member. However, when the islands meet again there could only be one senior cluster member so one of the senior cluster members will stop playing that role. When that happens the JVM no longer playing that role will receive the
ClusterEventListener.leftCluster()
andClusterEventListener.joinedCluster()
events.- Specified by:
markedAsSeniorClusterMember
in interfaceClusterEventListener
-
-