javapns.notification
Class PushedNotification

java.lang.Object
  extended by javapns.notification.PushedNotification

public class PushedNotification
extends Object

An object representing the result of a push notification to a specific payload to a single device.

If any error occurred while trying to push the notification, an exception is attached.

If Apple's Push Notification Service returned an error-response packet, it is linked to the related PushedNotification so you can find out what the actual error was.

Author:
Sylvain Pedneault

Constructor Summary
protected PushedNotification(Device device, Payload payload)
           
  PushedNotification(Device device, Payload payload, Exception exception)
           
protected PushedNotification(Device device, Payload payload, int identifier)
           
 
Method Summary
protected  void addTransmissionAttempt()
           
static List<PushedNotification> findFailedNotifications(List<PushedNotification> notifications)
          Filters a list of pushed notifications and returns only the ones that failed.
static List<PushedNotification> findSuccessfulNotifications(List<PushedNotification> notifications)
          Filters a list of pushed notifications and returns only the ones that were successful.
 Device getDevice()
          Returns the device that the payload was pushed to.
 Exception getException()
          Get the exception that occurred while trying to push this notification, if any.
 long getExpiry()
          Returns the expiration date of the push notification.
 int getIdentifier()
          Returns the connection-unique identifier referred to by error-response packets.
 String getLatestTransmissionAttempt()
          Returns a human-friendly description of the number of attempts made to transmit the notification.
 Payload getPayload()
          Returns the payload that was pushed.
 ResponsePacket getResponse()
          If a response packet regarding this notification was received, this method returns it.
 int getTransmissionAttempts()
          Returns the number of attempts that have been made to transmit the notification.
 boolean isSuccessful()
          Returns true if no response packet was received for this notification, or if one was received but is not an error-response (ie command 8), or if one was received but its status is 0 (no error occurred).
 boolean isTransmissionCompleted()
          Indicates if the notification has been streamed successfully to Apple's server.
protected  void setDevice(Device device)
           
protected  void setExpiry(long expiry)
           
protected  void setIdentifier(int identifier)
           
protected  void setPayload(Payload payload)
           
protected  void setResponse(ResponsePacket response)
           
protected  void setTransmissionAttempts(int transmissionAttempts)
           
protected  void setTransmissionCompleted(boolean completed)
           
 String toString()
          Returns a human-friendly description of this pushed notification.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PushedNotification

protected PushedNotification(Device device,
                             Payload payload)

PushedNotification

protected PushedNotification(Device device,
                             Payload payload,
                             int identifier)

PushedNotification

public PushedNotification(Device device,
                          Payload payload,
                          Exception exception)
Method Detail

getPayload

public Payload getPayload()
Returns the payload that was pushed.

Returns:
the payload that was pushed

setPayload

protected void setPayload(Payload payload)

getDevice

public Device getDevice()
Returns the device that the payload was pushed to.

Returns:
the device that the payload was pushed to

setDevice

protected void setDevice(Device device)

getIdentifier

public int getIdentifier()
Returns the connection-unique identifier referred to by error-response packets.

Returns:
a connection-unique identifier

setIdentifier

protected void setIdentifier(int identifier)

getExpiry

public long getExpiry()
Returns the expiration date of the push notification.

Returns:
the expiration date of the push notification.

setExpiry

protected void setExpiry(long expiry)

setTransmissionAttempts

protected void setTransmissionAttempts(int transmissionAttempts)

addTransmissionAttempt

protected void addTransmissionAttempt()

getTransmissionAttempts

public int getTransmissionAttempts()
Returns the number of attempts that have been made to transmit the notification.

Returns:
a number of attempts

getLatestTransmissionAttempt

public String getLatestTransmissionAttempt()
Returns a human-friendly description of the number of attempts made to transmit the notification.

Returns:
a human-friendly description of the number of attempts made to transmit the notification

setTransmissionCompleted

protected void setTransmissionCompleted(boolean completed)

isTransmissionCompleted

public boolean isTransmissionCompleted()
Indicates if the notification has been streamed successfully to Apple's server. This does not indicate if an error-response was received or not, but simply that the library successfully completed the transmission of the notification to Apple's server.

Returns:
true if the notification was successfully streamed to Apple, false otherwise

setResponse

protected void setResponse(ResponsePacket response)

getResponse

public ResponsePacket getResponse()
If a response packet regarding this notification was received, this method returns it. Otherwise it returns null.

Returns:
a response packet, if one was received for this notification

isSuccessful

public boolean isSuccessful()

Returns true if no response packet was received for this notification, or if one was received but is not an error-response (ie command 8), or if one was received but its status is 0 (no error occurred).

Returns false if an error-response packet is attached and has a non-zero status code.

Returns false if an exception is attached.

Make sure you use the Feedback Service to cleanup your list of invalid device tokens, as Apple's documentation says.

Returns:
true if push was successful, false otherwise

findSuccessfulNotifications

public static List<PushedNotification> findSuccessfulNotifications(List<PushedNotification> notifications)
Filters a list of pushed notifications and returns only the ones that were successful.

Parameters:
notifications - a list of pushed notifications
Returns:
a filtered list containing only notifications that were succcessful

findFailedNotifications

public static List<PushedNotification> findFailedNotifications(List<PushedNotification> notifications)
Filters a list of pushed notifications and returns only the ones that failed.

Parameters:
notifications - a list of pushed notifications
Returns:
a filtered list containing only notifications that were not successful

toString

public String toString()
Returns a human-friendly description of this pushed notification.

Overrides:
toString in class Object

getException

public Exception getException()
Get the exception that occurred while trying to push this notification, if any.

Returns:
an exception (if any was thrown)


Copyright © 2013. All Rights Reserved.