org.openanzo.client
Class DatasetServiceReplicator

java.lang.Object
  extended by org.openanzo.client.DatasetServiceReplicator

public class DatasetServiceReplicator
extends java.lang.Object

The underlying graph implementation for local models. Caches tracked statements (and other data) locally to avoid server transactions for every graph operation.

Author:
Matthew Roy ( mroy@us.ibm.com , Christopher R. Vincent, Jordi A. Albornoz Mulligan

Constructor Summary
DatasetServiceReplicator(DatasetService datasetService, java.util.Properties properties, java.util.concurrent.locks.ReentrantReadWriteLock datasetLock)
          Create a new DatasetServiceReplicator
 
Method Summary
 boolean addTracker(org.openrdf.model.URI trackerSetURI, ISerializableTracker tracker)
          Start tracking a (possibly overlapping) set of statements.
 boolean addTrackerListener(org.openrdf.model.URI trackerSetURI, ISerializableTracker tracker, TrackerListener trackerListener)
          Adds a TrackerListener which will get events of changes to the graph that match the supplied tracker.
 void close()
          Close the replicator, stoping all timers, and clearing the tracker cache
 boolean containsTracker(org.openrdf.model.URI trackerSetURI, ISerializableTracker tracker)
          Return true if there is a tracker register and in the named trackerSet
 java.util.Collection<ISerializableTracker> getAllTrackers()
          Get all the registered trackers
 INotificationListener getNotificationListener()
          Get the notificationListener
 long getReplicationInterval()
          Get the replication interval
 int getReplicationMode()
          Get the current replication mode
 java.util.Set<ISerializableTracker> getTrackers(org.openrdf.model.URI trackerSetURI)
          Get a new collection containing all trackers for the given tracker set.
 void registerReplicationListener(IReplicationListener listener)
          Register an IReplicationListener listener
 void removeAllTrackers(org.openrdf.model.URI trackerSetURI)
          Remove all trackers that makeup the named tracker set
 boolean removeTracker(org.openrdf.model.URI trackerSetURI, ISerializableTracker tracker)
          Stop tracking a set of statements.
 boolean removeTrackerListener(java.lang.String trackerSetUri, ISerializableTracker tracker, TrackerListener trackerListener)
          Removes a TrackerListener so that is no longer gets events of changes to the graph that match the supplied tracker.
 void replicate(boolean synchronous)
          Replicate local and remote changes
 void setReplicationInterval(long interval)
          Set the interval of replications when in Automatic replication mode
 void setReplicationMode(int mode)
          Set the replication mode
 void unregisterReplicationListener(IReplicationListener listener)
          Unregister an IReplicationListener listener
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatasetServiceReplicator

public DatasetServiceReplicator(DatasetService datasetService,
                                java.util.Properties properties,
                                java.util.concurrent.locks.ReentrantReadWriteLock datasetLock)
Create a new DatasetServiceReplicator

Parameters:
datasetService - Parent datasetService
properties - Configuration properties
datasetLock - Shared datasetService lock
Method Detail

addTracker

public boolean addTracker(org.openrdf.model.URI trackerSetURI,
                          ISerializableTracker tracker)
                   throws ReplicationException
Start tracking a (possibly overlapping) set of statements. Note that this method does not immediately download all the matching statements from the server. To cause that, call the replicate method after adding trackers. The trackerSetURI argument is a URI that is used to group trackers together. This is useful for essentially distributing ownership of trackers. Each trackerSet is like an individual bucket of trackers. You can't add duplicate trackers to one bucket and once you remove a tracker from a bucket, it is no longer in that bucket. However, since you can create arbitrarily many buckets by simply specifying a different trackerSetURI, then you have the flexibility to manage your own bucket of trackers without fear of clashing with anyone else who might also be registering trackers into this object. Essentially, if you are willing to coordinate addition and removal of trackers then you should share the same trackerSetURI. If you are not willing or able to do that, then use a unique trackerSetURI. Note that a particular tracker may only be registered once and removed once from a given trackerSet, much like the semantics of add/remove of the java.util.Set interface. If the tracker already exists in the given trackerSet, then nothing happens and the method returns false. If it does NOT already existin the given trackerSet, then it is added and the method return true.

Parameters:
trackerSetURI -
tracker -
Returns:
true if the tracker didn't already exist.
Throws:
ReplicationException

removeTracker

public boolean removeTracker(org.openrdf.model.URI trackerSetURI,
                             ISerializableTracker tracker)
                      throws ReplicationException
Stop tracking a set of statements. Statements will remain cached if they match other trackers which are still active. Removing a tracker that does not exist is not an error. The method simply returns false in that case. Removing a tracker only removes it from the trackerSet specified by the given URI. It is possible that an equivalent or similar tracker exists in another trackerSet. In that case, the statements will still be tracked until those other trackers are removed from their respective trackerSets. Removing a tracker removes all of the listeners registered for that tracker and trackerSet. It won't, however, remove listeners for equivalent trackers in other trackerSets. Removing a tracker does not immediately delete any statement from the cache. It is possible that upon next replication, however, that statements that no longer match any trackers may be removed from the cache.

Parameters:
trackerSetURI -
tracker -
Returns:
true if the tracker existed.
Throws:
ReplicationException

addTrackerListener

public boolean addTrackerListener(org.openrdf.model.URI trackerSetURI,
                                  ISerializableTracker tracker,
                                  TrackerListener trackerListener)
                           throws AnzoException
Adds a TrackerListener which will get events of changes to the graph that match the supplied tracker. The given StatementTracker must have been previously added to the to tracketSet specified by the given URI before any listeners can be added. If the tracker hasn't been added to that trackerSet, the method throws a TrackerNotRegisteredException. If the given StatementTracker has been privously added to that trackerSet and the TrackerListener has also already been added, then the function returns sucessfuly but does not add the TrackerListener in duplicate.

Parameters:
trackerSetURI -
tracker -
trackerListener - must not be null
Returns:
true if the TrackerListener did not already exist.
Throws:
AnzoException
See Also:
addTracker(URI, ISerializableTracker)

removeTrackerListener

public boolean removeTrackerListener(java.lang.String trackerSetUri,
                                     ISerializableTracker tracker,
                                     TrackerListener trackerListener)
                              throws AnzoException
Removes a TrackerListener so that is no longer gets events of changes to the graph that match the supplied tracker. If the given StatementTracker isn't registered with the graph in the given trackerSet then the method throws a TrackerNotRegisteredException. It is not an error to remove a TrackerListener more than once even for the same StatementTracker in the same trackerSet. Note that when a StatementTracker is removed from the a trackerSet, all of its listeners for that tracker in that trackerSet are removed also.

Parameters:
trackerSetUri - URI of trackerset that this listener belongs
tracker - Tracker to which listener is to be removed
trackerListener - Listener to remove
Returns:
true if the TrackerListener existed.
Throws:
AnzoException - if the tracker was not registered
See Also:
removeTracker(URI, ISerializableTracker)

containsTracker

public boolean containsTracker(org.openrdf.model.URI trackerSetURI,
                               ISerializableTracker tracker)
Return true if there is a tracker register and in the named trackerSet

Parameters:
trackerSetURI - URI of trackerSet
tracker - to check
Returns:
true if there is a tracker register and in the named trackerSet

removeAllTrackers

public void removeAllTrackers(org.openrdf.model.URI trackerSetURI)
                       throws ReplicationException
Remove all trackers that makeup the named tracker set

Parameters:
trackerSetURI - URI of trackerSet
Throws:
ReplicationException

getAllTrackers

public java.util.Collection<ISerializableTracker> getAllTrackers()
Get all the registered trackers

Returns:
all registered trackers

getTrackers

public java.util.Set<ISerializableTracker> getTrackers(org.openrdf.model.URI trackerSetURI)
Get a new collection containing all trackers for the given tracker set.

Parameters:
trackerSetURI - URI of trackerSet
Returns:
a new collection containing all trackers for the given tracker set.

close

public void close()
Close the replicator, stoping all timers, and clearing the tracker cache


replicate

public void replicate(boolean synchronous)
               throws AnzoException
Replicate local and remote changes

Parameters:
synchronous - true to replicate in a blocking synchronous manor, asynchronous otherwise
Throws:
AnzoException

setReplicationInterval

public void setReplicationInterval(long interval)
                            throws ReplicationException
Set the interval of replications when in Automatic replication mode

Parameters:
interval - of replications
Throws:
ReplicationException

getReplicationInterval

public long getReplicationInterval()
Get the replication interval

Returns:
the replication interval

setReplicationMode

public void setReplicationMode(int mode)
                        throws ReplicationException
Set the replication mode

Parameters:
mode - replication mode to set
Throws:
ReplicationException
See Also:
IReplicationService.REPLICATION_AUTOMATIC, IReplicationService.REPLICATION_IMMEDIATE_SYNC, IReplicationService.REPLICATION_IMMEDIATE_ASYNC, IReplicationService.REPLICATION_MANUAL

getReplicationMode

public int getReplicationMode()
Get the current replication mode

Returns:
the current replication mode
See Also:
IReplicationService.REPLICATION_AUTOMATIC, IReplicationService.REPLICATION_IMMEDIATE_SYNC, IReplicationService.REPLICATION_IMMEDIATE_ASYNC, IReplicationService.REPLICATION_MANUAL

registerReplicationListener

public void registerReplicationListener(IReplicationListener listener)
Register an IReplicationListener listener

Parameters:
listener - to register

unregisterReplicationListener

public void unregisterReplicationListener(IReplicationListener listener)
Unregister an IReplicationListener listener

Parameters:
listener - to unregister

getNotificationListener

public INotificationListener getNotificationListener()
Get the notificationListener

Returns:
the notificationListener


Copyright © 2007 Cambridge Semantics Inc.. All Rights Reserved.