|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavapns.notification.transmission.NotificationThread
public class NotificationThread
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
Nested Class Summary | |
---|---|
static class |
NotificationThread.MODE
Working modes supported by Notification Threads. |
Constructor Summary | |
---|---|
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. |
Method Summary | |
---|---|
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()
Deprecated. Not thead-safe. use getPushedNotifications(true) instead. |
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()
Deprecated. Not thead-safe. use getPushedNotifications(true).getFailedNotifications() instead. |
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(boolean clearList)
Returns a list of all notifications pushed by this thread (successful or not). |
long |
getSleepBetweenNotifications()
|
PushedNotifications |
getSuccessfulNotifications()
Deprecated. Not thead-safe. use getPushedNotifications(true).getSuccessfulNotifications() instead. |
int |
getThreadNumber()
Return the thread number assigned by the parent NotificationThreads object, if any. |
boolean |
isBusy()
Determine if this thread is busy. |
int |
newMessageIdentifier()
Return a new sequential message identifier. |
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. |
int |
size()
Get the number of devices that this thread pushes to. |
NotificationThread |
start()
Start the transmission thread. |
void |
stopQueue()
Invoke stopQueue on all threads working for the queue. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
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 Device
public 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 PayloadPerDevice
public NotificationThread(PushNotificationManager notificationManager, AppleNotificationServer server, Payload payload, Object devices)
notificationManager
- 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 Device
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 PayloadPerDevice
public 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 withMethod Detail |
---|
public NotificationThread start()
start
in interface PushQueue
public void run()
run
in interface Runnable
public void stopQueue()
PushQueue
stopQueue
in interface PushQueue
public PushQueue add(Payload payload, String token) throws InvalidDeviceTokenFormatException
PushQueue
add
in interface PushQueue
payload
- a payloadtoken
- a device token
InvalidDeviceTokenFormatException
public PushQueue add(Payload payload, Device device)
PushQueue
add
in interface PushQueue
payload
- a payloaddevice
- a device
public PushQueue add(PayloadPerDevice message)
PushQueue
add
in interface PushQueue
message
- a payload/device pair
public void setMaxNotificationsPerConnection(int maxNotificationsPerConnection)
maxNotificationsPerConnection
- public int getMaxNotificationsPerConnection()
public void setSleepBetweenNotifications(long milliseconds)
milliseconds
- public long getSleepBetweenNotifications()
public List<Device> getDevices()
public int size()
public void setListener(NotificationProgressListener listener)
listener
- any object implementing the NotificationProgressListener interfacepublic NotificationProgressListener getListener()
public int getThreadNumber()
public int newMessageIdentifier()
public int getFirstMessageIdentifier()
public int getLastMessageIdentifier()
public PushedNotifications getPushedNotifications(boolean clearList)
getPushedNotifications
in interface PushQueue
clearList
- indicate if the internal list of pushed notifications should be emptied (recommended)
@Deprecated public void clearPushedNotifications()
clearPushedNotifications
in interface PushQueue
@Deprecated public PushedNotifications getFailedNotifications()
@Deprecated public PushedNotifications getSuccessfulNotifications()
public List<PayloadPerDevice> getMessages()
public boolean isBusy()
public Exception getCriticalException()
public List<Exception> getCriticalExceptions()
getCriticalExceptions
in interface PushQueue
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |