Permalink
Browse files

more flexible delegate

  • Loading branch information...
1 parent 8cd7844 commit 16807c1cb151f84c5b85e601c7544da98961b2b0 @notnoop committed Jun 25, 2011
@@ -37,54 +37,54 @@
/*
* The notification request was accepted and queued for delivery.
*/
- RECEIVED(200, "Received", "Connected", "Active"),
+ RECEIVED(200, "Received", "Connected", "Active", true, false),
/**
* The notification request was accepted and queued for delivery. However,
* the device is temporarily disconnected.
*/
- QUEUED(200, "Received", "Temporarily Disconnected", "Active"),
+ QUEUED(200, "Received", "Temporarily Disconnected", "Active", true, false),
/**
* Queue overflow. The web service should re-send the notification later.
* A best practice is to use an exponential backoff algorithm in minute
* increments.
*/
- QUEUE_FULL(200, "QueueFull", null, "Active"),
+ QUEUE_FULL(200, "QueueFull", null, "Active", false, true),
/**
* The push notification was received and dropped by the Push Notification
* Service. The Suppressed status can occur if the notification channel
* was configured to suppress push notifications for a particular push
* notification class.
*/
- SUPPRESSED(200, "Suppressed", null, "Active"),
+ SUPPRESSED(200, "Suppressed", null, "Active", false, false),
/**
* This error occurs when the web service sends a notification request
* with a bad XML document or malformed notification URI.
*/
- BAD_REQUEST(400, null, null, null),
+ BAD_REQUEST(400, null, null, null, false, false),
/**
* Sending this notification is unauthorized. This error can occur for one
* of the following reasons:
*/
- UNAUTHORIZED(401, null, null, null),
+ UNAUTHORIZED(401, null, null, null, false, false),
/**
* The subscription is invalid and is not present on the Push Notification
* Service. The web service should stop sending new notifications to this
* subscription, and drop the subscription state for its corresponding
* application session.
*/
- EXPIRED(404, "Dropped", null, "Expired"),
+ EXPIRED(404, "Dropped", null, "Expired", false, false),
/**
* Invalid method (PUT, DELETE, CREATE). Only POST is allowed when sending
* a notification request.
*/
- METHOD_NOT_ALLOWED(405, null, null, null),
+ METHOD_NOT_ALLOWED(405, null, null, null, false, false),
/**
* This error occurs when an unauthenticated web service has reached the
@@ -93,7 +93,7 @@
* error. The web service may need to wait up to 24 hours before normal
* notification flow will resume.
*/
- OVER_LIMIT(406, "Dropped", null, "Active"),
+ OVER_LIMIT(406, "Dropped", null, "Active", false, true),
/**
* The device is in an inactive state. The web service may re-attempt
@@ -102,28 +102,35 @@
* hour, the Push Notification Service will de-register or permanently
* block the web service.
*/
- INACTIVATE_STATE(412, "Dropped", "Inactive", null),
+ INACTIVATE_STATE(412, "Dropped", "Inactive", null, false, true),
/**
* The Push Notification Service is unable to process the request. The web
* service should re-send the notification later. A best practice is to
* use an exponential backoff algorithm in minute increments.
*/
- SERVICE_UNAVAILABLE(503, null, null, null);
+ SERVICE_UNAVAILABLE(503, null, null, null, false, true);
//// Response Code,NotificationStatus,DeviceConnectionStatus,SubscriptionStatus,Comments
private final int responseCode;
private final String notificationStatus;
private final String deviceConnectionStatus;
private final String subscriptionStatus;
+ private final boolean success;
+ private final boolean shouldRetry;
+
MpnsResponse(int responseCode, String notificationStatus,
String deviceConnectionStatus,
- String subscriptionStatus) {
+ String subscriptionStatus,
+ boolean success,
+ boolean requiresRetry) {
this.responseCode = responseCode;
this.notificationStatus = notificationStatus;
this.deviceConnectionStatus = deviceConnectionStatus;
this.subscriptionStatus = subscriptionStatus;
+ this.success = success;
+ this.shouldRetry = requiresRetry;
}
public int getResponseCode() {
@@ -141,4 +148,12 @@ public String getDeviceConnectionStatus() {
public String getSubscriptionStatus() {
return subscriptionStatus;
}
+
+ public boolean isSuccessful() {
+ return success;
+ }
+
+ public boolean shouldRetry() {
+ return shouldRetry;
+ }
}
@@ -160,7 +160,11 @@ public static void fireDelegate(MpnsNotification message, HttpResponse response,
if (delegate != null) {
MpnsResponse r = Utilities.logicalResponseFor(response);
- delegate.messageSent(message, r);
+ if (r.isSuccessful()) {
+ delegate.messageSent(message, r);
+ } else {
+ delegate.messageFailed(message, r);
+ }
}
}
}

0 comments on commit 16807c1

Please sign in to comment.