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();
}
}
}
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();
}
}
}
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();
}
}
}
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));
}
}
}
}
Aggregations