com.basho.riak.pbc.mapreduce
Class MapReduceBuilder

java.lang.Object
  extended by com.basho.riak.pbc.mapreduce.MapReduceBuilder

public class MapReduceBuilder
extends Object

Builds a map/reduce job description and submits it Uses the same chained method metaphor as StringBuilder or StringBuffer


Constructor Summary
MapReduceBuilder()
           
MapReduceBuilder(RiakClient riak)
           
 
Method Summary
 void addRiakObject(String bucket, String key)
          Adds a Riak object (bucket name/key pair) to the map/reduce job as inputs
 void clearRiakObjects()
          Remove all Riak objects from the input list
 String getBucket()
          Gets the name of the Riak bucket the map/reduce job will process
 RiakClient getRiakClient()
          The RiakClient to which this map reduce job will be submitted to when submit() is called.
 Map<String,Set<String>> getRiakObjects()
          Returns a copy of the Riak objects on the input list for a map/reduce job
 String getSearch()
          Gets the search query the map/reduce job will process
 int getTimeout()
          Gets the currently assigned timeout
 MapReduceBuilder link(String bucket, boolean keep)
          Adds a link phase to the job
 MapReduceBuilder link(String bucket, String tag, boolean keep)
          Adds a link phase to the job
 MapReduceBuilder map(MapReduceFunction function, boolean keep)
          Adds a map phase to the job
 MapReduceBuilder map(MapReduceFunction function, Object arg, boolean keep)
          Adds a map phase to the job
 MapReduceBuilder reduce(MapReduceFunction function, boolean keep)
          Adds a reduce phase to the job
 MapReduceBuilder reduce(MapReduceFunction function, Object arg, boolean keep)
          Adds a reduce phase to the job
 void removeRiakObject(String bucket, String key)
          Removes a Riak object (bucket name/key pair) for the job's input list
 MapReduceBuilder setBucket(String newBucket)
          Sets the name of the Riak bucket the map/reduce job will process
 MapReduceBuilder setRiakClient(RiakClient client)
           
 MapReduceBuilder setRiakObjects(Collection<RiakObject> objects)
           
 MapReduceBuilder setRiakObjects(Map<String,Set<String>> objects)
          Sets a collection of Riak object (bucket name/key pair) as the map/reduce job as inputs
 MapReduceBuilder setSearch(String search)
          Sets the name of the Riak bucket that will be searched and the query that will be executed
 void setTimeout(int timeout)
          How long the map/reduce job is allowed to execute Time is in milliseconds
 MapReduceResponseSource submit()
           
 MapReduceResponseSource submit(IRequestMeta meta)
          Submits the job to the Riak server
 JSONObject toJSON()
          Builds the JSON representation of a map/reduce job
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MapReduceBuilder

public MapReduceBuilder(RiakClient riak)
Parameters:
riak - RiakClient instance which is pointing to the map/reduce URL

MapReduceBuilder

public MapReduceBuilder()
Method Detail

getRiakClient

public RiakClient getRiakClient()
The RiakClient to which this map reduce job will be submitted to when submit() is called.


setRiakClient

public MapReduceBuilder setRiakClient(RiakClient client)

getBucket

public String getBucket()
Gets the name of the Riak bucket the map/reduce job will process


setBucket

public MapReduceBuilder setBucket(String newBucket)
Sets the name of the Riak bucket the map/reduce job will process

Throws:
IllegalStateException - - If objects have already been added to the job

getSearch

public String getSearch()
Gets the search query the map/reduce job will process


setSearch

public MapReduceBuilder setSearch(String search)
Sets the name of the Riak bucket that will be searched and the query that will be executed

Throws:
IllegalStateException - - If objects or bucket has already been added

addRiakObject

public void addRiakObject(String bucket,
                          String key)
Adds a Riak object (bucket name/key pair) to the map/reduce job as inputs

Throws:
IllegalStateException - - If a bucket name has already been set on the job

removeRiakObject

public void removeRiakObject(String bucket,
                             String key)
Removes a Riak object (bucket name/key pair) for the job's input list


getRiakObjects

public Map<String,Set<String>> getRiakObjects()
Returns a copy of the Riak objects on the input list for a map/reduce job


setRiakObjects

public MapReduceBuilder setRiakObjects(Map<String,Set<String>> objects)
Sets a collection of Riak object (bucket name/key pair) as the map/reduce job as inputs

Throws:
IllegalStateException - - If a bucket name has already been set on the job

setRiakObjects

public MapReduceBuilder setRiakObjects(Collection<RiakObject> objects)

clearRiakObjects

public void clearRiakObjects()
Remove all Riak objects from the input list


setTimeout

public void setTimeout(int timeout)
How long the map/reduce job is allowed to execute Time is in milliseconds


getTimeout

public int getTimeout()
Gets the currently assigned timeout


map

public MapReduceBuilder map(MapReduceFunction function,
                            boolean keep)
Adds a map phase to the job

Parameters:
function - function to run for the phase
keep - should the server keep and return the results
Returns:
current MapReduceBuilder instance. This is done so multiple calls to map, reduce, and link can be chained together a la StringBuffer

map

public MapReduceBuilder map(MapReduceFunction function,
                            Object arg,
                            boolean keep)
Adds a map phase to the job

Parameters:
function - function to run for the phase
arg - Static argument to pass to the function. Should be an object easily converted to JSON
keep - should the server keep and return the results
Returns:
current MapReduceBuilder instance. This is done so multiple calls to map, reduce, and link can be chained together a la StringBuffer

reduce

public MapReduceBuilder reduce(MapReduceFunction function,
                               boolean keep)
Adds a reduce phase to the job

Parameters:
function - function to run for the phase
keep - should the server keep and return the results
Returns:
current MapReduceBuilder instance. This is done so multiple calls to map, reduce, and link can be chained together a la StringBuffer

reduce

public MapReduceBuilder reduce(MapReduceFunction function,
                               Object arg,
                               boolean keep)
Adds a reduce phase to the job

Parameters:
function - function to run for the phase
arg - Static argument to pass to the function. Should be an object easily converted to JSON
keep - should the server keep and return the results
Returns:
current MapReduceBuilder instance. This is done so multiple calls to map, reduce, and link can be chained together a la StringBuffer

link

public MapReduceBuilder link(String bucket,
                             boolean keep)
Adds a link phase to the job

Parameters:
bucket - bucket to link walk
keep - should the server keep and return the results
Returns:
current MapReduceBuilder instance. This is done so multiple calls to map, reduce, and link can be chained together a la StringBuffer Pointing at a bucket without specifying a link tag will follow all links pointing to objects in the bucket

link

public MapReduceBuilder link(String bucket,
                             String tag,
                             boolean keep)
Adds a link phase to the job

Parameters:
bucket - bucket to link walk
tag - link tag to match
keep - should the server keep and return the results
Returns:
current MapReduceBuilder instance. This is done so multiple calls to map, reduce, and link can be chained together a la StringBuffer

submit

public MapReduceResponseSource submit(IRequestMeta meta)
                               throws IOException
Submits the job to the Riak server

Parameters:
meta - Extra metadata to attach to the request such as HTTP headers or query parameters.
Returns:
MapReduceResponse containing job results
Throws:
IOException
IllegalStateException - If this job has not been associated with a Riak instance by calling setRiakClient(RiakClient)
RiakIORuntimeException - If an error occurs during communication with the Riak server.
RiakResponseRuntimeException - If the Riak server returns a malformed response.

submit

public MapReduceResponseSource submit()
                               throws JSONException,
                                      IOException
Throws:
JSONException
IOException

toJSON

public JSONObject toJSON()
Builds the JSON representation of a map/reduce job



Copyright © 2012. All Rights Reserved.