Source code: mobile/jmsapi/Session.java
1 /** Java class "Session.java" generated from Poseidon for UML.
2 * Poseidon for UML is developed by <A HREF="http://www.gentleware.com">Gentleware</A>.
3 * Generated with <A HREF="http://jakarta.apache.org/velocity/">velocity</A> template engine.
4 */
5 package mobile.jmsapi;
6
7 import mobile.protocol.Reply;
8 import mobile.bearer.http.Protocol;
9
10 /**
11 * <p>
12 * class representing session of connection with JMS provider
13 * </p>
14 */
15 public abstract class Session extends Id_class implements Protocol{
16
17 ///////////////////////////////////////
18 // attributes
19
20 public static final int AUTO_ACKNOWLEDGE = JMSMessageConstants.AUTO_ACKNOWLEDGE;
21 public static final int DUPS_OK_ACKNOWLEDGE = JMSMessageConstants.DUPS_OK_ACKNOWLEDGE;
22 public static final int CLIENT_ACKNOWLEDGE = JMSMessageConstants.CLIENT_ACKNOWLEDGE;
23 public static final int SESSION_TRANSACTED = JMSMessageConstants.SESSION_TRANSACTED;
24
25
26 /**
27 * <p>
28 * determines if this session is transacted
29 * </p>
30 */
31 private int transacted;
32
33 ///////////////////////////////////////
34 // operations
35
36 /**
37 * <p>
38 * A "subclass responsibility" method
39 * Creates new Consumer, apropriate to the subclass type
40 * (QueueReciever xor TopicSubscriber)
41 * </p><p>
42 *
43 * @return a new Consumer of proper type
44 * </p>
45 */
46 protected abstract Consumer newConsumer();
47
48 /**
49 * <p>
50 * A "subclass responsibility" method
51 * creates new Producer, apropriate to the subclass type
52 * (QueueSender xor TopicPublisher)
53 * </p><p>
54 *
55 * @return a new Producer of proper type
56 * </p>
57 */
58 protected abstract Producer newProducer();
59
60
61
62 /**
63 * <p>
64 * creates new TextMessage to be filled and sent
65 * </p><p>
66 *
67 * @return a new TextMessage object
68 * </p>
69 */
70 public TextMessage createTextMessage()
71 {
72 return new TextMessage();
73 } // end createTextMessage
74
75 /**
76 * <p>
77 * creates new BytesMessage to be filled and sent
78 * </p><p>
79 *
80 * @return a new BytesMessage object
81 * </p>
82 */
83 public BytesMessage createBytesMessage()
84 {
85 return new BytesMessage();
86 } // end createBytesMessage
87
88 /**
89 * <p>
90 * Commits all messages done in this transaction and releases any locks currently held.
91 * </p><p>
92 *
93 * </p>
94 */
95 public void commit()
96 throws JMSException
97 {
98 try
99 {
100 Reply rep = request(COMMIT, new Integer(id));
101 }
102 catch (Throwable err)
103 {
104 throw new JMSException("communication lost");
105 }
106 } // end commit
107
108 /**
109 * <p>
110 * Rolls back any messages done in this transaction and releases any locks
111 * currently held. </p>
112 */
113 public void rollback()
114 throws JMSException
115 {
116 try
117 {
118 Reply rep = request(ROLLBACK, new Integer(id));
119 }
120 catch (Throwable err)
121 {
122 throw new JMSException("communnication lost");
123 }
124 } // end rollback
125
126 /**
127 * <p>
128 * creates a new message consumer from specified source
129 * </p><p>
130 * @param _dest is a source of messages
131 * </p><p>
132 * @return new Consumer
133 * </p>
134 */
135 public Consumer createConsumer(Destination _dest)
136 throws JMSException
137 {
138 Reply rep;
139 Consumer retVal;
140
141 try
142 {
143 rep = request(CREATE_RECEIVER | TYPE_MASK(), new Integer(id), new Integer(_dest.id));
144 if (rep.code == (REP_RECEIVER | TYPE_MASK()))
145 {
146 retVal = newConsumer();
147 retVal.id = ( (Integer) rep.getData()[0]).intValue();
148 retVal.session = this;
149 retVal.setSource(_dest);
150 return retVal;
151 }
152 return null;
153 }
154 catch (Throwable e)
155 {
156 e.printStackTrace();
157 throw new JMSException("communication lost");
158 }
159 } // end createConsumer
160
161 /**
162 * <p>
163 * creates new message producer for specified destination
164 * </p><p>
165 * <p>
166 * @param _dest is a messages destination
167 * </p>
168 *
169 * @return new Producer
170 * </p>
171 */
172 public Producer createProducer(Destination _dest)
173 throws JMSException
174 {
175 Reply rep;
176 Producer retVal;
177 try
178 {
179 rep = request(CREATE_SENDER | TYPE_MASK(), new Integer(id), new Integer(_dest.id));
180 if (rep.code == (REP_SENDER | TYPE_MASK()))
181 {
182 retVal = newProducer();
183 retVal.id = ( (Integer) rep.getData()[0]).intValue();
184 retVal.session = this;
185 retVal.setDestination(_dest);
186 return retVal;
187 }
188 return null;
189 }
190 catch (Throwable e)
191 {
192 e.printStackTrace();
193 throw new JMSException("communication lost");
194 }
195 } // end createProducer
196
197
198
199 } // end Session
200
201
202
203
204