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
ResourcePool::Command(3) User Contributed Perl Documentation ResourcePool::Command(3)

ResourcePool::Command - The implementation of the Command design pattern with ResourcePool.

 package Command;
 
 use ResourcePool::Command;
 use vars qw(@ISA);
 
 push @ISA, qw(ResourcePool::Command);
 
 sub new($) {
     my $proto = shift;
     my $class = ref($proto) || $proto;
     my $self = {};
     bless($self, $class);
     return $self;
 }
 
 sub execute($$) {
     my ($self, $resource) = @_;
     return "The quick brown fox jumps over the lazy dog\n";
 }
 
 package main;
 
 my $pool; # imagine this is a ResourcePool 
           # or LoadBalancer instance
 my $cmd = Command->new();
 
 print $pool->execute($cmd);
 # prints "The quick brown fox jumps over the lazy dog" and a new line

The ResourcePool::Command class builds a base for commands like described in the GoF book "Design Patterns".

This makes it possible to use ResourcePool in a very different way, without manually calling the get(), free() or fail() methods. This common structure is encapsulated into the ResourcePool::Command::Execute class. The functionality can be accessed by using the execute() methods of ResourcePool and ResourcePool::LoadBalancer like shown above.

If you are new to this pattern, please consult one of the existing implementations (listed in the SEE ALSO section) to see how it works. This document provides information required to implement new Commands which is not necessary in most cases.

To use this pattern you have to derive a class from this class and overload the required methods. At least the execute() method has to be overloaded.

Please note that the available resource bindings might include generic commands which can be useful. In many cases you will be able to use this pattern without implementing Commands yourself. The SEE ALSO section includes references to all known Command implementations.

For the remainder of this document, I will use the ResourcePool::Command::DBI::Execute as an example, since most people are familiar with the perl DBI. Please note that the DBI examples used here do not build a complete description of the ResourcePool::Command::DBI::Execute package included in the DBI resource binding distribution.

The Command pattern does not introduce any limitations upon the constructor. It can be defined by the developer of the Command as required.

For an execution of an SQL command with DBI the constructor could take the SQL string as argument and store it for later execution.

Will be called with an valid resource from the pool or loadbalancer where the execute() method was invoked on.

This method must be defined by the derived class, you have to implement the logic which should happen upon execution within this method.

If this function returns normally, the result value will be passed to the caller. If it terminates abnormally by throwing an exception in some way, the execution environment will try again until the MaxExecTry value of the underlaying pool or loadbalancer has been reached. If it terminates abnormally by throwing an ResourcePool::Command::NoFailoverException, the execution environment will propagate this exception to the caller. Please have a look at the ERROR CONDITIONS section of the ResourcePool::Command::Execute class for further detail about error handling.

For the ResourcePool::Command::DBI::Execute example, this method would take the previously stored SQL string, prepare it, bind the supplied arguments, and execute it. Depending on the result it would have to throw an appropriate error to trigger the fail over and retry.

$resource
A valid resource from the pool/loadbalancer.
...
Additional argument which were passed to the execute() method of the pool or loadbalancer. This arguments are ignored by the execution environment and just passed one-by-one. This makes it possible to use a single instance of an Command with different parameters.

For example the DBI implementation allows to specify the arguments to the bind parameters to the execute() method, which makes it possible to use a prepared Command with different values.

This method is called by the execution environment if some problem occurred. The string returned by this method will be used for reporting purposes. Even if its not required to overload this method, it's highly recommended because it will make your life much easier. The default implementation just returns the class name of the Command.

ResourcePool::Command::DBI::SelectRow, ResourcePool::Command::DBI::Execute, ResourcePool::Command::SOAP::Lite::Call

    Copyright (C) 2001-2009 by Markus Winand <mws@fatalmind.com>

    This program is free software; you can redistribute it and/or
    modify it under the same terms as Perl itself.
2009-11-25 perl v5.32.1

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

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