]>
git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Lock/_static.pm
37233deed1310d0a79667b1ddf83e919d3d1b725
3 ################################################################################
5 # File: shared/Lock/_static.pm #
7 # Authors: Andre Malo <nd@o3media.de>, 2001-05-25 #
9 # Description: belongs to Locking and Filehandle class #
11 # save the lock object static information #
12 # (because the lock object is a blessed file handle) #
14 ################################################################################
23 ################################################################################
27 $VERSION = do { my @r =(q
$Revision$ =~ /\d+/g); sprintf "%d."."%02d" x
$#r, @r };
29 ################################################################################
33 my (%static, %access);
35 # define standard timeouts
39 shared
=> 10, # for shared and exclusive shared locks
40 exclusive
=> 10, # for exclusive locks
41 violent
=> 600, # for violent unlocks (10 minutes should justify a process abort)
42 master
=> 20 # for master locks
45 ### timeout ####################################################################
47 # set and read out the timeout
49 # Params: $type - timeout type (defined in %timeout, see above)
50 # in this case, the specified timeout will be returned
52 # %hash - (type => time) pairs
53 # the specified timouts will be set
55 # Return: specified timeout or nothing
58 my ($self, @ary) = @_;
60 return if (@ary == 0);
63 my $type = shift @ary;
64 my $hash = $self -> get_static
('timeout') || {};
66 return defined $hash->{$type}
72 $self->set_static(timeout
=> {%{$self -> get_static
('timeout') || {}},%hash});
77 ### set_static #################################################################
79 # set an object property
81 # Params: $key - property and method name
84 # Return: $value or nothing
87 my ($self, $key, $value) = @_;
89 $static{$self}={} unless exists($static{$self});
90 $static{$self}->{$key} = $value;
92 defined wantarray and return $value;
96 ### get_static #################################################################
98 # read out an object property
100 # Params: $key - property name
102 # Return: value or false
105 my ($self, $key) = @_;
107 return unless exists($static{$self});
108 $static{$self}->{$key};
111 ################################################################################
113 # define the lock file names
115 sub reffile
{shift -> filename
. '.lock.ref'}
116 sub lockfile
{shift -> filename
. '.lock'}
117 sub reflock
{shift -> filename
. '.lock.ref.lock'}
118 sub exshlock
{shift -> filename
. '.exshlock'}
119 sub masterlock
{shift -> filename
. '.masterlock'}
121 ################################################################################
123 # autoload the general access methods
126 %access = map {$_=>1} qw(
137 (my $attr = $Lock::_static
::AUTOLOAD
) =~ s/.*:://;
138 return if ($attr eq 'DESTROY');
140 if ($access{$attr}) {
141 return $self -> get_static
($attr);
146 my $sup = "SUPER::$attr";
147 return $self -> $sup(@_);
153 ################################################################################
155 # destrcutor - try to unlock, if neccessary and possible
160 $self -> unlock
if ($self =~ /^Lock=/);
161 delete $static{$self};
164 ################################################################################
166 # terminator, catch sigTERM and (try to) destroy all objects
169 $SIG{TERM
} = \
&destroy_all
;
171 $_ -> unlock
for (grep ((ref $_ and /^Lock=/) => keys %static));
176 $SIG{TERM
} = \
&destroy_all
;
179 # keep 'require' happy
184 ### end of Lock::_static #######################################################
patrick-canterino.de