Sessions
A session is a user defined context to which sent requests can be attached. Asynchronous events related to each session can be monitored in an efficient way, by using server-sent events.
All genomix requests accept a session name, specified with the s=name
parameter. This associates the request to the given session. Any asynchronous
event later generated by the request will be sent to the listeners of the
session.
Sessions can be created, stopped and asynchronous events for a given session can be watched with the following requests:
/session/start?s=name
This registers a new session in the server, that can be referred to by its name. The server replies with the session name.
Example:
% curl -i 'http://localhost:8080/session/start?s=foo'
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 3
foo
/session/stop?s=name
This destroys an existing session in the server. An asynchronous quit
event
is generated for all listeners of the session. The server replies with no
content.
Example:
% curl -i 'http://localhost:8080/session/stop?s=foo'
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 0
/session/listen?s=name
This listen to asynchronous events related to the session name. The returned data is a stream whose MIME type is text/event-stream and receiving sever-sent events, as standardized as part of HTML5 by this W3C draft.
Example:
% curl -i 'http://localhost:8080/session/listen?s=foo'
HTTP/1.1 200 OK
Content-Type: text/event-stream
Events that can be generated are quit
, request
or unload
.
event: quit
This event is generated when a session is closed. It contains no data
Example:
event: quit
event: request
This event is generated when a request is successfully sent or terminates (either normally or with an exception).
The associated data is the same as for the status
request.
Example:
event: request
data: {"id":"demo::2","status":"done","output":{"speedRef":"::demo::SLOW"}}
event: unload
This event is generated when a client is unloaded from the server.
The associated data is the client name.
Example:
event: unload
data: demo