com.relayrides.pushy.apns
Class PushManager<T extends ApnsPushNotification>

java.lang.Object
  extended by com.relayrides.pushy.apns.PushManager<T>

public class PushManager<T extends ApnsPushNotification>
extends Object

A PushManager is the main public-facing point of interaction with APNs. PushManagers manage the queue of outbound push notifications and manage connections to the various APNs servers.

Author:
Jon Chambers

Constructor Summary
PushManager(ApnsEnvironment environment, KeyStore keyStore, char[] keyStorePassword)
          Constructs a new PushManager that operates in the given environment with the given credentials and a single connection to APNs.
PushManager(ApnsEnvironment environment, KeyStore keyStore, char[] keyStorePassword, int concurrentConnections)
          Constructs a new PushManager that operates in the given environment with the given credentials and the given number of parallel connections to APNs.
 
Method Summary
 void enqueueAllNotifications(Collection<T> notifications)
          Enqueues a collection of push notifications for transmission to the APNs service.
 void enqueuePushNotification(T notification)
          Enqueues a push notification for transmission to the APNs service.
 ApnsEnvironment getEnvironment()
          Returns the environment in which this PushManager is operating.
 List<ExpiredToken> getExpiredTokens()
          Queries the APNs feedback service for expired tokens.
 KeyStore getKeyStore()
          Returns the KeyStore containing the client certificate to presented to TLS-enabled APNs servers.
 char[] getKeyStorePassword()
          Returns the key to unlock the KeyStore for this PushManager.
 void registerRejectedNotificationListener(RejectedNotificationListener<T> listener)
          Registers a listener for notifications rejected by APNs for specific reasons.
 List<T> shutdown()
          Disconnects from the APNs and gracefully shuts down all worker threads.
 void start()
          Opens all connections to APNs and prepares to send push notifications.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PushManager

public PushManager(ApnsEnvironment environment,
                   KeyStore keyStore,
                   char[] keyStorePassword)
Constructs a new PushManager that operates in the given environment with the given credentials and a single connection to APNs.

Parameters:
environment - the environment in which this PushManager operates
keyStore - A KeyStore containing the client key to present during a TLS handshake; may be null if the environment does not require TLS. The KeyStore should be loaded before being used here.
keyStorePassword - a password to unlock the given KeyStore; may be null

PushManager

public PushManager(ApnsEnvironment environment,
                   KeyStore keyStore,
                   char[] keyStorePassword,
                   int concurrentConnections)

Constructs a new PushManager that operates in the given environment with the given credentials and the given number of parallel connections to APNs. See Best Practices for Managing Connections for additional information.

Parameters:
environment - the environment in which this PushManager operates
keyStore - A KeyStore containing the client key to present during a TLS handshake; may be null if the environment does not require TLS. The KeyStore should be loaded before being used here.
keyStorePassword - a password to unlock the given KeyStore; may be null
concurrentConnections - the number of parallel connections to open to APNs
Method Detail

getEnvironment

public ApnsEnvironment getEnvironment()
Returns the environment in which this PushManager is operating.

Returns:
the environment in which this PushManager is operating

getKeyStore

public KeyStore getKeyStore()
Returns the KeyStore containing the client certificate to presented to TLS-enabled APNs servers.

Returns:
the KeyStore containing the client certificate to presented to TLS-enabled APNs servers

getKeyStorePassword

public char[] getKeyStorePassword()
Returns the key to unlock the KeyStore for this PushManager.

Returns:
the key to unlock the KeyStore for this PushManager

start

public void start()
Opens all connections to APNs and prepares to send push notifications. Note that enqueued push notifications will not be sent until this method is called.


enqueuePushNotification

public void enqueuePushNotification(T notification)

Enqueues a push notification for transmission to the APNs service. Notifications may not be sent to APNs immediately, and delivery is not guaranteed by APNs, but notifications rejected by APNs for specific reasons will be passed to registered RejectedNotificationListeners.

Parameters:
notification - the notification to enqueue
See Also:
registerRejectedNotificationListener(RejectedNotificationListener)

enqueueAllNotifications

public void enqueueAllNotifications(Collection<T> notifications)

Enqueues a collection of push notifications for transmission to the APNs service. Notifications may not be sent to APNs immediately, and delivery is not guaranteed by APNs, but notifications rejected by APNs for specific reasons will be passed to registered RejectedNotificationListeners.

Parameters:
notifications - the notifications to enqueue
See Also:
registerRejectedNotificationListener(RejectedNotificationListener)

shutdown

public List<T> shutdown()
                                              throws InterruptedException
Disconnects from the APNs and gracefully shuts down all worker threads.

Returns:
a list of notifications not sent before the PushManager shut down
Throws:
InterruptedException - if interrupted while waiting for worker threads to exit cleanly

registerRejectedNotificationListener

public void registerRejectedNotificationListener(RejectedNotificationListener<T> listener)

Registers a listener for notifications rejected by APNs for specific reasons. Note that listeners are stored as weak references, so callers should maintain a reference to listeners to prevent them from being garbage collected.

Parameters:
listener - the listener to register

getExpiredTokens

public List<ExpiredToken> getExpiredTokens()
                                    throws InterruptedException

Queries the APNs feedback service for expired tokens. Be warned that this is a destructive operation. According to Apple's documentation:

The feedback service’s list is cleared after you read it. Each time you connect to the feedback service, the information it returns lists only the failures that have happened since you last connected.

Returns:
a list of tokens that have expired since the last connection to the feedback service
Throws:
InterruptedException - if interrupted while waiting for a response from the feedback service


Copyright © 2013 RelayRides. All rights reserved.