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.ContextgetContext()Get the mapper contextintgetMyWorkerIndex()Get index for this workerlonggetSuperstep()Retrieves the current superstep.longgetTotalNumEdges()Get the total (all workers) number of edges that existed in the previous superstep.longgetTotalNumVertices()Get the total (all workers) number of vertices that existed in the previous superstep.intgetWorkerCount()Get number of workers.intgetWorkerForVertex(org.apache.hadoop.io.WritableComparable vertexId)voidincStep()voidlogToCommandLine(String line)Call this to log a line to command line of the job.abstract voidpostApplication()Finalize the WorkerContext.abstract voidpostSuperstep()Execute user code.abstract voidpreApplication()Initialize the WorkerContext.abstract voidpreSuperstep()Execute user code.voidreadFields(DataInput dataInput)voidreduce(String name, Object value)Reduce value by name.voidreduceMerge(String name, org.apache.hadoop.io.Writable value)voidsendMessageToWorker(org.apache.hadoop.io.Writable message, int workerIndex)Send message to another workervoidsetAggregatorManager(AggregatorManager aggregatorManager)voidsetCurStep(int step)Make sure this function is called after each step.voidsetFragment(IFragment fragment)voidwrite(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:
setAggregatorManagerin 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, IllegalAccessExceptionInitialize 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:
getWorkerCountin 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:
getMyWorkerIndexin 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:
getWorkerForVertexin 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:
writein interfaceorg.apache.hadoop.io.Writable- Throws:
IOException
-
readFields
public void readFields(DataInput dataInput) throws IOException
- Specified by:
readFieldsin interfaceorg.apache.hadoop.io.Writable- Throws:
IOException
-
reduce
public void reduce(String name, Object value)
Reduce value by name.- Specified by:
reducein interfaceorg.apache.giraph.worker.WorkerReduceUsage- Overrides:
reducein 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:
reduceMergein interfaceorg.apache.giraph.worker.WorkerReduceUsage- Overrides:
reduceMergein 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:
aggregatein interfaceorg.apache.giraph.worker.WorkerAggregatorUsage- Overrides:
aggregatein 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:
getAggregatedValuein interfaceorg.apache.giraph.aggregators.AggregatorUsage- Overrides:
getAggregatedValuein classWorkerAggregatorDelegator<org.apache.hadoop.io.WritableComparable,org.apache.hadoop.io.Writable,org.apache.hadoop.io.Writable>
-
-