Commit e3a4805d authored by dcoutadeur dcoutadeur's avatar dcoutadeur dcoutadeur

add a correct lock management for sessions: when a session is found in cache,...

add a correct lock management for sessions: when a session is found in cache, do not make lock calls to final session backend (MySQL for example) fix LEMONLDAP-742



git-svn-id: svn://svn.forge.objectweb.org/svnroot/lemonldap/branches/lemonldap-ng_version_1_4-bugfixes@3513 1dbb9719-a921-0410-b57f-c3a383c2c641
parent 14866479
......@@ -5,6 +5,7 @@ lib/Lemonldap/NG/Common/Apache/Session.pm
lib/Lemonldap/NG/Common/Apache/Session/Generate/SHA256.pm
lib/Lemonldap/NG/Common/Apache/Session/SOAP.pm
lib/Lemonldap/NG/Common/Apache/Session/Store.pm
lib/Lemonldap/NG/Common/Apache/Session/Lock.pm
lib/Lemonldap/NG/Common/Captcha.pm
lib/Lemonldap/NG/Common/CGI.pm
lib/Lemonldap/NG/Common/CGI/SOAPServer.pm
......
......@@ -12,6 +12,7 @@ use AutoLoader 'AUTOLOAD';
use Apache::Session;
use base qw(Apache::Session);
use Lemonldap::NG::Common::Apache::Session::Store;
use Lemonldap::NG::Common::Apache::Session::Lock;
our $VERSION = '1.4.0';
......@@ -50,6 +51,12 @@ sub populate {
$self->{object_store} =
Lemonldap::NG::Common::Apache::Session::Store->new($self);
}
# If cache is configured, use our specific lock_manager object module
if ( $self->{args}->{localStorage} ) {
$self->{args}->{lock_manager} = $self->{lock_manager};
$self->{lock_manager} =
Lemonldap::NG::Common::Apache::Session::Lock->new($self);
}
return $self;
}
......
package Lemonldap::NG::Common::Apache::Session::Lock;
use strict;
my $VERSION = '1.4.1';
sub new {
my $class = shift;
my $session = shift;
my $self = {};
$self->{args} = $session->{args};
bless $self, $class;
return $self;
}
sub module {
my $self = shift;
return $self->{args}->{lock_manager};
}
sub cache {
my $self = shift;
return $self->{cache} if $self->{cache};
my $module = $self->{args}->{localStorage};
eval "use $module;";
$self->{cache} = $module->new( $self->{args}->{localStorageOptions} );
return $self->{cache};
}
sub acquire_read_lock {
my $self = shift;
my $session = shift;
# Get session from cache
my $id = $session->{data}->{_session_id};
if ( $self->cache->get($id) ) {
# got session from cache, no need to ask for locks
}
else {
$self->module->acquire_read_lock($session);
}
}
sub acquire_write_lock {
my $self = shift;
my $session = shift;
# Get session from cache
my $id = $session->{data}->{_session_id};
if ( $self->cache->get($id) ) {
# got session from cache, no need to ask for locks
}
else {
$self->module->acquire_write_lock($session);
}
}
sub release_write_lock {
my $self = shift;
my $session = shift;
# Get session from cache
my $id = $session->{data}->{_session_id};
if ( $self->cache->get($id) ) {
# got session from cache, no need to ask for locks
}
else {
$self->module->release_write_lock($session);
}
}
sub release_all_locks {
my $self = shift;
my $session = shift;
# Get session from cache
my $id = $session->{data}->{_session_id};
if ( $self->cache->get($id) ) {
# got session from cache, no need to ask for locks
}
else {
$self->module->release_all_locks($session);
}
}
1;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment