Class AbstractServerEvent
- java.lang.Object
-
- org.silverpeas.core.notification.sse.AbstractServerEvent
-
- All Implemented Interfaces:
ServerEvent
- Direct Known Subclasses:
CommonServerEvent
public abstract class AbstractServerEvent extends Object implements ServerEvent
It is an abstract implementation of aServerEvent
. 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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.silverpeas.core.notification.sse.ServerEvent
ServerEvent.ServerEventName
-
-
Constructor Summary
Constructors Constructor Description AbstractServerEvent()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getData(String receiverSessionId, User receiver)
The data to send.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.long
getId()
Gets the identifier of the server event.
This identifier is unique during the lifetime of the server.boolean
send(SilverpeasServerEventContext context, String receiverSessionId, User receiver)
Sends the event by using the given response and taking into account the receiver linked to.String
toString()
protected <T extends AbstractServerEvent>
TwithData(String data)
Sets the specified data.
Given data are ignored ifwithData(BiFunction)
has been called with non null functional interface.protected <T extends AbstractServerEvent>
TwithData(BiFunction<String,User,String> dynamicData)
Sets a functional interface which will produced the data as string by taking into account a givenUser
which is the current user for which the server event will be send.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.silverpeas.core.notification.sse.ServerEvent
getName, isConcerned, isValidId, subType
-
-
-
-
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 interfaceServerEvent
- 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 interfaceServerEvent
- 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.
IfServerEvent.isConcerned(String, User)
indicates that the given receiver is not concerned, nothing is sent.- Specified by:
send
in interfaceServerEvent
- 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 ifwithData(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 givenUser
which is the current user for which the server event will be send. @param dynamicData functional interface which will be played at each call ofServerEvent.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 bywithData(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.
-
-