1 /*------------------------------------------------------------------------------
2 Name: DisconnectQos.java
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 Comment: Handling one xmlQoS
6 ------------------------------------------------------------------------------*/
7 package org.xmlBlaster.client.qos;
8
9 import java.util.Properties;
10
11 import org.xmlBlaster.util.Global;
12 import org.xmlBlaster.util.qos.DisconnectQosData;
13 import org.xmlBlaster.util.qos.ClientProperty;
14 import org.xmlBlaster.util.property.PropBoolean;
15
16 /**
17 * This class encapsulates the qos of a logout() or disconnect()
18 * <p />
19 * So you don't need to type the 'ugly' XML ASCII string by yourself.
20 * After construction access the ASCII-XML string with the toXml() method.
21 * <br />
22 * A typical <b>logout</b> qos could look like this:<br />
23 * <pre>
24 * <qos>
25 * <deleteSubjectQueue>true</deleteSubjectQueue>
26 * <clearSessions>false</clearSessions>
27 * </qos>
28 * </pre>
29 * <p />
30 * The following properties are evaluated (command line or xmlBlaster.properties)
31 * and control the behaviour on client side:
32 * <pre>
33 * dispatch/connection/shutdownDispatcher true/false
34 * dispatch/connection/shutdownCbServer true/false
35 * dispatch/connection/leaveServer true/false
36 * </pre>
37 * Additionally you can set these values as clientProperties, which have priority:
38 * <pre>
39 * <qos>
40 * <clientProperty name='shutdownDispatcher'>true</clientProperty>
41 * <clientProperty name='shutdownCbServer'>true</clientProperty>
42 * <clientProperty name='leaveServer'>false</clientProperty>
43 * </qos>
44 * </pre>
45 * @see <a href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/interface.disconnect.html">The interface.disconnect requirement</a>
46 * @see org.xmlBlaster.test.classtest.DisconnectQosTest
47 */
48 public class DisconnectQos
49 {
50 private final Global glob;
51 private final DisconnectQosData disconnectQosData;
52
53 private PropBoolean clearClientQueue = new PropBoolean(true);
54 private boolean shutdownDispatcher;
55 private boolean shutdownCbServer;
56 private boolean leaveServer;
57
58 public DisconnectQos(Global glob) {
59 this(glob, null);
60 }
61
62 /**
63 * Constructor for internal use.
64 * @param disconnectQosData The struct holding the data
65 */
66 public DisconnectQos(Global glob, DisconnectQosData disconnectQosData) {
67 this.glob = (glob==null) ? Global.instance() : glob;
68 this.disconnectQosData = (disconnectQosData==null) ? new DisconnectQosData(this.glob) : disconnectQosData;
69 init();
70 }
71
72 /** @deprecated */
73 public DisconnectQos() {
74 this(null, null);
75 }
76
77 /**
78 * Access the wrapped data holder
79 */
80 public DisconnectQosData getData() {
81 return this.disconnectQosData;
82 }
83
84 private void init() {
85
86 this.shutdownDispatcher = this.glob.getProperty().get("dispatch/connection/shutdownDispatcher", true);
87 if (this.disconnectQosData.getClientProperties().containsKey("shutdownDispatcher")) {
88 this.shutdownDispatcher = this.disconnectQosData.getClientProperty("shutdownDispatcher", this.shutdownDispatcher);
89 }
90
91 this.shutdownCbServer = this.glob.getProperty().get("dispatch/connection/shutdownCbServer", true);
92 if (this.disconnectQosData.getClientProperties().containsKey("shutdownCbServer")) {
93 this.shutdownCbServer = this.disconnectQosData.getClientProperty("shutdownCbServer", this.shutdownCbServer);
94 }
95
96 this.leaveServer = this.glob.getProperty().get("dispatch/connection/leaveServer", false);
97 if (this.disconnectQosData.getClientProperties().containsKey("leaveServer")) {
98 this.leaveServer = this.disconnectQosData.getClientProperty("leaveServer", this.leaveServer);
99 }
100 }
101
102 /**
103 * Return true if subject queue shall be deleted with last user session
104 * @return true;
105 */
106 public boolean deleteSubjectQueue() {
107 return this.disconnectQosData.deleteSubjectQueue();
108 }
109
110 /**
111 * If subject queue shall be deleted with last user session logout
112 * @param del defaults to true
113 */
114 public void deleteSubjectQueue(boolean del) {
115 this.disconnectQosData.deleteSubjectQueue(del);
116 }
117
118 /**
119 * Return true if we shall kill all other sessions of this user on logout (defaults to false).
120 * @return false
121 */
122 public boolean clearSessions() {
123 return this.disconnectQosData.clearSessions();
124 }
125
126 /**
127 * @param true if we shall kill all other sessions of this user on logout (defaults to false).
128 */
129 public void clearSessions(boolean del) {
130 this.disconnectQosData.clearSessions(del);
131 }
132
133 /**
134 * Sets a client property (an application specific property) to the
135 * given value.
136 * <p>
137 * Note that this is no multimap, later similar keys will overwrite the previous
138 * @param key
139 * @param value
140 */
141 public void addClientProperty(String key, Object value) {
142 this.disconnectQosData.addClientProperty(key, value);
143 }
144
145 /**
146 * Read back a property.
147 * @return The client property or null if not found
148 */
149 public ClientProperty getClientProperty(String key) {
150 return this.disconnectQosData.getClientProperty(key);
151 }
152
153 /**
154 * Converts the data into a valid XML ASCII string.
155 * @return An XML ASCII string
156 */
157 public String toString() {
158 return this.disconnectQosData.toXml();
159 }
160
161 /**
162 * Converts the data into a valid XML ASCII string.
163 * @return An XML ASCII string
164 */
165 public String toXml() {
166 return this.disconnectQosData.toXml();
167 }
168
169 public final String toXml(String extraOffset, Properties props) {
170 return this.disconnectQosData.toXml(extraOffset, props);
171 }
172
173 /**
174 * If there are tail back messages in the client side queue, what to do with them.
175 * <p>
176 * Controls client side behavior.
177 * </p>
178 * @param clearClientQueue true Removes all entries of the client side tailback queue which is default<br />
179 * false Keep persistent entries in client side queue, will be sent on next connect
180 * of the same client with the same public session ID.
181 */
182 public void clearClientQueue(boolean clearClientQueue) {
183 this.clearClientQueue.setValue(clearClientQueue);
184 }
185
186 /**
187 * @see #clearClientQueue(boolean)
188 */
189 public boolean clearClientQueue() {
190 return this.clearClientQueue.getValue();
191 }
192
193 public PropBoolean getClearClientQueueProp() {
194 return this.clearClientQueue;
195 }
196
197 /**
198 * Shutdown the client side dispatcher framework on disconnect, which
199 * includes the low level connection like CORBA.
200 * <p>
201 * Controls client side behavior.
202 * </p>
203 * @param shutdownDispatcher true is default
204 */
205 public void shutdownDispatcher(boolean shutdownDispatcher) {
206 this.shutdownDispatcher = shutdownDispatcher;
207 }
208
209 /**
210 * @return Defaults to true
211 */
212 public boolean shutdownDispatcher() {
213 return this.shutdownDispatcher;
214 }
215
216 /**
217 * Shutdown the client side callback server on disconnect.
218 * <p>
219 * Controls client side behavior.
220 * </p>
221 * @param shutdownCbServer true is default
222 */
223 public void shutdownCbServer(boolean shutdownCbServer) {
224 this.shutdownCbServer = shutdownCbServer;
225 }
226
227 /**
228 * @return Defaults to true
229 */
230 public boolean shutdownCbServer() {
231 return this.shutdownCbServer;
232 }
233
234 /**
235 * @return Returns the current setting
236 */
237 public boolean isLeaveServer() {
238 return this.leaveServer;
239 }
240
241 /**
242 * Set this to true if you just want to cleanup the
243 * client library but not disconnect from the server.
244 * At the server our session remains and will queue messages
245 * for us until we login again.
246 * @param leaveServer The leaveServer to set.
247 */
248 public void setLeaveServer(boolean leaveServer) {
249 this.leaveServer = leaveServer;
250 }
251 }
syntax highlighted by Code2HTML, v. 0.9.1