JXTA

net.jxta.impl.peer
Class PeerInfoServiceImpl

java.lang.Object
  extended by net.jxta.impl.peer.PeerInfoServiceImpl
All Implemented Interfaces:
PeerInfoService, Module, Service

public class PeerInfoServiceImpl
extends Object
implements PeerInfoService

Peer Info provides a mechanism to obtain information about peers.


Nested Class Summary
(package private)  class PeerInfoServiceImpl.PipQueryHandler
           
 
Field Summary
(package private) static Hashtable peerInfoServices
           
 
Fields inherited from interface net.jxta.platform.Module
START_AGAIN_PROGRESS, START_AGAIN_STALLED, START_DISABLED, START_OK
 
Constructor Summary
PeerInfoServiceImpl()
           
 
Method Summary
 long addMonitorListener(MonitorFilter monitorFilter, long reportRate, boolean includeCumulative, MonitorListener monitorListener)
          Get MonitorReports at a specified rates of metrics accrued over time from the ServiceMonitors (specified in the MonitorFilter) about the local Peer.
 void addRemoteMonitorListener(PeerID peerID, MonitorFilter monitorFilter, long reportRate, boolean includeCumulative, MonitorListener monitorListener, long lease, long timeout)
          Get MonitorReports at a specified rates of metrics accrued over time from the ServiceMonitors (specified in the MonitorFilter) about the specified remote Peer.
 long getBestReportRate(long desiredReportRate)
          Asynchronous reporting of Monitored data may be obtained only at rates supported by the MonitorManager on the peer.
 MonitorReport getCumulativeMonitorReport(MonitorFilter monitorFilter)
          Get a MonitorReport of total accumulated metrics from the ServiceMonitors (specified in the MonitorFilter) since they were created/reset for the local Peer.
 void getCumulativeMonitorReport(PeerID peerID, MonitorFilter monitorFilter, MonitorListener monitorListener, long timeout)
          Get a MonitorReport of total accumulated metrics from the ServiceMonitors (specified in the MonitorFilter) since they were created/reset for the specified remote Peer.
 PeerGroup getGroup()
          Returns the group to which this service is attached.
 Advertisement getImplAdvertisement()
          Returns the advertisement for this service.
 Service getInterface()
          Service objects are not manipulated directly to protect usage of the service.
(package private)  int getNextQueryId()
           
(package private)  PeerInfoHandler getPeerInfoHandler(String name)
           
 PeerMonitorInfo getPeerMonitorInfo()
          Obtain the monitoring capabilities of the Local Peer.
 void getPeerMonitorInfo(PeerID peerID, PeerMonitorInfoListener peerMonitorInfoListener, long timeout)
          Obtain the monitoring capabilities of a Remote Peer.
 long[] getSupportedReportRates()
          Asynchronous reporting of Monitored data may be obtained only at rates supported by the MonitorManager on the peer.
 void init(PeerGroup group, ID assignedID, Advertisement impl)
          Initialize the module, passing it its peer group and advertisement.
 boolean isLocalMonitoringAvailable()
          See if Local Monitoring is available on this Peer Local monitoring is only available if you are using a version of of jxta.jar that was build with metering activated.
 boolean isLocalMonitoringAvailable(ModuleClassID moduleClassID)
          See if Local monitoring is available from a specific ServiceMonitor.
 boolean isSupportedReportRate(long reportRate)
          Asynchronous reporting of Monitored data may be obtained only at rates supported by the MonitorManager on the peer.
 boolean removeMonitorListener(MonitorListener monitorListener)
          Stop the periodic reporting for all registered filters corresponding to this MonitorListener
 void removeRemoteMonitorListener(MonitorListener monitorListener, long timeout)
          Stop the periodic reporting for all registered filters to the all remote Peers corresponding to this MonitorListener.
 void removeRemoteMonitorListener(PeerID peerID, MonitorListener monitorListener, long timeout)
          Stop the periodic reporting for all registered filters to the specified Peer corresponding to this MonitorListener.
 int startApp(String[] arg)
          Complete any remaining initialization of the module.
 void stopApp()
          Stop a module.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

peerInfoServices

static Hashtable peerInfoServices
Constructor Detail

PeerInfoServiceImpl

public PeerInfoServiceImpl()
Method Detail

init

public void init(PeerGroup group,
                 ID assignedID,
                 Advertisement impl)
          throws PeerGroupException
Initialize the module, passing it its peer group and advertisement.

Note: when subclassing one of the existing PeerGroup implementations (which implement Module), it may not be recommended to overload the init method. See the documentation of the PeerGroup class being subclassed.

Specified by:
init in interface Module
Parameters:
group - The PeerGroup from which this Module can obtain services. If this module is a Service, this is also the PeerGroup of which this module is a service.
assignedID - Identity of Module within group. modules can use it as a the root of their namespace to create names that are unique within the group but predictable by the same module on another peer. This is normally the ModuleClassID which is also the name under which the module is known by other modules. For a group it is the PeerGroupID itself. The parameters of a service, in the Peer configuration, are indexed by the assignedID of that service, and a Service must publish its run-time parameters in the Peer Advertisement under its assigned ID.
impl - The implementation advertisement for this Module. It is permissible to pass null if no implementation advertisement is available. This may happen if the implementation was selected by explicit class name rather than by following an implementation advertisement. Modules are not required to support that style of loading, but if they do, then their documentation should mention it.
Throws:
PeerGroupException - This module failed to initialize.

startApp

public int startApp(String[] arg)
Complete any remaining initialization of the module. The module should be fully functional after startApp() is completed. That is also the opportunity to supply arbitrary arguments (mostly to applications).

If this module is a PeerGroup service, it may be invoked several times depending on its return value.

Specified by:
startApp in interface Module
Parameters:
arg - An array of Strings forming the parameters for this Module.
Returns:
int A status indication which may be one of Module.START_OK, Module.START_AGAIN_PROGRESS, Module.START_AGAIN_STALLED, which indicates partial or complete success, or any other value (negative values are recommended for future compatibility), which indicates failure.

stopApp

public void stopApp()
Stop a module. This may be called any time after init() completes and should not assume that startApp() has been called or completed.

The Module cannot be forced to comply, but in the future we might be able to deny it access to anything after some timeout.

Specified by:
stopApp in interface Module

getInterface

public Service getInterface()
Service objects are not manipulated directly to protect usage of the service. A Service interface is returned to access the service methods.

Specified by:
getInterface in interface Service
Returns:
Service public interface of the service

getImplAdvertisement

public Advertisement getImplAdvertisement()
Returns the advertisement for this service.

Specified by:
getImplAdvertisement in interface Service
Returns:
Advertisement the advertisement. This is always a ModuleImplAdvertisement.

getPeerInfoHandler

PeerInfoHandler getPeerInfoHandler(String name)

getNextQueryId

int getNextQueryId()

getGroup

public PeerGroup getGroup()
Returns the group to which this service is attached.

Returns:
PeerGroup the group

isLocalMonitoringAvailable

public boolean isLocalMonitoringAvailable()
See if Local Monitoring is available on this Peer Local monitoring is only available if you are using a version of of jxta.jar that was build with metering activated.

See the document:

Specified by:
isLocalMonitoringAvailable in interface PeerInfoService
Returns:
true if local monitoring is available

isLocalMonitoringAvailable

public boolean isLocalMonitoringAvailable(ModuleClassID moduleClassID)
See if Local monitoring is available from a specific ServiceMonitor. Local monitoring is only available if you are using a version of of jxta.jar that was build with metering activated.

See the document:

Specified by:
isLocalMonitoringAvailable in interface PeerInfoService
Parameters:
moduleClassID - The Module classID of the ServiceMonitor. Note that the ServiceMonitor moduleClassID is not the same as moduleClassID of the Service being monitored.
Returns:
true if local monitoring is available for a specific module

getSupportedReportRates

public long[] getSupportedReportRates()
Asynchronous reporting of Monitored data may be obtained only at rates supported by the MonitorManager on the peer. This method returns the locally supported rates (in milliseconds)

Specified by:
getSupportedReportRates in interface PeerInfoService
Returns:
all supported rates

isSupportedReportRate

public boolean isSupportedReportRate(long reportRate)
Asynchronous reporting of Monitored data may be obtained only at rates supported by the MonitorManager on the peer. This method validates whether a specific rate (in milliseconds) is locally supported.

Specified by:
isSupportedReportRate in interface PeerInfoService
Parameters:
reportRate - the report rate to check
Returns:
true if a report rate is supported

getBestReportRate

public long getBestReportRate(long desiredReportRate)
Asynchronous reporting of Monitored data may be obtained only at rates supported by the MonitorManager on the peer. This method supplies the closest (rounded up) rate (in milliseconds) to the specified rate that is locally supported.

Specified by:
getBestReportRate in interface PeerInfoService
Parameters:
desiredReportRate - the desired rate
Returns:
the desired rate

getPeerMonitorInfo

public PeerMonitorInfo getPeerMonitorInfo()
Obtain the monitoring capabilities of the Local Peer.

The PeerMonitorInfo provides:

Specified by:
getPeerMonitorInfo in interface PeerInfoService
Returns:
PeerMonitorInfo

getPeerMonitorInfo

public void getPeerMonitorInfo(PeerID peerID,
                               PeerMonitorInfoListener peerMonitorInfoListener,
                               long timeout)
                        throws MonitorException
Obtain the monitoring capabilities of a Remote Peer.

The PeerMonitorInfo provides:

Via the PeerMonitorInfoListener, you will be informed of the PeerMonitorInfo or why it was not provided (error, timeout, unavailable, etc)

Specified by:
getPeerMonitorInfo in interface PeerInfoService
Parameters:
peerID - The PeerID of the Peer you wish information about
peerMonitorInfoListener - The Listener to be told about the obtained PeerMonitorInfo
timeout - Generate a timeout event if no answer has been received in this time (in Milliseconds)
Throws:
MonitorException - if a monitor error occurs

getCumulativeMonitorReport

public MonitorReport getCumulativeMonitorReport(MonitorFilter monitorFilter)
                                         throws MonitorException
Get a MonitorReport of total accumulated metrics from the ServiceMonitors (specified in the MonitorFilter) since they were created/reset for the local Peer.

Specified by:
getCumulativeMonitorReport in interface PeerInfoService
Parameters:
monitorFilter - The MonitorFilter containing the specific ServiceMonitors and types of Service Metrics desired
Returns:
the report
Throws:
MonitorException - if a monitor error occurs

getCumulativeMonitorReport

public void getCumulativeMonitorReport(PeerID peerID,
                                       MonitorFilter monitorFilter,
                                       MonitorListener monitorListener,
                                       long timeout)
                                throws MonitorException
Get a MonitorReport of total accumulated metrics from the ServiceMonitors (specified in the MonitorFilter) since they were created/reset for the specified remote Peer.

Specified by:
getCumulativeMonitorReport in interface PeerInfoService
Parameters:
peerID - The PeerID of the Peer you wish information about
monitorFilter - The MonitorFilter containing the specific ServiceMonitors and types of Service Metrics desired
monitorListener - The Listener to obtain the report when it arrives (or timed out)
timeout - The timeout for reporting that the information has not arrived.
Throws:
MonitorException - if a monitor error occurs

addMonitorListener

public long addMonitorListener(MonitorFilter monitorFilter,
                               long reportRate,
                               boolean includeCumulative,
                               MonitorListener monitorListener)
                        throws MonitorException
Get MonitorReports at a specified rates of metrics accrued over time from the ServiceMonitors (specified in the MonitorFilter) about the local Peer. For many applications it is required to obtain metrics from the beginning of time and then augment over time as more data arrives.

There is a problem with the following approach:

  1. Call getCumulativeMonitorReport to get the cumulative totals
  2. Call addMonitorListener to get periodic changes
  3. Add the periodic data to the totals

Because of a potential race condition related to metrics that are measured between the two calls it is possible to lose some metrics. To address this, this method supports this by combining them into a single call that allows you to specify whether you wish the first report delivered to be a cumulative report.

Specified by:
addMonitorListener in interface PeerInfoService
Parameters:
monitorFilter - The MonitorFilter containing the specific ServiceMonitors and types of Service Metrics desired
reportRate - The rate at which you wish metric delta reports
includeCumulative - Should the first report you receive be the cumulative data since the ServiceMonitors were created/reset?
monitorListener - The Listener to obtain the report when it arrives (or timed out)
Returns:
report rate
Throws:
MonitorException - if a monitor error occurs

addRemoteMonitorListener

public void addRemoteMonitorListener(PeerID peerID,
                                     MonitorFilter monitorFilter,
                                     long reportRate,
                                     boolean includeCumulative,
                                     MonitorListener monitorListener,
                                     long lease,
                                     long timeout)
                              throws MonitorException
Get MonitorReports at a specified rates of metrics accrued over time from the ServiceMonitors (specified in the MonitorFilter) about the specified remote Peer. For many applications it is required to obtain metrics from the beginning of time and then augment over time as more data arrives.

There is a problem with the following approach:

  1. Call getCumulativeMonitorReport to get the cumulative totals
  2. Call addMonitorListener to get periodic changes
  3. Add the periodic data to the totals

Because of a potential race condition related to metrics that are measured between the two calls it is possible to lose some metrics. To address this, this method supports this by combining them into a single call that allows you to specify whether you wish the first report delivered to be a cumulative report.

Specified by:
addRemoteMonitorListener in interface PeerInfoService
Parameters:
peerID - The PeerID of the Peer you wish information about
monitorFilter - The MonitorFilter containing the specific ServiceMonitors and types of Service Metrics desired
reportRate - The rate at which you wish metric delta reports
includeCumulative - Should the first report you receive be the cumulative data since the ServiceMonitors were created/reset?
monitorListener - The Listener to obtain the report when it arrives (or timed out)
lease - the lease
timeout - The timeout for reporting that the information has not arrived.
Throws:
MonitorException - if a monitor error occurs

removeMonitorListener

public boolean removeMonitorListener(MonitorListener monitorListener)
                              throws MonitorException
Stop the periodic reporting for all registered filters corresponding to this MonitorListener

Specified by:
removeMonitorListener in interface PeerInfoService
Parameters:
monitorListener - the monitor listener
Returns:
true if successfully removed
Throws:
MonitorException - if a monitor error occurs

removeRemoteMonitorListener

public void removeRemoteMonitorListener(PeerID peerID,
                                        MonitorListener monitorListener,
                                        long timeout)
                                 throws MonitorException
Stop the periodic reporting for all registered filters to the specified Peer corresponding to this MonitorListener.

Specified by:
removeRemoteMonitorListener in interface PeerInfoService
Parameters:
peerID - The Peer that you wish to deregister periodic reporting
monitorListener - The MonitorListener that was originally registered
timeout - The timeout for reporting that the remote listener was acknowledged as deregistered
Throws:
MonitorException - if a monitor error occurs

removeRemoteMonitorListener

public void removeRemoteMonitorListener(MonitorListener monitorListener,
                                        long timeout)
                                 throws MonitorException
Stop the periodic reporting for all registered filters to the all remote Peers corresponding to this MonitorListener.

Specified by:
removeRemoteMonitorListener in interface PeerInfoService
Parameters:
monitorListener - The MonitorListener that was originally registered
timeout - The timeout for reporting that the remote listener was acknowledged as deregistered
Throws:
MonitorException - if a monitor error occurs

JXSE