Class PushServer

java.lang.Object
com.iizix.push.PushServer

public final class PushServer extends Object
Push server for VAPID, Firebase and APNS messages.
Author:
Christopher Mindus
  • Field Details

    • DEFAULT_TTL

      public static final int DEFAULT_TTL
      Default Time-to-Live for Notifications in milliseconds: 24 days, extremely long time!
      See Also:
  • Constructor Details

    • PushServer

      public PushServer(ExecutorService executorService, String vapidPublicKey, String vapidPrivateKey, String gcmApiKey, String subject) throws 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, or null for none.
      subject - The subject.
      Throws:
      NullPointerException - If executorService, vapidPublicKey, vapidPrivateKey or subject is null.
      GeneralSecurityException - General security exception in case of errors.
  • Method Details

    • createNotification

      public IPushNotification createNotification(IPushSubscription subscription, String payloadMessage, int ttl, PushUrgency urgency, 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:
      NullPointerException - If subscription, payloadMessage or urgency is null.
    • createSubscription

      public IPushSubscription createSubscription(String endPoint, String p256dh, 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:
      NullPointerException - If the endPoint is null.
      IllegalArgumentException - If p256dh or auth is not in valid Base64 scheme or invalid p256dh 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.