Annotation of loncom/LondTransaction.pm, revision 1.6
1.1 foxr 1: # This module defines and implements a class that represents
2: # a connection to a lond daemon.
3: #
1.6 ! foxr 4: # $Id: LondTransaction.pm,v 1.5 2003/06/11 02:04:35 foxr Exp $
1.1 foxr 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
1.3 foxr 30:
31: =head1 Synopsis
32:
1.2 foxr 33: LondTransaction objectifies the state of a transaction between lonc and
1.1 foxr 34: lond (loncnew really).
35:
36: =cut
37:
1.6 ! foxr 38: use strict;
! 39:
1.3 foxr 40: package LondTransaction;
1.2 foxr 41:
42: =pod
43: =head1 Description
44:
45: LondTransaction objects hold the state required to manage a
46: transaction between lonc and lond, from the loncnew point of view.
47: The state consists of the following member data:
48:
49: =item request
50:
51: The text of the request to send to lond.
52:
53: =item active
54:
55: If zero, the request is not active and the londSocket item is not
56: defined.
57:
58: =item londSocket
59:
1.3 foxr 60: If the request is active,
1.2 foxr 61: this member contains the LondConnection object reference that
62: this request is being processed on.
63:
64: =item deferred
65:
66: True if the request is a deferred (delayed) request.
67: The member data below are either present or not depending on
68: whether or not deferred is true.
69:
70: =item clientSocket
71:
72: If deferred is false, this member data is defined and is the
73: handle to the socket that is connected to the apache child that
74: has requested this transaction.
75:
76: =item DeferredFile
77:
78: If deferred is false, this member data is defined and is the name
79: of the file that contains the deferred request. When the transaction
80: is retired, this file will be deleted.
81:
82: =head1 Member Functions
83:
84: =head2 Operational functions
85:
1.3 foxr 86: =cut
87:
88: =pod
89:
1.2 foxr 90: =item new
91:
92: Creates a new transaction object.
93:
1.3 foxr 94: =cut
1.6 ! foxr 95:
! 96:
1.3 foxr 97:
98: sub new {
99: my $class = shift;
100: my $Transaction = shift;
101:
102:
103: my $self = {request => $Transaction,
104: active => 0,
105: deferred => 0};
106: bless($self, $class);
1.5 foxr 107: return $self;
1.3 foxr 108: }
109: =pod
110:
1.2 foxr 111: =item Activate
112:
113: Activates the transaction by assigning it to a LondConnection object
114:
1.3 foxr 115: Parameters:
116:
117: =over 3
118:
119: =item Connection
120:
121:
122: Reference to the LondConnection object along which the transaction
123: will be carried.
124:
125: =back
126:
127: =cut
128: sub Activate {
129: my $self = shift;
130: my $Connection = shift; # Reference to a lond connection.
131:
132: $self->{londSocket} = $Connection; # Store the connection object and
133: $self->{active} = 1; # Indicate it's active.
134:
135: }
136:
137: =pod
138:
1.2 foxr 139: =item Retire
140:
1.3 foxr 141:
142: Retires a transaction after successful completion. If the
143: transaction is deferred, the deferred file is destroyed.
144: Otherwise this is a noop.
145:
146: =cut
147: sub Retire {
148: my $self = shift;
149:
150: if($self->{deferred}) {
151: unlink $self->{DeferredFile};
152: }
153:
154: # Destroy my member data to release reference counts.
155:
156: delete $self->{londSocket};
157: delete $self->{clientSocket};
158: delete $self->{DeferredFile};
159:
160: }
161:
162: =pod
1.2 foxr 163:
164: =item SetDeferred
165:
166: Sets the state of a transaction to deferred, the deferred member
167: is set true, clientSocket is undefined, and DeferredFile is set.
168:
1.3 foxr 169: Parameters:
170:
171: =over 3
172:
173: =item File
174:
175: Name of the file that holds the deferred transaction.
176:
177: =back
178:
179: =cut
180: sub SetDeferred {
181: my $self = shift;
182: my $File = shift;
183:
184: $self->{deferred} = 1;
1.5 foxr 185: $self->{DeferredFile} = $File;
1.3 foxr 186: }
187:
188: =pod
189:
190: =item SetClient
1.2 foxr 191:
192: Sets the state of a transaction to not deferred. The deferred member
193: is set false, clientSocket is set and DeferredFile is undefined.
194:
1.3 foxr 195: Parameters:
196:
197: =over 3
198:
199: =item Socket
200:
201: The socket open on the client.
202:
203: =back
204:
205: =cut
206: sub SetClient {
207: my $self = shift;
208: my $Client = shift;
209:
210: $self->{deferred} = 0;
211: $self->{clientSocket} = $Client;
212: }
213:
214: =pod
215:
1.2 foxr 216: =head2 Selectors
217:
218:
219: =item isDeferred
220:
221: Returns the state of the deferred member.
222:
1.3 foxr 223: =cut
224: sub isDeferred {
225: my $self = shift;
226: return $self->{deferred};
227: }
228:
229: =pod
230:
1.2 foxr 231: =item isActive
232:
1.3 foxr 233: Returns the value of the active member.
234:
235: =cut
236: sub isActive {
237: my $self = shift;
238: return $self->{active};
239: }
240:
241: =pod
1.2 foxr 242:
243: =item getClient
244:
1.3 foxr 245: If not deferred returns the client socket, else returns undef.
246:
247: =cut
248: sub getClient {
249: my $self = shift;
250: if($self->{deferred}) {
251: return undef;
252: } else {
253: return $self->{clientSocket};
254: }
255: }
256:
257:
258: =pod
1.2 foxr 259:
260: =item getFile
261:
262: If deferred, returns the name of the deferred queue file else
263: returns undef.
264:
265: =cut
1.3 foxr 266: sub getFile {
267: my $self = shift;
268: if($self->{deferred}) {
269: return $self->{DeferredFile};
270: } else {
271: return undef;
272: }
273: }
274:
275:
276: =pod
277:
278: =item getServer
279:
280: If active returns the lond server socket else undef.
281:
282: =cut
283: sub getServer {
284: my $self = shift;
285:
286: if($self->{active}) {
287: return $self->{londSocket};
288: } else {
289: return undef;
290: }
291: }
292:
293: =pod
294:
295: =item getRequest
296:
297: Returns the remaining request text.
298:
299: =cut
300: sub getRequest {
301: my $self = shift;
302: return $self->{request};
303: }
304:
305:
1.5 foxr 306: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>