Class PushRelay

java.lang.Object
org.moera.lib.jsonrpc.JsonRpcClient
org.moera.lib.pushrelay.PushRelay
All Implemented Interfaces:
PushRelayApi

public class PushRelay extends JsonRpcClient implements PushRelayApi
The PushRelay class provides an implementation of the PushRelayApi interface to interact with the Moera Push Relay API. It extends the JsonRpcClient class to handle JSON-RPC interactions with relays and sending push notifications.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new PushRelay instance and initializes it with the specified Push Relay server URL.
    Constructs a new PushRelay instance using a custom fetcher function to handle JSON-RPC requests and responses.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    feedStatus(String feedName, int notViewed, long notViewedMoment, String nodeName, long signedAt, byte[] signature)
    Send a message to node's clients about number of new stories in a feed.
    protected <T> T
    fetch(Class<T> result, String method, Object... parameters)
    Performs a JSON-RPC call to invoke a method on a remote server.
    void
    register(String clientId, String nodeName, String lang, long signedAt, byte[] signature)
    Register a client to receive messages from the specified node.
    void
    storyAdded(StoryInfo story, String nodeName, long signedAt, byte[] signature)
    Send a message to node's clients about a new story.
    void
    storyDeleted(String storyId, String nodeName, long signedAt, byte[] signature)
    Send a message to node's clients about deleting a story.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PushRelay

      public PushRelay(String url)
      Constructs a new PushRelay instance and initializes it with the specified Push Relay server URL.
      Parameters:
      url - the URL of the Push Relay server to connect to. It must be a valid HTTP or HTTPS URL.
    • PushRelay

      public PushRelay(Function<JsonRpcRequest,JsonRpcResponse> fetcher)
      Constructs a new PushRelay instance using a custom fetcher function to handle JSON-RPC requests and responses.
      Parameters:
      fetcher - a Function that takes a JsonRpcRequest and returns a JsonRpcResponse. This function serves as a custom handler for executing JSON-RPC interactions.
  • Method Details

    • fetch

      protected <T> T fetch(Class<T> result, String method, Object... parameters)
      Description copied from class: JsonRpcClient
      Performs a JSON-RPC call to invoke a method on a remote server. Constructs a JSON-RPC request, sends it using the pre-configured fetcher, and processes the response. If the response contains an error, it throws a JsonRpcApiException. If the response is successful, the result is converted to the specified type and returned.
      Overrides:
      fetch in class JsonRpcClient
      Type Parameters:
      T - the type of the result object expected from the remote method
      Parameters:
      result - the class type of the result object. If the expected result is null or the remote method does not return a value, the method will return null.
      method - the name of the remote method to invoke
      parameters - the parameters to pass to the remote method
      Returns:
      the result of the remote method call, converted to the specified type, or null if the remote method does not return a value
    • register

      public void register(String clientId, String nodeName, String lang, long signedAt, byte[] signature)
      Description copied from interface: PushRelayApi
      Register a client to receive messages from the specified node. The client will be unregistered automatically if the relay gets an error from the push service indicating that the client cannot receive messages anymore.
      Specified by:
      register in interface PushRelayApi
      Parameters:
      clientId - ID/token of the target client to receive messages
      nodeName - name of the node that will send messages
      lang - language of the messages (use standard language codes, like "en_US" or "uk")
      signedAt - timestamp of the signature, the signature will be valid 2 minutes after the time specified
      signature - the signature (use Fingerprints.pushRelayRegister(java.lang.String, java.lang.String, java.sql.Timestamp) fingerprint)
    • feedStatus

      public void feedStatus(String feedName, int notViewed, long notViewedMoment, String nodeName, long signedAt, byte[] signature)
      Description copied from interface: PushRelayApi
      Send a message to node's clients about number of new stories in a feed.
      Specified by:
      feedStatus in interface PushRelayApi
      Parameters:
      feedName - name of the feed
      notViewed - number of stories that have not been viewed yet
      notViewedMoment - moment of the oldest non-viewed story
      nodeName - name of the node that is sending the message
      signedAt - timestamp of the signature, the signature will be valid 2 minutes after the time specified
      signature - the signature (use Fingerprints.pushRelayMessage(java.sql.Timestamp) fingerprint)
    • storyAdded

      public void storyAdded(StoryInfo story, String nodeName, long signedAt, byte[] signature)
      Description copied from interface: PushRelayApi
      Send a message to node's clients about a new story.
      Specified by:
      storyAdded in interface PushRelayApi
      Parameters:
      story - the story
      nodeName - name of the node that is sending the message
      signedAt - timestamp of the signature, the signature will be valid 2 minutes after the time specified
      signature - the signature (use Fingerprints.pushRelayMessage(java.sql.Timestamp) fingerprint)
    • storyDeleted

      public void storyDeleted(String storyId, String nodeName, long signedAt, byte[] signature)
      Description copied from interface: PushRelayApi
      Send a message to node's clients about deleting a story.
      Specified by:
      storyDeleted in interface PushRelayApi
      Parameters:
      storyId - ID of the story
      nodeName - name of the node that is sending the message
      signedAt - timestamp of the signature, the signature will be valid 2 minutes after the time specified
      signature - the signature (use Fingerprints.pushRelayMessage(java.sql.Timestamp) fingerprint)