You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/04/28 16:04:46 UTC
[2/2] camel git commit: CAMEL-6256: Re-creating xmpp connection
should clear out old stale connection during creation so you do not get a non
working connection next time. Thanks to Prakash Shetty for details.
CAMEL-6256: Re-creating xmpp connection should clear out old stale connection during creation so you do not get a non working connection next time. Thanks to Prakash Shetty for details.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/fa3ec4d9
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/fa3ec4d9
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/fa3ec4d9
Branch: refs/heads/camel-2.16.x
Commit: fa3ec4d997aab907c820782a7ffbf17836993840
Parents: 6beac84
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Apr 28 16:03:53 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Apr 28 16:04:33 2016 +0200
----------------------------------------------------------------------
.../camel/component/xmpp/XmppEndpoint.java | 36 ++++++++++++--------
1 file changed, 21 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/fa3ec4d9/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppEndpoint.java b/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppEndpoint.java
index a6659a1..d029054 100644
--- a/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppEndpoint.java
+++ b/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppEndpoint.java
@@ -54,7 +54,7 @@ import org.slf4j.LoggerFactory;
public class XmppEndpoint extends DefaultEndpoint implements HeaderFilterStrategyAware {
private static final Logger LOG = LoggerFactory.getLogger(XmppEndpoint.class);
- private XMPPConnection connection;
+ private volatile XMPPConnection connection;
private XmppBinding binding;
@UriPath @Metadata(required = "true")
@@ -152,56 +152,62 @@ public class XmppEndpoint extends DefaultEndpoint implements HeaderFilterStrateg
public synchronized XMPPConnection createConnection() throws XMPPException, SmackException, IOException {
if (connection != null && connection.isConnected()) {
+ // use existing working connection
return connection;
}
- if (connection == null) {
- connection = createConnectionInternal();
- }
+ // prepare for creating new connection
+ connection = null;
+
+ LOG.trace("Creating new connection ...");
+ XMPPConnection newConnection = createConnectionInternal();
- connection.connect();
+ newConnection.connect();
- connection.addPacketListener(new XmppLogger("INBOUND"), new PacketFilter() {
+ newConnection.addPacketListener(new XmppLogger("INBOUND"), new PacketFilter() {
public boolean accept(Packet packet) {
return true;
}
});
- connection.addPacketSendingListener(new XmppLogger("OUTBOUND"), new PacketFilter() {
+ newConnection.addPacketSendingListener(new XmppLogger("OUTBOUND"), new PacketFilter() {
public boolean accept(Packet packet) {
return true;
}
});
- if (!connection.isAuthenticated()) {
+ if (!newConnection.isAuthenticated()) {
if (user != null) {
if (LOG.isDebugEnabled()) {
- LOG.debug("Logging in to XMPP as user: {} on connection: {}", user, getConnectionMessage(connection));
+ LOG.debug("Logging in to XMPP as user: {} on connection: {}", user, getConnectionMessage(newConnection));
}
if (password == null) {
- LOG.warn("No password configured for user: {} on connection: {}", user, getConnectionMessage(connection));
+ LOG.warn("No password configured for user: {} on connection: {}", user, getConnectionMessage(newConnection));
}
if (createAccount) {
- AccountManager accountManager = AccountManager.getInstance(connection);
+ AccountManager accountManager = AccountManager.getInstance(newConnection);
accountManager.createAccount(user, password);
}
if (login) {
if (resource != null) {
- connection.login(user, password, resource);
+ newConnection.login(user, password, resource);
} else {
- connection.login(user, password);
+ newConnection.login(user, password);
}
}
} else {
if (LOG.isDebugEnabled()) {
- LOG.debug("Logging in anonymously to XMPP on connection: {}", getConnectionMessage(connection));
+ LOG.debug("Logging in anonymously to XMPP on connection: {}", getConnectionMessage(newConnection));
}
- connection.loginAnonymously();
+ newConnection.loginAnonymously();
}
// presence is not needed to be sent after login
}
+ // okay new connection was created successfully so assign it as the connection
+ LOG.debug("Created new connection successfully: {}", newConnection);
+ connection = newConnection;
return connection;
}