mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-29 23:42:06 +01:00
Compare commits
14 commits
6266f04682
...
bc503c7475
Author | SHA1 | Date | |
---|---|---|---|
|
bc503c7475 | ||
|
dcb66eef59 | ||
|
a4e4fbeee1 | ||
|
b8a575f4b0 | ||
|
8752605c74 | ||
|
63f133e68b | ||
|
c384849532 | ||
|
884ee327e1 | ||
|
a05b464032 | ||
|
ddc39030d7 | ||
|
f9292a23fb | ||
|
018cba7f4f | ||
|
5bd247c3e6 | ||
8a0371bcea |
10 changed files with 294 additions and 25 deletions
|
@ -123,7 +123,7 @@ allprojects {
|
||||||
// - https://issues.apache.org/jira/browse/MNG-6232
|
// - https://issues.apache.org/jira/browse/MNG-6232
|
||||||
// - https://issues.igniterealtime.org/browse/SMACK-858
|
// - https://issues.igniterealtime.org/browse/SMACK-858
|
||||||
jxmppVersion = '0.7.0-alpha6'
|
jxmppVersion = '0.7.0-alpha6'
|
||||||
miniDnsVersion = '0.4.0-alpha5'
|
miniDnsVersion = '0.4.0-alpha6'
|
||||||
smackMinAndroidSdk = 19
|
smackMinAndroidSdk = 19
|
||||||
junitVersion = '5.6.2'
|
junitVersion = '5.6.2'
|
||||||
commonsIoVersion = '2.6'
|
commonsIoVersion = '2.6'
|
||||||
|
|
|
@ -14,6 +14,7 @@ Currently supported XEPs of Smack (all sub-projects)
|
||||||
|
|
||||||
| Name | XEP | Version | Description |
|
| Name | XEP | Version | Description |
|
||||||
|---------------------------------------------|--------------------------------------------------------|-----------|----------------------------------------------------------------------------------------------------------|
|
|---------------------------------------------|--------------------------------------------------------|-----------|----------------------------------------------------------------------------------------------------------|
|
||||||
|
| Discovering Alternative XMPP Connection Methods | [XEP-0156](https://xmpp.org/extensions/xep-0156.html) | 1.3.0 | Defines ways to discover alternative connection methods. |
|
||||||
| Nonzas | [XEP-0360](https://xmpp.org/extensions/xep-0360.html) | n/a | Defines the term "Nonza", describing every top level stream element that is not a Stanza. |
|
| Nonzas | [XEP-0360](https://xmpp.org/extensions/xep-0360.html) | n/a | Defines the term "Nonza", describing every top level stream element that is not a Stanza. |
|
||||||
|
|
||||||
Currently supported XEPs of smack-tcp
|
Currently supported XEPs of smack-tcp
|
||||||
|
|
|
@ -688,7 +688,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We use an extra object for {@link #notifyWaitingThreads()} and {@link #waitForCondition(Supplier)}, because all state
|
* We use an extra object for {@link #notifyWaitingThreads()} and {@link #waitForConditionOrConnectionException(Supplier)}, because all state
|
||||||
* changing methods of the connection are synchronized using the connection instance as monitor. If we now would
|
* changing methods of the connection are synchronized using the connection instance as monitor. If we now would
|
||||||
* also use the connection instance for the internal process to wait for a condition, the {@link Object#wait()}
|
* also use the connection instance for the internal process to wait for a condition, the {@link Object#wait()}
|
||||||
* would leave the monitor when it waites, which would allow for another potential call to a state changing function
|
* would leave the monitor when it waites, which would allow for another potential call to a state changing function
|
||||||
|
@ -702,10 +702,10 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final boolean waitForCondition(Supplier<Boolean> condition) throws InterruptedException {
|
protected final boolean waitFor(Supplier<Boolean> condition) throws InterruptedException {
|
||||||
final long deadline = System.currentTimeMillis() + getReplyTimeout();
|
final long deadline = System.currentTimeMillis() + getReplyTimeout();
|
||||||
synchronized (internalMonitor) {
|
synchronized (internalMonitor) {
|
||||||
while (!condition.get().booleanValue() && !hasCurrentConnectionException()) {
|
while (!condition.get().booleanValue()) {
|
||||||
final long now = System.currentTimeMillis();
|
final long now = System.currentTimeMillis();
|
||||||
if (now >= deadline) {
|
if (now >= deadline) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -716,15 +716,19 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final void waitForCondition(Supplier<Boolean> condition, String waitFor) throws InterruptedException, NoResponseException {
|
protected final boolean waitForConditionOrConnectionException(Supplier<Boolean> condition) throws InterruptedException {
|
||||||
boolean success = waitForCondition(condition);
|
return waitFor(() -> condition.get().booleanValue() || hasCurrentConnectionException());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final void waitForConditionOrConnectionException(Supplier<Boolean> condition, String waitFor) throws InterruptedException, NoResponseException {
|
||||||
|
boolean success = waitForConditionOrConnectionException(condition);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
throw NoResponseException.newWith(this, waitFor);
|
throw NoResponseException.newWith(this, waitFor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final void waitForConditionOrThrowConnectionException(Supplier<Boolean> condition, String waitFor) throws InterruptedException, SmackException, XMPPException {
|
protected final void waitForConditionOrThrowConnectionException(Supplier<Boolean> condition, String waitFor) throws InterruptedException, SmackException, XMPPException {
|
||||||
waitForCondition(condition, waitFor);
|
waitForConditionOrConnectionException(condition, waitFor);
|
||||||
if (hasCurrentConnectionException()) {
|
if (hasCurrentConnectionException()) {
|
||||||
throwCurrentConnectionException();
|
throwCurrentConnectionException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,176 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2020 Aditya Borikar.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smack.altconnections;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
|
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||||
|
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||||
|
|
||||||
|
import org.jxmpp.jid.DomainBareJid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The HTTP lookup method uses web host metadata to list the URIs of alternative connection methods.
|
||||||
|
*
|
||||||
|
* <p>In order to obtain host-meta XRD element from the host in the form of an <i>InputStream</i>,
|
||||||
|
* use {@link #getXrdStream(DomainBareJid)} method. To obtain endpoints for Bosh or Websocket
|
||||||
|
* connection endpoints from host, use {@link LinkRelation#BOSH} and {@link LinkRelation#WEBSOCKET}
|
||||||
|
* respectively with the {@link #lookup(DomainBareJid, LinkRelation)} method. In case one is looking
|
||||||
|
* for endpoints described by other than BOSH or Websocket LinkRelation, use the more flexible
|
||||||
|
* {@link #lookup(DomainBareJid, String)} method.</p>
|
||||||
|
* Example:<br>
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* DomainBareJid xmppServerAddress = JidCreate.domainBareFrom("example.org");
|
||||||
|
* List<URI> endpoints = HttpLookupMethod.lookup(xmppServiceAddress, LinkRelation.WEBSOCKET);
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
* @see <a href="https://xmpp.org/extensions/xep-0156.html#http">
|
||||||
|
* HTTP Lookup Method from XEP-0156.
|
||||||
|
* </a>
|
||||||
|
*/
|
||||||
|
public final class HttpLookupMethod {
|
||||||
|
private static final String XRD_NAMESPACE = "http://docs.oasis-open.org/ns/xri/xrd-1.0";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies a link relation for the selected type of connection.
|
||||||
|
*/
|
||||||
|
public enum LinkRelation {
|
||||||
|
/**
|
||||||
|
* Selects link relation attribute as "urn:xmpp:alt-connections:xbosh".
|
||||||
|
*/
|
||||||
|
BOSH("urn:xmpp:alt-connections:xbosh"),
|
||||||
|
/**
|
||||||
|
* Selects link relation attribute as "urn:xmpp:alt-connections:websocket".
|
||||||
|
*/
|
||||||
|
WEBSOCKET("urn:xmpp:alt-connections:websocket");
|
||||||
|
private final String attribute;
|
||||||
|
LinkRelation(String relAttribute) {
|
||||||
|
this.attribute = relAttribute;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get remote endpoints for the given LinkRelation from host.
|
||||||
|
*
|
||||||
|
* @param xmppServiceAddress address of host
|
||||||
|
* @param relation LinkRelation as a string specifying type of connection
|
||||||
|
* @return list of endpoints
|
||||||
|
* @throws IOException exception due to input/output operations
|
||||||
|
* @throws XmlPullParserException exception encountered during XML parsing
|
||||||
|
* @throws URISyntaxException exception to indicate that a string could not be parsed as a URI reference
|
||||||
|
*/
|
||||||
|
public static List<URI> lookup(DomainBareJid xmppServiceAddress, String relation) throws IOException, XmlPullParserException, URISyntaxException {
|
||||||
|
try (InputStream inputStream = getXrdStream(xmppServiceAddress)) {
|
||||||
|
XmlPullParser xmlPullParser = PacketParserUtils.getParserFor(inputStream);
|
||||||
|
List<URI> endpoints = parseXrdLinkReferencesFor(xmlPullParser, relation);
|
||||||
|
return endpoints;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get remote endpoints for the given LinkRelation from host.
|
||||||
|
*
|
||||||
|
* @param xmppServiceAddress address of host
|
||||||
|
* @param relation {@link LinkRelation} specifying type of connection
|
||||||
|
* @return list of endpoints
|
||||||
|
* @throws IOException exception due to input/output operations
|
||||||
|
* @throws XmlPullParserException exception encountered during XML parsing
|
||||||
|
* @throws URISyntaxException exception to indicate that a string could not be parsed as a URI reference
|
||||||
|
*/
|
||||||
|
public static List<URI> lookup(DomainBareJid xmppServiceAddress, LinkRelation relation) throws IOException, XmlPullParserException, URISyntaxException {
|
||||||
|
return lookup(xmppServiceAddress, relation.attribute);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a HTTP connection with the host specified by the DomainBareJid
|
||||||
|
* and retrieves XRD element in the form of an InputStream. The method will
|
||||||
|
* throw a {@link FileNotFoundException} if host-meta isn't published.
|
||||||
|
*
|
||||||
|
* @param xmppServiceAddress address of host
|
||||||
|
* @return InputStream containing XRD element
|
||||||
|
* @throws IOException exception due to input/output operations
|
||||||
|
*/
|
||||||
|
public static InputStream getXrdStream(DomainBareJid xmppServiceAddress) throws IOException {
|
||||||
|
final String metadataUrl = "https://" + xmppServiceAddress + "/.well-known/host-meta";
|
||||||
|
final URL putUrl = new URL(metadataUrl);
|
||||||
|
final URLConnection urlConnection = putUrl.openConnection();
|
||||||
|
return urlConnection.getInputStream();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get remote endpoints for the provided LinkRelation from provided XmlPullParser.
|
||||||
|
*
|
||||||
|
* @param parser XmlPullParser that contains LinkRelations
|
||||||
|
* @param relation type of endpoints specified by the given LinkRelation
|
||||||
|
* @return list of endpoints
|
||||||
|
* @throws IOException exception due to input/output operations
|
||||||
|
* @throws XmlPullParserException exception encountered during XML parsing
|
||||||
|
* @throws URISyntaxException exception to indicate that a string could not be parsed as a URI reference
|
||||||
|
*/
|
||||||
|
public static List<URI> parseXrdLinkReferencesFor(XmlPullParser parser, String relation) throws IOException, XmlPullParserException, URISyntaxException {
|
||||||
|
List<URI> uriList = new ArrayList<>();
|
||||||
|
int initialDepth = parser.getDepth();
|
||||||
|
|
||||||
|
loop: while (true) {
|
||||||
|
XmlPullParser.TagEvent tag = parser.nextTag();
|
||||||
|
switch (tag) {
|
||||||
|
case START_ELEMENT:
|
||||||
|
String name = parser.getName();
|
||||||
|
String namespace = parser.getNamespace();
|
||||||
|
String rel = parser.getAttributeValue("rel");
|
||||||
|
|
||||||
|
if (!namespace.equals(XRD_NAMESPACE) || !name.equals("Link") || !rel.equals(relation)) {
|
||||||
|
continue loop;
|
||||||
|
}
|
||||||
|
String endpointUri = parser.getAttributeValue("href");
|
||||||
|
URI uri = new URI(endpointUri);
|
||||||
|
uriList.add(uri);
|
||||||
|
break;
|
||||||
|
case END_ELEMENT:
|
||||||
|
if (parser.getDepth() == initialDepth) {
|
||||||
|
break loop;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return uriList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get remote endpoints for the provided LinkRelation from provided XmlPullParser.
|
||||||
|
*
|
||||||
|
* @param parser XmlPullParser that contains LinkRelations
|
||||||
|
* @param relation type of endpoints specified by the given LinkRelation
|
||||||
|
* @return list of endpoints
|
||||||
|
* @throws IOException exception due to input/output operations
|
||||||
|
* @throws XmlPullParserException exception encountered during XML parsing
|
||||||
|
* @throws URISyntaxException exception to indicate that a string could not be parsed as a URI reference
|
||||||
|
*/
|
||||||
|
public static List<URI> parseXrdLinkReferencesFor(XmlPullParser parser, LinkRelation relation) throws IOException, XmlPullParserException, URISyntaxException {
|
||||||
|
return parseXrdLinkReferencesFor(parser, relation.attribute);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2020 Aditya Borikar.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Smack's API for <a href="https://xmpp.org/extensions/xep-0156.html"> XEP-0156: Discovering Alternative XMPP Connection Methods</a>.
|
||||||
|
* <br>
|
||||||
|
* XEP is partially supported as HTTP lookup is supported but DNS lookup isn't.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smack.altconnections;
|
|
@ -0,0 +1,57 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2020 Aditya Borikar.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smack.altconnections;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.altconnections.HttpLookupMethod.LinkRelation;
|
||||||
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
|
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.jxmpp.stringprep.XmppStringprepException;
|
||||||
|
|
||||||
|
public class HttpLookupMethodTest {
|
||||||
|
private static final String XRD_XML = "<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'>" +
|
||||||
|
"<Link rel='urn:xmpp:alt-connections:xbosh' href='https://igniterealtime.org:443/http-bind/'/>" +
|
||||||
|
"<Link rel='urn:xmpp:alt-connections:websocket' href='wss://xmpp.igniterealtime.org:7483/ws/'/>" +
|
||||||
|
"<Link rel='urn:xmpp:alt-connections:websocket' href='ws://xmpp.igniterealtime.org:7070/ws/'/>" +
|
||||||
|
"</XRD>";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parseXrdLinkReferencesForWebsockets() throws XmppStringprepException, IOException, XmlPullParserException, URISyntaxException {
|
||||||
|
List<URI> endpoints = new ArrayList<>();
|
||||||
|
endpoints.add(new URI("wss://xmpp.igniterealtime.org:7483/ws/"));
|
||||||
|
endpoints.add(new URI("ws://xmpp.igniterealtime.org:7070/ws/"));
|
||||||
|
List<URI> expectedEndpoints = HttpLookupMethod.parseXrdLinkReferencesFor(PacketParserUtils.getParserFor(XRD_XML), LinkRelation.WEBSOCKET);
|
||||||
|
assertEquals(expectedEndpoints, endpoints);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parseXrdLinkReferencesForBosh() throws URISyntaxException, IOException, XmlPullParserException {
|
||||||
|
List<URI> endpoints = new ArrayList<>();
|
||||||
|
endpoints.add(new URI("https://igniterealtime.org:443/http-bind/"));
|
||||||
|
List<URI> expectedEndpoints = HttpLookupMethod.parseXrdLinkReferencesFor(PacketParserUtils.getParserFor(XRD_XML), LinkRelation.BOSH);
|
||||||
|
assertEquals(expectedEndpoints, endpoints);
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,7 +9,6 @@ dependencies {
|
||||||
api project(':smack-java7')
|
api project(':smack-java7')
|
||||||
api project(':smack-legacy')
|
api project(':smack-legacy')
|
||||||
api project(':smack-omemo')
|
api project(':smack-omemo')
|
||||||
api project(':smack-omemo-signal')
|
|
||||||
api project(':smack-openpgp')
|
api project(':smack-openpgp')
|
||||||
api project(':smack-resolver-minidns')
|
api project(':smack-resolver-minidns')
|
||||||
api project(':smack-resolver-minidns-dox')
|
api project(':smack-resolver-minidns-dox')
|
||||||
|
|
|
@ -17,6 +17,7 @@ dependencies {
|
||||||
// smack-java*-full and since we may want to use parts of sinttest
|
// smack-java*-full and since we may want to use parts of sinttest
|
||||||
// in the REPL, we simply depend sinttest.
|
// in the REPL, we simply depend sinttest.
|
||||||
api project(':smack-integration-test')
|
api project(':smack-integration-test')
|
||||||
|
api project(':smack-omemo-signal')
|
||||||
|
|
||||||
compile "org.scala-lang:scala-library:$scalaVersion"
|
compile "org.scala-lang:scala-library:$scalaVersion"
|
||||||
compile "com.lihaoyi:ammonite_$scalaVersion:1.3.2"
|
compile "com.lihaoyi:ammonite_$scalaVersion:1.3.2"
|
||||||
|
|
|
@ -394,7 +394,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
||||||
if (isSmResumptionPossible()) {
|
if (isSmResumptionPossible()) {
|
||||||
smResumedSyncPoint = SyncPointState.request_sent;
|
smResumedSyncPoint = SyncPointState.request_sent;
|
||||||
sendNonza(new Resume(clientHandledStanzasCount, smSessionId));
|
sendNonza(new Resume(clientHandledStanzasCount, smSessionId));
|
||||||
waitForCondition(() -> smResumedSyncPoint == SyncPointState.successful || smResumptionFailed != null, "resume previous stream");
|
waitForConditionOrConnectionException(() -> smResumedSyncPoint == SyncPointState.successful || smResumptionFailed != null, "resume previous stream");
|
||||||
if (smResumedSyncPoint == SyncPointState.successful) {
|
if (smResumedSyncPoint == SyncPointState.successful) {
|
||||||
// We successfully resumed the stream, be done here
|
// We successfully resumed the stream, be done here
|
||||||
afterSuccessfulLogin(true);
|
afterSuccessfulLogin(true);
|
||||||
|
@ -500,27 +500,30 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
||||||
if (!packetWriter.done()) {
|
if (!packetWriter.done()) {
|
||||||
// First shutdown the writer, this will result in a closing stream element getting send to
|
// First shutdown the writer, this will result in a closing stream element getting send to
|
||||||
// the server
|
// the server
|
||||||
LOGGER.finer("PacketWriter shutdown()");
|
LOGGER.finer(packetWriter.threadName + " shutdown()");
|
||||||
packetWriter.shutdown(instant);
|
packetWriter.shutdown(instant);
|
||||||
LOGGER.finer("PacketWriter has been shut down");
|
LOGGER.finer(packetWriter.threadName + " shutdown() returned");
|
||||||
|
|
||||||
if (!instant) {
|
if (!instant) {
|
||||||
waitForClosingStreamTagFromServer();
|
waitForClosingStreamTagFromServer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGGER.finer("PacketReader shutdown()");
|
LOGGER.finer(packetReader.threadName + " shutdown()");
|
||||||
packetReader.shutdown();
|
packetReader.shutdown();
|
||||||
LOGGER.finer("PacketReader has been shut down");
|
LOGGER.finer(packetReader.threadName + " shutdown() returned");
|
||||||
|
|
||||||
CloseableUtil.maybeClose(socket, LOGGER);
|
CloseableUtil.maybeClose(socket, LOGGER);
|
||||||
|
|
||||||
setWasAuthenticated();
|
setWasAuthenticated();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
boolean readerAndWriterThreadsTermianted = waitForCondition(() -> !packetWriter.running && !packetReader.running);
|
boolean readerAndWriterThreadsTermianted = waitFor(() -> !packetWriter.running && !packetReader.running);
|
||||||
if (!readerAndWriterThreadsTermianted) {
|
if (!readerAndWriterThreadsTermianted) {
|
||||||
LOGGER.severe("Reader and writer threads did not terminate");
|
LOGGER.severe("Reader and/or writer threads did not terminate timely. Writer running: "
|
||||||
|
+ packetWriter.running + ", Reader running: " + packetReader.running);
|
||||||
|
} else {
|
||||||
|
LOGGER.fine("Reader and writer threads terminated");
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
LOGGER.log(Level.FINE, "Interrupted while waiting for reader and writer threads to terminate", e);
|
LOGGER.log(Level.FINE, "Interrupted while waiting for reader and writer threads to terminate", e);
|
||||||
|
@ -909,11 +912,11 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
||||||
void init() {
|
void init() {
|
||||||
done = false;
|
done = false;
|
||||||
|
|
||||||
|
running = true;
|
||||||
Async.go(new Runnable() {
|
Async.go(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
LOGGER.finer(threadName + " start");
|
LOGGER.finer(threadName + " start");
|
||||||
running = true;
|
|
||||||
try {
|
try {
|
||||||
parsePackets();
|
parsePackets();
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -1126,6 +1129,9 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
||||||
// The exception can be ignored if the the connection is 'done'
|
// The exception can be ignored if the the connection is 'done'
|
||||||
// or if the it was caused because the socket got closed.
|
// or if the it was caused because the socket got closed.
|
||||||
if (!done) {
|
if (!done) {
|
||||||
|
// Set running to false since this thread will exit here and notifyConnectionError() will wait until
|
||||||
|
// the reader and writer thread's 'running' value is false.
|
||||||
|
running = false;
|
||||||
// Close the connection and notify connection listeners of the
|
// Close the connection and notify connection listeners of the
|
||||||
// error.
|
// error.
|
||||||
notifyConnectionError(e);
|
notifyConnectionError(e);
|
||||||
|
@ -1178,11 +1184,11 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
queue.start();
|
queue.start();
|
||||||
|
running = true;
|
||||||
Async.go(new Runnable() {
|
Async.go(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
LOGGER.finer(threadName + " start");
|
LOGGER.finer(threadName + " start");
|
||||||
running = true;
|
|
||||||
try {
|
try {
|
||||||
writePackets();
|
writePackets();
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -1269,7 +1275,6 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writePackets() {
|
private void writePackets() {
|
||||||
Exception writerException = null;
|
|
||||||
try {
|
try {
|
||||||
// Write out packets from the queue.
|
// Write out packets from the queue.
|
||||||
while (!done()) {
|
while (!done()) {
|
||||||
|
@ -1318,7 +1323,12 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
||||||
|
|
||||||
CharSequence elementXml = element.toXML(outgoingStreamXmlEnvironment);
|
CharSequence elementXml = element.toXML(outgoingStreamXmlEnvironment);
|
||||||
if (elementXml instanceof XmlStringBuilder) {
|
if (elementXml instanceof XmlStringBuilder) {
|
||||||
((XmlStringBuilder) elementXml).write(writer, outgoingStreamXmlEnvironment);
|
try {
|
||||||
|
((XmlStringBuilder) elementXml).write(writer, outgoingStreamXmlEnvironment);
|
||||||
|
} catch (NullPointerException npe) {
|
||||||
|
LOGGER.log(Level.FINE, "NPE in XmlStringBuilder of " + element.getClass() + ": " + element, npe);
|
||||||
|
throw npe;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
writer.write(elementXml.toString());
|
writer.write(elementXml.toString());
|
||||||
|
@ -1374,15 +1384,14 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
||||||
// The exception can be ignored if the the connection is 'done'
|
// The exception can be ignored if the the connection is 'done'
|
||||||
// or if the it was caused because the socket got closed
|
// or if the it was caused because the socket got closed
|
||||||
if (!(done() || queue.isShutdown())) {
|
if (!(done() || queue.isShutdown())) {
|
||||||
writerException = e;
|
// Set running to false since this thread will exit here and notifyConnectionError() will wait until
|
||||||
|
// the reader and writer thread's 'running' value is false.
|
||||||
|
running = false;
|
||||||
|
notifyConnectionError(e);
|
||||||
} else {
|
} else {
|
||||||
LOGGER.log(Level.FINE, "Ignoring Exception in writePackets()", e);
|
LOGGER.log(Level.FINE, "Ignoring Exception in writePackets()", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Delay notifyConnectionError after shutdownDone has been reported in the finally block.
|
|
||||||
if (writerException != null) {
|
|
||||||
notifyConnectionError(writerException);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drainWriterQueueToUnacknowledgedStanzas() {
|
private void drainWriterQueueToUnacknowledgedStanzas() {
|
||||||
|
|
2
version
2
version
|
@ -1 +1 @@
|
||||||
4.4.0-alpha5-SNAPSHOT
|
4.4.0-alpha6-SNAPSHOT
|
||||||
|
|
Loading…
Reference in a new issue