Package tigase.server

Class MessageRouter

All Implemented Interfaces:
ClusteredComponentIfc, Configurable, XMPPService, ConfigurationChangedAware, Initializable, RegistrarBean, UnregisterAware, MessageReceiver, MessageRouterIfc, PacketWriterWithTimeout, ServerComponent, StatisticsContainer, StatisticsContainerIfc, VHostListener

@Bean(name="message-router", parent=Kernel.class, active=true) public class MessageRouter extends AbstractMessageReceiver implements MessageRouterIfc, RegistrarBean, UnregisterAware
Class MessageRouter
Created: Tue Nov 22 07:07:11 2005
Author:
Artur Hefczyc
  • Constructor Details

    • MessageRouter

      public MessageRouter()
  • Method Details

    • register

      public void register(Kernel kernel)
      Description copied from interface: RegistrarBean
      Method called when bean is being registered allowing developer to programatically register other beans.
      Specified by:
      register in interface RegistrarBean
      Parameters:
      kernel - - instance from local scope
    • unregister

      public void unregister(Kernel kernel)
      Description copied from interface: RegistrarBean
      Method called while bean is being unregistered.
      Specified by:
      unregister in interface RegistrarBean
      Parameters:
      kernel - - instance from local scope
    • getComponentsAll

      public Set<ServerComponent> getComponentsAll()
    • setComponentsAll

      public void setComponentsAll(Set<ServerComponent> components)
    • addComponent

      public void addComponent(ServerComponent component) throws ConfigurationException
      Throws:
      ConfigurationException
    • addRegistrator

      public void addRegistrator(ComponentRegistrator registr) throws ConfigurationException
      Throws:
      ConfigurationException
    • addRouter

      public void addRouter(MessageReceiver receiver) throws ConfigurationException
      Throws:
      ConfigurationException
    • beanConfigurationChanged

      public void beanConfigurationChanged(Collection<String> changedFields)
      Description copied from interface: ConfigurationChangedAware
      Method called when configuration was applied to bean.
      Specified by:
      beanConfigurationChanged in interface ConfigurationChangedAware
      Overrides:
      beanConfigurationChanged in class AbstractMessageReceiver
      Parameters:
      changedFields - collection of field names which were changed
    • hashCodeForPacket

      public int hashCodeForPacket(Packet packet)
      Description copied from class: AbstractMessageReceiver
      This method decides how incoming packets are distributed among processing threads. Different components needs different distribution to efficient use all threads and avoid packets re-ordering.
      If there are N processing threads, packets are distributed among threads using following code:
       int threadNo = Math.abs(hashCodeForPacket(packet) % N);
       

      For a PubSub component, for example, a better packets distribution would be based on the PubSub channel name, for SM a better distribution is based on the destination address, etc....
      Overrides:
      hashCodeForPacket in class AbstractMessageReceiver
      Parameters:
      packet - is a Packet which needs to be processed by some thread.
      Returns:
      a hash code generated for the input thread.
    • initialize

      public void initialize()
      Description copied from interface: Initializable
      Method will be called, when bean will be created, configured and ready to use.
      Specified by:
      initialize in interface Initializable
      Overrides:
      initialize in class BasicComponent
    • initBindings

      public void initBindings(Bindings binds)
      Description copied from class: BasicComponent
      Initialize a mapping of key/value pairs which can be used in scripts loaded by the server
      Overrides:
      initBindings in class BasicComponent
      Parameters:
      binds - A mapping of key/value pairs, all of whose keys are Strings.
    • processingInThreads

      public int processingInThreads()
      Description copied from class: AbstractMessageReceiver
      Concurrency control method. Returns preferable number of threads set for this component.
      Overrides:
      processingInThreads in class AbstractMessageReceiver
      Returns:
      preferable number of threads set for this component.
    • processingOutThreads

      public int processingOutThreads()
      Description copied from class: AbstractMessageReceiver
      Concurrency control method. Returns preferable number of threads set for this component.
      Overrides:
      processingOutThreads in class AbstractMessageReceiver
      Returns:
      preferable number of threads set for this component.
    • processPacket

      public void processPacket(Packet packet)
      Description copied from class: AbstractMessageReceiver
      This is the main Packet processing method. It is called concurrently from many threads so implementing it in thread save manner is essential. The method is called for each packet addressed to the component.
      Please note, the Packet instance may be processed by different parts of the server, different components or plugins at the same time. Therefore this is very important to tread the Packet instance as unmodifiable object.
      Processing in this method is asynchronous, therefore there is no result value. If there are some 'result' packets generated during processing, they should be passed back using addOutPacket(Packet) method.
      Specified by:
      processPacket in class AbstractMessageReceiver
      Parameters:
      packet - is an instance of the Packet class passed for processing.
    • processPacketMR

      public void processPacketMR(Packet packet, Queue<Packet> results)
    • removeComponent

      public void removeComponent(ServerComponent component)
    • removeRegistrator

      public void removeRegistrator(ComponentRegistrator registr)
    • removeRouter

      public void removeRouter(MessageReceiver receiver)
    • start

      public void start()
      Specified by:
      start in interface MessageReceiver
      Specified by:
      start in interface MessageRouterIfc
      Overrides:
      start in class AbstractMessageReceiver
    • stop

      public void stop()
      Overrides:
      stop in class AbstractMessageReceiver
    • getDiscoCategoryType

      public String getDiscoCategoryType()
      Description copied from class: BasicComponent
      Method returns component category type used for service discovery responses.
      Overrides:
      getDiscoCategoryType in class BasicComponent
      Returns:
      category type of a component
    • getDiscoDescription

      public String getDiscoDescription()
      Description copied from class: BasicComponent
      Method returns description used for service discovery responses.
      Overrides:
      getDiscoDescription in class BasicComponent
      Returns:
      description of a component
    • getStatistics

      public void getStatistics(StatisticsList list)
      Description copied from class: AbstractMessageReceiver
      Method returns component statistics. Please note, the method can be called every second by the server monitoring system therefore no extensive or lengthy calculations are allowed. If there are some statistics requiring lengthy operations like database access they must have Level.FINEST assigned and must be put inside the level guard to prevent generating them by the system monitor. The system monitor does not collect FINEST statistics.
      Level guard code looks like the example below:
       if (list.checkLevel(Level.FINEST)) {
         // Some CPU intensive calculations or lengthy operations
         list.add(getName(), "Statistic description", stat_value, Level.FINEST);
       }
      
       
      This way you make sure your extensive operation is not executed every second by the monitoring system and does not affect the server performance.
      Specified by:
      getStatistics in interface StatisticsContainerIfc
      Overrides:
      getStatistics in class AbstractMessageReceiver
      Parameters:
      list - is a StatistcsList where all statistics are stored.
    • setConfig

      public void setConfig(ConfiguratorAbstract config) throws ConfigurationException
      Specified by:
      setConfig in interface MessageRouterIfc
      Throws:
      ConfigurationException
    • setDetailedMemoryStatistics

      public void setDetailedMemoryStatistics(boolean detailedMemoryStatistics)
    • beforeUnregister

      public void beforeUnregister()
      Description copied from interface: UnregisterAware
      Method called before bean unregister.
      Specified by:
      beforeUnregister in interface UnregisterAware
    • getServiceEntityCaps

      public Optional<Element> getServiceEntityCaps(JID fromJid)
      Overrides:
      getServiceEntityCaps in class BasicComponent
    • getDiscoInfo

      public Element getDiscoInfo(JID toJid, JID fromJid, String node)
    • getMaxQueueSize

      protected Integer getMaxQueueSize(int def)
      Overrides:
      getMaxQueueSize in class AbstractMessageReceiver
    • reloadScripts

      protected void reloadScripts()
      Overrides:
      reloadScripts in class BasicComponent