View Javadoc

1   package fr.in2p3.jsaga.impl.resource.task;
2   
3   import fr.in2p3.jsaga.impl.monitoring.MetricImpl;
4   import fr.in2p3.jsaga.impl.monitoring.MetricMode;
5   import fr.in2p3.jsaga.impl.monitoring.MetricType;
6   import org.ogf.saga.error.*;
7   import org.ogf.saga.monitoring.Callback;
8   
9   /* ***************************************************
10   * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
11   * ***             http://cc.in2p3.fr/             ***
12   * ***************************************************/
13  public class ResourceStateMetricImpl<E> extends MetricImpl<E> {
14      private AbstractResourceTaskImpl m_listener;
15  
16      /** constructor */
17      public ResourceStateMetricImpl(AbstractResourceTaskImpl resource, String name, String desc, MetricMode mode, String unit, MetricType type, E initialValue) {
18          super(resource, name, desc, mode, unit, type, initialValue);
19          m_listener = resource;
20      }
21  
22      /** clone */
23      public ResourceStateMetricImpl<E> clone() throws CloneNotSupportedException {
24          // clone attributes
25          ResourceStateMetricImpl<E> clone = (ResourceStateMetricImpl<E>) super.clone();
26          clone.m_listener = m_listener;
27          return clone;
28      }
29  
30      public synchronized int addCallback(Callback cb) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, IncorrectStateException, TimeoutException, NoSuccessException {
31          int nbBefore = super.getNumberOfCallbacks();
32          int cookie = super.addCallback(cb);
33          int nbAfter = super.getNumberOfCallbacks();
34          if (nbBefore==0 && nbAfter==1) {
35              m_listener.startListening();
36          }
37          return cookie;
38      }
39  
40      public synchronized void removeCallback(int cookie) throws NotImplementedException, BadParameterException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, TimeoutException, NoSuccessException {
41          int nbBefore = super.getNumberOfCallbacks();
42          super.removeCallback(cookie);
43          int nbAfter = super.getNumberOfCallbacks();
44          if (nbBefore==1 && nbAfter==0) {
45              m_listener.stopListening();
46          }
47      }
48  }