File:  [LON-CAPA] / loncom / LondTransaction.pm
Revision 1.4: download - view: text, annotated - select for diffs
Thu May 15 02:21:45 2003 UTC (20 years, 11 months ago) by foxr
Branches: MAIN
CVS tags: version_0_99_1, version_0_99_0, conference_2003, HEAD
Don't need any stuff to keep track of sending the transaction... that's done
by LondConnection.

    1: #   This module defines and implements a class that represents
    2: #   a connection to a lond daemon.
    3: #
    4: # $Id: LondTransaction.pm,v 1.4 2003/05/15 02:21:45 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: }
  104: =pod
  105: 
  106: =item Activate
  107: 
  108: Activates the transaction by assigning it to a LondConnection object
  109: 
  110: Parameters:
  111: 
  112: =over 3
  113: 
  114: =item  Connection
  115: 
  116: 
  117: Reference to the LondConnection object along which the transaction
  118: will be carried.
  119: 
  120: =back 
  121: 
  122: =cut
  123: sub Activate {
  124:     my $self       = shift;
  125:     my $Connection = shift;	# Reference to a lond connection.
  126: 
  127:     $self->{londSocket} = $Connection; # Store the connection object and
  128:     $self->{active}     = 1;	       # Indicate it's active.
  129: 
  130: }
  131: 
  132: =pod
  133: 
  134: =item Retire
  135: 
  136: 
  137: Retires a transaction after successful completion.  If the
  138: transaction is deferred, the deferred file is destroyed.
  139: Otherwise this is a noop.
  140: 
  141: =cut
  142: sub Retire {
  143:     my $self     = shift;
  144: 
  145:     if($self->{deferred}) {
  146: 	unlink $self->{DeferredFile};
  147:     }
  148: 
  149:     #  Destroy my member data to release reference counts.
  150: 
  151:     delete $self->{londSocket};
  152:     delete $self->{clientSocket};
  153:     delete $self->{DeferredFile};
  154: 
  155: }
  156: 
  157: =pod
  158: 
  159: =item SetDeferred
  160: 
  161: Sets the state of a transaction to deferred, the deferred member
  162: is set true, clientSocket is undefined, and DeferredFile is set.
  163: 
  164: Parameters:
  165:  
  166: =over 3
  167: 
  168: =item File
  169: 
  170: Name of the file that holds the deferred transaction.
  171: 
  172: =back 
  173: 
  174: =cut
  175: sub SetDeferred {
  176:     my $self   = shift;
  177:     my $File   = shift;
  178: 
  179:     $self->{deferred}      = 1;
  180:     $self->{DeferrredFile} = $File;
  181: }
  182: 
  183: =pod
  184: 
  185: =item  SetClient
  186: 
  187: Sets the state of a transaction to not deferred.  The deferred member
  188: is set false, clientSocket is set and DeferredFile is undefined.
  189: 
  190: Parameters:
  191: 
  192: =over 3
  193: 
  194: =item Socket
  195: 
  196:   The socket open on the client.
  197: 
  198: =back
  199: 
  200: =cut
  201: sub SetClient {
  202:     my $self   = shift;
  203:     my $Client = shift;
  204:     
  205:     $self->{deferred}     = 0;
  206:     $self->{clientSocket} = $Client; 
  207: }
  208: 
  209: =pod
  210: 
  211: =head2  Selectors
  212: 
  213: 
  214: =item isDeferred
  215: 
  216: Returns the state of the deferred member.
  217: 
  218: =cut
  219: sub isDeferred {
  220:     my $self   = shift;
  221:     return $self->{deferred};
  222: }
  223: 
  224: =pod
  225: 
  226: =item isActive
  227: 
  228: Returns the value of the active member.
  229: 
  230: =cut
  231: sub isActive {
  232:     my $self = shift;
  233:     return $self->{active};
  234: }
  235: 
  236: =pod
  237: 
  238: =item getClient
  239: 
  240: If not deferred returns the client socket, else returns undef.
  241: 
  242: =cut
  243: sub getClient {
  244:     my $self = shift;
  245:     if($self->{deferred}) {
  246: 	return undef;
  247:     } else {
  248: 	return $self->{clientSocket};
  249:     }
  250: }
  251: 
  252: 
  253: =pod
  254: 
  255: =item getFile
  256: 
  257: If deferred, returns the name of the deferred queue file else
  258: returns undef.
  259: 
  260: =cut
  261: sub getFile {
  262:     my $self = shift;
  263:     if($self->{deferred}) {
  264: 	return $self->{DeferredFile};
  265:     } else {
  266: 	return undef;
  267:     }
  268: }
  269: 
  270: 
  271: =pod
  272: 
  273: =item getServer
  274: 
  275:   If active returns the lond server socket else undef.
  276: 
  277: =cut
  278: sub getServer {
  279:     my $self  = shift;
  280: 
  281:     if($self->{active}) {
  282: 	return $self->{londSocket};
  283:     } else {
  284: 	return undef;
  285:     }
  286: }
  287: 
  288: =pod
  289: 
  290: =item getRequest
  291: 
  292:   Returns the remaining request text.
  293: 
  294: =cut
  295: sub getRequest {
  296:     my $self = shift;
  297:     return $self->{request};
  298: }
  299: 
  300: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>