NAME

Osgood::Client - Client for the Osgood Passive, Persistent Event Queue

DESCRIPTION

Provides a client for sending events to or retrieving events from an Osgood queue.

SYNOPSIS

To send some events:

my $event = Osgood::Event->new(
    object => 'Moose',
    action => 'farted',
    date_occurred => DateTime->now
);
my $list = Osgood::EventList->new(events => [ $event ])
my $client = Osgood::Client->new(
    url => 'http://localhost',
    list => $list
);
my $retval = $client->send;
if($list->size == $retval) {
    print "Success :)\n";
} else {
    print "Failure :(\n";
}

To query for events

use DateTime;
use Osgood::Client;
use URI;

my $client = Osgood::Client->new(
    url => URI->new('http://localhost:3000'),
);
$client->query({ object => 'Moose', action => 'farted' });
if($client->list->size == 1) {
    print "Success\n";
} else {
    print "Failure\n";
}

METHODS

new

Creates a new Osgood::Client object.

list

Set/Get the EventList. For sending events, you should set this. For retrieving them, this will be populated by query returns.

send

Send events to the server.

query

Query the Osgood server for events. Takes a hashref in the following format:

{
  id => X,
  object => 'obj',
  action => 'foo',
  date => '2007-12-11'
}

At least one key is required.

A true or false value is returned to denote the success of failure of the query. If false, then the error will be set in the error accessor. On success the list may be retrived from the list accessor.

Implicitly sets $self->list(undef), to clear previous results.

timeout

The number of seconds to wait before timing out.

url

The url of the Osgood queue we should contact. Expects an instance of URI.

error

Returns the error message (if there was one) for this client. This should be called if query or send do not return what you expect.

PERFORMANCE

Originally Osgood used a combination of XML::DOM and XML::XPath for serialization. After some testing it has switched to using JSON, as JSON::XS is considerably faster. In tests on my machine (dual quad-core xeon) it takes about 10 seconds to deserialize 10_000 simple events.

Please keep in mind that the sending of events will also have a cost, as insertion into the database takes time. See the accompanying PERFORMANCE section of Osgood::Server.

AUTHOR

Cory 'G' Watson <gphat@cpan.org>

CONTRIBUTORS

Mike Eldridge (diz)

SEE ALSO

perl(1), Osgood::Event, Osgood::EventList

COPYRIGHT AND LICENSE

Copyright 2008-2009 by Magazines.com, LLC

You can redistribute and/or modify this code under the same terms as Perl itself.