java.lang.Object
org.gcube.informationsystem.resourceregistry.cluster.ClusterEvent

public class ClusterEvent extends Object
One immutable notification broadcast over the ClusterEventBus.

Carries its own identity (getEventId()) and the identity of the instance that emitted it (getOriginId()). Both exist because the bus delivers over two independent channels: the identity lets a receiver discard the second copy of an event it has already handled, and the origin lets it discard the echo of an event it emitted itself.

Author:
Luca Frosini (ISTI - CNR)
  • Field Details

    • EVENT_ID_FIELD

      public static final String EVENT_ID_FIELD
      Field name of the event identifier, in JSON and on the Live Query backstop record alike.
      See Also:
    • EVENT_TYPE_FIELD

      public static final String EVENT_TYPE_FIELD
      Field name of the event type, in JSON and on the Live Query backstop record alike.
      See Also:
    • PAYLOAD_FIELD

      public static final String PAYLOAD_FIELD
      Field name of the event payload, in JSON and on the Live Query backstop record alike.
      See Also:
    • ORIGIN_ID_FIELD

      public static final String ORIGIN_ID_FIELD
      Field name of the emitting instance identifier, in JSON and on the Live Query backstop record alike.
      See Also:
    • TIMESTAMP_FIELD

      public static final String TIMESTAMP_FIELD
      Field name of the emission timestamp, in JSON and on the Live Query backstop record alike.
      See Also:
  • Constructor Details

    • ClusterEvent

      public ClusterEvent(UUID eventId, ClusterEventType eventType, String payload, String originId, long timestamp)
      Creates an event with every field supplied explicitly. Used by deserialization and by the Live Query backstop, which rebuilds an event from a stored record.
      Parameters:
      eventId - the event's own identifier, unique across every instance
      eventType - the kind of event
      payload - the type-specific payload, may be null
      originId - the identifier of the instance that emitted the event
      timestamp - the emission time, in milliseconds since the epoch
  • Method Details

    • getEventId

      public UUID getEventId()
      Returns the event's own identifier, unique across every instance.
      Returns:
      the event identifier
    • getEventType

      public ClusterEventType getEventType()
      Returns the kind of event.
      Returns:
      the event type
    • getPayload

      public String getPayload()
      Returns the type-specific payload.
      Returns:
      the payload, or null if this event kind carries none
    • getOriginId

      public String getOriginId()
      Returns the identifier of the instance that emitted this event.
      Returns:
      the emitting instance identifier
    • getTimestamp

      public long getTimestamp()
      Returns the emission time.
      Returns:
      the emission time, in milliseconds since the epoch
    • toJson

      public String toJson() throws Exception
      Serializes this event to the JSON form used as the Redis pub/sub message payload.
      Returns:
      the serialized event
      Throws:
      Exception - if serialization fails
    • fromJson

      public static ClusterEvent fromJson(String json) throws Exception
      Deserializes an event from the JSON form produced by toJson().
      Parameters:
      json - the serialized event
      Returns:
      the deserialized event
      Throws:
      Exception - if deserialization fails