-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Labels
Description
The subgraph object can only be accessed after the compute class is instantiated. So a call to getSubgraph() inside constructor of compute class throws a NullPointerException.
Relevant code snippets:
Example where subgraph object might be used inside a constructor (full code):
/**
* Input has <num_clusters>,<max_edge_cuts>,<max_iters>
*
* @param initMsg
*/
public KMeans(String initMsg) {
String[] inp = initMsg.split(",");
//SubgraphValue value = new SubgraphValue();
value.k = Integer.parseInt(inp[0]);
value.maxEdgeCrossing = Long.parseLong(inp[1]);
value.maxIterations = Integer.parseInt(inp[2]);
// NOTE: Subgraph state is not available in the constructor.
//getSubgraph().setSubgraphValue(value);
}
Framework code snippet which creates subgraphCompute Object and assigns subgraph object to it (full code):
/*
* Creating SubgraphCompute objects
*/
for (ISubgraph<S, V, E, I, J, K> subgraph : partition.getSubgraphs()) {
Class<? extends AbstractSubgraphComputation<S, V, E, M, I, J, K>> subgraphComputeClass;
subgraphComputeClass = (Class<? extends AbstractSubgraphComputation<S, V, E, M, I, J, K>>) conf
.getClass(GraphJob.SUBGRAPH_COMPUTE_CLASS_ATTR, null);
if (subgraphComputeClass == null)
throw new RuntimeException("Could not load subgraph compute class");
AbstractSubgraphComputation<S, V, E, M, I, J, K> abstractSubgraphComputeRunner;
if (initialValue != null) {
Object []params = {initialValue};
abstractSubgraphComputeRunner = ReflectionUtils.newInstance(subgraphComputeClass, params);
}
else
abstractSubgraphComputeRunner = ReflectionUtils.newInstance(subgraphComputeClass);
// FIXME: Subgraph value is not available to user in the subgraph-compute's constructor,
// since it is added only after the object is created (using setSubgraph).
SubgraphCompute<S, V, E, M, I, J, K> subgraphComputeRunner = new SubgraphCompute<S, V, E, M, I, J, K>();
subgraphComputeRunner.setAbstractSubgraphCompute(abstractSubgraphComputeRunner);
abstractSubgraphComputeRunner.setSubgraphPlatformCompute(subgraphComputeRunner);
subgraphComputeRunner.setSubgraph(subgraph);
subgraphComputeRunner.init(this);
subgraphs.add(subgraphComputeRunner);
}