Class 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 of Components, 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
    • Constructor Detail

      • InternalComponentManager

        public InternalComponentManager()
    • Method Detail

      • 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 interface Module
        Overrides:
        initialize in class BasicModule
        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 interface Module
        Overrides:
        start in class BasicModule
      • 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 interface Module
        Overrides:
        stop in class BasicModule
      • destroy

        public void destroy()
        Description copied from class: BasicModule

        Destroys the module.

        Does nothing in the basic module.

        Specified by:
        destroy in interface Module
        Overrides:
        destroy in class BasicModule
      • addComponent

        public void addComponent​(String subdomain,
                                 org.xmpp.component.Component component)
                          throws org.xmpp.component.ComponentException
        Specified by:
        addComponent in interface org.xmpp.component.ComponentManager
        Throws:
        org.xmpp.component.ComponentException
      • removeComponent

        public void removeComponent​(String subdomain)
        Removes a component. The Component.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 interface org.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. Unlike removeComponent(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 interface org.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 interface org.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 interface org.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 interface org.xmpp.component.ComponentManager
      • setProperty

        public void setProperty​(String name,
                                String value)
        Specified by:
        setProperty in interface org.xmpp.component.ComponentManager
      • getServerName

        public String getServerName()
        Specified by:
        getServerName in interface org.xmpp.component.ComponentManager
      • getHomeDirectory

        public Path getHomeDirectory()
      • isExternalMode

        public boolean isExternalMode()
        Specified by:
        isExternalMode in interface org.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. Note that this method will return true only if the full JID exactly matches a component address, meaning that it returns 'false' for any argument that contains either a node-part or a resource-part.
        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 interface RoutableChannelHandler
        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 interface ChannelHandler<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 the XMPPServer.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 interface ClusterEventListener
      • 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 interface ClusterEventListener
        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 and joined 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 interface ClusterEventListener
      • 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 and joined 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 interface ClusterEventListener
        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() and ClusterEventListener.joinedCluster() events.

        Specified by:
        markedAsSeniorClusterMember in interface ClusterEventListener