1 /*------------------------------------------------------------------------------
2 Name: SessionQos.h
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 Comment: Factory for SessionQosData (for org::xmlBlaster::util::qos::ConnectReturnQos and org::xmlBlaster::util::qos::ConnectQos)
6 ------------------------------------------------------------------------------*/
7
8 #ifndef _UTIL_QOS_SESSIONQOS_H
9 #define _UTIL_QOS_SESSIONQOS_H
10
11 #include <util/xmlBlasterDef.h>
12 #include <string>
13 #include <util/XmlQoSBase.h>
14 #include <util/StringTrim.h>
15 #include <util/SessionName.h>
16
17 /**
18 *
19 * <session timeout='86400000'
20 * maxSessions='10'
21 * clearSessions='false'
22 * name='/node/http:/client/ticheta/-3'>
23 * <sessionId>IIOP:01110728321B0222011028</sessionId>
24 * </session>
25 *
26 */
27
28 namespace org { namespace xmlBlaster { namespace util { namespace qos {
29
30
31
32 class Dll_Export SessionQosData : public org::xmlBlaster::util::ReferenceCounterBase
33 {
34 private:
35 const std::string ME;
36 long timeout_;
37 int maxSessions_;
38 bool clearSessions_;
39 bool reconnectSameClientOnly_;
40 std::string sessionId_; // secret !
41 org::xmlBlaster::util::SessionNameRef sessionName_;
42 org::xmlBlaster::util::Global& global_;
43
44 friend class SessionQosFactory;
45
46 void copy(const SessionQosData& data);
47
48 void initialize();
49
50 public:
51 virtual ~SessionQosData();
52
53 /**
54 * When using this constructor you can let it assign the defaults by passing an empty std::string as the
55 * 'absoluteName' argument, or you force the SessionQos to set the SessionName to what you specify in the
56 * 'absoluteName' argument.
57 * @param absoluteName the sessionId to assign to this SessionQos. You can either pass an absolute name,
58 * or a relative name or an empty std::string.
59 */
60 SessionQosData(org::xmlBlaster::util::Global& global, const std::string& absoluteName="");
61
62 /**
63 * @defaultUserName is the name to use as a default for the user (the subjectId). It is stronger than the
64 * properties set but if an empty std::string is used, then the default name is taken from the 'user' property.
65 * This is just a default and as such it is weaker than the property 'session.name'. In other words, even
66 * if defaultUserName is not empty, it will be overwritten by eventual setting of the property 'session.name'.
67 *
68 * @publicSessionId is the public sessionId to be used. Note that this is just a suggestion, so if you
69 * have the 'session.name' property set, it will overwrite this. If the publicSessionId is '0', then it
70 * is omitted (the server will assign one for you).
71 */
72 SessionQosData(org::xmlBlaster::util::Global& global, const std::string& defaultUserName, long publicSessionId);
73 SessionQosData(const SessionQosData& data);
74 SessionQosData& operator =(const SessionQosData& data);
75 long getTimeout() const;
76 void setTimeout(long timeout);
77 int getMaxSessions() const;
78 void setMaxSessions(int maxSessions);
79 bool getClearSessions() const;
80 void setClearSessions(bool clearSessions);
81 bool getReconnectSameClientOnly() const;
82 void setReconnectSameClientOnly(bool reconnectSameClientOnly);
83
84 /**
85 * Sets the absolute name. It checks if it really is an absolute name,
86 * i.e. if it contains the well known structure '/node/....' it parses it,
87 * otherwise it leaves it untouched (i.e. it will not parse it).
88 */
89
90 /**
91 * Sets the absolute name. Note that you can overwrite the nodeId here. It returns 'true' if the
92 * name was absolute, 'false' otherwise.
93 * This is a convenience access for getSessionName()->setAbsoluteName(name)
94 */
95 void setAbsoluteName(/*const std::string nodeId="",*/ const std::string& name);
96 std::string getRelativeName() const;
97 std::string getAbsoluteName() const;
98 std::string getClusterNodeId() const;
99 void setClusterNodeId(const std::string& clusterNodeId);
100 std::string getSubjectId() const;
101 void setSubjectId(const std::string& subjectId);
102 long getPubSessionId() const;
103 void setPubSessionId(const long pubSessionId);
104 /**
105 * Your changes outside change the internal sessionName.
106 * @return A reference counted SessionName.
107 */
108 org::xmlBlaster::util::SessionNameRef getSessionName();
109
110 std::string getSecretSessionId() const;
111 void setSecretSessionId(const std::string& sessionId);
112 std::string toXml(const std::string& extraOffset="") const;
113 /**
114 * Get a usage string for the session parameters
115 */
116 static std::string usage();
117 };
118
119 class Dll_Export SessionQosFactory: public util::XmlQoSBase
120 {
121 private:
122 const std::string ME;
123 SessionQosData* sessionQos_;
124
125 public:
126 SessionQosFactory(org::xmlBlaster::util::Global& global);
127
128 ~SessionQosFactory();
129
130 /**
131 * This characters emulates the java version but keep in mind that it is
132 * not the virtual method inherited from DocumentHandler !!
133 */
134 void characters(const std::string &ch);
135
136 /**
137 * Start element, event from SAX parser.
138 * <p />
139 * @param name Tag name
140 * @param attrs the attributes of the tag
141 */
142 void startElement(const std::string &name, const parser::AttributeMap& attrs);
143
144 /**
145 * End element, event from SAX parser.
146 * <p />
147 * @param name Tag name
148 */
149 void endElement(const std::string &name);
150
151 void reset();
152
153 const SessionQosData& getData() const;
154
155 SessionQosData readObject(const std::string& qos);
156
157 };
158
159 typedef SessionQosData SessionQos;
160
161 typedef SessionQosData SessionReturnQos;
162
163 typedef org::xmlBlaster::util::ReferenceHolder<SessionQosData> SessionQosRef;
164 typedef org::xmlBlaster::util::ReferenceHolder<SessionReturnQos> SessionReturnQosRef;
165
166 }}}} // namespaces
167
168 #endif
syntax highlighted by Code2HTML, v. 0.9.1