org.hypergraphdb.peer
Class HyperGraphPeer

java.lang.Object
  extended by org.hypergraphdb.peer.HyperGraphPeer

public class HyperGraphPeer
extends java.lang.Object

Main class for the local peer. It will start the peer (set up the interface and register in the network) given a configuration. The class will wrap an existing HyperGraph instance. It is possible to create an instance of this class with an existing HyperGraph, or allow the peer to create its own based on the configuration properties. (if it is needed).

Author:
Cipri Costa

Constructor Summary
HyperGraphPeer(java.io.File configFile)
          Creates a peer from a file containing the JSON object
HyperGraphPeer(java.io.File configFile, HyperGraph graph)
          Creates a peer from a file containing the JSON object and a given local database.
HyperGraphPeer(java.util.Map<java.lang.String,java.lang.Object> configuration)
          Creates a peer from a JSON object.
HyperGraphPeer(java.util.Map<java.lang.String,java.lang.Object> configuration, HyperGraph graph)
          Creates a peer from a JSON object and a given local database.
 
Method Summary
 void bindIdentityToNetworkTarget(HGPeerIdentity id, java.lang.Object networkTarget)
           
 ActivityManager getActivityManager()
           
 java.util.List<RemotePeer> getConnectedPeers()
           
 java.util.concurrent.ExecutorService getExecutorService()
           
 HyperGraph getGraph()
           
 HGPeerIdentity getIdentity()
           Return this peer's identity.
 HGPeerIdentity getIdentity(java.lang.Object networkTarget)
           
 Log getLog()
           
 java.lang.Object getNetworkTarget(HGPeerIdentity id)
           
 java.util.Map<java.lang.String,java.lang.Object> getObjectContext()
           The objectContext is just a peer-global map of objects that are shared between activities.
 PeerInterface getPeerInterface()
           
 RemotePeer getRemotePeer(java.lang.String peerName)
          Returns a remote peer with the given name (if it is connected at that point - otherwise null).
 Subgraph getSubgraph(HGHandle handle)
          Announces the interests of this peer.
 HyperGraph getTempDb()
           
static java.util.Map<java.lang.String,java.lang.Object> loadConfiguration(java.io.File configFile)
           
 void setLog(Log log)
           
 boolean start(java.lang.String user, java.lang.String passwd)
          Starts the peer and leaves it in a state where all its functions are available.
 void stop()
           
 void unbindNetworkTargetFromIdentity(java.lang.Object networkTarget)
           
 void updateNetworkProperties()
          will broadcast messages and update the peers knowledge of the neighboring peers
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HyperGraphPeer

public HyperGraphPeer(java.util.Map<java.lang.String,java.lang.Object> configuration)
Creates a peer from a JSON object.

Parameters:
configuration -

HyperGraphPeer

public HyperGraphPeer(java.util.Map<java.lang.String,java.lang.Object> configuration,
                      HyperGraph graph)
Creates a peer from a JSON object and a given local database.

Parameters:
configuration -

HyperGraphPeer

public HyperGraphPeer(java.io.File configFile)
Creates a peer from a file containing the JSON object

Parameters:
configFile -

HyperGraphPeer

public HyperGraphPeer(java.io.File configFile,
                      HyperGraph graph)
Creates a peer from a file containing the JSON object and a given local database.

Parameters:
configFile -
Method Detail

getIdentity

public HGPeerIdentity getIdentity()

Return this peer's identity.


loadConfiguration

public static java.util.Map<java.lang.String,java.lang.Object> loadConfiguration(java.io.File configFile)

start

public boolean start(java.lang.String user,
                     java.lang.String passwd)
Starts the peer and leaves it in a state where all its functions are available.

Parameters:
user - The user name to use when the group is joined.
passwd - Password to use to authenticate against the group.
Returns:

stop

public void stop()

getSubgraph

public Subgraph getSubgraph(HGHandle handle)
Announces the interests of this peer. All the other peers that notice this announcement will send any content that matches the given predicate, regardless of whether this peer is on or off line.

Parameters:
pred - An atom predicate that needs to be matched by an atom in order for any operations on the atom to be sent to this peer.

updateNetworkProperties

public void updateNetworkProperties()
will broadcast messages and update the peers knowledge of the neighboring peers


getLog

public Log getLog()

setLog

public void setLog(Log log)

getGraph

public HyperGraph getGraph()

getConnectedPeers

public java.util.List<RemotePeer> getConnectedPeers()
Returns:
A list with all the connected peers in the form of RemotePeer objects.

getRemotePeer

public RemotePeer getRemotePeer(java.lang.String peerName)
Returns a remote peer with the given name (if it is connected at that point - otherwise null). If multiple peers are registered with the same name, there is no guarantees as to which will be returned.

Parameters:
peerName -
Returns:

getTempDb

public HyperGraph getTempDb()

getActivityManager

public ActivityManager getActivityManager()

getPeerInterface

public PeerInterface getPeerInterface()

getExecutorService

public java.util.concurrent.ExecutorService getExecutorService()

getIdentity

public HGPeerIdentity getIdentity(java.lang.Object networkTarget)

getNetworkTarget

public java.lang.Object getNetworkTarget(HGPeerIdentity id)

bindIdentityToNetworkTarget

public void bindIdentityToNetworkTarget(HGPeerIdentity id,
                                        java.lang.Object networkTarget)

unbindNetworkTargetFromIdentity

public void unbindNetworkTargetFromIdentity(java.lang.Object networkTarget)

getObjectContext

public java.util.Map<java.lang.String,java.lang.Object> getObjectContext()

The objectContext is just a peer-global map of objects that are shared between activities. Such objects can be instantiated at configuration time by BootstrapPeer implementation and/or create, removed or modified at a later time. The map is merely a convenience way to store and refer to such peer-wide objects.