Package com.lightstreamer.client.mpn
Class AbstractMpnDevice
- java.lang.Object
-
- com.lightstreamer.client.mpn.AbstractMpnDevice
-
- All Implemented Interfaces:
MpnDeviceInterface
- Direct Known Subclasses:
MpnDevice
public abstract class AbstractMpnDevice extends java.lang.Object implements MpnDeviceInterface
Abstract class representing a device that supports Mobile Push Notifications (MPN).
It contains device details and the listener needed to monitor its status.
Note: this abstract class is public due to implementation side effects. It is not meant to be implemented by the user. SeeMpnDevice
for its concrete subclass.
-
-
Constructor Summary
Constructors Constructor Description AbstractMpnDevice()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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.java.lang.String
getApplicationId()
The application ID of this MPN device, corresponding to the package name of the application.java.lang.String
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.java.lang.String
getDeviceToken()
The device token of this MPN device.java.util.List<MpnDeviceListener>
getListeners()
List containing theMpnDeviceListener
instances that were added to this MPN device object.java.lang.String
getPreviousDeviceToken()
The previous device token of this MPN device.java.lang.String
getStatus()
The status of the device.
The status can be:UNKNOWN
: when the MPN device object has just been created or deleted.long
getStatusTimestamp()
The server-side timestamp of the device status.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.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.void
removeListener(MpnDeviceListener listener)
Removes a listener from the MPN device object so that it will not receive events anymore.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.lightstreamer.client.mpn.MpnDeviceInterface
getPlatform
-
-
-
-
Method Detail
-
addListener
public void 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.- Specified by:
addListener
in interfaceMpnDeviceInterface
- Parameters:
listener
- An object that will receive the events as documented in theMpnDeviceListener
interface.- See Also:
removeListener(MpnDeviceListener)
- Lifecycle:
- A listener can be added at any time. A call to add a listener already present will be ignored.
-
removeListener
public void removeListener(MpnDeviceListener listener)
Removes a listener from the MPN device object so that it will not receive events anymore.- Specified by:
removeListener
in interfaceMpnDeviceInterface
- Parameters:
listener
- The listener to be removed.- See Also:
addListener(MpnDeviceListener)
- Lifecycle:
- A listener can be removed at any time.
-
getListeners
public java.util.List<MpnDeviceListener> getListeners()
List containing theMpnDeviceListener
instances that were added to this MPN device object.- Specified by:
getListeners
in interfaceMpnDeviceInterface
- Returns:
- a list containing the listeners that were added to this device.
- See Also:
addListener(MpnDeviceListener)
-
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.- Specified by:
isRegistered
in interfaceMpnDeviceInterface
- Returns:
- true if the MPN device object is currently registered on the server.
- See Also:
getStatus()
- 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.- Specified by:
isSuspended
in interfaceMpnDeviceInterface
- Returns:
- true if the MPN device object is currently suspended on the server.
- See Also:
getStatus()
- Lifecycle:
- This method can be called at any time.
-
getStatus
@Nonnull public java.lang.String 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.
- Specified by:
getStatus
in interfaceMpnDeviceInterface
- Returns:
- the status of the device.
- See Also:
isRegistered()
,isSuspended()
- Lifecycle:
- This method can be called at any time.
-
getStatusTimestamp
public long getStatusTimestamp()
The server-side timestamp of the device status.- Specified by:
getStatusTimestamp
in interfaceMpnDeviceInterface
- Returns:
- The server-side timestamp of the device status, expressed as a Java time.
- See Also:
getStatus()
- Lifecycle:
- This method can be called at any time.
-
getApplicationId
public java.lang.String 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.- Specified by:
getApplicationId
in interfaceMpnDeviceInterface
- Returns:
- the MPN device application ID.
- Lifecycle:
- This method can be called at any time.
-
getDeviceToken
public java.lang.String 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.- Specified by:
getDeviceToken
in interfaceMpnDeviceInterface
- Returns:
- the MPN device token.
- Lifecycle:
- This method can be called at any time.
-
getPreviousDeviceToken
public java.lang.String 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.- Specified by:
getPreviousDeviceToken
in interfaceMpnDeviceInterface
- 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.
-
getDeviceId
public java.lang.String 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.- Specified by:
getDeviceId
in interfaceMpnDeviceInterface
- Returns:
- the MPN device ID.
- Lifecycle:
- This method can be called at any time.
-
-