AutoMedPeer
Keywords: uk.ac.ic.doc.automed.p2p.AutoMedPeer class

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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

    java.lang.Object
      uk.ac.ic.doc.automed.p2p.communication.AbstractRequestListener
          uk.ac.ic.doc.automed.p2p.AutoMedPeer

All Implemented Interfaces:
  RequestListener, StateChangedListener

Direct Known Subclasses:
  Peer

    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. 4/2006: AutoMedPeer has been designed to act as both a peer and a directory service peer

Author:
  Charis, Duc M Le

Nested Class Summary
`static class` | `AutoMedPeer.PeerProcessDescription`

Field Summary
`protected AppToolKit.NodeConfig` | `config`
`protected java.net.InetAddress` | `peerAddress`
`protected int` | `role`
`static int` | `ROLE_AUTOMED_PEER`
`static int` | `ROLE_DSP`
`static int` | `ROLE_PEER`
`protected static AutoMedPeer` | `thePeer`

Constructor Summary
`protected` | `AutoMedPeer(java.lang.String name, PeerStateHandler stateHandler)` Create the one `AutoMedPeer` that is allowed in any JVM: to prevent more than one being created, this is a private method, and you must call `#newAutoMedPeer()` to create the peer.

Method Summary
`void` | `addRequestListener(RequestListener listener)` Register a `RequestListener` object for client requests
`void` | `authenticate()` Authenticate using the authentication helper
`void` | `close()` Close down the peer and its message handler, allowing another instance of this class to be created.
`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` | `getDaemonPort()` public boolean isRegistered() { return this.registered; }
`P2PDirectory` | `getDirectory()` Return directory service object
`MessageHandler` | `getMessageHandler()`
`AutoMedMessagingHelper` | `getMessagingHelper()` Return reference to the `AutoMedMessagingHelper` object
`java.lang.String` | `getName()`
`java.lang.String` | `getPeerAddress()` Added by dmle 27/10/2005 to get a peer's IP address
`AppToolKit.NodeConfig` | `getPeerConfig()` Return the configuration of the peer
`java.lang.String` | `getPeerHost()` Added by dmle 27/10/2005 to get a peer's host name
`int` | `getPeerPort(AutoMedPeer.PeerProcessDescription peerProcess, boolean useCache)`
`int` | `getPeerState()` Return the current state of the peer as managed by `PeerStateHandler`
`IQueryAggregator` | `getQueryAggregator()` Return an instance of `IQueryAggregator`
`IQueryMediator` | `getQueryMediator()` Return query mediator instance
`AbstractMessage` | `getReplyForRequest(AbstractMessage request, java.lang.String address, int port)`
`int` | `getRole()` Return this peer's role
`PeerStateHandler` | `getStateHandler()` Return reference to state handler
`byte[]` | `handleRequest(byte[] dataReceived, ResponseHandler output)` Implements the method for handling network requests from other peers.
`void` | `initAuthentication()` Initialise the authentication module
`P2PDirectory` | `initDirectory()` This special method offers the flexibility of starting a `P2PDirectory` object for and 'attaching' it to a peer.
`void` | `initDirectoryRepository()` This method allows a peer to indirectly re-initialises the directory repository used by the peer's `P2PDirectory` instance
`void` | `initMessagingPeer()` Start the messaging clients in the background
`P2PRegistry` | `initRegistry()` This special method offers the flexibility of starting a `P2PRegistry` object for and 'attaching' it to a peer.
`static void` | `initRepository()` Initialise the `AutoMedPeer` repository based on the default configuration file loaded at a previous stage
`boolean` | `isJoinedNetwork()`
`static AutoMedPeer` | `newAutoMedPeer(java.lang.String name, PeerStateHandler stateHandler)` Create a new `AutoMedPeer` if one does not already exist.
`void` | `outputPathway(AbstractMessage message, ResponseHandler output)`
`void` | `outputPathwayToSource(AbstractMessage request, ResponseHandler output)` Deprecated. use `#outputSourcePathways(AbstractMessage request, OutputStream output)` to get multiple pathways
`void` | `outputQuery(AbstractMessage request, ResponseHandler output)` Use `QEP` protocol to execute the query
`void` | `outputSchema(AbstractMessage request, ResponseHandler output)`
`void` | `outputSourcePathways(AbstractMessage request, ResponseHandler output)` Output all possible pathways to all data sources attached to a given public schema
`void` | `performStateAction(int newState)` Implements interface `PeerStateListener`
`void` | `register()`
`AbstractMessage` | `requestPathToSource(java.lang.String host, java.lang.String peerName, java.lang.String schemaName)`
`AbstractMessage` | `requestPathway(java.lang.String host, java.lang.String peerName, java.lang.String fromSchema, java.lang.String toSchema)`
`AbstractMessage` | `requestQuery(java.lang.String host, java.lang.String peerName, java.lang.String schema, java.lang.String query)`
`AbstractMessage` | `requestSchema(java.lang.String host, java.lang.String peerName, java.lang.String schemaName)`
`AbstractMessage` | `sendRequest(java.lang.String host, java.lang.String peerName, AbstractMessage message)`
`void` | `setName(java.lang.String name)` Set a new name for peer
`void` | `setPeerAddress(java.net.InetAddress address)`
`void` | `setPeerState(int newState)` Return reference to `PeerStateHandler` object
`void` | `unregister()` Notify directory server that this peer is logged out

Methods inherited from class uk.ac.ic.doc.automed.p2p.communication.AbstractRequestListener
`getRequestMessage, getResponseData, getType, handleRequest, handleRequest, handleRequest, handleUDPRequest, handleUDPRequest, handleUDPRequest`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### thePeer

    protected static AutoMedPeer thePeer

### peerAddress

    protected java.net.InetAddress peerAddress

### config

    protected AppToolKit.NodeConfig config

### role

    protected int role

### ROLE_AUTOMED_PEER

    public static final int ROLE_AUTOMED_PEER

See Also:
  Constant Field Values

### ROLE_DSP

    public static final int ROLE_DSP

See Also:
  Constant Field Values

### ROLE_PEER

    public static final int ROLE_PEER

See Also:
  Constant Field Values

Constructor Detail

### AutoMedPeer

    protected AutoMedPeer(java.lang.String name,
                          PeerStateHandler stateHandler)
                   throws StateChangedException,
                          AutoMedException

  Create the one `AutoMedPeer` that is allowed in any JVM: to prevent more than one being created, this is a private method, and you must call `#newAutoMedPeer()` to create the peer.

  Throws:
    `StateChangedException`
    `AutoMedException`

Method Detail

### addRequestListener

    public void addRequestListener(RequestListener listener)

  Register a `RequestListener` object for client requests

### initRegistry

    public P2PRegistry initRegistry()
                             throws AutoMedException

  This special method offers the flexibility of starting a `P2PRegistry`
  object for and 'attaching' it to a peer. This method is particularly used in single-peer-per-local-network setup
  in which one registry serves only one `AutoMedPeer` instance

  Throws:
    `AutoMedException`

### initDirectory

    public P2PDirectory initDirectory()
                               throws AutoMedException

  This special method offers the flexibility of starting a `P2PDirectory`
  object for and 'attaching' it to a peer. This method is particularly used in single-peer-per-local-network setup
  in which one registry serves only one `AutoMedPeer` instance

  Throws:
    `AutoMedException`

### getDirectory

    public P2PDirectory getDirectory()

  Return directory service object

### initDirectoryRepository

    public void initDirectoryRepository()
                                 throws AutoMedException

  This method allows a peer to indirectly re-initialises the directory repository
  used by the peer's `P2PDirectory` instance

  Throws:
    `AutoMedException`

### initAuthentication

    public void initAuthentication()
                            throws AutoMedException

  Initialise the authentication module

  Throws:
    `AutoMedException`

### initRepository

    public static void initRepository()
                               throws AutoMedException

  Initialise the `AutoMedPeer` repository based on the default configuration file
  loaded at a previous stage

  Throws:
    `AutoMedException`

### authenticate

    public void authenticate()
                      throws AuthenticationException

  Authenticate using the authentication helper

  Throws:
    `AuthenticationException`

### 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,
                                             PeerStateHandler stateHandler)
                                      throws P2PException,
                                             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.

### getMessageHandler

    public MessageHandler getMessageHandler()

### getMessagingHelper

    public AutoMedMessagingHelper getMessagingHelper()

  Return reference to the `AutoMedMessagingHelper` object

### setPeerState

    public void setPeerState(int newState)
                      throws StateChangedException

  Return reference to `PeerStateHandler` object

  Throws:
    `StateChangedException`

### getPeerState

    public int getPeerState()

  Return the current state of the peer as managed by `PeerStateHandler`

### getStateHandler

    public PeerStateHandler getStateHandler()

  Return reference to state handler

### getPeerConfig

    public AppToolKit.NodeConfig getPeerConfig()

  Return the configuration of the peer

### initMessagingPeer

    public void initMessagingPeer()
                           throws AutoMedException

  Start the messaging clients in the background

  Throws:
    `AutoMedException`

### setName

    public void setName(java.lang.String name)

  Set a new name for peer

  Parameters:
    `name` - the new peer name

### sendRequest

    public AbstractMessage sendRequest(java.lang.String host,
                                       java.lang.String peerName,
                                       AbstractMessage message)
                                throws AutoMedException

  Parameters:
    `host` -
    `peerName` -
    `message` -
  Returns:
  Throws:
    `java.io.IOException`
    `CommunicationException`
    `AutoMedException`

### requestSchema

    public AbstractMessage requestSchema(java.lang.String host,
                                         java.lang.String peerName,
                                         java.lang.String schemaName)
                                  throws AutoMedException

  Throws:
    `AutoMedException`

### requestPathToSource

    public AbstractMessage requestPathToSource(java.lang.String host,
                                               java.lang.String peerName,
                                               java.lang.String schemaName)
                                        throws AutoMedException

  Throws:
    `AutoMedException`

### requestQuery

    public AbstractMessage requestQuery(java.lang.String host,
                                        java.lang.String peerName,
                                        java.lang.String schema,
                                        java.lang.String query)
                                 throws AutoMedException

  Throws:
    `AutoMedException`

### requestPathway

    public AbstractMessage requestPathway(java.lang.String host,
                                          java.lang.String peerName,
                                          java.lang.String fromSchema,
                                          java.lang.String toSchema)
                                   throws AutoMedException

  Throws:
    `AutoMedException`

### getReplyForRequest

    public AbstractMessage getReplyForRequest(AbstractMessage request,
                                              java.lang.String address,
                                              int port)
                                       throws AutoMedException

  Throws:
    `AutoMedException`

### getPeerPort

    public int getPeerPort(AutoMedPeer.PeerProcessDescription peerProcess,
                           boolean useCache)
                    throws AutoMedException

  Throws:
    `AutoMedException`

### register

    public void register()
                  throws AutoMedException

  Throws:
    `AutoMedException`

### handleRequest

    public byte[] handleRequest(byte[] dataReceived,
                                ResponseHandler output)
                         throws CommunicationException

  Implements the method for handling network requests from other peers.
  This method was inherited from `AbstractRequestListener` abstract class.

  This handler is for server functions.

  Specified by:
    `handleRequest` in interface `RequestListener`
  Overrides:
    `handleRequest` in class `AbstractRequestListener`
  Throws:
    `CommunicationException`

### outputPathway

    public void outputPathway(AbstractMessage message,
                              ResponseHandler output)
                       throws CommunicationException

  Throws:
    `CommunicationException`

### outputSchema

    public void outputSchema(AbstractMessage request,
                             ResponseHandler output)
                      throws CommunicationException

  Throws:
    `CommunicationException`

### outputSourcePathways

    public void outputSourcePathways(AbstractMessage request,
                                     ResponseHandler output)
                              throws CommunicationException

  Output all possible pathways to all data sources attached to a given
  public schema

  Throws:
    `CommunicationException`

### outputPathwayToSource

    public void outputPathwayToSource(AbstractMessage request,
                                      ResponseHandler output)
                               throws CommunicationException

  Deprecated. use `#outputSourcePathways(AbstractMessage request, OutputStream output)`
  to get multiple pathways

  Throws:
    `CommunicationException`

### outputQuery

    public void outputQuery(AbstractMessage request,
                            ResponseHandler output)
                     throws CommunicationException

  Use `QEP` protocol to execute the query

  Throws:
    `CommunicationException`

### getName

    public java.lang.String getName()

### getRole

    public int getRole()

  Return this peer's role

### getQueryMediator

    public IQueryMediator getQueryMediator()

  Return query mediator instance

### getQueryAggregator

    public IQueryAggregator getQueryAggregator()

  Return an instance of `IQueryAggregator`

### getDaemonPort

    public int getDaemonPort()

  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.

### setPeerAddress

    public void setPeerAddress(java.net.InetAddress address)

### 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

### isJoinedNetwork

    public boolean isJoinedNetwork()

### performStateAction

    public void performStateAction(int newState)

  Implements interface `PeerStateListener`

  Specified by:
    `performStateAction` in interface `StateChangedListener`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD