javapns.notification
Class PushNotificationManager

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

public class PushNotificationManager
extends Object

The main class used to send notification and handle a connection to Apple SSLServerSocket. This class is not multi-threaded. One instance per thread must be created.

Author:
Maxime Pilon, Sylvain Pedneault, Others...

Constructor Summary
PushNotificationManager()
          Constructs a PushNotificationManager
PushNotificationManager(DeviceFactory deviceManager)
          Deprecated. The DeviceFactory-based architecture is deprecated.
 
Method Summary
 void addDevice(String id, String token)
          Deprecated. The DeviceFactory-based architecture is deprecated.
 Device getDevice(String id)
          Deprecated. The DeviceFactory-based architecture is deprecated.
 DeviceFactory getDeviceFactory()
          Deprecated. The DeviceFactory-based architecture is deprecated.
static long getRestartConnectionAfterInactivity()
           
 int getRetryAttempts()
          Get the number of retry attempts
 int getSslSocketTimeout()
          Get the SSL socket timeout currently in use.
 void initializeConnection(AppleNotificationServer server)
          Initialize a connection and create a SSLSocket
 void initializePreviousConnection()
          Initialize a connection using server settings from the previous connection.
static boolean isResendFeatureEnabled()
           
 void removeDevice(String id)
          Deprecated. The DeviceFactory-based architecture is deprecated.
 void restartConnection(AppleNotificationServer server)
          Stop and restart the current connection to the Apple server
 PushedNotification sendNotification(Device device, Payload payload)
          Send a notification to a single device and close the connection.
 PushedNotification sendNotification(Device device, Payload payload, boolean closeAfter)
          Send a notification (Payload) to the given device
 PushedNotification sendNotification(Device device, Payload payload, boolean closeAfter, int identifier)
          Send a notification (Payload) to the given device
 PushedNotification sendNotification(Device device, Payload payload, int identifier)
          Send a notification (Payload) to the given device
 PushedNotifications sendNotifications(Payload payload, Device... devices)
          Send a notification to a multiple devices in a single connection and close the connection.
 PushedNotifications sendNotifications(Payload payload, List<Device> devices)
          Send a notification to a multiple devices in a single connection and close the connection.
 void setDeviceFactory(DeviceFactory deviceFactory)
          Deprecated. The DeviceFactory-based architecture is deprecated.
static void setEnhancedNotificationFormatEnabled(boolean enabled)
          Enable or disable the enhanced notification format (enabled by default).
static void setHeavyDebugMode(boolean enabled)
          Enable or disable a special heavy debug mode which causes verbose details to be written to local files.
static void setResendFeatureEnabled(boolean resendFeatureEnabled)
           
static void setRestartConnectionAfterInactivity(long restartConnectionAfterInactivity)
           
 void setRetryAttempts(int retryAttempts)
          Set the number of retry attempts
 void setSslSocketTimeout(int sslSocketTimeout)
          Set the SSL socket timeout to use.
 void setTrustAllServerCertificates(boolean trustAllServerCertificates)
          Set whether or not to enable the "trust all server certificates" feature to simplify SSL communications.
 void stopConnection()
          Read and process any pending error-responses, and then close the connection.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PushNotificationManager

public PushNotificationManager()
Constructs a PushNotificationManager


PushNotificationManager

@Deprecated
public PushNotificationManager(DeviceFactory deviceManager)
Deprecated. The DeviceFactory-based architecture is deprecated.

Constructs a PushNotificationManager using a supplied DeviceFactory

Parameters:
deviceManager -
Method Detail

initializeConnection

public void initializeConnection(AppleNotificationServer server)
                          throws CommunicationException,
                                 KeystoreException
Initialize a connection and create a SSLSocket

Parameters:
server - The Apple server to connect to.
Throws:
CommunicationException - thrown if a communication error occurs
KeystoreException - thrown if there is a problem with your keystore

initializePreviousConnection

public void initializePreviousConnection()
                                  throws CommunicationException,
                                         KeystoreException
Initialize a connection using server settings from the previous connection.

Throws:
CommunicationException - thrown if a communication error occurs
KeystoreException - thrown if there is a problem with your keystore

restartConnection

public void restartConnection(AppleNotificationServer server)
                       throws CommunicationException,
                              KeystoreException
Stop and restart the current connection to the Apple server

Parameters:
server - the server to start
Throws:
CommunicationException - thrown if a communication error occurs
KeystoreException - thrown if there is a problem with your keystore

stopConnection

public void stopConnection()
                    throws CommunicationException,
                           KeystoreException
Read and process any pending error-responses, and then close the connection.

Throws:
CommunicationException - thrown if a communication error occurs
KeystoreException - thrown if there is a problem with your keystore

sendNotification

public PushedNotification sendNotification(Device device,
                                           Payload payload)
                                    throws CommunicationException
Send a notification to a single device and close the connection.

Parameters:
device - the device to be notified
payload - the payload to send
Returns:
a pushed notification with details on transmission result and error (if any)
Throws:
CommunicationException - thrown if a communication error occurs

sendNotifications

public PushedNotifications sendNotifications(Payload payload,
                                             List<Device> devices)
                                      throws CommunicationException,
                                             KeystoreException
Send a notification to a multiple devices in a single connection and close the connection.

Parameters:
payload - the payload to send
devices - the device to be notified
Returns:
a list of pushed notifications, each with details on transmission results and error (if any)
Throws:
CommunicationException - thrown if a communication error occurs
KeystoreException - thrown if there is a problem with your keystore

sendNotifications

public PushedNotifications sendNotifications(Payload payload,
                                             Device... devices)
                                      throws CommunicationException,
                                             KeystoreException
Send a notification to a multiple devices in a single connection and close the connection.

Parameters:
payload - the payload to send
devices - the device to be notified
Returns:
a list of pushed notifications, each with details on transmission results and error (if any)
Throws:
CommunicationException - thrown if a communication error occurs
KeystoreException - thrown if there is a problem with your keystore

sendNotification

public PushedNotification sendNotification(Device device,
                                           Payload payload,
                                           boolean closeAfter)
                                    throws CommunicationException
Send a notification (Payload) to the given device

Parameters:
device - the device to be notified
payload - the payload to send
closeAfter - indicates if the connection should be closed after the payload has been sent
Returns:
a pushed notification with details on transmission result and error (if any)
Throws:
CommunicationException - thrown if a communication error occurs

sendNotification

public PushedNotification sendNotification(Device device,
                                           Payload payload,
                                           int identifier)
                                    throws CommunicationException
Send a notification (Payload) to the given device

Parameters:
device - the device to be notified
payload - the payload to send
identifier - a unique identifier which will match any error reported later (if any)
Returns:
a pushed notification with details on transmission result and error (if any)
Throws:
CommunicationException - thrown if a communication error occurs

sendNotification

public PushedNotification sendNotification(Device device,
                                           Payload payload,
                                           boolean closeAfter,
                                           int identifier)
                                    throws CommunicationException
Send a notification (Payload) to the given device

Parameters:
device - the device to be notified
payload - the payload to send
closeAfter - indicates if the connection should be closed after the payload has been sent
identifier - a unique identifier which will match any error reported later (if any)
Returns:
a pushed notification with details on transmission result and error (if any)
Throws:
CommunicationException - thrown if a communication error occurs

addDevice

@Deprecated
public void addDevice(String id,
                                 String token)
               throws DuplicateDeviceException,
                      NullIdException,
                      NullDeviceTokenException,
                      Exception
Deprecated. The DeviceFactory-based architecture is deprecated.

Add a device

Parameters:
id - The device id
token - The device token
Throws:
DuplicateDeviceException
NullDeviceTokenException
NullIdException
Exception

getDevice

@Deprecated
public Device getDevice(String id)
                 throws UnknownDeviceException,
                        NullIdException
Deprecated. The DeviceFactory-based architecture is deprecated.

Get a device according to his id

Parameters:
id - The device id
Returns:
The device
Throws:
UnknownDeviceException
NullIdException

removeDevice

@Deprecated
public void removeDevice(String id)
                  throws UnknownDeviceException,
                         NullIdException
Deprecated. The DeviceFactory-based architecture is deprecated.

Remove a device

Parameters:
id - The device id
Throws:
UnknownDeviceException
NullIdException

getRetryAttempts

public int getRetryAttempts()
Get the number of retry attempts

Returns:
int

setRetryAttempts

public void setRetryAttempts(int retryAttempts)
Set the number of retry attempts

Parameters:
retryAttempts -

setDeviceFactory

@Deprecated
public void setDeviceFactory(DeviceFactory deviceFactory)
Deprecated. The DeviceFactory-based architecture is deprecated.

Sets the DeviceFactory used by this PushNotificationManager. Usually useful for dependency injection.

Parameters:
deviceFactory - an object implementing DeviceFactory

getDeviceFactory

@Deprecated
public DeviceFactory getDeviceFactory()
Deprecated. The DeviceFactory-based architecture is deprecated.

Returns the DeviceFactory used by this PushNotificationManager.

Returns:
the DeviceFactory in use

setSslSocketTimeout

public void setSslSocketTimeout(int sslSocketTimeout)
Set the SSL socket timeout to use.

Parameters:
sslSocketTimeout -

getSslSocketTimeout

public int getSslSocketTimeout()
Get the SSL socket timeout currently in use.

Returns:
the current SSL socket timeout value.

setTrustAllServerCertificates

public void setTrustAllServerCertificates(boolean trustAllServerCertificates)
Set whether or not to enable the "trust all server certificates" feature to simplify SSL communications.

Parameters:
trustAllServerCertificates -

setEnhancedNotificationFormatEnabled

public static void setEnhancedNotificationFormatEnabled(boolean enabled)
Enable or disable the enhanced notification format (enabled by default).

Parameters:
enabled - true to enable, false to disable

setHeavyDebugMode

public static void setHeavyDebugMode(boolean enabled)
Enable or disable a special heavy debug mode which causes verbose details to be written to local files. The last raw APSN message will be written to a "apns-message.bytes" file in the working directory. A detailed description of local and peer SSL certificates will be written to a "apns-certificatechain.txt" file in the working directory.

Parameters:
enabled - true to enable, false to disable

setResendFeatureEnabled

public static void setResendFeatureEnabled(boolean resendFeatureEnabled)

isResendFeatureEnabled

public static boolean isResendFeatureEnabled()

setRestartConnectionAfterInactivity

public static void setRestartConnectionAfterInactivity(long restartConnectionAfterInactivity)

getRestartConnectionAfterInactivity

public static long getRestartConnectionAfterInactivity()