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.
Modifier and Type | Method and Description |
---|---|
void |
addFeatureNegotiator(StreamFeatureNegotiator<? extends StreamFeature> streamFeatureNegotiator)
Adds a new feature negotiator, which is responsible for negotiating an individual feature.
|
java.util.concurrent.Future<java.lang.Void> |
awaitNegotiation(java.lang.Class<? extends StreamFeature> streamFeature)
Waits until the given feature will be negotiated.
|
void |
cancelNegotiation()
Cancels negotiation and releases any locks.
|
java.util.concurrent.Future<java.lang.Void> |
completeNegotiation()
Negotiates all pending features, if any, and waits until all features have been negotiated.
|
java.util.Map<java.lang.Class<? extends StreamFeature>,StreamFeature> |
getFeatures()
Gets the available features, which the server has advertised.
|
<T> java.util.List<T> |
getFeatures(java.lang.Class<T> clazz) |
boolean |
handleElement(java.lang.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.
|
isEnabled, setEnabled
public final java.util.Map<java.lang.Class<? extends StreamFeature>,StreamFeature> getFeatures()
Gets the available features, which the server has advertised.
public final <T> java.util.List<T> getFeatures(java.lang.Class<T> clazz)
public final void addFeatureNegotiator(StreamFeatureNegotiator<? extends StreamFeature> streamFeatureNegotiator)
Adds a new feature negotiator, which is responsible for negotiating an individual feature.
streamFeatureNegotiator
- The feature negotiator, which is responsible for the feature.public final void removeFeatureNegotiator(StreamFeatureNegotiator<? extends StreamFeature> streamFeatureNegotiator)
Removes a feature negotiator.
streamFeatureNegotiator
- The feature negotiator.public final void processFeatures(StreamFeatures featuresElement) throws StreamNegotiationException
Processes the <stream:features/>
element and immediately starts negotiating the first feature.
featuresElement
- The <stream:features/>
element.StreamNegotiationException
- If an exception occurred during feature negotiation.public final boolean handleElement(java.lang.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.
handleElement
in interface StreamHandler
element
- The element.StreamNegotiationException
- If an exception occurred during feature negotiation.public final java.util.concurrent.Future<java.lang.Void> awaitNegotiation(java.lang.Class<? extends StreamFeature> streamFeature)
Waits until the given feature will be negotiated. If the feature has already been negotiated it immediately returns.
streamFeature
- The stream feature class.public final java.util.concurrent.Future<java.lang.Void> completeNegotiation() throws StreamNegotiationException
Negotiates all pending features, if any, and waits until all features have been negotiated.
StreamNegotiationException
- If the stream negotiation failed.public void cancelNegotiation()
Cancels negotiation and releases any locks.
Copyright © 2014–2019 XMPP.rocks. All rights reserved.