public class NotificationThread extends Object implements Runnable, PushQueue
A NotificationThread is created with one of two modes: LIST or QUEUE. In LIST mode, the thread is given a predefined list of devices and pushes all notifications as soon as it is started. Its work is complete and the thread ends as soon as all notifications have been sent. In QUEUE mode, the thread is started with no notification to send. It opens a connection and waits for messages to be added to its queue using the addMessageToQueue(..) method. This lifecyle is useful for creating connection pools.
No more than maxNotificationsPerConnection are pushed over a single connection.
When that maximum is reached, the connection is restarted automatically and push continues.
This is intended to avoid an undocumented notification-per-connection limit observed
occasionnally with Apple servers.
Usage (LIST): once a NotificationThread is created using any LIST-mode constructor, invoke start() to push the payload to all devices in a separate thread.
Usage (QUEUE): once a NotificationThread is created using any QUEUE-mode constructor, invoke start() to open a connection and wait for notifications to be queued.
NotificationThread.MODE,
NotificationThreads| Modifier and Type | Class and Description |
|---|---|
static class |
NotificationThread.MODE
Working modes supported by Notification Threads.
|
| Constructor and Description |
|---|
NotificationThread(AppleNotificationServer server)
Create a standalone thread in QUEUE mode, awaiting messages to push.
|
NotificationThread(NotificationThreads threads,
PushNotificationManager notificationManager,
AppleNotificationServer server)
Create a grouped thread in QUEUE mode, awaiting messages to push.
|
NotificationThread(NotificationThreads threads,
PushNotificationManager notificationManager,
AppleNotificationServer server,
Object messages)
Create a grouped thread in LIST mode for pushing individual payloads to a list of devices
and coordinating with a parent NotificationThreads object.
|
NotificationThread(NotificationThreads threads,
PushNotificationManager notificationManager,
AppleNotificationServer server,
Payload payload,
Object devices)
Create a grouped thread in LIST mode for pushing a single payload to a list of devices
and coordinating with a parent NotificationThreads object.
|
NotificationThread(PushNotificationManager notificationManager,
AppleNotificationServer server)
Create a standalone thread in QUEUE mode, awaiting messages to push.
|
NotificationThread(PushNotificationManager notificationManager,
AppleNotificationServer server,
Object messages)
Create a standalone thread in LIST mode for pushing individual payloads to a list of devices.
|
NotificationThread(PushNotificationManager notificationManager,
AppleNotificationServer server,
Payload payload,
Object devices)
Create a standalone thread in LIST mode for pushing a single payload to a list of devices.
|
| Modifier and Type | Method and Description |
|---|---|
PushQueue |
add(Payload payload,
Device device)
Queue a message for delivery.
|
PushQueue |
add(PayloadPerDevice message)
Queue a message for delivery.
|
PushQueue |
add(Payload payload,
String token)
Queue a message for delivery.
|
void |
clearPushedNotifications()
Clear the internal list of PushedNotification objects.
|
Exception |
getCriticalException()
If this thread experienced a critical exception (communication error, keystore issue, etc.), this method returns the exception.
|
List<Exception> |
getCriticalExceptions()
Wrap a critical exception (if any occurred) into a List to satisfy the NotificationQueue interface contract.
|
List<Device> |
getDevices()
Get the list of devices associated with this thread.
|
PushedNotifications |
getFailedNotifications()
Returns list of all notifications that this thread attempted to push but that failed.
|
int |
getFirstMessageIdentifier()
Returns the first message identifier generated by this thread.
|
int |
getLastMessageIdentifier()
Returns the last message identifier generated by this thread.
|
NotificationProgressListener |
getListener() |
int |
getMaxNotificationsPerConnection() |
List<PayloadPerDevice> |
getMessages()
Get the messages associated with this thread, if any.
|
PushedNotifications |
getPushedNotifications()
Returns list of all notifications pushed by this thread (successful or not).
|
long |
getSleepBetweenNotifications() |
PushedNotifications |
getSuccessfulNotifications()
Returns list of all notifications that this thread attempted to push and succeeded.
|
int |
getThreadNumber()
Return the thread number assigned by the parent NotificationThreads object, if any.
|
boolean |
isBusy()
Determine if this thread is busy.
|
void |
run()
Run method for the thread; do not call this method directly.
|
void |
setListener(NotificationProgressListener listener)
Provide an event listener which will be notified of this thread's progress.
|
void |
setMaxNotificationsPerConnection(int maxNotificationsPerConnection)
Set a maximum number of notifications that should be streamed over a continuous connection
to an Apple server.
|
void |
setSleepBetweenNotifications(long milliseconds)
Set a delay the thread should sleep between each notification.
|
NotificationThread |
start()
Start the transmission thread.
|
public NotificationThread(NotificationThreads threads, PushNotificationManager notificationManager, AppleNotificationServer server, Payload payload, Object devices)
threads - the parent NotificationThreads object that is coordinating multiple threadsnotificationManager - the notification manager to useserver - the server to communicate withpayload - a payload to pushdevices - a list or an array of tokens or devices: String[], List<String>, Device[], List<Device>, String or Devicepublic NotificationThread(NotificationThreads threads, PushNotificationManager notificationManager, AppleNotificationServer server, Object messages)
threads - the parent NotificationThreads object that is coordinating multiple threadsnotificationManager - the notification manager to useserver - the server to communicate withmessages - a list or an array of PayloadPerDevice: List<PayloadPerDevice>, PayloadPerDevice[] or PayloadPerDevicepublic NotificationThread(PushNotificationManager notificationManager, AppleNotificationServer server, Payload payload, Object devices)
public NotificationThread(PushNotificationManager notificationManager, AppleNotificationServer server, Object messages)
notificationManager - the notification manager to useserver - the server to communicate withmessages - a list or an array of PayloadPerDevice: List<PayloadPerDevice>, PayloadPerDevice[] or PayloadPerDevicepublic NotificationThread(NotificationThreads threads, PushNotificationManager notificationManager, AppleNotificationServer server)
threads - the parent NotificationThreads object that is coordinating multiple threadsnotificationManager - the notification manager to useserver - the server to communicate withpublic NotificationThread(PushNotificationManager notificationManager, AppleNotificationServer server)
notificationManager - the notification manager to useserver - the server to communicate withpublic NotificationThread(AppleNotificationServer server)
server - the server to communicate withpublic NotificationThread start()
This method returns immediately, as the thread starts working on its own.
public void run()
public PushQueue add(Payload payload, String token) throws InvalidDeviceTokenFormatException
PushQueueadd in interface PushQueuepayload - a payloadtoken - a device tokenInvalidDeviceTokenFormatExceptionpublic PushQueue add(Payload payload, Device device)
PushQueuepublic PushQueue add(PayloadPerDevice message)
PushQueuepublic int getMaxNotificationsPerConnection()
public void setMaxNotificationsPerConnection(int maxNotificationsPerConnection)
Default is 200 (recommended).
maxNotificationsPerConnection - public long getSleepBetweenNotifications()
public void setSleepBetweenNotifications(long milliseconds)
Default is 0.
milliseconds - public List<Device> getDevices()
public NotificationProgressListener getListener()
public void setListener(NotificationProgressListener listener)
listener - any object implementing the NotificationProgressListener interfacepublic int getThreadNumber()
public int getFirstMessageIdentifier()
public int getLastMessageIdentifier()
public PushedNotifications getPushedNotifications()
getPushedNotifications in interface PushQueuepublic void clearPushedNotifications()
clearPushedNotifications in interface PushQueuepublic PushedNotifications getFailedNotifications()
public PushedNotifications getSuccessfulNotifications()
public List<PayloadPerDevice> getMessages()
public boolean isBusy()
public Exception getCriticalException()
public List<Exception> getCriticalExceptions()
getCriticalExceptions in interface PushQueueCopyright © 2016. All rights reserved.