Search in sources :

Example 1 with BackOffStrategy

use of com.wedevol.xmpp.util.BackOffStrategy in project fcmxmppserverv2 by carlosCharz.

the class CcsClient method sendPacket.

/**
 * Sends a downstream message to FCM with back off strategy
 */
public void sendPacket(String jsonRequest) {
    final Stanza request = new FcmPacketExtension(jsonRequest).toPacket();
    final BackOffStrategy backoff = new BackOffStrategy();
    while (backoff.shouldRetry()) {
        try {
            connection.sendStanza(request);
            backoff.doNotRetry();
        } catch (NotConnectedException | InterruptedException e) {
            logger.log(Level.INFO, "The packet could not be sent due to a connection problem. Packet: " + request.toXML());
            backoff.errorOccured();
        }
    }
}
Also used : BackOffStrategy(com.wedevol.xmpp.util.BackOffStrategy) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) Stanza(org.jivesoftware.smack.packet.Stanza) ForEveryStanza(org.jivesoftware.smack.sm.predicates.ForEveryStanza)

Example 2 with BackOffStrategy

use of com.wedevol.xmpp.util.BackOffStrategy in project fcmxmppserverv2 by carlosCharz.

the class CcsClient method reconnect.

private synchronized void reconnect() {
    logger.info("Initiating reconnection ...");
    final BackOffStrategy backoff = new BackOffStrategy(5, 1000);
    while (backoff.shouldRetry()) {
        try {
            connect();
            sendQueuedMessages();
            backoff.doNotRetry();
        } catch (XMPPException | SmackException | IOException | InterruptedException | KeyManagementException | NoSuchAlgorithmException e) {
            logger.info("The notifier server could not reconnect after the connection draining message.");
            backoff.errorOccured();
        }
    }
}
Also used : BackOffStrategy(com.wedevol.xmpp.util.BackOffStrategy) SmackException(org.jivesoftware.smack.SmackException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) XMPPException(org.jivesoftware.smack.XMPPException) KeyManagementException(java.security.KeyManagementException)

Example 3 with BackOffStrategy

use of com.wedevol.xmpp.util.BackOffStrategy in project fcmxmppserverv2 by carlosCharz.

the class CcsClient method sendAck.

/**
 * Sends an ACK to FCM with back off strategy
 *
 * @param jsonRequest
 */
private void sendAck(String jsonRequest) {
    logger.info("Sending ack.");
    final Stanza packet = new FcmPacketExtension(jsonRequest).toPacket();
    final BackOffStrategy backoff = new BackOffStrategy();
    while (backoff.shouldRetry()) {
        try {
            xmppConn.sendStanza(packet);
            backoff.doNotRetry();
        } catch (NotConnectedException | InterruptedException e) {
            logger.info("The packet could not be sent due to a connection problem. Backing off the packet: {}", packet.toXML(null));
            backoff.errorOccured();
        }
    }
}
Also used : BackOffStrategy(com.wedevol.xmpp.util.BackOffStrategy) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) Stanza(org.jivesoftware.smack.packet.Stanza) ForEveryStanza(org.jivesoftware.smack.sm.predicates.ForEveryStanza)

Example 4 with BackOffStrategy

use of com.wedevol.xmpp.util.BackOffStrategy in project fcmxmppserverv2 by carlosCharz.

the class CcsClient method sendDownstreamMessageInternal.

/**
 * Sends a downstream message to FCM with back off strategy
 */
private void sendDownstreamMessageInternal(String messageId, String jsonRequest) {
    final Stanza request = new FcmPacketExtension(jsonRequest).toPacket();
    final BackOffStrategy backoff = new BackOffStrategy();
    while (backoff.shouldRetry()) {
        try {
            xmppConn.sendStanza(request);
            backoff.doNotRetry();
        } catch (NotConnectedException | InterruptedException e) {
            logger.info("The packet could not be sent due to a connection problem. Backing off the packet: {}", request.toXML(null));
            try {
                backoff.errorOccured2();
            } catch (Exception e2) {
                // all the attempts failed
                removeMessageFromSyncMessages(messageId);
                pendingMessages.put(messageId, Message.from(jsonRequest));
            }
        }
    }
}
Also used : BackOffStrategy(com.wedevol.xmpp.util.BackOffStrategy) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) Stanza(org.jivesoftware.smack.packet.Stanza) ForEveryStanza(org.jivesoftware.smack.sm.predicates.ForEveryStanza) SmackException(org.jivesoftware.smack.SmackException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) XMPPException(org.jivesoftware.smack.XMPPException)

Aggregations

BackOffStrategy (com.wedevol.xmpp.util.BackOffStrategy)4 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)3 Stanza (org.jivesoftware.smack.packet.Stanza)3 ForEveryStanza (org.jivesoftware.smack.sm.predicates.ForEveryStanza)3 IOException (java.io.IOException)2 KeyManagementException (java.security.KeyManagementException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 SmackException (org.jivesoftware.smack.SmackException)2 XMPPException (org.jivesoftware.smack.XMPPException)2 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)1