uk.ac.ic.doc.automed.p2p.protocol
Class SICP

java.lang.Object
  extended by uk.ac.ic.doc.automed.p2p.protocol.SICP

public class SICP
extends java.lang.Object

SICP.java

Schema Information Control Protocol: provides standard interface functions for publishing/obtaining information regarding resources on the P2P network.

Author:
Duc M Le dmle@doc.ic.ac.uk
Created on April 10, 2006
Department of Computing, Imperial College

Field Summary
private static DirectoryServicePeer _dsp
           
private static SICP _instance
           
private static AutoMedPeer _mainPeer
           
private static MessagingService _msgService
           
 
Constructor Summary
private SICP(AutoMedPeer mainPeer)
          Creates a new instance of SICP
 
Method Summary
 void advertiseKeywords(java.lang.String schema, java.util.Map dict)
          Peer->DSP: advertise the keywords to the DSP to be stored there
 void advertisePathway(java.lang.String schemaName)
          Peer->DSP: advertise pathway to a schema to the DSP
private  void advertisePathwayAbstract(AbstractMessage request, ResponseHandler outputHandler)
          Peer->DS: advertise pathway abstraction/b> to the directory service for routing
 java.util.Map askDomainKeywords(java.lang.String schema)
          Peer->DSP: ask a dsp for the keyword map of this domain if schema is specified then return keywords for a specific schema otherwise return all keywords
private  void askPathwayToSourceAbstract(PeerDescription peerDesc, java.lang.String schemaName)
          DS->Peer: Directory service ask peer for pathways abstraction
 java.lang.String askPeerDescription(java.lang.String peerName, java.lang.String peerURL)
          Peer->DSP: ask for the description of a peer
 java.lang.String askPeerSchemaAssociation(java.lang.String schema)
          Peer -> DSP: similar to {#requestPeerSchemaAssociations(String peer, String schema)} Ask the dsp for a list of peer-to-schema associations but return the first one that is found
 java.util.Map askPeerSchemaAssociations(java.lang.String peer, java.lang.String schema)
          Peer -> DSP: Ask the dsp for a list of peer-to-schema associations.
 java.util.Collection askPeersImplementingSchema(java.lang.String schemaName, java.util.Collection excludePeers)
          Find all peers that implement a public schema which are not in a given set of peers (optional)
 java.util.Collection askRelatedKeywords(java.lang.String kw)
          Peer->DSP: ask a dsp for the related keywords of a keyword
 java.lang.String[] askSchemaList(java.lang.String schemaType, PeerProcessDescription peerDesc)
          Peer->Peer: Peer asks another peer for a schema list
 void askToWrapSchema(java.lang.String schema, PeerProcessDescription peerDesc)
          Peer->Peer: Peer asks another peer to wrap a schema from the directroy service
 void close()
           
private  void confirmAdvertiseKeywords(AbstractMessage request, ResponseHandler outputHandler)
          DSP->Peer: update the keywords and send confirmation to peer
private  void confirmAdvertisePathway(AbstractMessage request, ResponseHandler outputHandler)
          DSP->Peer: store the fact that a peer is implementing a public schema and, if successful, replies with a confirmation.
static SICP getInstance(AutoMedPeer mainPeer)
          Return a single instance of SICP protocol
 java.lang.String getLinkAddress()
          Return the IP address of the network interface which connects a peer to the network
private  java.lang.Object handleDomainEvent(DomainEvent de)
          Handle a domain event.
 boolean isLinkUp()
          Test whether or not the peer's link to the network is up
static void main(java.lang.String[] args)
           
private  void processPathwayAbstract(AbstractMessage advert, ResponseHandler outputHandler)
          DS<-Peer: Directory service process pathways advertised by a peer
 void publishSchema(java.lang.String schemaName, java.lang.String globalName, java.lang.String desc)
          This peer publish a public schema to the network
private  void registerDirectoryHandlers()
          DSP: Register message handlers on the directory server
private  void registerPeerHandlers()
          Peer: Register message handlers on the peer
private  void replyAbstractPathwayToSource(AbstractMessage request, ResponseHandler outputHandler)
          DSP->Peer: reply to requestAbstractPathwayToSource(String schemaName) by a peer
 java.util.List requestAbstractPathwayToSource(java.lang.String schemaName)
          Peer->DS: A peer invokes this method to request the directory service about possible pathways to data source for a public schema that the peer knows
private  void setPeerInstance(AutoMedPeer peer)
          Because we must maintain separate AutoMedPeer instances for normal peer and directory service, we must decide which instance to use at protocol initialisation time
private  void tellDomainKeywords(AbstractMessage request, ResponseHandler outputHandler)
          DSP->Peer: tells the peer about the keyword map of this domain
private  void tellPeerDescription(AbstractMessage request, ResponseHandler outputHandler)
          DSP->Peer: DSP notifies a peer of the description of that peer
private  void tellPeerSchemaAssociations(AbstractMessage request, ResponseHandler outputHandler)
          DSP->Peer: reply to requestPeerSchemaAssociations(String peer, String schema) by a peer
private  void tellRelatedKeywords(AbstractMessage request, ResponseHandler outputHandler)
          DSP->Peer: reply to peer with the collection of related keywords to a keyword
 Schema wrapSchema(java.lang.String schemaName, PeerDescription pd)
          Wrap a public schema from the network
 Schema wrapSchema(java.lang.String schemaName, java.lang.String newName, PeerDescription pd)
          Takes an additional parameter to allow caller to specified a new schema name
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_instance

private static SICP _instance

_mainPeer

private static AutoMedPeer _mainPeer

_dsp

private static DirectoryServicePeer _dsp

_msgService

private static MessagingService _msgService
Constructor Detail

SICP

private SICP(AutoMedPeer mainPeer)
Creates a new instance of SICP

Method Detail

getInstance

public static SICP getInstance(AutoMedPeer mainPeer)
Return a single instance of SICP protocol


setPeerInstance

private void setPeerInstance(AutoMedPeer peer)
Because we must maintain separate AutoMedPeer instances for normal peer and directory service, we must decide which instance to use at protocol initialisation time


askSchemaList

public java.lang.String[] askSchemaList(java.lang.String schemaType,
                                        PeerProcessDescription peerDesc)
                                 throws CommunicationException,
                                        AutoMedException
Peer->Peer: Peer asks another peer for a schema list

Throws:
CommunicationException
AutoMedException

publishSchema

public void publishSchema(java.lang.String schemaName,
                          java.lang.String globalName,
                          java.lang.String desc)
                   throws AutoMedException
This peer publish a public schema to the network

Throws:
AutoMedException

advertiseKeywords

public void advertiseKeywords(java.lang.String schema,
                              java.util.Map dict)
                       throws AutoMedException
Peer->DSP: advertise the keywords to the DSP to be stored there

Parameters:
keywords -
Throws:
AutoMedException

confirmAdvertiseKeywords

private void confirmAdvertiseKeywords(AbstractMessage request,
                                      ResponseHandler outputHandler)
                               throws CommunicationException
DSP->Peer: update the keywords and send confirmation to peer

Parameters:
request -
outputHandler -
Throws:
CommunicationException

askRelatedKeywords

public java.util.Collection askRelatedKeywords(java.lang.String kw)
                                        throws AutoMedException
Peer->DSP: ask a dsp for the related keywords of a keyword

Parameters:
schema -
kw -
Returns:
Throws:
AutoMedException

tellRelatedKeywords

private void tellRelatedKeywords(AbstractMessage request,
                                 ResponseHandler outputHandler)
                          throws CommunicationException
DSP->Peer: reply to peer with the collection of related keywords to a keyword

Parameters:
schema -
kw -
Throws:
AutoMedException
CommunicationException

askDomainKeywords

public java.util.Map askDomainKeywords(java.lang.String schema)
                                throws AutoMedException
Peer->DSP: ask a dsp for the keyword map of this domain if schema is specified then return keywords for a specific schema otherwise return all keywords

Returns:
Throws:
AutoMedException

tellDomainKeywords

private void tellDomainKeywords(AbstractMessage request,
                                ResponseHandler outputHandler)
                         throws CommunicationException
DSP->Peer: tells the peer about the keyword map of this domain

Parameters:
request -
outputHandler -
Throws:
CommunicationException

askToWrapSchema

public void askToWrapSchema(java.lang.String schema,
                            PeerProcessDescription peerDesc)
                     throws CommunicationException,
                            AutoMedException
Peer->Peer: Peer asks another peer to wrap a schema from the directroy service

Throws:
CommunicationException
AutoMedException

askPeerDescription

public java.lang.String askPeerDescription(java.lang.String peerName,
                                           java.lang.String peerURL)
                                    throws AutoMedException
Peer->DSP: ask for the description of a peer

Returns:
Throws:
AutoMedException

tellPeerDescription

private void tellPeerDescription(AbstractMessage request,
                                 ResponseHandler outputHandler)
                          throws CommunicationException
DSP->Peer: DSP notifies a peer of the description of that peer

Parameters:
request -
outputHandler -
Throws:
AutoMedException
CommunicationException

wrapSchema

public Schema wrapSchema(java.lang.String schemaName,
                         PeerDescription pd)
                  throws CommunicationException,
                         AutoMedException
Wrap a public schema from the network

Parameters:
schemaName - the public schema name
pd - a PeerDescription object that encapsulates the current peer information for use by the wrapper
Returns:
Throws:
CommunicationException
AutoMedException

wrapSchema

public Schema wrapSchema(java.lang.String schemaName,
                         java.lang.String newName,
                         PeerDescription pd)
                  throws CommunicationException,
                         AutoMedException
Takes an additional parameter to allow caller to specified a new schema name

Parameters:
schemaName -
newName -
pd -
Returns:
Throws:
CommunicationException
AutoMedException

askPathwayToSourceAbstract

private void askPathwayToSourceAbstract(PeerDescription peerDesc,
                                        java.lang.String schemaName)
                                 throws CommunicationException,
                                        AutoMedException
DS->Peer: Directory service ask peer for pathways abstraction

Parameters:
peerDesc - a PeerDescription object that was created with address, name and port
schemaName - the schema whose data sources we wish to obtain pathways from
Throws:
CommunicationException
AutoMedException

requestAbstractPathwayToSource

public java.util.List requestAbstractPathwayToSource(java.lang.String schemaName)
                                              throws CommunicationException,
                                                     AutoMedException
Peer->DS: A peer invokes this method to request the directory service about possible pathways to data source for a public schema that the peer knows

Returns:
List a list of PathwayDescripition objects
Throws:
CommunicationException
AutoMedException

replyAbstractPathwayToSource

private void replyAbstractPathwayToSource(AbstractMessage request,
                                          ResponseHandler outputHandler)
                                   throws CommunicationException
DSP->Peer: reply to requestAbstractPathwayToSource(String schemaName) by a peer

Throws:
CommunicationException

advertisePathway

public void advertisePathway(java.lang.String schemaName)
                      throws AutoMedException
Peer->DSP: advertise pathway to a schema to the DSP

Parameters:
schemaName -
Throws:
AutoMedException

confirmAdvertisePathway

private void confirmAdvertisePathway(AbstractMessage request,
                                     ResponseHandler outputHandler)
                              throws CommunicationException
DSP->Peer: store the fact that a peer is implementing a public schema and, if successful, replies with a confirmation.

Parameters:
request -
outputHandler -
Throws:
CommunicationException

advertisePathwayAbstract

private void advertisePathwayAbstract(AbstractMessage request,
                                      ResponseHandler outputHandler)
                               throws CommunicationException
Peer->DS: advertise pathway abstraction/b> to the directory service for routing

Throws:
CommunicationException

processPathwayAbstract

private void processPathwayAbstract(AbstractMessage advert,
                                    ResponseHandler outputHandler)
                             throws CommunicationException
DS<-Peer: Directory service process pathways advertised by a peer

Throws:
CommunicationException

askPeerSchemaAssociations

public java.util.Map askPeerSchemaAssociations(java.lang.String peer,
                                               java.lang.String schema)
                                        throws CommunicationException,
                                               AutoMedException
Peer -> DSP: Ask the dsp for a list of peer-to-schema associations. Specify a wild-cart "*" for both peer and schema to get all assocations.

Parameters:
peer - name of the peer (use wild cart '*' for any)
schema - name of the schema (use wild cart '*' for any)
Returns:
Map a hash map PeerDescription -> String<schemaname>
Throws:
CommunicationException
AutoMedException

askPeersImplementingSchema

public java.util.Collection askPeersImplementingSchema(java.lang.String schemaName,
                                                       java.util.Collection excludePeers)
                                                throws CommunicationException,
                                                       AutoMedException
Find all peers that implement a public schema which are not in a given set of peers (optional)

Parameters:
schemaName -
excludePeers - a collection of peer names to exclude
Returns:
Throws:
CommunicationException
AutoMedException

askPeerSchemaAssociation

public java.lang.String askPeerSchemaAssociation(java.lang.String schema)
                                          throws CommunicationException,
                                                 AutoMedException
Peer -> DSP: similar to {#requestPeerSchemaAssociations(String peer, String schema)} Ask the dsp for a list of peer-to-schema associations but return the first one that is found

Parameters:
schema -
Returns:
Throws:
CommunicationException
AutoMedException

tellPeerSchemaAssociations

private void tellPeerSchemaAssociations(AbstractMessage request,
                                        ResponseHandler outputHandler)
                                 throws CommunicationException
DSP->Peer: reply to requestPeerSchemaAssociations(String peer, String schema) by a peer

Throws:
CommunicationException

isLinkUp

public boolean isLinkUp()
Test whether or not the peer's link to the network is up


getLinkAddress

public java.lang.String getLinkAddress()
Return the IP address of the network interface which connects a peer to the network


handleDomainEvent

private java.lang.Object handleDomainEvent(DomainEvent de)
                                    throws AutoMedException
Handle a domain event. In most cases, this means the current DSP asking one or more other domains DSPs for information

Throws:
AutoMedException

registerDirectoryHandlers

private void registerDirectoryHandlers()
DSP: Register message handlers on the directory server


registerPeerHandlers

private void registerPeerHandlers()
Peer: Register message handlers on the peer


close

public void close()

main

public static void main(java.lang.String[] args)