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

java.lang.Object
  extended by uk.ac.ic.doc.automed.p2p.communication.AbstractRequestListener
      extended by uk.ac.ic.doc.automed.p2p.AutoMedPeer
All Implemented Interfaces:
RequestListener, StateChangedListener

public class AutoMedPeer
extends AbstractRequestListener
implements StateChangedListener

Represent the AutoMed Repository in this Java Virtual Machine (JVM) as a peer on a peer-to-peer (P2P) network. Thus there should never be more than one instance of this class in any JVM. For this to function correctly, there must be a P2PRegistry running on the local machine, and a directory.P2PDirectory running on some host accesible by this peer.


Method Summary
 void close()
          Close down the peer and its message handler, allowing another instance of this class to be created.
 boolean connected()
          Determine if the current JVM is a peer on the P2P.
static AutoMedPeer getAutoMedPeer()
          Return the AutoMedPeer that represents the repository in the JVM on the P2P network.
 PeerCache getCache()
          Return the PeerCache that this AutoMedPeer keeps, containing data fetched form the P2PDirectory of other peers and public schemas.
 int getLocalPort()
          public boolean isRegistered() { return this.registered; }
 MessageHandler getMessageHandler()
           
 java.lang.String getName()
           
 java.lang.String getPeerAddress()
          Added by dmle 27/10/2005 to get a peer's IP address
 PeerApplication getPeerApplication()
          Return the reference to the actual PeerApplication
 java.lang.String getPeerHost()
          Added by dmle 27/10/2005 to get a peer's host name
 int getPeerState()
          Return the current state of the peer as managed by PeerStateHandler
static QueryCache getQueryCache()
          Get query cache object
 java.io.InputStream getReplyForRequest(uk.ac.ic.doc.automed.p2p.messages.abstractlayer.AbstractMessage request, java.net.InetAddress address, int port)
           
 void handleRequest(uk.ac.ic.doc.automed.p2p.messages.abstractlayer.AbstractMessage message, java.io.OutputStream output)
          Handle TCP-type requests
 void initMessagingPeer()
          Start the messaging clients in the background
static AutoMedPeer newAutoMedPeer(java.lang.String name, PeerApplication peerApp, PeerStateHandler stateHandler)
          Create a new AutoMedPeer if one does not already exist.
 void outputPathway(uk.ac.ic.doc.automed.p2p.messages.abstractlayer.AbstractMessage message, java.io.OutputStream os)
           
 void outputPathwayToSource(uk.ac.ic.doc.automed.p2p.messages.abstractlayer.AbstractMessage request, java.io.OutputStream output)
          Deprecated. use outputSourcePathways(AbstractMessage request, OutputStream output)
to get multiple pathways
 void outputQuery(uk.ac.ic.doc.automed.p2p.messages.abstractlayer.AbstractMessage request, java.io.OutputStream output)
           
 void outputSchema(uk.ac.ic.doc.automed.p2p.messages.abstractlayer.AbstractMessage request, java.io.OutputStream output)
           
 void outputSourcePathways(uk.ac.ic.doc.automed.p2p.messages.abstractlayer.AbstractMessage request, java.io.OutputStream output)
          Output all possible pathways to all data sources attached to a given
public schema dmle 9/11/2005
 void performStateAction(int newState)
          Implements interface PeerStateListener
 void register()
           
 java.io.InputStream requestPathToSource(java.lang.String host, java.lang.String peerName, java.lang.String schemaName)
           
 java.io.InputStream requestPathway(java.lang.String host, java.lang.String peerName, java.lang.String fromSchema, java.lang.String toSchema)
           
 java.io.InputStream requestQuery(java.lang.String host, java.lang.String peerName, java.lang.String schema, java.lang.String query)
           
 java.io.InputStream requestSchema(java.lang.String host, java.lang.String peerName, java.lang.String schemaName)
           
 java.io.InputStream sendRequest(java.lang.String host, java.lang.String peerName, uk.ac.ic.doc.automed.p2p.messages.abstractlayer.AbstractMessage message)
           
 void setName(java.lang.String name)
          Set a new name for peer
 void unregister()
          Notify directory server that this peer is logged out
 
Methods inherited from class uk.ac.ic.doc.automed.p2p.communication.AbstractRequestListener
handleRequest, handleUDPRequest, handleUDPRequest, handleUDPRequest
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

close

public void close()
Close down the peer and its message handler, allowing another instance of this class to be created.


unregister

public void unregister()
Notify directory server that this peer is logged out


newAutoMedPeer

public static AutoMedPeer newAutoMedPeer(java.lang.String name,
                                         PeerApplication peerApp,
                                         PeerStateHandler stateHandler)
                                  throws P2PException,
                                         java.io.IOException,
                                         AutoMedException
Create a new AutoMedPeer if one does not already exist.

Returns:
An AutoMedPeer with the given name
Throws:
P2PException - if an AutoMedPeer already exists for this JVM
java.io.IOException - if unable to connect the P2PRegistry
AutoMedException

getAutoMedPeer

public static AutoMedPeer getAutoMedPeer()
Return the AutoMedPeer that represents the repository in the JVM on the P2P network.


connected

public boolean connected()
Determine if the current JVM is a peer on the P2P.

Returns:
true if connected, false if login needs to be performed

getMessageHandler

public MessageHandler getMessageHandler()

getPeerState

public int getPeerState()
Return the current state of the peer as managed by PeerStateHandler


getPeerApplication

public PeerApplication getPeerApplication()
Return the reference to the actual PeerApplication


initMessagingPeer

public void initMessagingPeer()
Start the messaging clients in the background


setName

public void setName(java.lang.String name)
Set a new name for peer

Parameters:
name - the new peer name

sendRequest

public java.io.InputStream sendRequest(java.lang.String host,
                                       java.lang.String peerName,
                                       uk.ac.ic.doc.automed.p2p.messages.abstractlayer.AbstractMessage message)
                                throws java.io.IOException,
                                       CommunicationException
Throws:
java.io.IOException
CommunicationException

requestSchema

public java.io.InputStream requestSchema(java.lang.String host,
                                         java.lang.String peerName,
                                         java.lang.String schemaName)
                                  throws java.io.IOException,
                                         CommunicationException
Throws:
java.io.IOException
CommunicationException

requestPathToSource

public java.io.InputStream requestPathToSource(java.lang.String host,
                                               java.lang.String peerName,
                                               java.lang.String schemaName)
                                        throws java.io.IOException,
                                               CommunicationException
Throws:
java.io.IOException
CommunicationException

requestQuery

public java.io.InputStream requestQuery(java.lang.String host,
                                        java.lang.String peerName,
                                        java.lang.String schema,
                                        java.lang.String query)
                                 throws java.io.IOException,
                                        CommunicationException
Throws:
java.io.IOException
CommunicationException

requestPathway

public java.io.InputStream requestPathway(java.lang.String host,
                                          java.lang.String peerName,
                                          java.lang.String fromSchema,
                                          java.lang.String toSchema)
                                   throws java.io.IOException,
                                          CommunicationException
Throws:
java.io.IOException
CommunicationException

getReplyForRequest

public java.io.InputStream getReplyForRequest(uk.ac.ic.doc.automed.p2p.messages.abstractlayer.AbstractMessage request,
                                              java.net.InetAddress address,
                                              int port)
                                       throws java.io.IOException
Throws:
java.io.IOException

register

public void register()
              throws java.io.IOException
Throws:
java.io.IOException

handleRequest

public void handleRequest(uk.ac.ic.doc.automed.p2p.messages.abstractlayer.AbstractMessage message,
                          java.io.OutputStream output)
                   throws java.io.IOException
Description copied from class: AbstractRequestListener
Handle TCP-type requests

Specified by:
handleRequest in interface RequestListener
Overrides:
handleRequest in class AbstractRequestListener
Throws:
java.io.IOException

outputPathway

public void outputPathway(uk.ac.ic.doc.automed.p2p.messages.abstractlayer.AbstractMessage message,
                          java.io.OutputStream os)
                   throws java.io.IOException
Throws:
java.io.IOException

outputSchema

public void outputSchema(uk.ac.ic.doc.automed.p2p.messages.abstractlayer.AbstractMessage request,
                         java.io.OutputStream output)
                  throws java.io.IOException
Throws:
java.io.IOException

outputSourcePathways

public void outputSourcePathways(uk.ac.ic.doc.automed.p2p.messages.abstractlayer.AbstractMessage request,
                                 java.io.OutputStream output)
                          throws java.io.IOException
Output all possible pathways to all data sources attached to a given
public schema dmle 9/11/2005

Throws:
java.io.IOException

outputPathwayToSource

public void outputPathwayToSource(uk.ac.ic.doc.automed.p2p.messages.abstractlayer.AbstractMessage request,
                                  java.io.OutputStream output)
                           throws java.io.IOException
Deprecated. use outputSourcePathways(AbstractMessage request, OutputStream output)
to get multiple pathways

Throws:
java.io.IOException

outputQuery

public void outputQuery(uk.ac.ic.doc.automed.p2p.messages.abstractlayer.AbstractMessage request,
                        java.io.OutputStream output)
                 throws java.io.IOException
Throws:
java.io.IOException

getName

public java.lang.String getName()

getLocalPort

public int getLocalPort()
public boolean isRegistered() { return this.registered; }


getCache

public PeerCache getCache()
Return the PeerCache that this AutoMedPeer keeps, containing data fetched form the P2PDirectory of other peers and public schemas.


getPeerAddress

public java.lang.String getPeerAddress()
Added by dmle 27/10/2005 to get a peer's IP address

Returns:
String the peer's IP address

getPeerHost

public java.lang.String getPeerHost()
Added by dmle 27/10/2005 to get a peer's host name

Returns:
String the peer's host name

getQueryCache

public static QueryCache getQueryCache()
Get query cache object


performStateAction

public void performStateAction(int newState)
Implements interface PeerStateListener

Specified by:
performStateAction in interface StateChangedListener