Tibco::Rv::Dispatcher - Tibco Queue dispatching thread


Tibco-Rv documentation Contained in the Tibco-Rv distribution.

Index


Code Index:

NAME

Top

Tibco::Rv::Dispatcher - Tibco Queue dispatching thread

SYNOPSIS

Top

   $queue = $rv->createQueue;
   $dispatcher = new Tibco::Rv::Dispatcher( dispatchable => $queue );

DESCRIPTION

Top

A Tibco::Rv::Dispatcher object is an independent thread that repeatedly dispatches events waiting on the specified dispatchable. A dispatchable is either a Tibco::Rv::Queue or a Tibco::Rv::QueueGroup.

CONSTRUCTOR

Top

$dispatcher = new Tibco::Rv::Dispatcher( %args )
   %args:
      dispatchable => $dispatchable,
      name => $name,
      idleTimeout => $idleTimeout

Creates a Tibco::Rv::Dispatcher. If not specified, dispatchable defaults to the Default Queue, name defaults to 'dispatcher', and idleTimeout defaults to Tibco::Rv::WAIT_FOREVER.

Upon creating $dispatcher, it starts a separate thread, which repeatedly calls timedDispatch on $dispatchable, passing it the $idleTimeout value. The thread exits after $idleTimeout seconds have passed without any events being placed on the $dispatchable. $idleTimeout can specify fractional seconds.

If $idleTimeout is Tibco::Rv::WAIT_FOREVER (the default value), then $dispatcher continues dispatching events until DESTROY is called or the program exits -- when no events are waiting on the $dispatchable in this case, $dispatcher simply blocks. If $idleTimeout is Tibco::Rv::NO_WAIT, then $dispatcher dispatches events until no events are waiting on $dispatchable, at which point the thread exits.

METHODS

Top

$dispatchable = $dispatcher->dispatchable

Returns the Queue or QueueGroup that $dispatcher is dispatching events on.

$idleTimeout = $dispatcher->dispatchable

Returns the idleTimeout value $dispatcher is using to call timedDispatch on its dispatchable.

$name = $dispatcher->name

Returns the name of $dispatcher.

$dispatcher->name( $name )

Sets $dispatcher's name to $name. Use this to distinguish multiple dispatchers and assist troubleshooting. If $name is undef, sets name to ''.

$dispatcher->DESTROY

Exits the thread and destroys $dispatcher. Called automatically at program exit.

SEE ALSO

Top

Tibco::Rv::Queue
Tibco::Rv::QueueGroup

AUTHOR

Top

Paul Sturm <sturm@branewave.com>


Tibco-Rv documentation Contained in the Tibco-Rv distribution.

package Tibco::Rv::Dispatcher;


use vars qw/ $VERSION /;
$VERSION = '1.11';


use Inline with => 'Tibco::Rv::Inline';
use Inline C => 'DATA', NAME => __PACKAGE__,
   VERSION => $Tibco::Rv::Inline::VERSION;


sub new
{
   my ( $proto ) = shift;
   my ( %params ) = ( dispatchable => $Tibco::Rv::Queue::DEFAULT,
      idleTimeout => Tibco::Rv::WAIT_FOREVER, name => 'dispatcher' );
   my ( %args ) = @_;
   map { Tibco::Rv::die( Tibco::Rv::INVALID_ARG )
      unless ( exists $params{$_} ) } keys %args;
   %params = ( %params, %args );
   my ( $class ) = ref( $proto ) || $proto;
   my ( $self ) = bless { id => undef, %params }, $class;

   my ( $status ) = Dispatcher_Create(
      $self->{id}, $self->{dispatchable}{id}, $self->{idleTimeout} );
   Tibco::Rv::die( $status ) unless ( $status == Tibco::Rv::OK );
   $self->name( $params{name} ) if ( defined $params{name} );

   return $self;
}


sub dispatchable { return shift->{dispatchable} }
sub idleTimeout { return shift->{idleTimeout} }


sub name
{
   my ( $self ) = shift;
   return @_ ? $self->_setName( @_ ) : $self->{name};
}


sub _setName
{
   my ( $self, $name ) = @_;
   $name = '' unless ( defined $name );
   my ( $status ) = tibrvDispatcher_SetName( $self->{id}, $name );
   Tibco::Rv::die( $status ) unless ( $status == Tibco::Rv::OK );
   return $self->{name} = $name;
}


# blah -- tibrvDispatcher_Destroy gets called automatically when
# idleTimeout times out, or you can call it manually!
# how would the idleTimeout inform this object?  Listening on
# DISPATCHER.THREAD_EXITED?
sub DESTROY
{
   my ( $self ) = @_;
   return unless ( exists $self->{id} );

   my ( $status ) = tibrvDispatcher_Destroy( $self->{id} );
   delete $self->{id};
   Tibco::Rv::die( $status ) unless ( $status == Tibco::Rv::OK );
}


1;



__DATA__
__C__

tibrv_status tibrvDispatcher_SetName( tibrvDispatcher dispatcher,
   const char * name );
tibrv_status tibrvDispatcher_Destroy( tibrvDispatcher dispatcher );


tibrv_status Dispatcher_Create( SV * sv_dispatcher,
   tibrvDispatchable dispatchable, tibrv_f64 idleTimeout )
{
   tibrvDispatcher dispatcher = (tibrvDispatcher)NULL;
   tibrv_status status = tibrvDispatcher_CreateEx( &dispatcher, dispatchable,
      idleTimeout );
   sv_setiv( sv_dispatcher, (IV)dispatcher );
   return status;
}