File:  [LON-CAPA] / loncom / LondTransaction.pm
Revision 1.7: download - view: text, annotated - select for diffs
Tue Jun 1 10:06:52 2004 UTC (19 years, 10 months ago) by foxr
Branches: MAIN
CVS tags: version_1_99_1_tmcc, version_1_99_0_tmcc, version_1_3_X, version_1_3_3, version_1_3_2, version_1_3_1, version_1_3_0, version_1_2_X, version_1_2_99_1, version_1_2_99_0, version_1_2_1, version_1_2_0, version_1_1_99_5, version_1_1_99_4, version_1_1_99_3, version_1_1_99_2, version_1_1_99_1, version_1_1_99_0, HEAD
Receive parameters via @_ when number > 1 as per standard.

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

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