GIRAPH-1168
closes #57
diff --git a/giraph-core/src/main/java/org/apache/giraph/conf/GiraphConstants.java b/giraph-core/src/main/java/org/apache/giraph/conf/GiraphConstants.java
index 9340472..44b2a44 100644
--- a/giraph-core/src/main/java/org/apache/giraph/conf/GiraphConstants.java
+++ b/giraph-core/src/main/java/org/apache/giraph/conf/GiraphConstants.java
@@ -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 @@
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 =
diff --git a/giraph-core/src/main/java/org/apache/giraph/conf/ImmutableClassesGiraphConfiguration.java b/giraph-core/src/main/java/org/apache/giraph/conf/ImmutableClassesGiraphConfiguration.java
index 1d541c3..680368b 100644
--- a/giraph-core/src/main/java/org/apache/giraph/conf/ImmutableClassesGiraphConfiguration.java
+++ b/giraph-core/src/main/java/org/apache/giraph/conf/ImmutableClassesGiraphConfiguration.java
@@ -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 @@
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 @@
* @return Instantiated user OutEdges
*/
public OutEdges<I, E> createOutEdges() {
- return ReflectionUtils.newInstance(getOutEdgesClass(), this);
+ return outEdgesFactory.newInstance();
}
/**
@@ -1132,7 +1139,7 @@
* @return Instantiated user input OutEdges
*/
public OutEdges<I, E> createInputOutEdges() {
- return ReflectionUtils.newInstance(getInputOutEdgesClass(), this);
+ return inputOutEdgesFactory.newInstance();
}
/**
diff --git a/giraph-core/src/main/java/org/apache/giraph/factories/DefaultInputOutEdgesFactory.java b/giraph-core/src/main/java/org/apache/giraph/factories/DefaultInputOutEdgesFactory.java
new file mode 100644
index 0000000..85e9664
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/factories/DefaultInputOutEdgesFactory.java
@@ -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);
+ }
+}
diff --git a/giraph-core/src/main/java/org/apache/giraph/factories/DefaultOutEdgesFactory.java b/giraph-core/src/main/java/org/apache/giraph/factories/DefaultOutEdgesFactory.java
new file mode 100644
index 0000000..a32218f
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/factories/DefaultOutEdgesFactory.java
@@ -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);
+ }
+}
diff --git a/giraph-core/src/main/java/org/apache/giraph/factories/OutEdgesFactory.java b/giraph-core/src/main/java/org/apache/giraph/factories/OutEdgesFactory.java
new file mode 100644
index 0000000..621855e
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/factories/OutEdgesFactory.java
@@ -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();
+}