Package com.mxgraph.sharing
Class mxSession
java.lang.Object
com.mxgraph.sharing.mxSession
- All Implemented Interfaces:
mxSharedState.mxDiagramChangeListener
Implements a session that may be attached to a shared diagram. The session
contains a synchronized buffer which is used to hold the pending edits which
are to be sent to a specific client. The update mechnism between the server
and the client uses HTTP requests (polling). The request is kept on the server
for an amount of time or wakes up / returns immediately if the buffer is no
longer empty.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringBuffer
Holds the send buffer for this session.static int
Default timeout is 10000 ms.protected mxSharedState
Reference to the shared diagram.protected String
Holds the session ID.protected long
Holds the last active time millis. -
Constructor Summary
ConstructorsConstructorDescriptionmxSession
(String id, mxSharedState diagram) Constructs a new session with the given ID. -
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy()
Destroys the session and removes its listener from the shared diagram.void
diagramChanged
(Object sender, String edits) Fires when the shared diagram was changed.getId()
Returns the session ID.Returns an XML string that represents the current state of the session and the shared diagram.long
Returns the number of milliseconds this session has been inactive.init()
Initializes the session buffer and returns a string that represents the state of the session.poll()
Returns the changes received by other sessions for the shared diagram.poll
(long timeout) Returns the changes received by other sessions for the shared diagram.void
Posts the change represented by the given XML string to the shared diagram.
-
Field Details
-
DEFAULT_TIMEOUT
public static int DEFAULT_TIMEOUTDefault timeout is 10000 ms. -
id
Holds the session ID. -
diagram
Reference to the shared diagram. -
buffer
Holds the send buffer for this session. -
lastTimeMillis
protected long lastTimeMillisHolds the last active time millis.
-
-
Constructor Details
-
Method Details
-
getId
Returns the session ID. -
init
Initializes the session buffer and returns a string that represents the state of the session.- Returns:
- Returns the initial state of the session.
-
getInitialMessage
Returns an XML string that represents the current state of the session and the shared diagram. A globally unique ID is used as the session's namespace, which is used on the client side to prefix IDs of newly created cells. -
receive
Posts the change represented by the given XML string to the shared diagram.- Parameters:
message
- XML that represents the change.
-
poll
Returns the changes received by other sessions for the shared diagram. The method returns an empty XML node if no change was received within 10 seconds.- Returns:
- Returns a string representing the changes to the shared diagram.
- Throws:
InterruptedException
-
poll
Returns the changes received by other sessions for the shared diagram. The method returns an empty XML node if no change was received within the given timeout.- Parameters:
timeout
- Time in milliseconds to wait for changes.- Returns:
- Returns a string representing the changes to the shared diagram.
- Throws:
InterruptedException
-
diagramChanged
Description copied from interface:mxSharedState.mxDiagramChangeListener
Fires when the shared diagram was changed.- Specified by:
diagramChanged
in interfacemxSharedState.mxDiagramChangeListener
- Parameters:
sender
- Session where the change was received from.edits
- String that represents the edits.
-
inactiveTimeMillis
public long inactiveTimeMillis()Returns the number of milliseconds this session has been inactive. -
destroy
public void destroy()Destroys the session and removes its listener from the shared diagram.
-