NAME
Memcached::Client::Connection - Class to manage Memcached::Client server connections
VERSION
version 2.01
SYNOPSIS
use Memcached::Client::Connection;
my $connection = Memcached::Client::Connection->new ("server:port");
$connection->enqueue ($request);
DESCRIPTION
A Memcached::Client::Connection
object is responsible for managing a connection to a particular memcached server, and a queue of requests destined for that server.
Connections are, by default, made lazily.
The connection handler will try to automatically reconnect several times on connection failure, only returning failure responses for all queued requests as a last resort.
METHODS
new
new()
builds a new connection object. The object is constructed and returned immediately.
Takes two parameters: one is the server specification, in the form of "hostname" or "hostname:port". If no port is specified, ":11211" (the default memcached port) is appended to the server name.
The other, optional, parameter is a subroutine reference that will be invoked on the raw filehandle before connection. Generally only useful for putting the filehandle in binary mode.
No connection is initiated at construction time, because that would require that we perhaps accept a callback to signal completion, or create a condvar, etc. Simpler to lazily construct the connection when the conditions are already right for doing our asynchronous dance.
log
connect
connect()
initiates a connection to the specified server.
If it succeeds in connecting, it will start sending requests for the server to satisfy.
If it fails, it will respond to all outstanding requests by invoking their failback routine.
disconnect
disconnect
will disconnect any extant handle from the server it is connected to, destroy it, and then fail all queued requests.
enqueue
enqueue()
adds the specified request object to the queue of requests to be processed, if there is already a request in progress, otherwise, it begins execution of the specified request. If necessary, it will initiate connection to the server as well.
dequeue
dequeue()
checks to see if there's already a request processing, and if so, it simply returns (when that request finishes, it will call ->complete, which will call dequeue).
If nothing is processing, it will attempt to pull the next item from the queue and start it processing.
complete
fail
fail()
is called when there is an error on the handle, and it invokes the failbacks of all queued requests.
AUTHOR
Michael Alan Dorman <mdorman@ironicdesign.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2010 by Michael Alan Dorman.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.