Changeset 3aa185bfecd34f5a0f526297df835f6484df31ac in xas


Ignore:
Timestamp:
08/25/15 10:23:35 (2 years ago)
Author:
Kevin L. Esteb <kevin@…>
Branches:
master
Children:
e4ae52787f79097612444755cba6f78dee723cfe
Parents:
e5ded116dbf8a4f73f0c6b5413b8f165f1d54285
git-author:
Kevin L. Esteb <kevin@…> (08/25/15 10:23:35)
git-committer:
Kevin L. Esteb <kevin@…> (08/25/15 10:23:35)
Message:

Added a default exception handler to a Session.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/XAS/Lib/POE/Session.pm

    rd5946e6cc9a331b66265cbba35c959e84f4e1695 r3aa185bfecd34f5a0f526297df835f6484df31ac  
    11package XAS::Lib::POE::Session; 
    22 
    3 our $VERSION = '0.03'; 
     3our $VERSION = '0.04'; 
    44 
    55use POE; 
     
    99  version   => $VERSION, 
    1010  base      => 'XAS::Base', 
    11   utils     => 'weaken', 
     11  mixin     => 'XAS::Lib::Mixins::Handlers', 
     12  utils     => 'weaken dotid', 
    1213  accessors => 'session', 
    1314  vars => { 
     
    7677sub session_stop { 
    7778    my $self = shift; 
     79 
     80} 
     81 
     82sub session_exception { 
     83    my $self = shift; 
     84    my $hash = shift; 
     85 
     86    my $alias = $self->alias; 
     87    my $ex    = $hash->{'error_str'}; 
     88 
     89    $self->log->debug("$alias: session_exception() - session"); 
     90    $self->error_handler($ex); 
    7891 
    7992} 
     
    113126                session_shutdown  => '_session_shutdown', 
    114127                session_interrupt => '_session_interrupt', 
     128                session_exception => '_session_exception', 
    115129            }, 
    116130        ] 
     
    137151 
    138152        $self->throw_msg( 
    139             'xas.session._session_start.noalias', 
     153            dotid($self->class) . '._session_start.noalias', 
    140154            'session_noalias', 
    141155            $alias 
     
    144158    } 
    145159 
     160    $poe_kernel->sig('DIE', 'session_exception'); 
    146161    $poe_kernel->post($alias, 'session_init'); 
    147162 
     
    215230 
    216231    $self->session_interrupt($signal); 
     232 
     233} 
     234 
     235sub _session_exception { 
     236    my ($self, $sig, $ex) = @_[OBJECT,ARG0,ARG1]; 
     237 
     238    my $alias = $self->alias; 
     239 
     240    $self->log->debug("$alias: _session_exception()"); 
     241 
     242    $self->log->debug(sprintf("%s: file:  %s", $alias, $ex->{'file'})); 
     243    $self->log->debug(sprintf("%s: line:  %s", $alias, $ex->{'line'})); 
     244    $self->log->debug(sprintf("%s: state: %s", $alias, $ex->{'from_state'} || '')); 
     245    $self->log->debug(sprintf("%s: source: %s", $alias, $ex->{'source_session'} || '')); 
     246    $self->log->debug(sprintf("%s: destinaion: %s", $alias, $ex->{'dest_session'} || '')); 
     247 
     248    $poe_kernel->sig_handled(); 
     249 
     250    if ($ex->{'source_session'} ne $_[SESSION]) { 
     251 
     252        $poe_kernel->signal($ex->{'source_session'}, 'DIE', $sig, $ex); 
     253 
     254    } else { 
     255 
     256        $self->session_exception($ex); 
     257 
     258    } 
    217259 
    218260} 
     
    280322HUP signal. 
    281323 
    282 =head2 session_interrupt 
     324=head2 session_interrupt($signal) 
    283325 
    284326This is called when the process receives a signal. By default, when a  
    285327HUP signal is received it will call session_reload() otherwise it  
    286328calls session_shutdown(). 
     329 
     330=over 4 
     331 
     332=item B<$signal> 
     333 
     334The signal that was trapped. 
     335 
     336=back 
     337 
     338=head2 session_exception($ex) 
     339 
     340This is called when a exception or "die" happens. By default, this just 
     341prints out the messages and continues on. This provides a default exception 
     342handler for a session. 
     343 
     344=over 4 
     345 
     346=item B<$ex> 
     347 
     348The exception hash that is generated by POE. The field 'error_str' is used 
     349to print out the exception message. 
     350 
     351=back 
    287352 
    288353=head2 session_stop 
Note: See TracChangeset for help on using the changeset viewer.