Package tigase.server

# Class MessageRouter

java.lang.Object
tigase.server.BasicComponent
tigase.server.AbstractMessageReceiver
tigase.server.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

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from class tigase.server.BasicComponent

  `BasicComponent.ServerInfoVHostItemExtension`

  ## Nested classes/interfaces inherited from interface tigase.server.PacketWriterWithTimeout

  `PacketWriterWithTimeout.Handler`

- ## Field Summary

  ### Fields inherited from class tigase.server.AbstractMessageReceiver

  `HOUR, INCOMING_FILTERS_PROP_KEY, INCOMING_FILTERS_PROP_VAL, MAX_QUEUE_SIZE_PROP_KEY, MAX_QUEUE_SIZE_PROP_VAL, maxInQueueSize, maxOutQueueSize, maxQueueSize, MINUTE, OUTGOING_FILTERS_PROP_KEY, OUTGOING_FILTERS_PROP_VAL, PACKET_DELIVERY_RETRY_COUNT_PROP_KEY, SCHEDULER_THREADS_PROP_KEY, SECOND`

  ### Fields inherited from class tigase.server.BasicComponent

  `admins, ALL_PROP_KEY, COMMAND_PROP_NODE, scriptCommands, scriptEngineManager, SCRIPTS_DIR_PROP_DEF, SCRIPTS_DIR_PROP_KEY, trusted, vHostManager`

  ### Fields inherited from interface tigase.conf.Configurable

  `ADMINS_PROP_KEY, AMP_CLASS_NAME, AMP_CLUST_CLASS_NAME, AUTH_DOMAIN_POOL_CLASS, AUTH_REPO_DOMAINS_PROP_KEY, AUTH_REPO_PARAMS_NODE, AUTH_REPO_POOL_CLASS, AUTH_REPO_URL_PROP_KEY, BOSH_CLUST_COMP_CLASS_NAME, BOSH_COMP_CLASS_NAME, C2S_CLUST_COMP_CLASS_NAME, C2S_COMP_CLASS_NAME, CL_COMP_CLASS_NAME, CLUSTER_CONECT, CLUSTER_CONTR_CLASS_NAME, CLUSTER_LISTEN, CLUSTER_MODE, CLUSTER_NODES, CLUSTER_NODES_PROP_KEY, COMP_PROT_CLASS_NAME, COMPONENT_ID_PROP_KEY, DEF_AMP_NAME, DEF_BOSH_NAME, DEF_C2S_NAME, DEF_CL_COMP_NAME, DEF_CLUST_CONTR_NAME, DEF_COMP_PROT_NAME, DEF_EVENTBUS_NAME, DEF_EXT_COMP_NAME, DEF_HOSTNAME_PROP_KEY, DEF_MONITOR_NAME, DEF_S2S_NAME, DEF_SM_NAME, DEF_STATS_NAME, DEF_VHOST_MAN_NAME, DEF_WS2S_NAME, DERBY_REPO_CLASS_PROP_VAL, DERBY_REPO_URL_PROP_VAL, DRUPAL_REPO_URL_PROP_VAL, DRUPALWP_REPO_CLASS_PROP_VAL, DUMMY_REPO_CLASS_PROP_VAL, EVENTBUS_CLASS_NAME, EXT_COMP_CLASS_NAME, GEN_ADMINS, GEN_AUTH_DB, GEN_AUTH_DB_URI, GEN_COMP_CLASS, GEN_COMP_NAME, GEN_CONF, GEN_CONFIG, GEN_CONFIG_ALL, GEN_CONFIG_COMP, GEN_CONFIG_CS, GEN_CONFIG_DEF, GEN_CONFIG_SM, GEN_DEBUG, GEN_DEBUG_PACKAGES, GEN_EXT_COMP, GEN_MAX_QUEUE_SIZE, GEN_SCRIPT_DIR, GEN_SM_PLUGINS, GEN_SREC_ADMINS, GEN_SREC_DB, GEN_SREC_DB_URI, GEN_TEST, GEN_TRUSTED, GEN_USER_DB, GEN_USER_DB_URI, GEN_USER_DB_URI_PROP_KEY, GEN_VIRT_HOSTS, HOSTNAMES_PROP_KEY, LIBRESOURCE_REPO_CLASS_PROP_VAL, LIBRESOURCE_REPO_URL_PROP_VAL, MONITOR_CLASS_NAME, MONITOR_CLUST_CLASS_NAME, MONITORING, MYSQL_REPO_CLASS_PROP_VAL, MYSQL_REPO_URL_PROP_VAL, PGSQL_REPO_CLASS_PROP_VAL, PGSQL_REPO_URL_PROP_VAL, ROUTER_COMP_CLASS_NAME, S2S_CLUST_COMP_CLASS_NAME, S2S_COMP_CLASS_NAME, SHARED_AUTH_REPO_PARAMS_PROP_KEY, SHARED_AUTH_REPO_PROP_KEY, SHARED_USER_REPO_PARAMS_PROP_KEY, SHARED_USER_REPO_PROP_KEY, SM_CLUST_COMP_CLASS_NAME, SM_COMP_CLASS_NAME, STANZA_WHITE_CHAR_ACK, STANZA_XMPP_ACK, STATS_CLASS_NAME, STRINGPREP_PROCESSOR, TIGASE_AUTH_REPO_CLASS_PROP_VAL, TIGASE_AUTH_REPO_URL_PROP_VAL, TIGASE_CUSTOM_AUTH_REPO_CLASS_PROP_VAL, TRUSTED_PROP_KEY, USER_DOMAIN_POOL_CLASS, USER_REPO_DOMAINS_PROP_KEY, USER_REPO_PARAMS_NODE, USER_REPO_POOL_CLASS, USER_REPO_POOL_SIZE, USER_REPO_POOL_SIZE_PROP_KEY, USER_REPO_URL_PROP_KEY, VHOST_MAN_CLASS_NAME, VHOST_MAN_CLUST_CLASS_NAME, WS2S_CLASS_NAME, WS2S_CLUST_CLASS_NAME, XML_REPO_CLASS_PROP_VAL, XML_REPO_URL_PROP_VAL, XMPP_STANZA_ACK`

  ### Fields inherited from interface tigase.disco.XMPPService

  `CMD_FEATURES, DEF_FEATURES, INFO_XMLNS, ITEMS_XMLNS`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `MessageRouter()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addComponent(ServerComponent component)`
  `void`
  `addRegistrator(ComponentRegistrator registr)`
  `void`
  `addRouter(MessageReceiver receiver)`
  `void`
  `beanConfigurationChanged(Collection<String> changedFields)`
  Method called when configuration was applied to bean.
  `void`
  `beforeUnregister()`
  Method called before bean unregister.
  `Set<ServerComponent>`
  `getComponentsAll()`
  `String`
  `getDiscoCategoryType()`
  Method returns component category type used for service discovery responses.
  `String`
  `getDiscoDescription()`
  Method returns description used for service discovery responses.
  `Element`
  `getDiscoInfo(JID toJid, JID fromJid, String node)`
  `protected Integer`
  `getMaxQueueSize(int def)`
  `Optional<Element>`
  `getServiceEntityCaps(JID fromJid)`
  `void`
  `getStatistics(StatisticsList list)`
  Method returns component statistics.
  `int`
  `hashCodeForPacket(Packet packet)`
  This method decides how incoming packets are distributed among processing threads.
  `void`
  `initBindings(Bindings binds)`
  Initialize a mapping of key/value pairs which can be used in scripts loaded by the server
  `void`
  `initialize()`
  Method will be called, when bean will be created, configured and ready to use.
  `int`
  `processingInThreads()`
  Concurrency control method.
  `int`
  `processingOutThreads()`
  Concurrency control method.
  `void`
  `processPacket(Packet packet)`
  This is the main `Packet` processing method.
  `void`
  `processPacketMR(Packet packet, Queue<Packet> results)`
  `void`
  `register(Kernel kernel)`
  Method called when bean is being registered allowing developer to programatically register other beans.
  `protected void`
  `reloadScripts()`
  `void`
  `removeComponent(ServerComponent component)`
  `void`
  `removeRegistrator(ComponentRegistrator registr)`
  `void`
  `removeRouter(MessageReceiver receiver)`
  `void`
  `setComponentsAll(Set<ServerComponent> components)`
  `void`
  `setConfig(ConfiguratorAbstract config)`
  `void`
  `setDetailedMemoryStatistics(boolean detailedMemoryStatistics)`
  `void`
  `start()`
  `void`
  `stop()`
  `void`
  `unregister(Kernel kernel)`
  Method called while bean is being unregistered.

  ### Methods inherited from class tigase.server.AbstractMessageReceiver

  `addOutPacket, addOutPacketNB, addOutPackets, addOutPacketWithTimeout, addOutPacketWithTimeout, addPacket, addPacketNB, addPackets, addRegexRouting, addTimerTask, addTimerTask, addTimerTask, addTimerTaskWithTimeout, addTimerTaskWithTimeout, clearRegexRoutings, everyHour, everyMinute, everySecond, getRegexRoutings, getResourceForPacketWithTimeout, isInRegexRoutings, newPacketId, processOutPacket, processPacket, release, removeRegexRouting, schedulerThreads, setCompId, setIncoming_filters, setName, setOutgoing_filters, setParent, setSchedulerThreads_size, updateFiltersName`

  ### Methods inherited from class tigase.server.BasicComponent

  `addComponentDomain, canCallCommand, canCallCommand, checkCommandAcl, checkCommandAcl, createScriptEngineManager, getComponentId, getComponentInfo, getDefaults, getDefHostName, getDefVHostItem, getDiscoCategory, getDiscoExtensionsForm, getDiscoFeatures, getDiscoFeatures, getDiscoInfo, getDiscoItems, getName, getNodesConnected, getNodesConnectedWithLocal, getScriptCommands, getScriptItems, getServiceEntity, getVHostItem, handlesLocalDomains, handlesNameSubdomains, handlesNonLocalDomains, initializationCompleted, isAdmin, isInitializationComplete, isLocalDomain, isLocalDomainOrComponent, isNonAdminCommands, isSubdomain, isTrusted, isTrusted, nodeConnected, nodeDisconnected, onNodeConnected, onNodeDisconnected, processScriptCommand, removeComponentDomain, removeServiceDiscoveryItem, setAdmins, setClusterController, setCommandsACL, setProperties, setScriptsBaseDir, setVHostManager, updateServiceDiscoveryItem, updateServiceDiscoveryItem, updateServiceDiscoveryItem, updateServiceEntity`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface tigase.server.MessageReceiver

  `getDefHostName`

  ### Methods inherited from interface tigase.server.ServerComponent

  `getComponentId, getComponentInfo, getName, initializationCompleted, isInitializationComplete, processPacket, release, setName`

  ### Methods inherited from interface tigase.stats.StatisticsContainerIfc

  `getName`

- ## 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`