Package com.iizix.push
Class PushServer
- java.lang.Object
- com.iizix.push.PushServer
public final class PushServer extends java.lang.Object
Push server for VAPID, Firebase and APNS messages.- Author:
- Christopher Mindus
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_TTL
Default Time-to-Live for Notifications in milliseconds: 24 days, extremely long time!
Constructor Summary
Constructors Constructor Description PushServer(java.util.concurrent.ExecutorService executorService, java.lang.String vapidPublicKey, java.lang.String vapidPrivateKey, java.lang.String gcmApiKey, java.lang.String subject)
Constructs the push server.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description IPushNotification
createNotification(IPushSubscription subscription, java.lang.String payloadMessage, int ttl, PushUrgency urgency, java.lang.String topic)
Constructs a new notification instance for use with browsers and non-Apple devices.IPushSubscription
createSubscription(java.lang.String endPoint, java.lang.String p256dh, java.lang.String auth)
Gets the subscription for a client used to later send a push notification.void
push(com.iizix.push.PushNotification notification)
Adds a push notification to be sent to the client.
Field Detail
DEFAULT_TTL
public static final int DEFAULT_TTL
Default Time-to-Live for Notifications in milliseconds: 24 days, extremely long time!- See Also:
- Constant Field Values
Constructor Detail
PushServer
public PushServer(java.util.concurrent.ExecutorService executorService, java.lang.String vapidPublicKey, java.lang.String vapidPrivateKey, java.lang.String gcmApiKey, java.lang.String subject) throws java.security.GeneralSecurityException
Constructs the push server.- Parameters:
executorService
- The executor service handling multi-threading depending on the CPU config and queued requests.vapidPublicKey
- The VAPIC public key.vapidPrivateKey
- The VAPIC private key.gcmApiKey
- Google Cloud Messaging API key, ornull for none
.subject
- The subject.- Throws:
java.lang.NullPointerException
- IfexecutorService
,vapidPublicKey
,vapidPrivateKey
orsubject
isnull
.java.security.GeneralSecurityException
- General security exception in case of errors.
Method Detail
createNotification
public IPushNotification createNotification(IPushSubscription subscription, java.lang.String payloadMessage, int ttl, PushUrgency urgency, java.lang.String topic)
Constructs a new notification instance for use with browsers and non-Apple devices.- Parameters:
subscription
- The subscription.payloadMessage
- The payload message as plain text.ttl
- The Time-to-Live in milliseconds of the message, zero or less for default 28 days = (2_419_200_000 milliseconds).urgency
- The urgency of the notification.topic
- The topic of the notification.- Returns:
- A new notification instance.
- Throws:
java.lang.NullPointerException
- Ifsubscription
,payloadMessage
orurgency
isnull
.
createSubscription
public IPushSubscription createSubscription(java.lang.String endPoint, java.lang.String p256dh, java.lang.String auth)
Gets the subscription for a client used to later send a push notification. The subscription can be stored in the IClientSessionGyro as it doesn't change for the client session.- Parameters:
endPoint
- The end point URL String.p256dh
- The key encoded as a Base64 String.auth
- The authentication encoded as a Base64 String.- Returns:
- The subscription for the client.
- Throws:
java.security.spec.InvalidKeySpecException
java.security.NoSuchProviderException
java.security.NoSuchAlgorithmException
java.lang.NullPointerException
- If theendPoint
isnull
.java.lang.IllegalArgumentException
- Ifp256dh
orauth
is not in valid Base64 scheme or invalidp256dh
key encoding.
push
public void push(com.iizix.push.PushNotification notification)
Adds a push notification to be sent to the client. The notification will be done by the executor service as soon as possible.- Parameters:
notification
- The notification to be sent.