com.sun.sgs.impl.service.nodemap.affinity.dlpa.graph
Class WeightedGraphBuilder

java.lang.Object
  extended by com.sun.sgs.impl.service.nodemap.affinity.BasicState
      extended by com.sun.sgs.impl.service.nodemap.affinity.graph.AbstractAffinityGraphBuilder
          extended by com.sun.sgs.impl.service.nodemap.affinity.dlpa.graph.WeightedGraphBuilder
All Implemented Interfaces:
DLPAGraphBuilder, AffinityGraphBuilder

public class WeightedGraphBuilder
extends AbstractAffinityGraphBuilder
implements DLPAGraphBuilder

A graph builder which builds an affinity graph consisting of identities as vertices and a single weighted edges representing objects used by both identities.

The data access information naturally forms a bipartite graph, with vertices being either identities or objects, and an edge connecting each identity which has accessed an object. However, we want a graph with vertices for identities, and edges representing object accesses between identities, so we need the bipartite graph to be folded.

We build the folded graph on the fly by keeping track of which objects have been used by which identities. Edges between identities are weighted, and represent the number of object accesses the two identities have in common.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.sun.sgs.impl.service.nodemap.affinity.BasicState
BasicState.State
 
Field Summary
 
Fields inherited from class com.sun.sgs.impl.service.nodemap.affinity.graph.AbstractAffinityGraphBuilder
DEFAULT_PERIOD, DEFAULT_PERIOD_COUNT, logger, PERIOD_COUNT_PROPERTY, PERIOD_PROPERTY, periodCount, PROP_BASE, snapshot, wrappedProps
 
Fields inherited from class com.sun.sgs.impl.service.nodemap.affinity.BasicState
state
 
Constructor Summary
WeightedGraphBuilder(Properties properties, ComponentRegistry systemRegistry, TransactionProxy txnProxy)
          Creates a weighted graph builder.
 
Method Summary
 void disable()
          Disables this builder.
 void enable()
          Enables this builder.
 edu.uci.ics.jung.graph.UndirectedGraph<LabelVertex,WeightedEdge> getAffinityGraph()
          Returns the current graph, with identities as vertices, and edges representing each object accessed by both identity endpoints.
 LPAAffinityGroupFinder getAffinityGroupFinder()
          Returns the affinity group finder created by this builder, or null if none was created.
 Map<Long,Map<Object,Long>> getConflictMap()
          Returns a map of detected cross node data conflicts.
 Map<Object,Map<Identity,Long>> getObjectUseMap()
          Returns a map of local object uses to the identities that used the objects, and a count of the number of uses.
 Runnable getPruneTask()
          Get the task which prunes the graph.
 LabelVertex getVertex(Identity id)
          Gets the graph vertex for the given Identity.
 void noteConflictDetected(Object objId, long nodeId, boolean forUpdate)
          TBD: This will be the implementation of our conflict detection listener.
 void removeNode(long nodeId)
          Note that a node has failed.
 void shutdown()
          Shuts down this builder.
 void updateGraph(Identity owner, AccessedObjectsDetail detail)
          Update the graph based on the objects accessed in a task.
 
Methods inherited from class com.sun.sgs.impl.service.nodemap.affinity.BasicState
checkForDisabledOrShutdownState, checkForShutdownState, setDisabledState, setEnabledState, setShutdownState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WeightedGraphBuilder

public WeightedGraphBuilder(Properties properties,
                            ComponentRegistry systemRegistry,
                            TransactionProxy txnProxy)
                     throws Exception
Creates a weighted graph builder.

Parameters:
properties - the properties for configuring this builder
systemRegistry - the registry of available system components
txnProxy - the transaction proxy
Throws:
Exception - if an error occurs
Method Detail

updateGraph

public void updateGraph(Identity owner,
                        AccessedObjectsDetail detail)
Update the graph based on the objects accessed in a task. If the builder is disabled, does nothing.

This method is called by a single thread but must protect itself from changes to data structures made by the pruner.

Specified by:
updateGraph in interface AffinityGraphBuilder
Parameters:
owner - the task owner (the object making the accesses)
detail - detailed information about the object accesses, including a list of the accessed objects

getAffinityGraph

public edu.uci.ics.jung.graph.UndirectedGraph<LabelVertex,WeightedEdge> getAffinityGraph()
Returns the current graph, with identities as vertices, and edges representing each object accessed by both identity endpoints. An empty graph will be returned if there is no affinity data collected.

The returned graph can not be modified.

Specified by:
getAffinityGraph in interface AffinityGraphBuilder
Returns:
the graph of access information

getObjectUseMap

public Map<Object,Map<Identity,Long>> getObjectUseMap()
Returns a map of local object uses to the identities that used the objects, and a count of the number of uses. An empty map will be returned if there are no object uses.

Specified by:
getObjectUseMap in interface DLPAGraphBuilder
Returns:
the map of local object uses

getConflictMap

public Map<Long,Map<Object,Long>> getConflictMap()
Returns a map of detected cross node data conflicts. Conflicts occur when an object is in use by the current node but is needed by another node. This is a map of node IDs (the nodes requesting the object) to object IDs, and a count of the number of conflicts on the object with that node. An empty map will be returned if there are no conflicts. If more than one node needs an object at about the same time, it is only required that one node be recorded as a conflict.

Specified by:
getConflictMap in interface DLPAGraphBuilder
Returns:
the map of detected cross node data conflicts

disable

public void disable()
Disables this builder. Disabled builders can be enabled or shutdown. Multiple calls to disable are allowed.

While disabled, no new graph updates are applied, but the graph pruners continue to discard old data.

Specified by:
disable in interface AffinityGraphBuilder

enable

public void enable()
Enables this builder. Enabled builders can be disabled or shutdown. Multiple calls to enable are allowed.

Specified by:
enable in interface AffinityGraphBuilder

shutdown

public void shutdown()
Shuts down this builder. Once shut down, a builder cannot be enabled or disabled. Multiple calls to shutdown are allowed.

Specified by:
shutdown in interface AffinityGraphBuilder

getVertex

public LabelVertex getVertex(Identity id)
Gets the graph vertex for the given Identity.

Specified by:
getVertex in interface AffinityGraphBuilder
Parameters:
id - an identity
Returns:
the graph vertex for the identity, or null if there is no such vertex

getAffinityGroupFinder

public LPAAffinityGroupFinder getAffinityGroupFinder()
Returns the affinity group finder created by this builder, or null if none was created. Some algorithms only create the finder on the server node.

Specified by:
getAffinityGroupFinder in interface AffinityGraphBuilder
Returns:
the affinity group finder or null

noteConflictDetected

public void noteConflictDetected(Object objId,
                                 long nodeId,
                                 boolean forUpdate)
TBD: This will be the implementation of our conflict detection listener.

Note that forUpdate is currently not used.

Parameters:
objId - the object that was evicted
nodeId - the node that caused the eviction
forUpdate - true if this eviction was for an update, false if it was for read only access

removeNode

public void removeNode(long nodeId)
Note that a node has failed. Does nothing if the nodeId is unknown or has already been noted as failed.

Specified by:
removeNode in interface DLPAGraphBuilder
Parameters:
nodeId - the id of the failed node

getPruneTask

public Runnable getPruneTask()
Get the task which prunes the graph. This is useful for testing.

Returns:
the runnable which prunes the graph.
Throws:
UnsupportedOperationException - if this builder does not support graph pruning.

RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved