public abstract class AbstractComponent extends Object implements Component
Component implementation. Most of the
default functionality can be overridden by overriding specific methods.
These XMPP features are implemented in the abstract component:
get or set type, as required by
the XMPP specification. If the abstract component cannot formulate a valid
response and the extending implementation does not provide a response either
(by returning null on invocations of handleIQGet(IQ) and
handleIQSet(IQ)) an IQ error response is returned.
The behavior described above can be disabled by setting a corresponding flag
in one of the constructors. If an instance is configured in such a way,
null responses provided by the extending implementation are not
translated in an IQ error. This allows the extending implementation to
respond to IQ requests in an asynchrous manner. It will be up to the
extending implementation to ensure that every IQ request is responded to.
Note that instances of this class can be used to implement internal (e.g.
Openfire plugins) as well as external components.| Modifier and Type | Field and Description |
|---|---|
protected ComponentManager |
compMan
The component manager to which this Component has been registered.
|
protected JID |
jid
The JID of the component, set after registration with a Component manager.
|
protected org.slf4j.Logger |
log
The object that's responsible for logging.
|
static String |
NAMESPACE_DISCO_INFO
The XMPP 'service discovery info' namespace.
|
static String |
NAMESPACE_DISCO_ITEMS
The XMPP 'service discovery items' namespace.
|
static String |
NAMESPACE_ENTITY_TIME
The 'Entity Time' namespace
|
static String |
NAMESPACE_LAST_ACTIVITY
The 'Last Activity' namespace
|
static String |
NAMESPACE_XMPP_PING
The 'XMPP Ping' namespace
|
| Constructor and Description |
|---|
AbstractComponent()
Instantiates a new AbstractComponent with a maximum thread pool size of
17 and a maximum queue size of 1000.
|
AbstractComponent(int maxThreadpoolSize,
int maxQueueSize,
boolean enforceIQResult)
Instantiates a new AbstractComponent.
|
| Modifier and Type | Method and Description |
|---|---|
protected String[] |
discoInfoFeatureNamespaces()
This method returns a String array that should contain all namespaces of
features that this component offers.
|
protected String |
discoInfoIdentityCategory()
Returns the category of the Service Discovery Identity of this component
(this implementation will only hold exactly one Identity for the
component).
|
protected String |
discoInfoIdentityCategoryType()
Returns the type of the Service Discovery Identity of this component
(this implementation will only hold exactly one Identity for the
component).
|
protected boolean |
dropStanza(IQ iq) |
abstract String |
getDescription()
Returns the description of this component.
|
String |
getDomain()
Returns the XMPP domain to which this component is registered to.
|
JID |
getJID()
Returns the XMPP address / Jabber ID (JID) of this component.
|
abstract String |
getName()
Returns the name of this component.
|
protected IQ |
handleDiscoInfo(IQ iq)
Default handler of Service Discovery Info requests.
|
protected IQ |
handleDiscoItems(IQ iq)
Default handler of Service Discovery Info requests.
|
protected IQ |
handleEntityTime(IQ iq)
Default handler of Entity Time requests (XEP-0202).
|
protected void |
handleIQError(IQ iq)
Override this method to handle the IQ stanzas of type
error that
are received by the component. |
protected IQ |
handleIQGet(IQ iq)
Override this method to handle the IQ stanzas of type
get that
could not be processed by the AbstractComponent implementation. |
protected void |
handleIQResult(IQ iq)
Override this method to handle the IQ stanzas of type
result
that are received by the component. |
protected IQ |
handleIQSet(IQ iq)
Override this method to handle the IQ stanzas of type
set that
could not be processed by the AbstractComponent implementation. |
protected IQ |
handleLastActivity(IQ iq)
Default handler of Last Activity requests (XEP-0012).
|
protected void |
handleMessage(Message message)
Override this method to handle the Message stanzas that are received by
the component.
|
protected IQ |
handlePing(IQ iq)
Default handler of Ping requests (XEP-0199).
|
protected void |
handlePresence(Presence presence)
Override this method to handle the Presence stanzas that are received by
the component.
|
void |
initialize(JID jid,
ComponentManager componentManager)
Initialize the abstract component.
|
void |
postComponentShutdown()
This method gets called as part of the Component shutdown routine.
|
void |
postComponentStart()
This method gets called as part of the Component 'start' routine.
|
void |
preComponentShutdown()
This method gets called as part of the Component shutdown routine.
|
void |
preComponentStart()
This method gets called as part of the Component 'start' routine.
|
void |
processPacket(Packet packet)
Processes a packet sent to this Component.
|
protected void |
send(Packet packet)
Helper method to send packets.
|
boolean |
servesLocalUsersOnly()
Checks if the component can only be used by users of the XMPP domain that
the component has registered to.
|
void |
shutdown()
Default implementation of the shutdown() method of the
Component
interface. |
void |
start()
Default implementation of the start() method of the
Component
interface. |
protected final org.slf4j.Logger log
public static final String NAMESPACE_DISCO_ITEMS
public static final String NAMESPACE_DISCO_INFO
public static final String NAMESPACE_XMPP_PING
public static final String NAMESPACE_LAST_ACTIVITY
public static final String NAMESPACE_ENTITY_TIME
protected ComponentManager compMan
protected JID jid
public AbstractComponent()
public AbstractComponent(int maxThreadpoolSize,
int maxQueueSize,
boolean enforceIQResult)
maxThreadpoolSize - the maximum number of threads that will process work for this
component.maxQueueSize - capacity of the queue that holds tasks that are to be executed
by the thread pool.enforceIQResult - if true, the component will make sure that every
request that is received is answered, as specified by the XMPP
specification.public final void initialize(JID jid, ComponentManager componentManager) throws ComponentException
initialize in interface Componentjid - the XMPP address that this component is available at.componentManager - the component manager.ComponentException - if an error occured while initializing the component.Component.initialize(org.xmpp.packet.JID,
org.xmpp.component.ComponentManager)public final void processPacket(Packet packet)
ComponentprocessPacket in interface Componentpacket - the packet.Component.processPacket(org.xmpp.packet.Packet)protected boolean dropStanza(IQ iq)
protected void handleIQResult(IQ iq)
result
that are received by the component. If you do not override this method,
the stanzas are ignored.iq - The IQ stanza of type result that was received by
this component.protected void handleIQError(IQ iq)
error that
are received by the component. If you do not override this method, the
stanzas are ignored.iq - The IQ stanza of type error that was received by this
component.protected IQ handleIQGet(IQ iq) throws Exception
get that
could not be processed by the AbstractComponent implementation.
get must be replied to,
returning null from this method equals returning an IQ error
stanza of type 'feature-not-implemented' (this behavior can be disabled
by setting the enforceIQResult argument in the constructor to
false).
error, condition 'internal-server-error' will be returned to the
sender of the original request.
null. It is
expected that most child classes will override this method.iq - The IQ request stanza of type get that was received
by this component.null to indicate
'feature-not-available'.Exception - if internal error occurs.protected IQ handleIQSet(IQ iq) throws Exception
set that
could not be processed by the AbstractComponent implementation.
set must be replied to,
returning null from this method equals returning an IQ error
stanza of type 'feature-not-implemented' {this behavior can be disabled
by setting the enforceIQResult argument in the constructor to
false).
error, condition 'internal-server-error' will be returned to the
sender of the original request.
null. It is
expected that most child classes will override this method.iq - The IQ request stanza of type set that was received
by this component.null to indicate
'feature-not-available'.Exception - if internal error occurs.protected IQ handleDiscoItems(IQ iq)
null, which will result into a
'service-unavailable' response to be returned as a response to the
original request.iq - The Service Discovery Itemsprotected IQ handleDiscoInfo(IQ iq)
result packet that includes:
discoInfoIdentityCategory();discoInfoIdentityCategoryType();Component interface (which this class implements).discoInfoFeatureNamespaces().handleDiscoInfo(IQ) returns a non-null value.iq - The Service Discovery 'info' request stanza.protected IQ handlePing(IQ iq)
iq - The Ping request stanza.protected IQ handleLastActivity(IQ iq)
iq - The Last Activity request stanza.protected IQ handleEntityTime(IQ iq)
iq - Entity Time request stanza.public abstract String getDescription()
ComponentgetDescription in interface Componentpublic abstract String getName()
Componentpublic String getDomain()
null if this component has not been initialized yet.public JID getJID()
null if this component has
not been initialized yet.protected String discoInfoIdentityCategory()
protected String discoInfoIdentityCategoryType()
protected String[] discoInfoFeatureNamespaces()
handleIQGet(IQ) and/or
handleIQSet(IQ) methods. Also note that the default namespaces for
service discovery should not be returned by this method.
protected void handleMessage(Message message)
message - The Message stanza that was received by this component.protected void handlePresence(Presence presence)
presence - The Presence stanza that was received by this component.public boolean servesLocalUsersOnly()
true,
this will happen:
result and error are silently
ignored.get or set are responded to
with a IQ error response, type 'cancel', condition
'not-allowed'.
false. You can
override this method to change the behavior.true if this component serves local users only,
false otherwise.public final void shutdown()
Component
interface.protected void send(Packet packet)
packet - The packet to send.public void preComponentShutdown()
public void postComponentShutdown()
public void start()
Component
interface. Unless overridden, this method doesn't do anything. We get
called once for each host that we connect to, so we have to take care to
avoid double initialization.public void preComponentStart()
public void postComponentStart()
Copyright © 2009–2019 Ignite Realtime. All rights reserved.