org.knowhowlab.osgi.monitoradmin
Class MonitorAdminCommon

java.lang.Object
  extended by org.knowhowlab.osgi.monitoradmin.MonitorAdminCommon
All Implemented Interfaces:
MonitoringJobVisitor, MonitorListener

public class MonitorAdminCommon
extends java.lang.Object
implements MonitorListener, MonitoringJobVisitor

MonitorAdmin common actions that are not related on Permissions

Author:
dpishchukhin

Field Summary
static java.lang.String PATH_PATERN
           
 
Constructor Summary
MonitorAdminCommon(OsgiVisitor osgiVisitor, LogVisitor logVisitor)
           
 
Method Summary
 void addJob(AbstractMonitoringJob job)
          Add a new MonitoringJob to the list
 void cancelAllJobs()
          Cancel all jobs and clear the list
 void cancelJob(AbstractMonitoringJob job)
          Cancel Job and remove it from jobs list
 org.osgi.framework.ServiceReference findMonitorableReferenceById(java.lang.String monitorableId)
          Find Monitorable service reference by monitorable Id.
 void fireEvent(java.lang.String monitorableId, StatusVariable statusVariable, java.lang.String initiator)
          Fire StatusVariable update event
 java.lang.String getDescription(org.osgi.framework.ServiceReference serviceReference, java.lang.String statusVariableId)
          Returns a StatusVariable description addressed by Monitorable service reference and its id.
 java.lang.String[] getDisabledNotificationPaths()
          Get array with paths that are disabled for notificatios with switchEvents() method
 org.osgi.framework.ServiceReference[] getMonitorableReferences()
          Returns array of the Monitorable ServiceReferences that are currently registered.
 org.osgi.framework.ServiceReference[] getMonitorableReferences(java.lang.String monitorableIdFilter)
          Returns array of the Monitorable ServiceReferences that are currently registered.
 java.util.List<MonitoringJob> getRunningJobs()
          Get list of all running MonitoringJobs
 StatusVariable getStatusVariable(org.osgi.framework.ServiceReference serviceReference, java.lang.String statusVariableId)
          Returns a StatusVariable addressed by Monitorable service reference and its id.
 StatusVariable getStatusVariable(java.lang.String path)
          Returns a StatusVariable addressed by its full path.
 java.lang.String[] getStatusVariableNames(java.lang.String monitorableId)
          Returns the list of StatusVariable names published by a Monitorable instance.
static boolean isValidId(java.lang.String id)
          Validate Monitorable Id or StatusVariable name
 boolean notifiesOnChange(org.osgi.framework.ServiceReference serviceReference, java.lang.String statusVariableId)
          Returns a StatusVariable notification flag addressed by Monitorable service reference and its id.
 boolean resetStatusVariable(org.osgi.framework.ServiceReference serviceReference, java.lang.String statusVariableId)
          Reset StatusVariable description addressed by Monitorable service reference and its id.
 void switchEvents(java.util.Set<java.lang.String> paths, boolean on)
          Switch on/off events
 void updated(java.lang.String monitorableId, StatusVariable statusVariable)
          Callback for notification of a StatusVariable change.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PATH_PATERN

public static final java.lang.String PATH_PATERN
See Also:
Constant Field Values
Constructor Detail

MonitorAdminCommon

public MonitorAdminCommon(OsgiVisitor osgiVisitor,
                          LogVisitor logVisitor)
Method Detail

updated

public void updated(java.lang.String monitorableId,
                    StatusVariable statusVariable)
             throws java.lang.IllegalArgumentException
Callback for notification of a StatusVariable change.

Specified by:
updated in interface MonitorListener
Parameters:
monitorableId - the identifier of the Monitorable instance reporting the change
statusVariable - the StatusVariable that has changed
Throws:
java.lang.IllegalArgumentException - if the specified monitorable ID is invalid (null, empty, or contains illegal characters) or points to a non-existing Monitorable, or if statusVariable is null

getDisabledNotificationPaths

public java.lang.String[] getDisabledNotificationPaths()
Get array with paths that are disabled for notificatios with switchEvents() method

Returns:
array with StatusVariable paths

findMonitorableReferenceById

public org.osgi.framework.ServiceReference findMonitorableReferenceById(java.lang.String monitorableId)
                                                                 throws java.lang.IllegalArgumentException
Find Monitorable service reference by monitorable Id. Returns Monitorable service reference or throws exception. If multiple services exist for the same monitorableId, the service with the highest ranking (as specified in its Constants.SERVICE_RANKING property) is returned. If there is a tie in ranking, the service with the lowest service ID (as specified in its Constants.SERVICE_ID property); that is, the service that was regis- tered first is returned.

Parameters:
monitorableId - id that is userd to filter services
Returns:
Monitorable service reference with specified monitorableId.
Throws:
java.lang.IllegalArgumentException - monitorableId is null or monitorableId points to non-existing service or monitorableId is invalid

getMonitorableReferences

public org.osgi.framework.ServiceReference[] getMonitorableReferences()
Returns array of the Monitorable ServiceReferences that are currently registered.

The returned array contains the ServiceTeferences in alphabetical order by service PID. It cannot be null, an empty array is returned if no Monitorable services are registered.

Returns:
the array of Monitorable names

getMonitorableReferences

public org.osgi.framework.ServiceReference[] getMonitorableReferences(java.lang.String monitorableIdFilter)
Returns array of the Monitorable ServiceReferences that are currently registered.

The returned array contains the ServiceTeferences in alphabetical order by service PID. It cannot be null, an empty array is returned if no Monitorable services are registered.

Parameters:
monitorableIdFilter - Monitorable SERVICE_PID filter
Returns:
the array of Monitorable names

addJob

public void addJob(AbstractMonitoringJob job)
Add a new MonitoringJob to the list

Parameters:
job - MonitoringJob

getRunningJobs

public java.util.List<MonitoringJob> getRunningJobs()
Get list of all running MonitoringJobs

Returns:
list of running jobs

getStatusVariable

public StatusVariable getStatusVariable(java.lang.String path)
                                 throws java.lang.IllegalArgumentException
Returns a StatusVariable addressed by its full path.

Specified by:
getStatusVariable in interface MonitoringJobVisitor
Parameters:
path - the full path of the StatusVariable in [Monitorable_ID]/[StatusVariable_ID] format
Returns:
the StatusVariable object
Throws:
java.lang.IllegalArgumentException - if path is null or otherwise invalid, or points to a non-existing StatusVariable
See Also:
Monitorable.getStatusVariable(String)

getStatusVariable

public StatusVariable getStatusVariable(org.osgi.framework.ServiceReference serviceReference,
                                        java.lang.String statusVariableId)
Returns a StatusVariable addressed by Monitorable service reference and its id.

Parameters:
serviceReference - Monitorable service reference
statusVariableId - StatusVariable id
Returns:
the StatusVariable object
Throws:
java.lang.IllegalArgumentException - if points to a non-existing StatusVariable

getDescription

public java.lang.String getDescription(org.osgi.framework.ServiceReference serviceReference,
                                       java.lang.String statusVariableId)
Returns a StatusVariable description addressed by Monitorable service reference and its id.

Parameters:
serviceReference - Monitorable service reference
statusVariableId - StatusVariable id
Returns:
the StatusVariable description
Throws:
java.lang.IllegalArgumentException - if points to a non-existing StatusVariable

notifiesOnChange

public boolean notifiesOnChange(org.osgi.framework.ServiceReference serviceReference,
                                java.lang.String statusVariableId)
Returns a StatusVariable notification flag addressed by Monitorable service reference and its id.

Parameters:
serviceReference - Monitorable service reference
statusVariableId - StatusVariable id
Returns:
the StatusVariable notification flag
Throws:
java.lang.IllegalArgumentException - if points to a non-existing StatusVariable

resetStatusVariable

public boolean resetStatusVariable(org.osgi.framework.ServiceReference serviceReference,
                                   java.lang.String statusVariableId)
Reset StatusVariable description addressed by Monitorable service reference and its id.

Parameters:
serviceReference - Monitorable service reference
statusVariableId - StatusVariable id
Returns:
the StatusVariable description
Throws:
java.lang.IllegalArgumentException - if points to a non-existing StatusVariable

cancelJob

public void cancelJob(AbstractMonitoringJob job)
Cancel Job and remove it from jobs list

Specified by:
cancelJob in interface MonitoringJobVisitor
Parameters:
job - job to cancel

cancelAllJobs

public void cancelAllJobs()
Cancel all jobs and clear the list


fireEvent

public void fireEvent(java.lang.String monitorableId,
                      StatusVariable statusVariable,
                      java.lang.String initiator)
Fire StatusVariable update event

Specified by:
fireEvent in interface MonitoringJobVisitor
Parameters:
monitorableId - monitorableId
statusVariable - status variable
initiator - initiator. if null - is not added to event

switchEvents

public void switchEvents(java.util.Set<java.lang.String> paths,
                         boolean on)
Switch on/off events

Parameters:
paths - StatusVariable paths
on - false if event sending should be switched off, true if it should be switched on for the given path

getStatusVariableNames

public java.lang.String[] getStatusVariableNames(java.lang.String monitorableId)
Returns the list of StatusVariable names published by a Monitorable instance. Only those status variables are listed where the following two conditions are met: All other status variables are silently ignored, their names are omitted from the list.

The returned array does not contain duplicates, and the elements are in alphabetical order. It cannot be null, an empty array is returned if no (authorized and readable) Status Variables are provided by the given Monitorable.

Parameters:
monitorableId - the identifier of a Monitorable instance
Returns:
a list of StatusVariable objects names published by the specified Monitorable
Throws:
java.lang.IllegalArgumentException - if monitorableId is null or otherwise invalid, or points to a non-existing Monitorable

isValidId

public static boolean isValidId(java.lang.String id)
Validate Monitorable Id or StatusVariable name

Parameters:
id - id
Returns:
false - id is invalid, otherwise - true


Copyright © 2010 Know-How Lab. All Rights Reserved.