2 import org.opensrf.util.JSON;
3 import org.opensrf.net.xmpp.*;
5 public abstract class Session {
7 /** Represents the different connection states for a session */
8 public enum ConnectState {
14 /** the current connection state */
15 private ConnectState connectState;
17 /** The (jabber) address of the remote party we are communicating with */
18 private String remoteNode;
21 * The thread is used to link messages to a given session.
22 * In other words, each session has a unique thread, and all messages
23 * in that session will carry this thread around as an indicator.
25 private String thread;
28 connectState = ConnectState.DISCONNECTED;
32 * Sends a Message to our remoteNode.
34 public void send(Message omsg) throws XMPPException {
36 /** construct the XMPP message */
37 XMPPMessage xmsg = new XMPPMessage();
38 xmsg.setTo(remoteNode);
39 xmsg.setThread(thread);
40 xmsg.setBody(JSON.toJSON(omsg));
41 XMPPSession ses = XMPPSession.getGlobalSession();
44 XMPPSession.getGlobalSession().send(xmsg);
45 } catch(XMPPException e) {
47 connectState = ConnectState.DISCONNECTED;