Interface ServerEvent
-
- All Known Subinterfaces:
AfterSentToAllContexts
,IgnoreStoring
,KeepAlwaysLastStored
,SendEveryAmountOfTime
,StoreLastOnly
- All Known Implementing Classes:
AbstractServerEvent
,CommonServerEvent
,UserNotificationServerEvent
,UserSessionServerEvent
public interface ServerEvent
An event implying data the server has to push to client without the client requesting Silverpeas. This event is calledServer Event
.
Three elements compose a server event:id
, an identifier that identifies the eventname
, the name of the event. It can be taken like the name of a bus. This name is used by client to add listeners. For example, il the name of an event isUSER_SESSION
the client (in JavaScript) can listen to by codingnew EventSource(...).addEventListener('USER_SESSION', function(serverEvent){ ... })
data
, textual data (but it is not forbidden to render JSON structure as string)
- Author:
- Yohann Chastagnier
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
ServerEvent.ServerEventName
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description String
getData(String receiverSessionId, User receiver)
The data to send.long
getId()
Gets the identifier of the server event.
This identifier is unique during the lifetime of the server.ServerEvent.ServerEventName
getName()
Gets the name of the server event.default boolean
isConcerned(String receiverSessionId, User receiver)
Indicates if the given receiver (behind the session) is concerned by the event.default boolean
isValidId()
Indicates if identifier is a valid one.default boolean
send(SilverpeasServerEventContext context, String receiverSessionId, User receiver)
Sends the event by using the given response and taking into account the receiver linked to.default String
subType()
Gets the sub type the event if any.
-
-
-
Method Detail
-
isValidId
default boolean isValidId()
Indicates if identifier is a valid one.BE CAREFUL, this method calls
getId()
method and it could so generates the identifier.- Returns:
- true if valid, false otherwise.
-
getId
long getId()
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.- Returns:
- the name as unique
ServerEvent.ServerEventName
instance.
-
getName
ServerEvent.ServerEventName getName()
Gets the name of the server event.- Returns:
- the name as unique
ServerEvent.ServerEventName
instance.
-
subType
default String subType()
Gets the sub type the event if any.- Returns:
- the sub type of the event if any, empty string otherwise.
-
getData
String getData(String receiverSessionId, User receiver)
The data to send.- 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.
-
isConcerned
default boolean isConcerned(String receiverSessionId, User receiver)
Indicates if the given receiver (behind the session) is concerned by the event. If not, the event is not sent.- Parameters:
receiverSessionId
- the identifier of the receiver session.receiver
- the user that will receive the event in its WEB client.- Returns:
- true if given receiver is concerned, false otherwise.
-
send
default boolean send(SilverpeasServerEventContext context, String receiverSessionId, User receiver) throws IOException
Sends the event by using the given response and taking into account the receiver linked to.
IfisConcerned(String, User)
indicates that the given receiver is not concerned, nothing is sent.- 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.
-
-