public abstract class NFGraph
extends java.lang.Object
NFGraph represents a directed graph and is the base class for the two flavors of NetflixGraph
(NFBuildGraph and NFCompressedGraph). It defines the operations for retrieving connections
in the graph, given some node and property.
In the NetflixGraph library, each node in your graph is expected to be uniquely represented as a "type" and "ordinal".
Each "type" will be referred to by some String. An "ordinal", in this sense, is a number that uniquely defines the node
given its type. If a type of node has "n" instances, then each instance should be representable by some unique value
from 0 through (n-1). If nodes in the graph are represented as Objects externally to the NetflixGraph library, then
developers may find it helpful to use an OrdinalMap for each type to create and maintain a mapping between objects
and their ordinals. The OrdinalMap has been optimized with this use case in mind.
Use of the NFGraph is expected to generally follow some lifecycle:
NFGraphSpec, which serves as the schema for the graph data.NFBuildGraph, then populate it with connections.NFBuildGraph, which will return a representation of the data as an NFCompressedGraph.NFCompressedGraph to a stream. Netflix, for example, has a use case which streams this graph to Amazon Web Service's S3.In some cases, the location where the compact in-memory representation is necessary is the same as the location where this representation will be built. In these cases, steps (4) and (5) above will be omitted.
If there will be a producer of this graph and one or more consumers, then your producer code will resemble:
NFGraphSpec spec = new NFGraphSpec( ... );
NFBuildGraph buildGraph = new NFBuildGraph(spec);
for( ... each connection between nodes ... ) {
graph.addConnection( ... );
}
NFCompressedGraph compressedGraph = buildGraph.compress();
OutputStream os = ... stream to where you want the serialized data ...;
compressedGraph.writeTo(os);
And your consumer code will resemble:
InputStream is = ... stream from where the serialized data was written ...;
NFGraph graph = NFCompressedGraph.readFrom(is);
NFGraphSpec,
NFBuildGraph,
NFCompressedGraph| Modifier and Type | Field and Description |
|---|---|
protected NFGraphSpec |
graphSpec |
protected com.netflix.nfgraph.NFGraphModelHolder |
modelHolder |
| Modifier | Constructor and Description |
|---|---|
protected |
NFGraph(NFGraphSpec graphSpec) |
protected |
NFGraph(NFGraphSpec graphSpec,
com.netflix.nfgraph.NFGraphModelHolder modelHolder) |
| Modifier and Type | Method and Description |
|---|---|
protected abstract int |
getConnection(int connectionModelIndex,
java.lang.String nodeType,
int ordinal,
java.lang.String propertyName) |
int |
getConnection(java.lang.String nodeType,
int ordinal,
java.lang.String propertyName)
Retrieve a single connected ordinal, given the type and ordinal of the originating node, and the property by which this node is connected.
|
int |
getConnection(java.lang.String connectionModel,
java.lang.String nodeType,
int ordinal,
java.lang.String propertyName)
Retrieve a single connected ordinal in a given connection model, given the type and ordinal of the originating node, and the property by which this node is connected.
|
protected abstract OrdinalIterator |
getConnectionIterator(int connectionModelIndex,
java.lang.String nodeType,
int ordinal,
java.lang.String propertyName) |
OrdinalIterator |
getConnectionIterator(java.lang.String nodeType,
int ordinal,
java.lang.String propertyName)
Retrieve an
OrdinalIterator over all connected ordinals, given the type and ordinal of the originating node, and the property by which this node is connected. |
OrdinalIterator |
getConnectionIterator(java.lang.String connectionModel,
java.lang.String nodeType,
int ordinal,
java.lang.String propertyName)
Retrieve an
OrdinalIterator over all connected ordinals in a given connection model, given the type and ordinal of the originating node, and the property by which this node is connected. |
protected abstract OrdinalSet |
getConnectionSet(int connectionModelIndex,
java.lang.String nodeType,
int ordinal,
java.lang.String propertyName) |
OrdinalSet |
getConnectionSet(java.lang.String nodeType,
int ordinal,
java.lang.String propertyName)
Retrieve an
OrdinalSet over all connected ordinals, given the type and ordinal of the originating node, and the property by which this node is connected. |
OrdinalSet |
getConnectionSet(java.lang.String connectionModel,
java.lang.String nodeType,
int ordinal,
java.lang.String propertyName)
Retrieve an
OrdinalSet over all connected ordinals in a given connection model, given the type and ordinal of the originating node, and the property by which this node is connected. |
protected final NFGraphSpec graphSpec
protected final com.netflix.nfgraph.NFGraphModelHolder modelHolder
protected NFGraph(NFGraphSpec graphSpec)
protected NFGraph(NFGraphSpec graphSpec, com.netflix.nfgraph.NFGraphModelHolder modelHolder)
public int getConnection(java.lang.String nodeType,
int ordinal,
java.lang.String propertyName)
public int getConnection(java.lang.String connectionModel,
java.lang.String nodeType,
int ordinal,
java.lang.String propertyName)
public OrdinalIterator getConnectionIterator(java.lang.String nodeType, int ordinal, java.lang.String propertyName)
OrdinalIterator over all connected ordinals, given the type and ordinal of the originating node, and the property by which this node is connected.OrdinalIterator over all connected ordinalspublic OrdinalIterator getConnectionIterator(java.lang.String connectionModel, java.lang.String nodeType, int ordinal, java.lang.String propertyName)
OrdinalIterator over all connected ordinals in a given connection model, given the type and ordinal of the originating node, and the property by which this node is connected.OrdinalIterator over all connected ordinalspublic OrdinalSet getConnectionSet(java.lang.String nodeType, int ordinal, java.lang.String propertyName)
OrdinalSet over all connected ordinals, given the type and ordinal of the originating node, and the property by which this node is connected.OrdinalSet over all connected ordinalspublic OrdinalSet getConnectionSet(java.lang.String connectionModel, java.lang.String nodeType, int ordinal, java.lang.String propertyName)
OrdinalSet over all connected ordinals in a given connection model, given the type and ordinal of the originating node, and the property by which this node is connected.OrdinalSet over all connected ordinalsprotected abstract int getConnection(int connectionModelIndex,
java.lang.String nodeType,
int ordinal,
java.lang.String propertyName)
protected abstract OrdinalSet getConnectionSet(int connectionModelIndex, java.lang.String nodeType, int ordinal, java.lang.String propertyName)
protected abstract OrdinalIterator getConnectionIterator(int connectionModelIndex, java.lang.String nodeType, int ordinal, java.lang.String propertyName)