Skip to content
Permalink
Browse files
GIRAPH-1168
closes #57
  • Loading branch information
Maja Kabiljo committed Feb 1, 2018
1 parent f944f5c commit 1f959d076ed7f29c3f8a5c6e99cbfcc62c1058d9
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 2 deletions.
@@ -35,11 +35,14 @@
import org.apache.giraph.factories.ComputationFactory;
import org.apache.giraph.factories.DefaultComputationFactory;
import org.apache.giraph.factories.DefaultEdgeValueFactory;
import org.apache.giraph.factories.DefaultInputOutEdgesFactory;
import org.apache.giraph.factories.DefaultMessageValueFactory;
import org.apache.giraph.factories.DefaultOutEdgesFactory;
import org.apache.giraph.factories.DefaultVertexIdFactory;
import org.apache.giraph.factories.DefaultVertexValueFactory;
import org.apache.giraph.factories.EdgeValueFactory;
import org.apache.giraph.factories.MessageValueFactory;
import org.apache.giraph.factories.OutEdgesFactory;
import org.apache.giraph.factories.VertexIdFactory;
import org.apache.giraph.factories.VertexValueFactory;
import org.apache.giraph.graph.Computation;
@@ -198,6 +201,16 @@ public interface GiraphConstants {
ClassConfOption.create("giraph.inputOutEdgesClass",
ByteArrayEdges.class, OutEdges.class,
"Vertex edges class to be used during edge input only - optional");
/** OutEdges factory class - optional */
ClassConfOption<OutEdgesFactory> VERTEX_EDGES_FACTORY_CLASS =
ClassConfOption.create("giraph.outEdgesFactoryClass",
DefaultOutEdgesFactory.class, OutEdgesFactory.class,
"OutEdges factory class - optional");
/** OutEdges for input factory class - optional */
ClassConfOption<OutEdgesFactory> INPUT_VERTEX_EDGES_FACTORY_CLASS =
ClassConfOption.create("giraph.inputOutEdgesFactoryClass",
DefaultInputOutEdgesFactory.class, OutEdgesFactory.class,
"OutEdges for input factory class - optional");

/** Class for Master - optional */
ClassConfOption<MasterCompute> MASTER_COMPUTE_CLASS =
@@ -36,6 +36,7 @@
import org.apache.giraph.factories.ComputationFactory;
import org.apache.giraph.factories.EdgeValueFactory;
import org.apache.giraph.factories.MessageValueFactory;
import org.apache.giraph.factories.OutEdgesFactory;
import org.apache.giraph.factories.ValueFactories;
import org.apache.giraph.factories.VertexIdFactory;
import org.apache.giraph.factories.VertexValueFactory;
@@ -112,6 +113,10 @@
private Class<? extends Writable> mappingTargetClass = null;
/** Value (IVEMM) Factories */
private final ValueFactories<I, V, E> valueFactories;
/** Factory to create {@link OutEdges} for computation */
private final OutEdgesFactory<I, E> outEdgesFactory;
/** Factory to create {@link OutEdges} for input */
private final OutEdgesFactory<I, E> inputOutEdgesFactory;
/** Language values (IVEMM) are implemented in */
private final PerGraphTypeEnum<Language> valueLanguages;
/** Whether values (IVEMM) need Jython wrappers */
@@ -148,6 +153,8 @@ public ImmutableClassesGiraphConfiguration(Configuration conf) {
GiraphConstants.GRAPH_TYPES_NEEDS_WRAPPERS, conf);
isStaticGraph = GiraphConstants.STATIC_GRAPH.get(this);
valueFactories = new ValueFactories<I, V, E>(this);
outEdgesFactory = VERTEX_EDGES_FACTORY_CLASS.newInstance(this);
inputOutEdgesFactory = INPUT_VERTEX_EDGES_FACTORY_CLASS.newInstance(this);
}

/**
@@ -1083,7 +1090,7 @@ public Writable createMappingTarget() {
* @return Instantiated user OutEdges
*/
public OutEdges<I, E> createOutEdges() {
return ReflectionUtils.newInstance(getOutEdgesClass(), this);
return outEdgesFactory.newInstance();
}

/**
@@ -1132,7 +1139,7 @@ public OutEdges<I, E> createAndInitializeOutEdges(
* @return Instantiated user input OutEdges
*/
public OutEdges<I, E> createInputOutEdges() {
return ReflectionUtils.newInstance(getInputOutEdgesClass(), this);
return inputOutEdgesFactory.newInstance();
}

/**
@@ -0,0 +1,50 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.giraph.factories;

import org.apache.giraph.conf.GiraphConfigurationSettable;
import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration;
import org.apache.giraph.edge.OutEdges;
import org.apache.giraph.utils.ReflectionUtils;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;

/**
* Default factory class for creating {@link OutEdges} instances to be used
* during input. This factory simply creates an instance of the
* {@link OutEdges} class set in the configuration.
*
* @param <I> Vertex ID type.
* @param <E> Edge value type.
*/
public class DefaultInputOutEdgesFactory<I extends WritableComparable,
E extends Writable> implements OutEdgesFactory<I, E>,
GiraphConfigurationSettable {
/** Configuration */
private ImmutableClassesGiraphConfiguration<I, ?, E> conf;

@Override
public void setConf(ImmutableClassesGiraphConfiguration conf) {
this.conf = conf;
}

@Override
public OutEdges<I, E> newInstance() {
return ReflectionUtils.newInstance(conf.getInputOutEdgesClass(), conf);
}
}
@@ -0,0 +1,50 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.giraph.factories;

import org.apache.giraph.conf.GiraphConfigurationSettable;
import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration;
import org.apache.giraph.edge.OutEdges;
import org.apache.giraph.utils.ReflectionUtils;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;

/**
* Default factory class for creating {@link OutEdges} instances to be used
* during computation. This factory simply creates an instance of the
* {@link OutEdges} class set in the configuration.
*
* @param <I> Vertex ID type.
* @param <E> Edge value type.
*/
public class DefaultOutEdgesFactory<I extends WritableComparable,
E extends Writable> implements OutEdgesFactory<I, E>,
GiraphConfigurationSettable {
/** Configuration */
private ImmutableClassesGiraphConfiguration<I, ?, E> conf;

@Override
public void setConf(ImmutableClassesGiraphConfiguration conf) {
this.conf = conf;
}

@Override
public OutEdges<I, E> newInstance() {
return ReflectionUtils.newInstance(conf.getOutEdgesClass(), conf);
}
}
@@ -0,0 +1,41 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.giraph.factories;

import org.apache.giraph.edge.OutEdges;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;

import java.io.Serializable;

/**
* Factory interface for creating {@link OutEdges} instances.
*
* @param <I> Vertex ID type.
* @param <E> Edge value type.
*/
public interface OutEdgesFactory<I extends WritableComparable,
E extends Writable> extends Serializable {

/**
* Creates a new {@link OutEdges instance}.
*
* @return {@link OutEdges} instance.
*/
OutEdges<I, E> newInstance();
}

0 comments on commit 1f959d0

Please sign in to comment.