Package tigase.server
Class AbstractMessageReceiver
- java.lang.Object
-
- tigase.server.BasicComponent
-
- tigase.server.AbstractMessageReceiver
-
- All Implemented Interfaces:
ClusteredComponentIfc
,Configurable
,XMPPService
,ConfigurationChangedAware
,Initializable
,MessageReceiver
,PacketWriterWithTimeout
,ServerComponent
,StatisticsContainer
,StatisticsContainerIfc
,VHostListener
- Direct Known Subclasses:
AbstractComponent
,AbstractKernelBasedComponent
,AmpComponent
,ConnectionManager
,EchoComponent
,MessageRouter
,MonitorComponent
,SessionManager
public abstract class AbstractMessageReceiver extends BasicComponent implements StatisticsContainer, MessageReceiver, PacketWriterWithTimeout
This is an archetype for all classes processing user-level packets. The implementation is designed for a heavy packets processing with internal queues and number of separate threads depending on number of CPUs. Extensions of the class can process normall user packets and administrator packets via ad-hoc commands. Good examples of such components areMUC
,PubSub
,SessionManager
.
The class offers scripting API for administrator ad-hoc commands.
By default it internally uses priority queues which in some rare cases may lead to packets reordering. When this happens and it is unacceptable for the deployment non-priority queues can be used. The queues size is limited and depends on the available memory size.
Packets are processed byprocessPacket(Packet packet)
method which is concurrently called from multiple threads.
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 Modifier and Type Field Description protected static long
HOUR
Constant used in time calculation procedures.static java.lang.String
INCOMING_FILTERS_PROP_KEY
Configuration property key for setting incoming packets filters on the component level.static java.lang.String
INCOMING_FILTERS_PROP_VAL
Configuration property default vakue with a default incoming packet filter loaded by Tigase server.static java.lang.String
MAX_QUEUE_SIZE_PROP_KEY
Configuration property key allowing to overwrite a default (memory size dependent) size for the component internal queues.static java.lang.Integer
MAX_QUEUE_SIZE_PROP_VAL
A default value for max queue size property.protected int
maxInQueueSize
protected int
maxOutQueueSize
protected int
maxQueueSize
protected static long
MINUTE
Constant used in time calculation procedures.static java.lang.String
OUTGOING_FILTERS_PROP_KEY
Configuration property key for setting outgoing packets filters on the component level.static java.lang.String
OUTGOING_FILTERS_PROP_VAL
Configuration property default vakue with a default outgoing packet filter loaded by Tigase server.static java.lang.String
PACKET_DELIVERY_RETRY_COUNT_PROP_KEY
static java.lang.String
SCHEDULER_THREADS_PROP_KEY
Configuration property key for setting number of threads used by component ScheduledExecutorService.protected static long
SECOND
Constant used in time calculation procedures.-
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 AbstractMessageReceiver()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected boolean
addOutPacket(Packet packet)
protected boolean
addOutPacketNB(Packet packet)
Non blocking version ofaddOutPacket
.protected boolean
addOutPackets(java.util.Queue<Packet> packets)
boolean
addOutPacketWithTimeout(Packet packet, java.time.Duration timeout, PacketWriterWithTimeout.Handler handler)
boolean
addOutPacketWithTimeout(Packet packet, ReceiverTimeoutHandler handler, long delay, java.util.concurrent.TimeUnit unit)
boolean
addPacket(Packet packet)
Method adds aPacket
object to the internal input queue.boolean
addPacketNB(Packet packet)
This is a variant ofaddPacket(Packet)
method which addsPacket
to in the internal input queue without blocking.boolean
addPackets(java.util.Queue<Packet> packets)
This is a convenience method for adding all packets stored in given queue to the component's internal input queue.
The method callsaddPacket(Packet)
in a loop for each packet in the queue.void
addRegexRouting(java.lang.String address)
Method adds a new routing address for the component.void
addTimerTask(TimerTask task, long delay)
Method queues and executes timer tasks using ScheduledExecutorService which allows using more than one thread for executing tasks.void
addTimerTask(TimerTask task, long initialDelay, long period)
protected void
addTimerTask(TimerTask task, long delay, java.util.concurrent.TimeUnit unit)
Method queues and executes timer tasks using ScheduledExecutorService which allows using more than one thread for executing tasks.void
addTimerTaskWithTimeout(TimerTask task, long delay, long timeout)
Method queues and executes timer tasks using ScheduledExecutorService which allows using more than one thread for executing tasks.void
addTimerTaskWithTimeout(TimerTask task, long delay, long period, long timeout)
Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; please refer toScheduledExecutorService.scheduleAtFixedRate(java.lang.Runnable, long, long, java.util.concurrent.TimeUnit)
javadoc for details.void
beanConfigurationChanged(java.util.Collection<java.lang.String> changedFields)
Method called when configuration was applied to bean.void
clearRegexRoutings()
Method clears, removes all the component routing addresses.void
everyHour()
Utility method executed precisely every hour.void
everyMinute()
Utility method executed precisely every minute.void
everySecond()
Utility method executed precisely every second.protected java.lang.Integer
getMaxQueueSize(int def)
java.util.Set<java.util.regex.Pattern>
getRegexRoutings()
Method returns aSet
with all component's routings as a compiled regular expression patterns.protected java.lang.String
getResourceForPacketWithTimeout()
void
getStatistics(StatisticsList list)
Method returns component statistics.int
hashCodeForPacket(Packet packet)
This method decides how incoming packets are distributed among processing threads.boolean
isInRegexRoutings(java.lang.String address)
java.lang.String
newPacketId(java.lang.String prefix)
int
processingInThreads()
Concurrency control method.int
processingOutThreads()
Concurrency control method.void
processOutPacket(Packet packet)
By default this method just copies the given packet between queue.abstract void
processPacket(Packet packet)
This is the mainPacket
processing method.void
processPacket(Packet packet, java.util.Queue<Packet> results)
processPacket
is a blocking processing method implemented by all components.void
release()
Method called when component is being stopped and unloaded.boolean
removeRegexRouting(java.lang.String address)
int
schedulerThreads()
Method returns default number of threads used by SchedulerExecutorServicevoid
setCompId(JID jid)
void
setIncoming_filters(PacketFiltersBean.IncomingPacketFiltersBean incoming_filters)
void
setName(java.lang.String name)
Method used to assign component name (localpart of the component)void
setOutgoing_filters(PacketFiltersBean.OutgoingPacketFiltersBean outgoing_filters)
void
setParent(MessageReceiver parent)
void
setSchedulerThreads_size(int size)
void
start()
void
stop()
protected void
updateFiltersName()
-
Methods inherited from class tigase.server.BasicComponent
addComponentDomain, canCallCommand, canCallCommand, checkCommandAcl, checkCommandAcl, createScriptEngineManager, getComponentId, getComponentInfo, getDefaults, getDefHostName, getDefVHostItem, getDiscoCategory, getDiscoCategoryType, getDiscoDescription, getDiscoExtensionsForm, getDiscoFeatures, getDiscoFeatures, getDiscoInfo, getDiscoItems, getName, getNodesConnected, getNodesConnectedWithLocal, getScriptCommands, getScriptItems, getServiceEntity, getServiceEntityCaps, getVHostItem, handlesLocalDomains, handlesNameSubdomains, handlesNonLocalDomains, initBindings, initializationCompleted, initialize, isAdmin, isInitializationComplete, isLocalDomain, isLocalDomainOrComponent, isNonAdminCommands, isSubdomain, isTrusted, isTrusted, nodeConnected, nodeDisconnected, onNodeConnected, onNodeDisconnected, processScriptCommand, reloadScripts, 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
-
Methods inherited from interface tigase.stats.StatisticsContainerIfc
getName
-
-
-
-
Field Detail
-
INCOMING_FILTERS_PROP_KEY
public static final java.lang.String INCOMING_FILTERS_PROP_KEY
Configuration property key for setting incoming packets filters on the component level.- See Also:
- Constant Field Values
-
INCOMING_FILTERS_PROP_VAL
public static final java.lang.String INCOMING_FILTERS_PROP_VAL
Configuration property default vakue with a default incoming packet filter loaded by Tigase server.
This is a comma-separated list of classes which should be loaded as packet filters. The classes must implementPacketFilterIfc
interface.- See Also:
- Constant Field Values
-
MAX_QUEUE_SIZE_PROP_KEY
public static final java.lang.String MAX_QUEUE_SIZE_PROP_KEY
Configuration property key allowing to overwrite a default (memory size dependent) size for the component internal queues. By default the queue size is adjusted to the available memory size to avoid out of memory errors.- See Also:
- Constant Field Values
-
MAX_QUEUE_SIZE_PROP_VAL
public static final java.lang.Integer MAX_QUEUE_SIZE_PROP_VAL
A default value for max queue size property. The value is calculated at the server startup time using following formula:
Runtime.getRuntime().maxMemory() / 400000L
You can change the default queue size by setting a different value for theMAX_QUEUE_SIZE_PROP_KEY
property in the server configuration.
-
OUTGOING_FILTERS_PROP_KEY
public static final java.lang.String OUTGOING_FILTERS_PROP_KEY
Configuration property key for setting outgoing packets filters on the component level. This is a comma-separated list of classes which should be loaded as packet filters. The classes must implementPacketFilterIfc
interface.- See Also:
- Constant Field Values
-
OUTGOING_FILTERS_PROP_VAL
public static final java.lang.String OUTGOING_FILTERS_PROP_VAL
Configuration property default vakue with a default outgoing packet filter loaded by Tigase server.
This is a comma-separated list of classes which should be loaded as packet filters. The classes must implementPacketFilterIfc
interface.- See Also:
- Constant Field Values
-
PACKET_DELIVERY_RETRY_COUNT_PROP_KEY
public static final java.lang.String PACKET_DELIVERY_RETRY_COUNT_PROP_KEY
- See Also:
- Constant Field Values
-
SCHEDULER_THREADS_PROP_KEY
public static final java.lang.String SCHEDULER_THREADS_PROP_KEY
Configuration property key for setting number of threads used by component ScheduledExecutorService.- See Also:
- Constant Field Values
-
SECOND
protected static final long SECOND
Constant used in time calculation procedures. Indicates a second that is 1000 milliseconds.- See Also:
- Constant Field Values
-
MINUTE
protected static final long MINUTE
Constant used in time calculation procedures. Indicates a minute that is 60SECOND
s.- See Also:
- Constant Field Values
-
HOUR
protected static final long HOUR
Constant used in time calculation procedures. Indicates a hour that is 60MINUTE
s.- See Also:
- Constant Field Values
-
maxInQueueSize
protected int maxInQueueSize
-
maxOutQueueSize
protected int maxOutQueueSize
-
maxQueueSize
@ConfigField(desc="Maximum size of internal queues", alias="max-queue-size") protected int maxQueueSize
-
-
Method Detail
-
addPacket
public boolean addPacket(Packet packet)
Method adds aPacket
object to the internal input queue. Packets from the input queue are later passed to theprocessPacket(Packet)
method. This is a blocking method waiting if necessary for the room if the queue is full.
The method returns aboolean
value oftrue
if the packet has been successfully added to the queue andfalse
otherwise.
There can be many queues and many threads processing packets for the component, however the method makes the best effort to guarantee that packets are later processed in the correct order. For example that packets for a single user always end up in the same exact queue. You can tweak the packets distribution among threads by overwritinghashCodeForPacket(Packet)
method.
If there isN
threads the packets are distributed among thread using following logic:
int threadNo = Math.abs(hashCodeForPacket(packet) % N);
This is a preferred method to be used by most Tigase components. If the queues are full the component should stop and wait for more room. The blocking methods aim to prevent from the system overloading or wasting resources for generating packets which can't be processed anyway.- Specified by:
addPacket
in interfaceMessageReceiver
- Parameters:
packet
- is aPacket
instance being put to the component internal input queue.- Returns:
- a
boolean
value oftrue
if the packet has been successfully added to the queue andfalse
otherwise.
-
addPacketNB
public boolean addPacketNB(Packet packet)
This is a variant ofaddPacket(Packet)
method which addsPacket
to in the internal input queue without blocking.
The method returns aboolean
value oftrue
if the packet has been successful added to the queue andfalse
otherwise.
Use of the non-blocking methods is not recommended for most of the components implementations. The only component which is allowed to use them is the serverMessageRouter
implementation which can not hang on any method. This would cause a dead-lock in the application. All other components must use blocking methods and wait if the system is under so high load that it's queues are full.
SeeaddPacket(Packet)
method's documentation for some more details.- Specified by:
addPacketNB
in interfaceMessageReceiver
- Parameters:
packet
- is aPacket
instance being put to the component internal input queue.- Returns:
- a
boolean
value oftrue
if the packet has been successfully added to the queue andfalse
otherwise. - See Also:
addPacket(Packet packet)
-
addPackets
public boolean addPackets(java.util.Queue<Packet> packets)
This is a convenience method for adding all packets stored in given queue to the component's internal input queue.
The method callsaddPacket(Packet)
in a loop for each packet in the queue. If the call returnstrue
then the packet is removed from the given queue, otherwise the methods ends the loop and returnsfalse
.
Please note, if the method returnstrue
it means that all the packets from the queue passed as a parameter have been successfuly run through theaddPacket(Packet)
method and the queue passed as a parameter should be empty. If the method returns false then at least one packet from the parameter queue wasn't successfully run through theaddPacket(Packet)
method. If the method returnsfalse
then the queue passed as a parameter is not empty and it contains packet which was unseccessfully run through theaddPacket(Packet)
method and all the packets which were not run at all.- Specified by:
addPackets
in interfaceMessageReceiver
- Parameters:
packets
- is aQueue
of packets for adding to the component internal input queue. All the packets are later processed byprocessPacket(Packet)
method in the same exact order if they are processed by the same thread. See documentationhashCodeForPacket(Packet)
method how to control assiging packets to particular threads.- Returns:
- a
boolean
value oftrue
if all packets has been successfully added to the component's internal input queue andfalse
otherwise. - See Also:
hashCodeForPacket(Packet packet)
-
addRegexRouting
public void addRegexRouting(java.lang.String address)
Method adds a new routing address for the component. Routing addresses are used by theMessageRouter
to calculate packet's destination. If the packet's destination address matches one of the component's routing addresses the packet is added to the component's internal input queue.
By default all components accept packets addressed to the componentId and to:
component.getName() + '@' + any virtual domain
TODO: The future implementation most likely accept packets addressed to:
any virtual domain + '/' + component.getName()
instead.
The routings are passed as Java regular expression strings are the extra addresses accepted by the component. In most cases this is used by the external component protocol implementations which can dynamically change accepted addresses depending on the connected external components.- Parameters:
address
- is a Java regular expression string for the packet's destination address accepted by this component.
-
addTimerTask
public void addTimerTask(TimerTask task, long delay)
Method queues and executes timer tasks using ScheduledExecutorService which allows using more than one thread for executing tasks.
-
addTimerTask
public void addTimerTask(TimerTask task, long initialDelay, long period)
-
addTimerTaskWithTimeout
public void addTimerTaskWithTimeout(TimerTask task, long delay, long timeout)
Method queues and executes timer tasks using ScheduledExecutorService which allows using more than one thread for executing tasks. It allows to set a timeout to cancel long running tasks- Parameters:
task
- a task implementingTimerTask
delay
- in milliseconds delay after which task will be startedtimeout
- in milliseconds after which task will be cancelled disregarding whether it has finished or not
-
addTimerTaskWithTimeout
public void addTimerTaskWithTimeout(TimerTask task, long delay, long period, long timeout)
Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; please refer toScheduledExecutorService.scheduleAtFixedRate(java.lang.Runnable, long, long, java.util.concurrent.TimeUnit)
javadoc for details. It utilizes TigaseTimerTask
and allows setting a timeout to cancel long running tasks- Parameters:
task
- a task implementingTimerTask
delay
- in milliseconds, the time to delay first executionperiod
- in milliseconds, the period between successive executionstimeout
- in milliseconds after which task will be cancelled disregarding whether it has finished or not
-
clearRegexRoutings
public void clearRegexRoutings()
Method clears, removes all the component routing addresses. After this method call the component accepts only packets addressed to default routings that is component ID or the component name + '@' + virtual domains
-
everyHour
public void everyHour()
Utility method executed precisely every hour. A component can overwrite the method to put own code to be executed at the regular intervals of time.
Note, no extensive calculations should happen in this method nor long lasting operations. It is essential that the method processing does not exceed 1 hour. The overriding method must call the the super method first and only then run own code.- Overrides:
everyHour
in classBasicComponent
-
everyMinute
public void everyMinute()
Utility method executed precisely every minute. A component can overwrite the method to put own code to be executed at the regular intervals of time.
Note, no extensive calculations should happen in this method nor long lasting operations. It is essential that the method processing does not exceed 1 minute. The overriding method must call the the super method first and only then run own code.- Overrides:
everyMinute
in classBasicComponent
-
everySecond
public void everySecond()
Utility method executed precisely every second. A component can overwrite the method to put own code to be executed at the regular intervals of time.
Note, no extensive calculations should happen in this method nor long lasting operations. It is essential that the method processing does not exceed 1 second. The overriding method must call the the super method first and only then run own code.- Overrides:
everySecond
in classBasicComponent
-
hashCodeForPacket
public int hashCodeForPacket(Packet packet)
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....- Parameters:
packet
- is aPacket
which needs to be processed by some thread.- Returns:
- a hash code generated for the input thread.
-
newPacketId
public java.lang.String newPacketId(java.lang.String prefix)
-
processingInThreads
public int processingInThreads()
Concurrency control method. Returns preferable number of threads set for this component.- Returns:
- preferable number of threads set for this component.
-
processingOutThreads
public int processingOutThreads()
Concurrency control method. Returns preferable number of threads set for this component.- Returns:
- preferable number of threads set for this component.
-
processOutPacket
public void processOutPacket(Packet packet)
By default this method just copies the given packet between queue. This method operates on packets which have been already processed somehow by the component so usually the default action is the best one, however some components in rare cases may choose to process packets differently. In most cases this method should not be overridden.- Parameters:
packet
- is an output packet which normally has to go to other component for further processing.
-
processPacket
public abstract void processPacket(Packet packet)
This is the mainPacket
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, thePacket
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 thePacket
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 usingaddOutPacket(Packet)
method.- Parameters:
packet
- is an instance of thePacket
class passed for processing.
-
processPacket
public final void processPacket(Packet packet, java.util.Queue<Packet> results)
Description copied from interface:ServerComponent
processPacket
is a blocking processing method implemented by all components. This method processes packet and returns results instantly without waiting for any resources.- Specified by:
processPacket
in interfaceServerComponent
- Overrides:
processPacket
in classBasicComponent
- Parameters:
packet
- aPacket
value
-
release
public void release()
Description copied from interface:ServerComponent
Method called when component is being stopped and unloaded.- Specified by:
release
in interfaceServerComponent
- Overrides:
release
in classBasicComponent
-
removeRegexRouting
public boolean removeRegexRouting(java.lang.String address)
-
schedulerThreads
public int schedulerThreads()
Method returns default number of threads used by SchedulerExecutorService- Returns:
- a value of
int
-
start
public void start()
- Specified by:
start
in interfaceMessageReceiver
-
stop
public void stop()
-
getRegexRoutings
public java.util.Set<java.util.regex.Pattern> getRegexRoutings()
Method returns aSet
with all component's routings as a compiled regular expression patterns. TheSet
can be empty but it can not be null.- Returns:
- a
Set
with all component's routings as a compiled regular expression patterns.
-
getStatistics
public void getStatistics(StatisticsList list)
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 haveLevel.FINEST
assigned and must be put inside the level guard to prevent generating them by the system monitor. The system monitor does not collectFINEST
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 interfaceStatisticsContainerIfc
- Overrides:
getStatistics
in classBasicComponent
- Parameters:
list
- is aStatistcsList
where all statistics are stored.
-
isInRegexRoutings
public boolean isInRegexRoutings(java.lang.String address)
- Specified by:
isInRegexRoutings
in interfaceMessageReceiver
-
setIncoming_filters
public void setIncoming_filters(PacketFiltersBean.IncomingPacketFiltersBean incoming_filters)
-
setOutgoing_filters
public void setOutgoing_filters(PacketFiltersBean.OutgoingPacketFiltersBean outgoing_filters)
-
updateFiltersName
protected void updateFiltersName()
-
beanConfigurationChanged
public void beanConfigurationChanged(java.util.Collection<java.lang.String> changedFields)
Description copied from interface:ConfigurationChangedAware
Method called when configuration was applied to bean.- Specified by:
beanConfigurationChanged
in interfaceConfigurationChangedAware
- Overrides:
beanConfigurationChanged
in classBasicComponent
- Parameters:
changedFields
- collection of field names which were changed
-
setCompId
public void setCompId(JID jid)
- Overrides:
setCompId
in classBasicComponent
-
setName
public void setName(java.lang.String name)
Description copied from interface:ServerComponent
Method used to assign component name (localpart of the component)- Specified by:
setName
in interfaceServerComponent
- Overrides:
setName
in classBasicComponent
- Parameters:
name
- to be assigned
-
setParent
public void setParent(MessageReceiver parent)
- Specified by:
setParent
in interfaceMessageReceiver
-
setSchedulerThreads_size
public void setSchedulerThreads_size(int size)
-
addOutPacketWithTimeout
public boolean addOutPacketWithTimeout(Packet packet, ReceiverTimeoutHandler handler, long delay, java.util.concurrent.TimeUnit unit)
-
addOutPacketWithTimeout
public boolean addOutPacketWithTimeout(Packet packet, java.time.Duration timeout, PacketWriterWithTimeout.Handler handler)
- Specified by:
addOutPacketWithTimeout
in interfacePacketWriterWithTimeout
-
addOutPacket
protected boolean addOutPacket(Packet packet)
-
addOutPacketNB
protected boolean addOutPacketNB(Packet packet)
Non blocking version ofaddOutPacket
.- Parameters:
packet
- aPacket
value- Returns:
- a
boolean
value
-
addOutPackets
protected boolean addOutPackets(java.util.Queue<Packet> packets)
-
addTimerTask
protected void addTimerTask(TimerTask task, long delay, java.util.concurrent.TimeUnit unit)
Method queues and executes timer tasks using ScheduledExecutorService which allows using more than one thread for executing tasks.
-
getMaxQueueSize
protected java.lang.Integer getMaxQueueSize(int def)
-
getResourceForPacketWithTimeout
protected java.lang.String getResourceForPacketWithTimeout()
-
-