uk.ac.ic.doc.automed.p2p
Class PeerCache

java.lang.Object
  extended by uk.ac.ic.doc.automed.p2p.PeerCache
All Implemented Interfaces:
java.util.Iterator, Cacheable

public class PeerCache
extends java.lang.Object
implements Cacheable

Author:
Charis A cache of information fetched from the P2PDirectory for the local AutoMedPeer

Field Summary
(package private)  java.util.List cacheListeners
           
(package private)  MessageHandler myHandler
           
 java.util.Set mySchemas
           
(package private)  java.lang.String name
           
 java.util.Map otherPeers
           
 java.util.HashSet publicSchemas
           
 
Constructor Summary
PeerCache(AutoMedPeer myPeer)
           
 
Method Summary
 void addListener(CacheListener listener)
          Add a listener to the cache
 void clear()
          Clear the cache
 CacheContentDescription getContentObject()
          Get the actual content object
 java.util.Set getMySchemas()
           
 java.util.HashSet getPeerDescriptions(SchemaDescription schema)
          Return a Map of PeerDescriptions for a given SchemaDescription.
 java.util.Set getPublicSchemas()
          Return a Set containing SchemaDescriptions
 boolean hasNext()
           
 void initialiseCache()
           
 boolean isSchemaInfoCached(java.lang.String schema)
           
 java.lang.Object next()
           
private  void notifyListeners()
           
 void notifyListeners(Cacheable cacheObj)
          Notify listeners to handle a specific event
 void refresh()
          Refresh cache content
 void refreshMySchemas()
           
 java.util.HashSet refreshPeersOf(SchemaDescription schema)
           
 java.util.HashSet refreshPublicSchemas()
           
 void remove()
           
 void setPublicSchemas(java.util.List schemas)
          Assign a list of public schemas (i.e.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

mySchemas

public java.util.Set mySchemas

publicSchemas

public java.util.HashSet publicSchemas

otherPeers

public java.util.Map otherPeers

myHandler

MessageHandler myHandler

name

java.lang.String name

cacheListeners

java.util.List cacheListeners
Constructor Detail

PeerCache

public PeerCache(AutoMedPeer myPeer)
Method Detail

initialiseCache

public void initialiseCache()
                     throws UnsuccessfulReplyException,
                            java.io.IOException,
                            AutoMedException
Throws:
UnsuccessfulReplyException
java.io.IOException
AutoMedException

addListener

public void addListener(CacheListener listener)
Add a listener to the cache

Specified by:
addListener in interface Cacheable

remove

public void remove()
Specified by:
remove in interface java.util.Iterator

next

public java.lang.Object next()
Specified by:
next in interface java.util.Iterator

hasNext

public boolean hasNext()
Specified by:
hasNext in interface java.util.Iterator

notifyListeners

public void notifyListeners(Cacheable cacheObj)
Notify listeners to handle a specific event

Specified by:
notifyListeners in interface Cacheable
Parameters:
cacheObj - the Cacheable object to be used by listener to handle event

clear

public void clear()
Clear the cache

Specified by:
clear in interface Cacheable

refresh

public void refresh()
Refresh cache content

Specified by:
refresh in interface Cacheable

getContentObject

public CacheContentDescription getContentObject()
Get the actual content object

Specified by:
getContentObject in interface Cacheable

refreshPeersOf

public java.util.HashSet refreshPeersOf(SchemaDescription schema)
                                 throws UnsuccessfulReplyException,
                                        java.io.IOException,
                                        AutoMedException
Throws:
UnsuccessfulReplyException
java.io.IOException
AutoMedException

refreshPublicSchemas

public java.util.HashSet refreshPublicSchemas()
                                       throws UnsuccessfulReplyException,
                                              java.io.IOException,
                                              AutoMedException
Throws:
UnsuccessfulReplyException
java.io.IOException
AutoMedException

refreshMySchemas

public void refreshMySchemas()
                      throws UnsuccessfulReplyException,
                             java.io.IOException,
                             AutoMedException
Throws:
UnsuccessfulReplyException
java.io.IOException
AutoMedException

getPeerDescriptions

public java.util.HashSet getPeerDescriptions(SchemaDescription schema)
Return a Map of PeerDescriptions for a given SchemaDescription.


isSchemaInfoCached

public boolean isSchemaInfoCached(java.lang.String schema)

getPublicSchemas

public java.util.Set getPublicSchemas()
Return a Set containing SchemaDescriptions


setPublicSchemas

public void setPublicSchemas(java.util.List schemas)
Assign a list of public schemas (i.e. SchemaDescriptions) to cache


getMySchemas

public java.util.Set getMySchemas()

notifyListeners

private void notifyListeners()

toString

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