Class StreamFeaturesManager
- java.lang.Object
-
- rocks.xmpp.core.session.Manager
-
- rocks.xmpp.core.stream.client.StreamFeaturesManager
-
- All Implemented Interfaces:
StreamHandler
public final class StreamFeaturesManager extends Manager implements StreamHandler
Manages the various features, which are advertised during stream negotiation.Because the receiving entity for a stream acts as a gatekeeper to the domains it services, it imposes certain conditions for connecting as a client or as a peer server. At a minimum, the initiating entity needs to authenticate with the receiving entity before it is allowed to send stanzas to the receiving entity (for client-to-server streams this means using SASL as described under Section 6). However, the receiving entity can consider conditions other than authentication to be mandatory-to-negotiate, such as encryption using TLS as described under Section 5. The receiving entity informs the initiating entity about such conditions by communicating "stream features": the set of particular protocol interactions that the initiating entity needs to complete before the receiving entity will accept XML stanzas from the initiating entity, as well as any protocol interactions that are voluntary-to-negotiate but that might improve the handling of an XML stream (e.g., establishment of application-layer compression as described in [XEP-0138]).
Each feature is associated with a feature negotiator, which negotiates the particular feature.
This class manages these negotiators, receives XML elements and delegates them to the responsible feature negotiator for further processing.
It negotiates the stream by sequentially negotiating each stream feature.
This class is thread-safe.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFeatureNegotiator(StreamFeatureNegotiator<? extends StreamFeature> streamFeatureNegotiator)
Adds a new feature negotiator, which is responsible for negotiating an individual feature.Future<Void>
awaitNegotiation(Class<? extends StreamFeature> streamFeature)
Waits until the given feature will be negotiated.void
cancelNegotiation()
Cancels negotiation and releases any locks.Future<Void>
completeNegotiation()
Negotiates all pending features, if any, and waits until all features have been negotiated.Map<Class<? extends StreamFeature>,StreamFeature>
getFeatures()
Gets the available features, which the server has advertised.<T> List<T>
getFeatures(Class<T> clazz)
boolean
handleElement(Object element)
Tries to process an element, which is a feature or may belong to a feature protocol, e.g. the<proceed/>
element from TLS negotiation.void
processFeatures(StreamFeatures featuresElement)
Processes the<stream:features/>
element and immediately starts negotiating the first feature.void
removeFeatureNegotiator(StreamFeatureNegotiator<? extends StreamFeature> streamFeatureNegotiator)
Removes a feature negotiator.-
Methods inherited from class rocks.xmpp.core.session.Manager
isEnabled, setEnabled
-
-
-
-
Method Detail
-
getFeatures
public final Map<Class<? extends StreamFeature>,StreamFeature> getFeatures()
Gets the available features, which the server has advertised.- Returns:
- The features.
-
addFeatureNegotiator
public final void addFeatureNegotiator(StreamFeatureNegotiator<? extends StreamFeature> streamFeatureNegotiator)
Adds a new feature negotiator, which is responsible for negotiating an individual feature.- Parameters:
streamFeatureNegotiator
- The feature negotiator, which is responsible for the feature.
-
removeFeatureNegotiator
public final void removeFeatureNegotiator(StreamFeatureNegotiator<? extends StreamFeature> streamFeatureNegotiator)
Removes a feature negotiator.- Parameters:
streamFeatureNegotiator
- The feature negotiator.
-
processFeatures
public final void processFeatures(StreamFeatures featuresElement) throws StreamNegotiationException
Processes the<stream:features/>
element and immediately starts negotiating the first feature.- Parameters:
featuresElement
- The<stream:features/>
element.- Throws:
StreamNegotiationException
- If an exception occurred during feature negotiation.
-
handleElement
public final boolean handleElement(Object element) throws StreamNegotiationException
Tries to process an element, which is a feature or may belong to a feature protocol, e.g. the<proceed/>
element from TLS negotiation.- Specified by:
handleElement
in interfaceStreamHandler
- Parameters:
element
- The element.- Returns:
- True, if the stream needs to be restarted, after a feature has been negotiated.
- Throws:
StreamNegotiationException
- If an exception occurred during feature negotiation.
-
awaitNegotiation
public final Future<Void> awaitNegotiation(Class<? extends StreamFeature> streamFeature)
Waits until the given feature will be negotiated. If the feature has already been negotiated it immediately returns.- Parameters:
streamFeature
- The stream feature class.- Returns:
- The future which is complete when the negotiation of the stream feature is completed.
-
completeNegotiation
public final Future<Void> completeNegotiation() throws StreamNegotiationException
Negotiates all pending features, if any, and waits until all features have been negotiated.- Returns:
- The future which is complete when all pending features have been negotiated.
- Throws:
StreamNegotiationException
- If the stream negotiation failed.
-
cancelNegotiation
public void cancelNegotiation()
Cancels negotiation and releases any locks.
-
-