context.arch.discoverer
Class DiscovererMediator

java.lang.Object
  extended bycontext.arch.discoverer.DiscovererMediator

public class DiscovererMediator
extends java.lang.Object

This mediator allows to handle the dialog between the discoverer and the DiscovererDataModel, the LeasesKeeper. It is able to store components into the database, to update and remove them. It handles queries and subscription queries. It asks the discoverer to check the components' liveliness

Author:
Agathe

Field Summary
 boolean useLogFile
          Boolean to keep a logfile
 
Constructor Summary
DiscovererMediator(Discoverer discoverer, boolean keepLogFile)
          Creates new DiscovererMediator
 
Method Summary
 Error add(ComponentDescription comp, Lease lease)
          This method allows to register a ComponentDescription object
 void addToLog(ComponentDescription comp)
          Adds a component description to the log file
 boolean exists(java.lang.Object stringOrInteger)
          Return true if the component is registered by the discoverer
 ComponentDescription getComponentDescription(java.lang.Object stringOrInteger)
          Returns the ComponentDescription of a registered component
 void handleIndependentReply(IndependentCommunication independentCommunication)
          Overrides the method that handle independent Reply.
 java.lang.Object rawSearch(AbstractQueryItem query)
          Gets an AbstractQueryObject and returns a array with for each index of registered components a value yes/no to indicate if this component fits the query or not TO DO : complete the search to remove the widget included in server: USEFUL??
 Error remove(java.lang.Object stringOrInteger)
          Removes a component from the discoverer base
 void removeFromLog(ComponentDescription comp)
          Adds the information that a component is removed from the database into the log file
 void removeFromLog(java.lang.String header, ComponentDescription comp)
          Adds the remove information into the log file
 DataObject search(AbstractQueryItem query)
          Take a query and returns the corresponding components
 void sendLeaseEndNotificationTo(java.util.ArrayList listOfComponents)
          This method allows to send a lease end notification to each component whose lease ends.
 java.lang.String toString()
          Returns a printable version of this object: the database content, the leases.
 Error update(ComponentDescription component, Lease lease)
          Update the description of a component and its lease
 Error updateLease(java.lang.Object stringOrInteger, Lease lease)
          Update a registered component lease
 Error updateLease(java.lang.String compId, Lease lease)
          Updates a lease for a registered component
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

useLogFile

public boolean useLogFile
Boolean to keep a logfile

Constructor Detail

DiscovererMediator

public DiscovererMediator(Discoverer discoverer,
                          boolean keepLogFile)
Creates new DiscovererMediator

Parameters:
discoverer - The discoverer object
Method Detail

add

public Error add(ComponentDescription comp,
                 Lease lease)
This method allows to register a ComponentDescription object

Parameters:
comp - the ComponentDescription object
lease - The lease specified for this ComponentDescripion object
Returns:
Error

updateLease

public Error updateLease(java.lang.String compId,
                         Lease lease)
Updates a lease for a registered component

Parameters:
compId - The id of the component
lease - The new Lease object
Returns:
Error

search

public DataObject search(AbstractQueryItem query)
Take a query and returns the corresponding components

Parameters:
query - The abstractquery object
Returns:
DataObject Contains the component descriptions of the component matching the query

rawSearch

public java.lang.Object rawSearch(AbstractQueryItem query)
Gets an AbstractQueryObject and returns a array with for each index of registered components a value yes/no to indicate if this component fits the query or not TO DO : complete the search to remove the widget included in server: USEFUL??

Parameters:
query - The abstract query object
Returns:
Object An int[][] array

toString

public java.lang.String toString()
Returns a printable version of this object: the database content, the leases.

Returns:
String

remove

public Error remove(java.lang.Object stringOrInteger)
Removes a component from the discoverer base

Parameters:
stringOrInteger - The component's index or id
Returns:
Error

update

public Error update(ComponentDescription component,
                    Lease lease)
Update the description of a component and its lease

Parameters:
component - The component to update
lease - The new Lease
Returns:
Error

updateLease

public Error updateLease(java.lang.Object stringOrInteger,
                         Lease lease)
Update a registered component lease

Parameters:
stringOrInteger - The component id or index
lease - The new lease
Returns:
Error

getComponentDescription

public ComponentDescription getComponentDescription(java.lang.Object stringOrInteger)
Returns the ComponentDescription of a registered component

Returns:
ComponentDescription

sendLeaseEndNotificationTo

public void sendLeaseEndNotificationTo(java.util.ArrayList listOfComponents)
This method allows to send a lease end notification to each component whose lease ends. The reply received by the component either renews the lease or confirms it. The list of components is sent back to the discoverer that take care of sending a message to them


exists

public boolean exists(java.lang.Object stringOrInteger)
Return true if the component is registered by the discoverer

Parameters:
stringOrInteger - The component index or id
Returns:
boolean

addToLog

public void addToLog(ComponentDescription comp)
Adds a component description to the log file

Parameters:
comp - The component description

removeFromLog

public void removeFromLog(ComponentDescription comp)
Adds the information that a component is removed from the database into the log file

Parameters:
comp - The component description to remove

removeFromLog

public void removeFromLog(java.lang.String header,
                          ComponentDescription comp)
Adds the remove information into the log file

Parameters:
header - The header information
comp - The component description removed

handleIndependentReply

public void handleIndependentReply(IndependentCommunication independentCommunication)
Overrides the method that handle independent Reply. If the independent communication has been sent by this class, this class handles it. Otherwise the super class handleIndependeReply is called. Catches: - Discoverer+Registerer+Ping message TO DO: restore the lease?? not useful because the next time the discoverer will check the component, the component will send its lease