Skip to content

Commit

Permalink
more flexible delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
notnoop committed Jun 25, 2011
1 parent 8cd7844 commit 16807c1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
39 changes: 27 additions & 12 deletions src/main/java/com/notnoop/mpns/MpnsResponse.java
Expand Up @@ -37,54 +37,54 @@ public enum MpnsResponse {
/*
* 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
Expand All @@ -93,7 +93,7 @@ public enum MpnsResponse {
* 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
Expand All @@ -102,28 +102,35 @@ public enum MpnsResponse {
* 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() {
Expand All @@ -141,4 +148,12 @@ public String getDeviceConnectionStatus() {
public String getSubscriptionStatus() {
return subscriptionStatus;
}

public boolean isSuccessful() {
return success;
}

public boolean shouldRetry() {
return shouldRetry;
}
}
6 changes: 5 additions & 1 deletion src/main/java/com/notnoop/mpns/internal/Utilities.java
Expand Up @@ -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.