com.netflix.nfgraph
Class NFGraph

java.lang.Object
  extended by com.netflix.nfgraph.NFGraph
Direct Known Subclasses:
NFBuildGraph, NFCompressedGraph

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:

  1. Define an NFGraphSpec, which serves as the schema for the graph data.
  2. Instantiate an NFBuildGraph, then populate it with connections.
  3. Compress the NFBuildGraph, which will return a representation of the data as an NFCompressedGraph.
  4. Serialize the NFCompressedGraph to a stream. Netflix, for example, has a use case which streams this graph to Amazon Web Service's S3.
  5. Deserialize the stream where the compact in-memory representation of the graph data is necessary.

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);
 
 

See Also:
NFGraphSpec, NFBuildGraph, NFCompressedGraph

Field Summary
protected  NFGraphSpec graphSpec
           
protected  com.netflix.nfgraph.NFGraphModelHolder modelHolder
           
 
Constructor Summary
protected NFGraph(NFGraphSpec graphSpec)
           
protected NFGraph(NFGraphSpec graphSpec, com.netflix.nfgraph.NFGraphModelHolder modelHolder)
           
 
Method Summary
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

graphSpec

protected final NFGraphSpec graphSpec

modelHolder

protected final com.netflix.nfgraph.NFGraphModelHolder modelHolder
Constructor Detail

NFGraph

protected NFGraph(NFGraphSpec graphSpec)

NFGraph

protected NFGraph(NFGraphSpec graphSpec,
                  com.netflix.nfgraph.NFGraphModelHolder modelHolder)
Method Detail

getConnection

public 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.

Returns:
the connected ordinal, or -1 if there is no such ordinal

getConnection

public 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.

Returns:
the connected ordinal, or -1 if there is no such ordinal

getConnectionIterator

public 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.

Returns:
an OrdinalIterator over all connected ordinals

getConnectionIterator

public 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.

Returns:
an OrdinalIterator over all connected ordinals

getConnectionSet

public 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.

Returns:
an OrdinalSet over all connected ordinals

getConnectionSet

public 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.

Returns:
an OrdinalSet over all connected ordinals

getConnection

protected abstract int getConnection(int connectionModelIndex,
                                     java.lang.String nodeType,
                                     int ordinal,
                                     java.lang.String propertyName)

getConnectionSet

protected abstract OrdinalSet getConnectionSet(int connectionModelIndex,
                                               java.lang.String nodeType,
                                               int ordinal,
                                               java.lang.String propertyName)

getConnectionIterator

protected abstract OrdinalIterator getConnectionIterator(int connectionModelIndex,
                                                         java.lang.String nodeType,
                                                         int ordinal,
                                                         java.lang.String propertyName)