]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/java/org/opensrf/Session.java
added initial opensrf stack layer objects. more tuning/testing of the jabber layer
[OpenSRF.git] / src / java / org / opensrf / Session.java
1 package org.opensrf;
2 import org.opensrf.util.JSON;
3 import org.opensrf.net.xmpp.*;
4
5 public abstract class Session {
6
7     /** Represents the different connection states for a session */
8     public enum ConnectState {
9         DISCONNECTED,
10         CONNECTING,
11         CONNECTED
12     };
13
14     /** the current connection state */
15     private ConnectState connectState;
16
17     /** The (jabber) address of the remote party we are communicating with */
18     private String remoteNode;
19
20     /** 
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.
24      */
25     private String thread;
26
27     public Session() {
28         connectState = ConnectState.DISCONNECTED;
29     }
30     
31     /**
32      * Sends a Message to our remoteNode.
33      */
34     public void send(Message omsg) throws XMPPException {
35
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();
42
43         try {
44             XMPPSession.getGlobalSession().send(xmsg);
45         } catch(XMPPException e) {
46             /* XXX log */
47             connectState = ConnectState.DISCONNECTED;
48         }
49     }
50 }