GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  THREAD::QUEUE::QUEUEABLE (3)

.ds Aq ’

NAME

Thread::Queue::Queueable - abstract class for marshalling elements for a Thread::Queue::Duplex queue

CONTENTS

SYNOPSIS



        use Thread::Queue::Queueable;
        use base qw(Thread::Queue::Queueable);
        #
        #       implement onEnqueue method
        #       (default implementation shown)
        #
        sub onEnqueue {
                my $obj = shift;
        #
        #       capture class name, and create shared
        #       version of object
        #
                return $obj->isa(ARRAY) ?
                        (ref $obj, share([ @$obj ])) :
                        (ref $obj, share({ %$obj }));
        }
        #
        #       implement onDequeue method
        #       (default implementation shown)
        #
        sub onDequeue {
                my ($class, $obj) = @_;
        #
        #       reconstruct as non-shared
        #
                $obj = (ref $obj eq ARRAY) ? [ @$obj ] : { %$obj };
                bless $obj, $class;
                return $obj;
        }
        #
        #       permit the object to be reconstructed on dequeueing
        #
        sub onCancel {
                my $obj = shift;
                return 1;
        }
        #
        #       curse (ie, unbless) the object into a shared structure
        #
        sub curse {
                my $obj = shift;

                if ($obj->isa(HASH)) {
                        my %cursed : shared = ();
                        $cursed{$_} = $obj->{$_}
                                foreach (keys %$obj);
                        return \%cursed;
                }

                my @cursed : shared = ();
                $cursed[$_] = $obj->[$_]
                        foreach (0..$#$obj);
                return \@cursed;
        }
        #
        #       redeem (ie, rebless) the object into
        #       the class
        #
        sub redeem {
                my ($class, $obj) = @_;

                if (ref $obj eq HASH) {
                        my $redeemed = {};
                        $redeemed->{$_} = $obj->{$_}
                                foreach (keys %$obj);
                        return bless $redeemed, $class;
                }

                my $redeemed = [];
                $redeemed->[$_] = $obj->[$_]
                        foreach (0..$#$obj);
                return bless $redeemed, $class;
        }



DESCRIPTION

Thread::Queue::Queueable (aka TQQ) provides abstract methods to be invoked whenever an object is enqueued or dequeued, in either the request or response direction, on a Thread::Queue::Duplex (TQD) queue.

The primary purpose is to simplify application logic so that marshalling/unmarhsalling of objects between threads is performed automatically. In addition, when subclassed, the application class can modify or add logic (e.g., notifying a server thread object to update its reference count when a wrapped object is passed between threads - see DBIx::Threaded for an example).

METHODS

Refer to the included classdocs for summary and detailed method descriptions.

SEE ALSO

Thread::Queue::Duplex, threads, threads::shared, Thread::Queue

AUTHOR, COPYRIGHT, & LICENSE

Dean Arnold, Presicient Corp. darnold@presicient.com

Copyright(C) 2005, Presicient Corp., USA

Permission is granted to use this software under the same terms as Perl itself. Refer to the Perl Artistic License for details.

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 THREAD::QUEUE::QUEUEABLE (3) 2006-03-18

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.