Package com.lightstreamer.client.mpn
Class MpnDevice
java.lang.Object
com.lightstreamer.client.mpn.MpnDevice
Class representing a device that supports Mobile Push Notifications (MPN).
It contains device details and the listener needed to monitor its status.
An MPN device is created from the application context, the sender ID (a.k.a. authorized entity) and a device token (a.k.a. registration token) obtained from Firebase Cloud Messaging APIs, and must be registered on the
After creation, an MpnDevice object is in "unknown" state. It must then be passed to the Lightstreamer Server with the
Upon registration on the server, active MPN subscriptions of the device are received and exposed with the
An MpnDevice's state may become "suspended" if errors occur during push notification delivery. In this case MPN subscriptions stop sending notifications and the device state is reset to "registered" at the first subsequent registration.
It contains device details and the listener needed to monitor its status.
An MPN device is created from the application context, the sender ID (a.k.a. authorized entity) and a device token (a.k.a. registration token) obtained from Firebase Cloud Messaging APIs, and must be registered on the
LightstreamerClient
in order to successfully subscribe an MPN subscription.
See MpnSubscription
.After creation, an MpnDevice object is in "unknown" state. It must then be passed to the Lightstreamer Server with the
LightstreamerClient.registerForMpn(MpnDevice)
method, which enables the client to subscribe MPN subscriptions and sends the device details to the
server's MPN Module, where it is assigned a permanent device ID and its state is switched to "registered".Upon registration on the server, active MPN subscriptions of the device are received and exposed with the
LightstreamerClient.getMpnSubscriptions(String)
method.An MpnDevice's state may become "suspended" if errors occur during push notification delivery. In this case MPN subscriptions stop sending notifications and the device state is reset to "registered" at the first subsequent registration.
-
Constructor Summary
ConstructorDescriptionCreates an object to be used to describe an MPN device that is going to be registered to the MPN Module of Lightstreamer Server.
During creation the MpnDevice tries to acquires some more details: The package name, through the Application Context. Any previously registered device token, from the Shared Preferences storage. It then saves the current device token on the Shared Preferences storage. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(MpnDeviceListener listener) Adds a listener that will receive events from the MPN device object.
The same listener can be added to several different MPN device objects.The application ID of this MPN device, corresponding to the package name of the application.The server-side unique persistent ID of the device.
The ID is available only after the MPN device object has been successfully registered on the server.The device token of this MPN device.List containing theMpnDeviceListener
instances that were added to this MPN device object.The platform identifier of this MPN device.The previous device token of this MPN device.The status of the device.
The status can be:UNKNOWN
: when the MPN device object has just been created or deleted.long
The server-side timestamp of the device status.boolean
Checks whether the MPN device object is currently registered on the server or not.
This flag is switched to true by server sent registration events, and back to false in case of client disconnection or server sent suspension events.boolean
Checks whether the MPN device object is currently suspended on the server or not.
An MPN device may be suspended if errors occur during push notification delivery.
This flag is switched to true by server sent suspension events, and back to false in case of client disconnection or server sent resume events.void
removeListener
(MpnDeviceListener listener) Removes a listener from the MPN device object so that it will not receive events anymore.
-
Constructor Details
-
MpnDevice
Creates an object to be used to describe an MPN device that is going to be registered to the MPN Module of Lightstreamer Server.
During creation the MpnDevice tries to acquires some more details:- The package name, through the Application Context.
- Any previously registered device token, from the Shared Preferences storage.
- Parameters:
appContext
- the Application Contexttoken
- the device token- Throws:
IllegalArgumentException
- ifcontext
,senderId
ortoken
are null.
-
-
Method Details
-
addListener
Adds a listener that will receive events from the MPN device object.
The same listener can be added to several different MPN device objects.- Parameters:
listener
- An object that will receive the events as documented in theMpnDeviceListener
interface.- See Also:
- Lifecycle:
- A listener can be added at any time. A call to add a listener already present will be ignored.
-
removeListener
Removes a listener from the MPN device object so that it will not receive events anymore.- Parameters:
listener
- The listener to be removed.- See Also:
- Lifecycle:
- A listener can be removed at any time.
-
getPlatform
The platform identifier of this MPN device. In theMpnDevice
implementation it equals to the constantGoogle
and is used by the server as part of the device identification.- Returns:
- the MPN device platform.
- Lifecycle:
- This method can be called at any time.
-
getApplicationId
The application ID of this MPN device, corresponding to the package name of the application. In theMpnDevice
implementation it is determined automatically from the Application Context during creation and is used by the server as part of the device identification.- Returns:
- the MPN device application ID.
- Lifecycle:
- This method can be called at any time.
-
getDeviceToken
The device token of this MPN device. In theMpnDevice
implementation it is passed during creation and is used by the server as part of the device identification.- Returns:
- the MPN device token.
- Lifecycle:
- This method can be called at any time.
-
getPreviousDeviceToken
The previous device token of this MPN device. In theMpnDevice
implementation it is obtained automatically from the Shared Preferences storage during creation and is used by the server to restore MPN subscriptions associated with this previous token. May be null if no MPN device has been registered yet on the application.- Returns:
- the previous MPN device token, or null if no MPN device has been registered yet.
- Lifecycle:
- This method can be called at any time.
-
isRegistered
public boolean isRegistered()Checks whether the MPN device object is currently registered on the server or not.
This flag is switched to true by server sent registration events, and back to false in case of client disconnection or server sent suspension events.- Returns:
- true if the MPN device object is currently registered on the server.
- See Also:
- Lifecycle:
- This method can be called at any time.
-
isSuspended
public boolean isSuspended()Checks whether the MPN device object is currently suspended on the server or not.
An MPN device may be suspended if errors occur during push notification delivery.
This flag is switched to true by server sent suspension events, and back to false in case of client disconnection or server sent resume events.- Returns:
- true if the MPN device object is currently suspended on the server.
- See Also:
- Lifecycle:
- This method can be called at any time.
-
getStatus
The status of the device.
The status can be:UNKNOWN
: when the MPN device object has just been created or deleted. In this statusisRegistered()
andisSuspended()
are both false.REGISTERED
: when the MPN device object has been successfully registered on the server. In this statusisRegistered()
is true andisSuspended()
is false.SUSPENDED
: when a server error occurred while sending push notifications to this MPN device and consequently it has been suspended. In this statusisRegistered()
andisSuspended()
are both true.
- Returns:
- the status of the device.
- See Also:
- Lifecycle:
- This method can be called at any time.
-
getStatusTimestamp
public long getStatusTimestamp()The server-side timestamp of the device status.- Returns:
- The server-side timestamp of the device status, expressed as a Java time.
- See Also:
- Lifecycle:
- This method can be called at any time.
-
getDeviceId
The server-side unique persistent ID of the device.
The ID is available only after the MPN device object has been successfully registered on the server. I.e. when its status isREGISTERED
orSUSPENDED
.
Note: a device token change, if the previous device token was correctly stored on the Shared Preferences storage, does not cause the device ID to change: the server moves previous MPN subscriptions from the previous token to the new one and the device ID remains unaltered.- Returns:
- the MPN device ID.
- Lifecycle:
- This method can be called at any time.
-
getListeners
List containing theMpnDeviceListener
instances that were added to this MPN device object.- Returns:
- a list containing the listeners that were added to this device.
- See Also:
-