cvsuser 02/03/19 14:51:07
Added: P5EEx/Blue/P5EEx/Blue SharedDatastore.pm
SharedResourceSet.pm
P5EEx/Blue/P5EEx/Blue/SharedResourceSet IPCLocker.pm
Log:
addition of two shared-resource services
Revision Changes Path
1.1 p5ee/P5EEx/Blue/P5EEx/Blue/SharedDatastore.pm
Index: SharedDatastore.pm
===================================================================
#############################################################################
## $Id: SharedDatastore.pm,v 1.1 2002/03/19 22:51:06 spadkins Exp $
#############################################################################
package P5EEx::Blue::SharedDatastore;
use P5EEx::Blue::P5EE;
use P5EEx::Blue::Service;
@ISA = ( "P5EEx::Blue::Service" );
use strict;
=head1 NAME
P5EEx::Blue::SharedDatastore - Interface for sharing data between processes
=head1 SYNOPSIS
use P5EEx::Blue::P5EE;
$context = P5EEx::Blue::P5EE->context();
$sds = $context->service("SharedDatastore");
$sds = $context->shared_datastore();
=head1 DESCRIPTION
A SharedDatastore service represents a single hash in which scalars or
deep references may be stored (basically an MLDBM).
=cut
#############################################################################
# CLASS GROUP
#############################################################################
=head1 Class Group: SharedDatastore
The following classes might be a part of the SharedDatastore Class Group.
=over
=item * Class: P5EEx::Blue::SharedDatastore
=item * Class: P5EEx::Blue::SharedDatastore::IPCMM
=item * Class: P5EEx::Blue::SharedDatastore::DBI
=item * Class: P5EEx::Blue::SharedDatastore::MLDBM
=item * Class: P5EEx::Blue::SharedDatastore::ApacheSession
=item * Class: P5EEx::Blue::SharedDatastore::IPCShareLite
=item * Class: P5EEx::Blue::SharedDatastore::IPCShareable
=back
=cut
#############################################################################
# CLASS
#############################################################################
=head1 Class: P5EEx::Blue::SharedDatastore
A SharedDatastore service represents a single hash in which scalars or
deep references may be stored. (They are automatically serialized using
Storable for storage.)
It is essentially identical to an MLDBM, but it supports more
implementations than an MLDBM, and it does not support the "tie" interface.
* Throws: P5EEx::Blue::Exception::SharedDatastore
* Since: 0.01
=cut
#############################################################################
# CONSTRUCTOR METHODS
#############################################################################
=head1 Constructor Methods:
=cut
#############################################################################
# new()
#############################################################################
=head2 new()
The constructor is inherited from
L<C<P5EEx::Blue::Service>|P5EEx::Blue::Service/"new()">.
=cut
#############################################################################
# PUBLIC METHODS
#############################################################################
=head1 Public Methods:
=cut
#############################################################################
# get()
#############################################################################
=head2 get()
* Signature: $value = $sds->get($key);
* Param: $key string
* Return: $value anything
* Throws: P5EEx::Blue::Exception::SharedDatastore
* Since: 0.01
Sample Usage:
$context = P5EEx::Blue::P5EE->context();
$sds = $context->service("SharedDatastore");
$hash = $sds->get("user.spadkins");
print %$hash, "\n";
=cut
sub get {
my ($self, $key) = @_;
my ($value);
$value;
}
#############################################################################
# set()
#############################################################################
=head2 set()
* Signature: $value = $sds->set($key,$value);
* Param: $key string
* Param: $value anything
* Return: void
* Throws: P5EEx::Blue::Exception::SharedDatastore
* Since: 0.01
Sample Usage:
$context = P5EEx::Blue::P5EE->context();
$sds = $context->service("SharedDatastore");
$hash = $sds->set("user.spadkins");
print %$hash, "\n";
=cut
sub set {
my ($self, $key, $value) = @_;
}
#############################################################################
# PROTECTED METHODS
#############################################################################
=head1 Protected Methods:
=cut
#############################################################################
# Method: service_type()
#############################################################################
=head2 service_type()
Returns 'SharedDatastore';
* Signature: $service_type = P5EEx::Blue::SharedDatastore->service_type();
* Param: void
* Return: $service_type string
* Since: 0.01
$service_type = $widget->service_type();
=cut
sub service_type () { 'SharedDatastore'; }
=head1 ACKNOWLEDGEMENTS
* Author: Stephen Adkins <[EMAIL PROTECTED]>
* License: This is free software. It is licensed under the same terms as Perl
itself.
=head1 SEE ALSO
L<C<P5EEx::Blue::Context>|P5EEx::Blue::Context>,
L<C<P5EEx::Blue::Service>|P5EEx::Blue::Service>
=cut
1;
1.1 p5ee/P5EEx/Blue/P5EEx/Blue/SharedResourceSet.pm
Index: SharedResourceSet.pm
===================================================================
#############################################################################
## $Id: SharedResourceSet.pm,v 1.1 2002/03/19 22:51:06 spadkins Exp $
#############################################################################
package P5EEx::Blue::SharedResourceSet;
use P5EEx::Blue::P5EE;
use P5EEx::Blue::Service;
@ISA = ( "P5EEx::Blue::Service" );
use strict;
=head1 NAME
P5EEx::Blue::SharedResourceSet - Interface for locking shared resources
=head1 SYNOPSIS
use P5EEx::Blue::P5EE;
$context = P5EEx::Blue::P5EE->context();
$srs = $context->service("SharedResourceSet"); # or ...
$srs = $context->shared_resource_set();
=head1 DESCRIPTION
A SharedResourceSet service represents a collection of "advisory" (or "cooperative")
resource locks.
=cut
#############################################################################
# CLASS GROUP
#############################################################################
=head1 Class Group: SharedResourceSet
The following classes might be a part of the SharedResourceSet Class Group.
=over
=item * Class: P5EEx::Blue::SharedResourceSet
=item * Class: P5EEx::Blue::SharedResourceSet::IPCLocker
=item * Class: P5EEx::Blue::SharedResourceSet::IPCSemaphore
=item * Class: P5EEx::Blue::SharedResourceSet::BerkeleyDB
=back
=cut
#############################################################################
# CLASS
#############################################################################
=head1 Class: P5EEx::Blue::SharedResourceSet
A SharedResourceSet service represents a collection of "advisory" (or "cooperative")
resource locks. These can be used to synchronize access to and modification
of shared resources such as are stored in a SharedDatastore.
* Throws: P5EEx::Blue::Exception::SharedResourceSet
* Since: 0.01
=cut
#############################################################################
# CONSTRUCTOR METHODS
#############################################################################
=head1 Constructor Methods:
=cut
#############################################################################
# new()
#############################################################################
=head2 new()
The constructor is inherited from
L<C<P5EEx::Blue::Service>|P5EEx::Blue::Service/"new()">.
=cut
#############################################################################
# PUBLIC METHODS
#############################################################################
=head1 Public Methods:
=cut
#############################################################################
# lock()
#############################################################################
=head2 lock()
* Signature: $resource_name = $srs->lock($resource_pool);
* Signature: $resource_name = $srs->lock($named);
* Param: $resource_pool string
* Param: resourcePool string
* Param: nonBlocking boolean
* Param: nonExclusive boolean
* Param: maxWaitTimeMS integer
* Return: $resource_name string
* Throws: P5EEx::Blue::Exception::SharedResourceSet
* Since: 0.01
Sample Usage:
$context = P5EEx::Blue::P5EE->context();
$srs = $context->service("SharedResourceSet");
$srs->lock("shmem01");
The lock() method on a SharedResourceSet is for the purposes of cooperative
resource locking.
=cut
sub lock {
my ($self, $arg) = @_;
my ($resource_pool, $resource_name);
if (ref($arg) eq "HASH") {
$resource_pool = $arg->{resourcePool};
}
elsif (ref($arg) eq "") {
$resource_pool = $arg;
}
return undef if (! $resource_pool);
# this is a dummy implementation. it does no real locking.
# it returns a resource name which is the same as the resource pool
$resource_name = $resource_pool;
return ($resource_name);
}
#############################################################################
# unlock()
#############################################################################
=head2 unlock()
* Signature: $srs->unlock($resource_name);
* Param: $resource_name string
* Return: void
* Throws: P5EEx::Blue::Exception::SharedResourceSet
* Since: 0.01
Sample Usage:
$context = P5EEx::Blue::P5EE->context();
$srs = $context->service("SharedResourceSet");
$srs->unlock("shmem01");
=cut
sub unlock {
my ($self, $resource_name) = @_;
}
#############################################################################
# PROTECTED METHODS
#############################################################################
=head1 Protected Methods:
=cut
#############################################################################
# Method: service_type()
#############################################################################
=head2 service_type()
Returns 'SharedResourceSet';
* Signature: $service_type = P5EEx::Blue::SharedResourceSet->service_type();
* Param: void
* Return: $service_type string
* Since: 0.01
$service_type = $widget->service_type();
=cut
sub service_type () { 'SharedResourceSet'; }
=head1 ACKNOWLEDGEMENTS
* Author: Stephen Adkins <[EMAIL PROTECTED]>
* License: This is free software. It is licensed under the same terms as Perl
itself.
=head1 SEE ALSO
L<C<P5EEx::Blue::Context>|P5EEx::Blue::Context>,
L<C<P5EEx::Blue::Service>|P5EEx::Blue::Service>
=cut
1;
1.1 p5ee/P5EEx/Blue/P5EEx/Blue/SharedResourceSet/IPCLocker.pm
Index: IPCLocker.pm
===================================================================
#############################################################################
## $Id: IPCLocker.pm,v 1.1 2002/03/19 22:51:07 spadkins Exp $
#############################################################################
package P5EEx::Blue::SharedResourceSet::IPCLocker;
use P5EEx::Blue::P5EE;
use P5EEx::Blue::SharedResourceSet;
@ISA = ( "P5EEx::Blue::SharedResourceSet" );
use IPC::::Locker;
use strict;
=head1 NAME
P5EEx::Blue::SharedResourceSet::IPCLocker - locking shared resources using
IPC::Locker
=head1 SYNOPSIS
use P5EEx::Blue::P5EE;
$context = P5EEx::Blue::P5EE->context();
$srs = $context->service("SharedResourceSet"); # or ...
$srs = $context->shared_resource_set();
=head1 DESCRIPTION
A SharedResourceSet service represents a collection of "advisory"
(or "cooperative")
resource locks. The IPCLocker implementation uses the IPC::Locker
distribution available on CPAN. Locking is implemented by a Locker Daemon
(lockerd), so that locking may be effectively achieved across an entire
network.
=cut
#############################################################################
# CLASS
#############################################################################
=head1 Class: P5EEx::Blue::SharedResourceSet::IPCLocker
A SharedResourceSet service represents a collection of "advisory" (or "cooperative")
resource locks. These can be used to synchronize access to and modification
of shared resources such as are stored in a SharedDatastore.
* Throws: P5EEx::Blue::Exception::SharedResourceSet
* Since: 0.01
The SharedResourceSet may be configured with the following parameters, which govern
all locks accessed in the SharedResourceSet (as per IPC::Locker).
family IPC (fifo) family to communicate with the lock server
INET: use TCP/IP networking
UNIX: use Unix named pipes (created with "mknod p /path/to/fifo")
default: INET
host default: localhost (only needed for INET family)
port default for INET: 1751 (or as defined in /etc/services for "lockerd")
default for UNIX: /var/locks/lockerd
timeout Time at which the server will release the lock if not explicitly
unlocked by then
default: 600 sec (10 min) (0 is "unlimited")
The "nonBlocking" option works in this implementation.
However, all locks are exclusive (the nonExclusive option is ignored).
The "maxWaitTimeMS" option is not yet implemented.
=cut
#############################################################################
# CONSTRUCTOR METHODS
#############################################################################
=head1 Constructor Methods:
=cut
#############################################################################
# new()
#############################################################################
=head2 new()
The constructor is inherited from
L<C<P5EEx::Blue::Service>|P5EEx::Blue::Service/"new()">.
=cut
#############################################################################
# PUBLIC METHODS
#############################################################################
=head1 Public Methods:
=cut
#############################################################################
# lock()
#############################################################################
=head2 lock()
* Signature: $resource_name = $srs->lock($resource_pool);
* Signature: $resource_name = $srs->lock($named);
* Param: $resource_pool string
* Param: resourcePool string
* Param: nonBlocking boolean
* Param: nonExclusive boolean
* Param: maxWaitTimeMS integer
* Return: $resource_name string
* Throws: P5EEx::Blue::Exception::SharedResourceSet
* Since: 0.01
Sample Usage:
$context = P5EEx::Blue::P5EE->context();
$srs = $context->service("SharedResourceSet");
$srs->lock("shmem01");
The lock() method on a SharedResourceSet is for the purposes of cooperative
resource locking.
=cut
sub lock {
my ($self, $arg) = @_;
my ($resource_pool, $args);
if (ref($arg) eq "HASH") {
$resource_pool = $arg->{resourcePool};
$args = $arg;
}
elsif (ref($arg) eq "") {
$resource_pool = $arg;
$args = {};
}
return undef if (! $resource_pool);
my (@params, $lock, $resource_names, $resource_name);
# substitute the list of items in the pool for the pool name
$resource_names = $resource_pool;
$resource_names = $self->{resourcePool}{$resource_pool}
if (defined $self->{resourcePool}{$resource_pool});
push(@params, "lock", $resource_names);
push(@params, "family", $self->{family}) if (defined $self->{family});
push(@params, "host", $self->{host}) if (defined $self->{host});
push(@params, "port", $self->{port}) if (defined $self->{port});
push(@params, "timeout", $self->{timeout}) if (defined $self->{timeout});
# I need to investigate more what IPC::Locker does with this name
# I may need to use "$user-$session_id"
# The default "name" is "$hostname-$pid" or something similar
#push(@params, "user", $self->{context}->user());
push(@params, "block", ($args->{nonBlocking} ? 0 : 1));
$lock = IPC::Locker->lock(@params);
$resource_name = $lock->lock_name();
if (defined $resource_name) {
$self->{lock}{$resource_name} = $lock; # save for later unlocking
}
return ($resource_name);
}
#############################################################################
# unlock()
#############################################################################
=head2 unlock()
* Signature: $srs->unlock($resource_name);
* Param: $resource_name string
* Return: void
* Throws: P5EEx::Blue::Exception::SharedResourceSet
* Since: 0.01
Sample Usage:
$context = P5EEx::Blue::P5EE->context();
$srs = $context->service("SharedResourceSet");
$srs->unlock("shmem01");
=cut
sub unlock {
my ($self, $resource_name) = @_;
my ($lock);
$lock = $self->{lock}{$resource_name};
if (defined $lock) {
$lock->unlock();
delete $self->{lock}{$resource_name};
}
}
=head1 ACKNOWLEDGEMENTS
* Author: Stephen Adkins <[EMAIL PROTECTED]>
* License: This is free software. It is licensed under the same terms as Perl
itself.
=head1 SEE ALSO
L<C<P5EEx::Blue::SharedResourceSet>|P5EEx::Blue::SharedResourceSet>,
L<C<P5EEx::Blue::Context>|P5EEx::Blue::Context>,
L<C<P5EEx::Blue::Service>|P5EEx::Blue::Service>
=cut
1;