File:
[LON-CAPA] /
loncom /
LondTransaction.pm
Revision
1.5:
download - view:
text,
annotated -
select for diffs
Wed Jun 11 02:04:35 2003 UTC (21 years, 3 months ago) by
foxr
Branches:
MAIN
CVS tags:
version_1_0_3,
version_1_0_2,
version_1_0_1,
version_1_0_0,
version_0_99_5,
version_0_99_4,
version_0_99_3,
version_0_99_2,
HEAD
Support delayed transactions... this is done uniformly by encapsulating
transactions in an object ... a LondTransaction that is implemented by
LondTransaction.pm
1: # This module defines and implements a class that represents
2: # a connection to a lond daemon.
3: #
4: # $Id: LondTransaction.pm,v 1.5 2003/06/11 02:04:35 foxr Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: =pod
30:
31: =head1 Synopsis
32:
33: LondTransaction objectifies the state of a transaction between lonc and
34: lond (loncnew really).
35:
36: =cut
37:
38: package LondTransaction;
39:
40: =pod
41: =head1 Description
42:
43: LondTransaction objects hold the state required to manage a
44: transaction between lonc and lond, from the loncnew point of view.
45: The state consists of the following member data:
46:
47: =item request
48:
49: The text of the request to send to lond.
50:
51: =item active
52:
53: If zero, the request is not active and the londSocket item is not
54: defined.
55:
56: =item londSocket
57:
58: If the request is active,
59: this member contains the LondConnection object reference that
60: this request is being processed on.
61:
62: =item deferred
63:
64: True if the request is a deferred (delayed) request.
65: The member data below are either present or not depending on
66: whether or not deferred is true.
67:
68: =item clientSocket
69:
70: If deferred is false, this member data is defined and is the
71: handle to the socket that is connected to the apache child that
72: has requested this transaction.
73:
74: =item DeferredFile
75:
76: If deferred is false, this member data is defined and is the name
77: of the file that contains the deferred request. When the transaction
78: is retired, this file will be deleted.
79:
80: =head1 Member Functions
81:
82: =head2 Operational functions
83:
84: =cut
85:
86: =pod
87:
88: =item new
89:
90: Creates a new transaction object.
91:
92: =cut
93:
94: sub new {
95: my $class = shift;
96: my $Transaction = shift;
97:
98:
99: my $self = {request => $Transaction,
100: active => 0,
101: deferred => 0};
102: bless($self, $class);
103: return $self;
104: }
105: =pod
106:
107: =item Activate
108:
109: Activates the transaction by assigning it to a LondConnection object
110:
111: Parameters:
112:
113: =over 3
114:
115: =item Connection
116:
117:
118: Reference to the LondConnection object along which the transaction
119: will be carried.
120:
121: =back
122:
123: =cut
124: sub Activate {
125: my $self = shift;
126: my $Connection = shift; # Reference to a lond connection.
127:
128: $self->{londSocket} = $Connection; # Store the connection object and
129: $self->{active} = 1; # Indicate it's active.
130:
131: }
132:
133: =pod
134:
135: =item Retire
136:
137:
138: Retires a transaction after successful completion. If the
139: transaction is deferred, the deferred file is destroyed.
140: Otherwise this is a noop.
141:
142: =cut
143: sub Retire {
144: my $self = shift;
145:
146: if($self->{deferred}) {
147: unlink $self->{DeferredFile};
148: }
149:
150: # Destroy my member data to release reference counts.
151:
152: delete $self->{londSocket};
153: delete $self->{clientSocket};
154: delete $self->{DeferredFile};
155:
156: }
157:
158: =pod
159:
160: =item SetDeferred
161:
162: Sets the state of a transaction to deferred, the deferred member
163: is set true, clientSocket is undefined, and DeferredFile is set.
164:
165: Parameters:
166:
167: =over 3
168:
169: =item File
170:
171: Name of the file that holds the deferred transaction.
172:
173: =back
174:
175: =cut
176: sub SetDeferred {
177: my $self = shift;
178: my $File = shift;
179:
180: $self->{deferred} = 1;
181: $self->{DeferredFile} = $File;
182: }
183:
184: =pod
185:
186: =item SetClient
187:
188: Sets the state of a transaction to not deferred. The deferred member
189: is set false, clientSocket is set and DeferredFile is undefined.
190:
191: Parameters:
192:
193: =over 3
194:
195: =item Socket
196:
197: The socket open on the client.
198:
199: =back
200:
201: =cut
202: sub SetClient {
203: my $self = shift;
204: my $Client = shift;
205:
206: $self->{deferred} = 0;
207: $self->{clientSocket} = $Client;
208: }
209:
210: =pod
211:
212: =head2 Selectors
213:
214:
215: =item isDeferred
216:
217: Returns the state of the deferred member.
218:
219: =cut
220: sub isDeferred {
221: my $self = shift;
222: return $self->{deferred};
223: }
224:
225: =pod
226:
227: =item isActive
228:
229: Returns the value of the active member.
230:
231: =cut
232: sub isActive {
233: my $self = shift;
234: return $self->{active};
235: }
236:
237: =pod
238:
239: =item getClient
240:
241: If not deferred returns the client socket, else returns undef.
242:
243: =cut
244: sub getClient {
245: my $self = shift;
246: if($self->{deferred}) {
247: return undef;
248: } else {
249: return $self->{clientSocket};
250: }
251: }
252:
253:
254: =pod
255:
256: =item getFile
257:
258: If deferred, returns the name of the deferred queue file else
259: returns undef.
260:
261: =cut
262: sub getFile {
263: my $self = shift;
264: if($self->{deferred}) {
265: return $self->{DeferredFile};
266: } else {
267: return undef;
268: }
269: }
270:
271:
272: =pod
273:
274: =item getServer
275:
276: If active returns the lond server socket else undef.
277:
278: =cut
279: sub getServer {
280: my $self = shift;
281:
282: if($self->{active}) {
283: return $self->{londSocket};
284: } else {
285: return undef;
286: }
287: }
288:
289: =pod
290:
291: =item getRequest
292:
293: Returns the remaining request text.
294:
295: =cut
296: sub getRequest {
297: my $self = shift;
298: return $self->{request};
299: }
300:
301:
302: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>