GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  STF::DISPATCHER::PSGI (3)

.ds Aq ’

NAME

STF::Dispatcher::PSGI - Pluggable STF Dispatcher Interface

CONTENTS

SYNOPSIS



    # in your stf.psgi
    use STF::Dispatcher::PSGI;

    my $object = ...;
    STF::Dispatcher::PSGI->new( impl => $object )->to_app;



DESCRIPTION

STF::Dispatcher::PSGI implements the basic STF Protocol (http://stf-storage.github.com) dispatcher component. It does not know how to actually store or retrieve data, so you must implement that portion yourself.

The reason this exists is mainly to allow you to testing systems that interact with STF servers. For example, setting up the main STF implementation is quite a pain if all you want to do is to test your application, but with this module, you can easily create a dummy STF dispatcher.

For example, you can use STF::Dispatcher::Impl::Hash (which stores all data in a has in memory) for your tests:



    # in your stf.psgi
    use STF::Dispatcher::PSGI;
    use STF::Dispatcher::Impl::Hash;

    my $object = STF::Dispatcher::Impl::Hash->new();
    STF::Dispatcher::PSGI->new( impl => $object )->to_app;



And then you can do something like below in your application test to start a dummy STF server with Plack:



    use Plack::Runner;
    use Test::TCP;

    my $guard = Test::TCP->new(sub {
        my $port = shift;
        my $runner = Plack::Runner->new;
        $runner->parse_options(-p => $port);
        $runner->run( do "stf.psgi" );
    });

    my $stf_uri = sprintf "http://127.0.0.1:%d", $guard->port;
    $ua->get( "$stf_uri/path/to/myobject.png" );



Of course, this is not only useful for testing, but it allows you to create a STF clone with a completely different backend without having to reimplement the entire STF protocol.

METHODS

CW$self = CW$class->( impl => CW$object [, CW%args ] )

Creates a new instance of STF::Dispatcher::PSGI. <B>implB> must be the imeplementation object (see below).

Other arguments may include:
nosniff_header : Bool Automatically adds X-Content-Type-Options: nosniff to the response.

By default nosniff_header is enabled.

CW$psgi_app = CW$self->to_app()

Creates a PSGI app.

THE ‘‘IMPLEMENTATION’’ OBJECT

As described elsewhere, this module by itself DOES NOT work as a real STF server. This module will parse the request and extract the required data from that request, but has no idea how to actually use it. You must therefore provide it with an implementation.

The simplest implementation is provided with this distribution: STF::Dispatcher::Impl::Hash. This implementation simply puts all the objects in an in-memory hash. See STF for a heavy duty example.

You can choose to create your own STF implementation. In that case, you need to implement list of methods described later.

In these methods, you may choose to throw an exception instead of returning a response. For example, in STF, we use X-Reproxy-URL to serve the objects. This means we cannot just return the fetched object. In that case, we throw an exception that Plack::Middleware::HTTPExceptions can handle (our to_app method automatically enables Plack::Middleware::HTTPExceptions).

See the documentation for that module for details.

LIST OF REQUIRED METHODS IN THE IMPLEMENTATION

CW$object = CW$impl->create_bucket(%args)

Used to create a bucket.

The implementation’s get_bucket method will receive the following named parameters:
<B>requestB> => $object Plack::Request for this request
<B>bucket_nameB> => $string The name of the bucket

CW$object = CW$impl->get_bucket(%args)

Used to retrieve a bucket. If there are no buckets that match the request, you should return undef.

The implementation’s get_bucket method will receive the following named parameters:
<B>requestB> => $object Plack::Request for this request
<B>bucket_nameB> => $string The name of the bucket

CW$object = CW$impl->get_object(%args)

Used to retrieve an object. If there are no object that matcht the request, you should return undef.

Note that this method will be called for both GET and HEAD requests.

The implementation’s get_object method will receive the following named parameters:
<B>requestB> => $object Plack::Request for this request
<B>bucketB> => $object The bucket returned by get_bucket().
<B>object_nameB> => $string The name of the object.
<B>force_masterB> => $bool Set to true if X-STF-Force-MasterDB header was sent

CW$impl->delete_bucket(%args)

<B>requestB> => $object Plack::Request for this request
<B>bucketB> => $object The bucket returned by get_bucket().
<B>recursiveB> => $bool Set to true if the X-STF-Recursive-Delete header was specified

CW$impl->create_object(%args)

<B>requestB> => $object Plack::Request for this request
<B>bucketB> => $object The bucket returned by get_bucket().
<B>object_nameB> => $string The name of the object.
<B>consistencyB> => $int The minimum consistency (number of replicas that must be created by the end of create_object call.
<B>sizeB> => $int The size of the object
<B>suffixB> => $string The suffix to be used for the object. defaults to .dat
<B>inputB> => $handle The input handle to read the data from
<B>replicasB> => $int Number of replicas that the system should keep in the end.

CW$impl->modify_object(%args)

<B>replicasB> => $int Number of replicas that the system should keep in the end.
<B>requestB> => $object Plack::Request for this request
<B>bucketB> => $object The bucket returned by get_bucket().
<B>object_nameB> => $string The name of the object.

CW$impl->delete_object(%args)

<B>requestB> => $object Plack::Request for this request
<B>bucketB> => $object The bucket returned by get_bucket().
<B>object_nameB> => $string The name of the object.

AUTHOR

Daisuke Maki <daisuke@endeworks.jp>

COPYRIGHT AND LICENSE

Copyright (C) 2011 by Daisuke Maki

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.0 or, at your option, any later version of Perl 5 you may have available.

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 STF::DISPATCHER::PSGI (3) 2016-04-03

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.