public final class StreamFeaturesManager extends Manager
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 streamFeatureNegotiator)
Adds a new feature negotiator, which is responsible for negotiating an individual feature.
|
void |
awaitNegotiation(Class<? extends StreamFeature> streamFeature,
Duration timeout)
Waits until the given feature will be negotiated.
|
void |
cancelNegotiation()
Cancels negotiation and releases any locks.
|
void |
completeNegotiation(Duration timeout)
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.
|
boolean |
processElement(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. |
isEnabled, setEnabledpublic final Map<Class<? extends StreamFeature>,StreamFeature> getFeatures()
public final void addFeatureNegotiator(StreamFeatureNegotiator streamFeatureNegotiator)
streamFeatureNegotiator - The feature negotiator, which is responsible for the feature.public final void processFeatures(StreamFeatures featuresElement) throws StreamNegotiationException
<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 processElement(Object element) throws StreamNegotiationException
<proceed/> element from TLS negotiation.element - The element.StreamNegotiationException - If an exception occurred during feature negotiation.public final void awaitNegotiation(Class<? extends StreamFeature> streamFeature, Duration timeout) throws InterruptedException, NoResponseException
streamFeature - The stream feature class.timeout - The timeout.InterruptedException - If the current thread is interrupted.NoResponseException - If the server didn't respond.public final void completeNegotiation(Duration timeout) throws InterruptedException, NoResponseException, StreamNegotiationException
timeout - The timeout.InterruptedException - If the current thread is interrupted.NoResponseException - If the server didn't respond.StreamNegotiationException - If the stream negotiation failed.public void cancelNegotiation()
Copyright © 2014–2016 XMPP.rocks. All rights reserved.