public class NotificationThreads extends ThreadGroup implements PushQueue
The list of devices is spread evenly into multiple NotificationThreads.
Usage: once a NotificationThreads is created, invoke start() to start all NotificationThread threads.
You can provide a NotificationProgressListener to receive events about the work being done.
NotificationThread.MODE,
NotificationThread| Constructor and Description |
|---|
NotificationThreads(AppleNotificationServer server,
int numberOfThreads)
Create a pool of notification threads in QUEUE mode.
|
NotificationThreads(AppleNotificationServer server,
List<PayloadPerDevice> messages,
int numberOfThreads)
Create the specified number of notification threads and spread the messages evenly between the threads.
|
NotificationThreads(AppleNotificationServer server,
Payload payload,
List<Device> devices,
int numberOfThreads)
Create the specified number of notification threads and spread the devices evenly between the threads.
|
NotificationThreads(Object keystore,
String password,
boolean production,
Payload payload,
List<Device> devices,
int numberOfThreads)
Create the specified number of notification threads and spread the devices evenly between the threads.
|
NotificationThreads(Object keystore,
String password,
boolean production,
Payload payload,
List<Device> devices,
List<NotificationThread> threads)
Spread the devices evenly between the provided threads.
|
NotificationThreads(Object keystore,
String password,
boolean production,
Payload payload,
List<NotificationThread> threads)
Use the provided threads which should already each have their group of devices to work with.
|
| 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 maintained in each thread.
|
List<Exception> |
getCriticalExceptions()
Get a list of critical exceptions that threads experienced.
|
long |
getDelayBetweenThreads()
Get the amount of time that the library will wait after starting a thread and before starting the next one.
|
PushedNotifications |
getFailedNotifications()
Get a list of all notifications that all threads attempted to push but that failed.
|
NotificationProgressListener |
getListener()
Get the progress listener, if any is attached.
|
PushedNotifications |
getPushedNotifications()
Get a list of all notifications pushed by all threads.
|
PushedNotifications |
getSuccessfulNotifications()
Get a list of all notifications that all threads attempted to push and succeeded.
|
List<NotificationThread> |
getThreads()
Get a list of threads created to push notifications.
|
void |
setDelayBetweenThreads(long delayBetweenThreads)
Set the amount of time that the library will wait after starting a thread and before starting the next one.
|
void |
setListener(NotificationProgressListener listener)
Attach an event listener to this object as well as all linked threads.
|
void |
setMaxNotificationsPerConnection(int notifications)
Configure in all threads the maximum number of notifications per connection.
|
void |
setSleepBetweenNotifications(long milliseconds)
Configure in all threads the number of milliseconds that threads should wait between each notification.
|
NotificationThreads |
start()
Start all notification threads.
|
void |
waitForAllThreads()
Wait for all threads to complete their work.
|
void |
waitForAllThreads(boolean throwCriticalExceptions)
Wait for all threads to complete their work, but throw any critical exception that occurs in a thread.
|
activeCount, activeGroupCount, allowThreadSuspension, checkAccess, destroy, enumerate, enumerate, enumerate, enumerate, getMaxPriority, getName, getParent, interrupt, isDaemon, isDestroyed, list, parentOf, resume, setDaemon, setMaxPriority, stop, suspend, toString, uncaughtExceptionpublic NotificationThreads(AppleNotificationServer server, Payload payload, List<Device> devices, int numberOfThreads)
server - the server to push topayload - the payload to pushdevices - a very large list of devicesnumberOfThreads - the number of threads to create to share the workpublic NotificationThreads(AppleNotificationServer server, List<PayloadPerDevice> messages, int numberOfThreads)
server - the server to push tomessages - a very large list of payload/device pairsnumberOfThreads - the number of threads to create to share the workpublic NotificationThreads(Object keystore, String password, boolean production, Payload payload, List<Device> devices, int numberOfThreads) throws Exception
keystore - the keystore to use (can be a File, an InputStream, a String for a file path, or a byte[] array)password - the keystore's passwordproduction - true to use Apple's production servers, false to use the sandboxpayload - the payload to pushdevices - a very large list of devicesnumberOfThreads - the number of threads to create to share the workExceptionpublic NotificationThreads(Object keystore, String password, boolean production, Payload payload, List<Device> devices, List<NotificationThread> threads) throws Exception
keystore - the keystore to use (can be a File, an InputStream, a String for a file path, or a byte[] array)password - the keystore's passwordproduction - true to use Apple's production servers, false to use the sandboxpayload - the payload to pushdevices - a very large list of devicesthreads - a list of pre-built threadsExceptionpublic NotificationThreads(Object keystore, String password, boolean production, Payload payload, List<NotificationThread> threads) throws Exception
keystore - the keystore to use (can be a File, an InputStream, a String for a file path, or a byte[] array)password - the keystore's passwordproduction - true to use Apple's production servers, false to use the sandboxpayload - the payload to pushthreads - a list of pre-built threadsException - If the keystore cannot be loadedpublic NotificationThreads(AppleNotificationServer server, int numberOfThreads)
server - the server to push tonumberOfThreads - the number of threads to create in the poolpublic 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 NotificationThreads start()
This method returns immediately, as all threads start working on their own. To wait until all threads are finished, use the waitForAllThreads() method.
public void setMaxNotificationsPerConnection(int notifications)
As soon as a thread reaches that maximum, it will automatically close the connection, initialize a new connection and continue pushing more notifications.
notifications - the maximum number of notifications that threads will push in a single connection (default is 200)public void setSleepBetweenNotifications(long milliseconds)
This feature is intended to alleviate intense resource usage that can occur when sending large quantities of notifications very quickly.
milliseconds - the number of milliseconds threads should sleep between individual notifications (default is 0)public List<NotificationThread> getThreads()
public NotificationProgressListener getListener()
public void setListener(NotificationProgressListener listener)
listener - public void waitForAllThreads()
throws InterruptedException
This method blocks and returns only when all threads are done. When using this method, you need to check critical exceptions manually to make sure that all threads were able to do their work.
This method should not be used in QUEUE mode, as threads stay idle and never end.
InterruptedExceptionpublic void waitForAllThreads(boolean throwCriticalExceptions)
throws Exception
This method blocks and returns only when all threads are done.
This method should not be used in QUEUE mode, as threads stay idle and never end.
throwCriticalExceptions - If true, this method will throw the first critical exception that occured in a thread (if any). If false, critical exceptions will not be checked.Exception - if throwCriticalExceptions is true and a critical exception did occur in a threadpublic PushedNotifications getPushedNotifications()
getPushedNotifications in interface PushQueuepublic void clearPushedNotifications()
clearPushedNotifications in interface PushQueuepublic PushedNotifications getFailedNotifications()
public PushedNotifications getSuccessfulNotifications()
public List<Exception> getCriticalExceptions()
getCriticalExceptions in interface PushQueuepublic long getDelayBetweenThreads()
public void setDelayBetweenThreads(long delayBetweenThreads)
delayBetweenThreads - a number of millisecondsCopyright © 2016. All rights reserved.