org.hypergraphdb.peer
Class RemotePeer

java.lang.Object
  extended by org.hypergraphdb.peer.RemotePeer
Direct Known Subclasses:
JXTARemotePeer

public abstract class RemotePeer
extends java.lang.Object

Author:
Cipri Costa Offers an interface to a remote peer. The peers are identified by name. Subclasses will implement the actual communication with the remote peer (get/add/remove/replace + query).

Constructor Summary
RemotePeer()
           
RemotePeer(java.lang.String name)
           
 
Method Summary
abstract  HGHandle add(java.lang.Object atom)
          Adds the atom on the remote peer.
abstract  void copyFrom(HGPersistentHandle handle)
          Copies the atom with a given handle from the remote peer to the local peer.
abstract  void copyTo(HGHandle handle)
          Copies the atom from a given handle from the local peer to the remote peer.
abstract  void define(HGPersistentHandle handle, java.lang.Object atom)
          Similar to add but with a given handle
 java.util.List<?> endBatch()
          After this call, the operations will be imediatelly sent to the remote peer.
 java.util.List<?> flushBatch()
          Sends the current list of queued operations to the remote peer.
abstract  java.lang.Object get(HGHandle handle)
           
 HyperGraphPeer getLocalPeer()
           
 java.lang.String getName()
           
 boolean insideBatch()
           
abstract  java.util.ArrayList<?> query(HGQueryCondition condition, boolean getObjects)
          Executes a query on the remote peer
abstract  HGHandle remove(HGPersistentHandle handle)
          Removes the handle from the remote peer.
abstract  void replace(HGPersistentHandle handle, java.lang.Object atom)
          Replaces the atom with the given handle on the remote peer.
 void setLocalPeer(HyperGraphPeer localPeer)
           
 void setName(java.lang.String name)
           
 void startBatch()
          Starts a batch.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RemotePeer

public RemotePeer()

RemotePeer

public RemotePeer(java.lang.String name)
Method Detail

query

public abstract java.util.ArrayList<?> query(HGQueryCondition condition,
                                             boolean getObjects)
Executes a query on the remote peer

Parameters:
condition - a HGQueryCondition to be executed on the remote peer.
getObjects - if true the actual objects are returned, otherwise the client will just get a set of handles.
Returns:
The result of the remote query (depending on the getObjects parameter the list will contain the objects of just the handles)

get

public abstract java.lang.Object get(HGHandle handle)
Parameters:
handle - The handle of the atom to be retrieved
Returns:
The atom with the given handle from the remote peer. If no such handle exists on the remote peer, the function will return null

add

public abstract HGHandle add(java.lang.Object atom)
Adds the atom on the remote peer. The operation is implemented using the replication mechanism, so, even if it fails, it is registered in the logs and will be sent to the target when the target will start a catch-up phase.

Parameters:
atom - The atom to be added
Returns:

define

public abstract void define(HGPersistentHandle handle,
                            java.lang.Object atom)
Similar to add but with a given handle

Parameters:
handle -
atom -

copyTo

public abstract void copyTo(HGHandle handle)
Copies the atom from a given handle from the local peer to the remote peer.

Parameters:
handle -

copyFrom

public abstract void copyFrom(HGPersistentHandle handle)
Copies the atom with a given handle from the remote peer to the local peer.

Parameters:
handle -

remove

public abstract HGHandle remove(HGPersistentHandle handle)
Removes the handle from the remote peer. The operation is implemented using the replication mechanism, so, even if it fails, it is registered in the logs and will be sent to the target when the target will start a catch-up phase.

Parameters:
handle - the handle to remove from the remote peer.
Returns:

replace

public abstract void replace(HGPersistentHandle handle,
                             java.lang.Object atom)
Replaces the atom with the given handle on the remote peer. The operation is implemented using the replication mechanism, so, even if it fails, it is registered in the logs and will be sent to the target when the target will start a catch-up phase.

Parameters:
handle - the handle of the atom to be replaced
atom - the new atom

startBatch

public void startBatch()
Starts a batch. After this call and until the endBatch call, all functions that send data to the remote peer will be queued. In order to send the messages use flushBatch or endBatch


endBatch

public java.util.List<?> endBatch()
After this call, the operations will be imediatelly sent to the remote peer. Also calls the flush method if there are any outstanding calls to be sent.

Returns:

flushBatch

public java.util.List<?> flushBatch()
Sends the current list of queued operations to the remote peer.

Returns:

insideBatch

public boolean insideBatch()

getName

public java.lang.String getName()

setName

public void setName(java.lang.String name)

getLocalPeer

public HyperGraphPeer getLocalPeer()

setLocalPeer

public void setLocalPeer(HyperGraphPeer localPeer)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object