Package org.apache.giraph.worker
Class WorkerContext
- java.lang.Object
-
- org.apache.giraph.conf.DefaultImmutableClassesGiraphConfigurable<I,V,E>
-
- org.apache.giraph.worker.WorkerAggregatorDelegator<org.apache.hadoop.io.WritableComparable,org.apache.hadoop.io.Writable,org.apache.hadoop.io.Writable>
-
- org.apache.giraph.worker.WorkerContext
-
- All Implemented Interfaces:
org.apache.giraph.aggregators.AggregatorUsage
,org.apache.giraph.conf.GiraphConfigurationSettable<org.apache.hadoop.io.WritableComparable,org.apache.hadoop.io.Writable,org.apache.hadoop.io.Writable>
,org.apache.giraph.conf.ImmutableClassesGiraphConfigurable<org.apache.hadoop.io.WritableComparable,org.apache.hadoop.io.Writable,org.apache.hadoop.io.Writable>
,org.apache.giraph.worker.WorkerAggregatorUsage
,org.apache.giraph.worker.WorkerBroadcastUsage
,org.apache.giraph.worker.WorkerGlobalCommUsage
,org.apache.giraph.worker.WorkerIndexUsage<org.apache.hadoop.io.WritableComparable>
,org.apache.giraph.worker.WorkerReduceUsage
,org.apache.hadoop.io.Writable
- Direct Known Subclasses:
AggregateBenchmark.AggregateBenchmarkWorkerContext
,MessageBenchMark.MessageBenchMarkWorkerContext
,PageRank.SimplePageRankWorkerContext
,SSSP.SSSPWorkerContext
,Traverse.TraverseContext
public abstract class WorkerContext extends WorkerAggregatorDelegator<org.apache.hadoop.io.WritableComparable,org.apache.hadoop.io.Writable,org.apache.hadoop.io.Writable> implements org.apache.hadoop.io.Writable, org.apache.giraph.worker.WorkerIndexUsage<org.apache.hadoop.io.WritableComparable>
WorkerContext allows for the execution of user code on a per-worker basis. There's one WorkerContext per worker.Giraph worker context is abstract. Our implementation should contains all necessary interfaces needed. see
DefaultWorkerContext
-
-
Constructor Summary
Constructors Constructor Description WorkerContext()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <A extends org.apache.hadoop.io.Writable>
voidaggregate(String name, A value)
<A extends org.apache.hadoop.io.Writable>
AgetAggregatedValue(String name)
List<org.apache.hadoop.io.Writable>
getAndClearMessagesFromOtherWorkers()
Get messages which other workers sent to this worker and clear them (can be called once per superstep)org.apache.hadoop.mapreduce.Mapper.Context
getContext()
Get the mapper contextint
getMyWorkerIndex()
Get index for this workerlong
getSuperstep()
Retrieves the current superstep.long
getTotalNumEdges()
Get the total (all workers) number of edges that existed in the previous superstep.long
getTotalNumVertices()
Get the total (all workers) number of vertices that existed in the previous superstep.int
getWorkerCount()
Get number of workers.int
getWorkerForVertex(org.apache.hadoop.io.WritableComparable vertexId)
void
incStep()
void
logToCommandLine(String line)
Call this to log a line to command line of the job.abstract void
postApplication()
Finalize the WorkerContext.abstract void
postSuperstep()
Execute user code.abstract void
preApplication()
Initialize the WorkerContext.abstract void
preSuperstep()
Execute user code.void
readFields(DataInput dataInput)
void
reduce(String name, Object value)
Reduce value by name.void
reduceMerge(String name, org.apache.hadoop.io.Writable value)
void
sendMessageToWorker(org.apache.hadoop.io.Writable message, int workerIndex)
Send message to another workervoid
setAggregatorManager(AggregatorManager aggregatorManager)
void
setCurStep(int step)
Make sure this function is called after each step.void
setFragment(IFragment fragment)
void
write(DataOutput dataOutput)
-
Methods inherited from class org.apache.giraph.worker.WorkerAggregatorDelegator
getBroadcast
-
-
-
-
Method Detail
-
setFragment
public void setFragment(IFragment fragment)
-
setAggregatorManager
public void setAggregatorManager(AggregatorManager aggregatorManager)
- Overrides:
setAggregatorManager
in classWorkerAggregatorDelegator<org.apache.hadoop.io.WritableComparable,org.apache.hadoop.io.Writable,org.apache.hadoop.io.Writable>
-
setCurStep
public void setCurStep(int step)
Make sure this function is called after each step.- Parameters:
step
-
-
incStep
public void incStep()
-
preApplication
public abstract void preApplication() throws InstantiationException, IllegalAccessException
Initialize the WorkerContext. This method is executed once on each Worker before the first superstep starts.- Throws:
IllegalAccessException
- Thrown for getting the classInstantiationException
- Expected instantiation in this method.
-
postApplication
public abstract void postApplication()
Finalize the WorkerContext. This method is executed once on each Worker after the last superstep ends.
-
preSuperstep
public abstract void preSuperstep()
Execute user code. This method is executed once on each Worker before each superstep starts.
-
getWorkerCount
public final int getWorkerCount()
Get number of workers.We use fragment fnum to represent fragment number.
- Specified by:
getWorkerCount
in interfaceorg.apache.giraph.worker.WorkerIndexUsage<org.apache.hadoop.io.WritableComparable>
- Returns:
- Number of workers
-
getMyWorkerIndex
public final int getMyWorkerIndex()
Get index for this worker- Specified by:
getMyWorkerIndex
in interfaceorg.apache.giraph.worker.WorkerIndexUsage<org.apache.hadoop.io.WritableComparable>
- Returns:
- Index of this worker
-
getWorkerForVertex
public final int getWorkerForVertex(org.apache.hadoop.io.WritableComparable vertexId)
- Specified by:
getWorkerForVertex
in interfaceorg.apache.giraph.worker.WorkerIndexUsage<org.apache.hadoop.io.WritableComparable>
-
getAndClearMessagesFromOtherWorkers
public List<org.apache.hadoop.io.Writable> getAndClearMessagesFromOtherWorkers()
Get messages which other workers sent to this worker and clear them (can be called once per superstep)- Returns:
- Messages received
-
sendMessageToWorker
public void sendMessageToWorker(org.apache.hadoop.io.Writable message, int workerIndex)
Send message to another worker- Parameters:
message
- Message to sendworkerIndex
- Index of the worker to send the message to
-
postSuperstep
public abstract void postSuperstep()
Execute user code. This method is executed once on each Worker after each superstep ends.
-
getSuperstep
public long getSuperstep()
Retrieves the current superstep.- Returns:
- Current superstep
-
getTotalNumVertices
public final long getTotalNumVertices()
Get the total (all workers) number of vertices that existed in the previous superstep.- Returns:
- Total number of vertices (-1 if first superstep) (?)
-
getTotalNumEdges
public final long getTotalNumEdges()
Get the total (all workers) number of edges that existed in the previous superstep.- Returns:
- Total number of edges (-1 if first superstep)
-
getContext
public final org.apache.hadoop.mapreduce.Mapper.Context getContext()
Get the mapper context- Returns:
- Mapper context
-
logToCommandLine
public void logToCommandLine(String line)
Call this to log a line to command line of the job. Use in moderation - it's a synchronous call to Job client- Parameters:
line
- Line to print
-
write
public void write(DataOutput dataOutput) throws IOException
- Specified by:
write
in interfaceorg.apache.hadoop.io.Writable
- Throws:
IOException
-
readFields
public void readFields(DataInput dataInput) throws IOException
- Specified by:
readFields
in interfaceorg.apache.hadoop.io.Writable
- Throws:
IOException
-
reduce
public void reduce(String name, Object value)
Reduce value by name.- Specified by:
reduce
in interfaceorg.apache.giraph.worker.WorkerReduceUsage
- Overrides:
reduce
in classWorkerAggregatorDelegator<org.apache.hadoop.io.WritableComparable,org.apache.hadoop.io.Writable,org.apache.hadoop.io.Writable>
- Parameters:
name
- keyvalue
- value
-
reduceMerge
public void reduceMerge(String name, org.apache.hadoop.io.Writable value)
- Specified by:
reduceMerge
in interfaceorg.apache.giraph.worker.WorkerReduceUsage
- Overrides:
reduceMerge
in classWorkerAggregatorDelegator<org.apache.hadoop.io.WritableComparable,org.apache.hadoop.io.Writable,org.apache.hadoop.io.Writable>
-
aggregate
public <A extends org.apache.hadoop.io.Writable> void aggregate(String name, A value)
- Specified by:
aggregate
in interfaceorg.apache.giraph.worker.WorkerAggregatorUsage
- Overrides:
aggregate
in classWorkerAggregatorDelegator<org.apache.hadoop.io.WritableComparable,org.apache.hadoop.io.Writable,org.apache.hadoop.io.Writable>
-
getAggregatedValue
public <A extends org.apache.hadoop.io.Writable> A getAggregatedValue(String name)
- Specified by:
getAggregatedValue
in interfaceorg.apache.giraph.aggregators.AggregatorUsage
- Overrides:
getAggregatedValue
in classWorkerAggregatorDelegator<org.apache.hadoop.io.WritableComparable,org.apache.hadoop.io.Writable,org.apache.hadoop.io.Writable>
-
-