1 package org.xmlBlaster.client.qos;
2
3 import org.xmlBlaster.util.Global;
4 import org.xmlBlaster.util.SessionName;
5 import org.xmlBlaster.util.qos.address.ServerRef;
6 import org.xmlBlaster.util.XmlBlasterException;
7 import org.xmlBlaster.util.qos.ConnectQosData;
8 import org.xmlBlaster.util.qos.SessionQos;
9 import org.xmlBlaster.util.qos.storage.CbQueueProperty;
10 import org.xmlBlaster.util.dispatch.ConnectionStateEnum;
11
12 /**
13 * This class wraps the return string of
14 * <code>org.xmlBlaster.authentication.Authenticate.connect(...)</code>.
15 * <p>
16 * It is used on the server side to wrap the return, and on the client side
17 * to parse the returned ASCII xml string.
18 * Please see documentation at ConnectQos which implements all features.
19 * </p>
20 * <p>
21 * The only thing you may be interested in is the returned sessionId, and
22 * the flag if you have reconnected to your previous setting:
23 * <p>
24 * <pre>
25 *<qos>
26 *
27 * <securityService type='htpasswd' version='1.0'>
28 * <![CDATA[
29 * <user>joe</user>
30 * <passwd>secret</passwd>
31 * ]]>
32 * </securityService>
33 *
34 * <ptp>true</ptp>
35 *
36 * <session name='/node/heron/client/joe/2' timeout='86400000'
37 * maxSessions='10' clearSessions='false'
38 * sessionId='sessionId:192.168.1.2-null-1018875420070--582319444-3'/>
39 *
40 * <reconnected>false</reconnected> <!-- Has the client reconnected to an existing session? -->
41 *
42 * <!-- CbQueueProperty -->
43 * <queue relating='callback'>
44 * <callback type='SOCKET'>
45 * 192.168.1.2:33301
46 * </callback>
47 * </queue>
48 *
49 *</qos>
50 * </pre>
51 * @see org.xmlBlaster.client.qos.ConnectQos
52 * @see <a href="http://www.xmlblaster.org/xmlBlaster/doc/requirements/interface.connect.html">connect interface</a>
53 */
54 public class ConnectReturnQos {
55 public static final String ME = "ConnectReturnQos";
56 private Global glob;
57 private ConnectQosData connectQosData;
58
59 public ConnectReturnQos(Global glob, ConnectQosData connectQosData) throws XmlBlasterException {
60 this.glob = (glob==null) ? Global.instance() : glob;
61 //this.log = glob.getLog("client");
62 this.connectQosData = connectQosData;
63 }
64 public ConnectReturnQos(Global glob, String xmlQos) throws XmlBlasterException {
65 this(glob, glob.getConnectQosFactory().readObject(xmlQos));
66 }
67
68 /**
69 * Access the wrapped data holder (for internal use only).
70 */
71 public ConnectQosData getData() {
72 return this.connectQosData;
73 }
74
75 /**
76 * The address of the xmlBlaster server to which we are connected.
77 */
78 public final ServerRef getServerRef() {
79 return this.connectQosData.getServerRef();
80 }
81
82 /**
83 * The secret sessionId which you need to use for further communication
84 * @see SessionQos#getSecretSessionId()
85 */
86 public String getSecretSessionId() {
87 return this.connectQosData.getSessionQos().getSecretSessionId();
88 }
89
90 /**
91 * The object holding the unique connection name of the client.
92 * @see SessionQos#getSessionName()
93 */
94 public SessionName getSessionName() {
95 return this.connectQosData.getSessionQos().getSessionName();
96 }
97
98 /**
99 * The object holding all session specific information.
100 */
101 public SessionQos getSessionQos() {
102 return this.connectQosData.getSessionQos();
103 }
104
105 /**
106 * The user ID as used by the security framework.
107 */
108 public String getUserId() {
109 return this.connectQosData.getUserId();
110 }
111
112 /**
113 * The callback queue exists exactly once per login session, it
114 * is used to hold the callback messages for the session.
115 * @return never null.
116 */
117 public CbQueueProperty getSessionCbQueueProperty() {
118 return this.connectQosData.getSessionCbQueueProperty();
119 }
120
121 /**
122 * The subjectQueue is exactly one instance for a subjectId (a loginName), it
123 * is used to hold the PtP messages send to this subject.
124 * <p>
125 * The subjectQueue has never callback addresses, the addresses of the sessions are used
126 * if configured.
127 * </p>
128 * @return never null.
129 */
130 public CbQueueProperty getSubjectQueueProperty() {
131 return this.connectQosData.getSubjectQueueProperty();
132 }
133
134 /**
135 * Returns the connection state directly after the connect() method returns.
136 * @return Usually ConnectionStateEnum.ALIVE or ConnectionStateEnum.POLLING
137 */
138 public ConnectionStateEnum getInitialConnectionState() {
139 return this.connectQosData.getInitialConnectionState();
140 }
141
142 /**
143 * @return true A client has reconnected to an existing session
144 */
145 public boolean isReconnected() {
146 return this.connectQosData.isReconnected();
147 }
148
149 /**
150 * Unique id of the xmlBlaster server, changes on each restart.
151 * If 'node/heron' is restarted, the instanceId changes.
152 * @return nodeId + timestamp, '/node/heron/instanceId/33470080380'
153 */
154 public String getServerInstanceId() {
155 return this.connectQosData.getInstanceId();
156 }
157
158 public final String toXml() {
159 return this.connectQosData.toXml();
160 }
161
162 public final String toXml(String extraOffset) {
163 return this.connectQosData.toXml(extraOffset);
164 }
165 }
syntax highlighted by Code2HTML, v. 0.9.1