Class AbstractServerEvent

  • All Implemented Interfaces:
    ServerEvent
    Direct Known Subclasses:
    CommonServerEvent

    public abstract class AbstractServerEvent
    extends Object
    implements ServerEvent
    It is an abstract implementation of a ServerEvent. It defines the common properties all the concrete events should have. A concrete resource event can extend this class to inherit the basic properties without to implement them by itself.
    This abstraction handles the identifier of the event which is auto-generated. The start of identifier counting is reset after each server start or restart
    Author:
    Yohann Chastagnier
    • Constructor Detail

      • AbstractServerEvent

        public AbstractServerEvent()
    • Method Detail

      • getEventSourceURIs

        public List<String> getEventSourceURIs()
        Gets the Event Source URI on which the event is handled.
        If empty, then the event must be sent on all Event Sources.
        Returns:
        an URI as string.
      • getId

        public long getId()
        Description copied from interface: ServerEvent
        Gets the identifier of the server event.
        This identifier is unique during the lifetime of the server. After the server is restarted, the counter starts again to zero.
        Specified by:
        getId in interface ServerEvent
        Returns:
        the name as unique ServerEvent.ServerEventName instance.
      • getData

        public String getData​(String receiverSessionId,
                              User receiver)
        Description copied from interface: ServerEvent
        The data to send.
        Specified by:
        getData in interface ServerEvent
        Parameters:
        receiverSessionId - the identifier of the receiver session.
        receiver - the user that will receive the event in its WEB client.
        Returns:
        the data as string.
      • send

        public boolean send​(SilverpeasServerEventContext context,
                            String receiverSessionId,
                            User receiver)
                     throws IOException
        Description copied from interface: ServerEvent
        Sends the event by using the given response and taking into account the receiver linked to.
        If ServerEvent.isConcerned(String, User) indicates that the given receiver is not concerned, nothing is sent.
        Specified by:
        send in interface ServerEvent
        Parameters:
        context - the context from which the communication has been opened.
        receiverSessionId - the identifier of the receiver session.
        receiver - the receiver instance.
        Returns:
        true if send has been performed, false otherwise.
        Throws:
        IOException - if the sending fails.
      • withData

        protected <T extends AbstractServerEvent> T withData​(String data)
        Sets the specified data.
        Given data are ignored if withData(BiFunction) has been called with non null functional interface.
        Type Parameters:
        T - a subtype of AbstractServerEvent
        Parameters:
        data - the data the event must return to WEB client.
        Returns:
        the instance itself.
      • withData

        protected <T extends AbstractServerEvent> T withData​(BiFunction<String,​User,​String> dynamicData)
        Sets a functional interface which will produced the data as string by taking into account a given User which is the current user for which the server event will be send. @param dynamicData functional interface which will be played at each call of ServerEvent.send(SilverpeasServerEventContext, String, User) method. The functional interface provides one parameter: User, the user for which the server event will be sent. It produces the data to send.
        If a functional interface is given, data eventually set by withData(String) are ignored.
        Type Parameters:
        T - a subtype of AbstractServerEvent
        Parameters:
        dynamicData - the data the vent must return to WEB client.
        Returns:
        the instance itself.