Class: AbstractGraph

AbstractGraph

An AbstractGraph contains the hosts and AbstractNodes that makes up the model.

An AbstractGraph can be thought of as a set of augmented linked-lists. Each host is associated with a linked-list that is "augmented" in the sense that nodes can also be connected to nodes in other linked lists. The first and last nodes in each linked list are dummy head and tail nodes respectively.

Traversing an AbstractGraph is much like traversing a linked list. For example, to visit all nodes whose host is equal to "loadBalancer":

var currentNode = this.getHeadByHost('loadBalancer').getNext();
while (!currentNode.isTail()) {
    // do something to currentNode
    currentNode = currentNode.getNext();
}

The AbstractGraph class makes the following guarantees about nodes in the graph:

  • node.getNext() == null if and only if node.isTail() == true
  • node.getPrev() == null if and only if node.isHead() == true
  • AbstractGraph implements the observer pattern. AbstractGraph will notify registered observers when certain events happen such as the removal of a node, the addition of edges between nodes, removal of a host, etc.

    Constructor

    (abstract) new AbstractGraph()

    The constructor for this abstract class will typically be invoked by concrete sub-classes
    Source:

    Methods

    addObserver(type, context, callback)

    Adds an observer to this graph. The observer will be notified (by invoking the provided callback function) of events when events of the specified type occur. There cannot exist two observers that are identical. The newly added observer will replace another if it is identical to the other one. Two observers are considered identical if they were registered with the same type and callback.

    Parameters:
    Name Type Description
    type function The type of event you want to observe. Use the constructor function of the event class. For example, if you want to observe AddNodeEvents, type would just be "AddNodeEvent".
    context * This object will be provided to the callback function when it is invoked.
    callback AbstractGraph~ObserverCallback The callback function. The parameters of the callback should be event, context
    Source:

    getAllNodes() → {Array.<AbstractNode>}

    Gets all nodes including dummy nodes

    This function makes no guarantees about the ordering of nodes in the array returned. Also note that a new array is created to prevent modification of the underlying private data structure, so this function takes linear rather than constant time on the number of nodes.

    Source:
    Returns:
    an array of all nodes in the model
    Type
    Array.<AbstractNode>

    getDummyNodes() → {Array.<AbstractNode>}

    Gets all dummy (head/tail) nodes in the graph as an array.

    This function makes no guarantees about the ordering of nodes in the array returned. Also note that a new array is created to prevent modification of the underlying private data structure, so this function takes linear rather than constant time on the number of nodes.

    Source:
    Returns:
    an array of all dummy nodes
    Type
    Array.<AbstractNode>

    getHead(host) → {AbstractNode}

    Gets the dummy head node for a host.
    Parameters:
    Name Type Description
    host String the name of the host
    Source:
    Returns:
    the head node, or null if none is found
    Type
    AbstractNode

    getHosts() → {Array.<String>}

    Gets the hosts as an array
    Source:
    Returns:
    a copy of the array of host names
    Type
    Array.<String>

    getNodes() → {Array.<AbstractNode>}

    Gets all non-dummy (i.e non-head and non-tail) nodes in the graph as an array.

    This function makes no guarantees about the ordering of nodes in the array returned. Also note that a new array is created to prevent modification of the underlying private data structure, so this function takes linear rather than constant time on the number of nodes.

    Source:
    Returns:
    an array of all non-dummy nodes
    Type
    Array.<AbstractNode>

    getNodesTopologicallySorted() → {Array.<AbstractNode>}

    Returns the non-dummy nodes of the graph in topologically sorted order. A topologically sorted order is one where, for all i and j such that j > i, there does not exist a directed edge from nodes[j] to nodes[i].

    In the case that there are multiple permissible orderings, this method makes no guarantees about which one will be returned. This method may not even return the same order each time it's called.

    Source:
    Throws:
    An exception if the graph contains a cycle. There cannot exist a topologically sorted order if there exists a cycle.
    Returns:
    the nodes in topologically sorted order.
    Type
    Array.<AbstractNode>

    getTail(host) → {AbstractNode}

    Gets the dummy tail node for a host
    Parameters:
    Name Type Description
    host String the name of the host
    Source:
    Returns:
    the tail node, or null if none is found
    Type
    AbstractNode

    hasHost(host) → {Boolean}

    Checks if this graph has the specified host
    Parameters:
    Name Type Description
    host String The host to check for
    Source:
    Returns:
    True if the host exists
    Type
    Boolean

    removeHost(host)

    Removes a host from the model. The host itself and all nodes on the host will be removed. In addition all connections to and from this host will be removed. If the host doesn't exist, this method does nothing
    Parameters:
    Name Type Description
    host String the name of the host to hide
    Source:

    removeObserver(type, callback)

    Removes an observer from this graph. If the specified observer cannot be found, this function does nothing.

    Parameters:
    Name Type Description
    type function The type of event you want to observe. Use the constructor function of the event class. For example, if you want to remove an observer for AbstractGraphs, type would just be "AddNodeEvent".
    callback AbstractGraph~ObserverCallback The callback function.
    Source:

    Type Definitions

    ObserverCallback(event, context)

    The callback function invoked when an event occurs
    Parameters:
    Name Type Description
    event Event The event object.
    context * Arbitrary data provided to the callback function specified when adding observers
    Source: