View Javadoc

1   package fr.in2p3.jsaga.impl.monitoring;
2   
3   import fr.in2p3.jsaga.helpers.cloner.SagaObjectCloner;
4   import fr.in2p3.jsaga.impl.AbstractSagaObjectImpl;
5   import org.ogf.saga.SagaObject;
6   import org.ogf.saga.error.*;
7   import org.ogf.saga.monitoring.*;
8   import org.ogf.saga.session.Session;
9   
10  import java.util.HashMap;
11  import java.util.Map;
12  
13  /* ***************************************************
14  * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
15  * ***             http://cc.in2p3.fr/             ***
16  * ***************************************************
17  * File:   AbstractMonitorableImpl
18  * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
19  * Date:   17 sept. 2007
20  * ***************************************************
21  * Description:                                      */
22  /**
23   *
24   */
25  public abstract class AbstractMonitorableImpl extends AbstractSagaObjectImpl implements Monitorable {
26      private Map<String,Metric> m_metrics;
27  
28      /** constructor */
29      public AbstractMonitorableImpl(Session session) {
30          super(session);
31          m_metrics = new HashMap<String,Metric>();
32      }
33  
34      /** clone */
35      public SagaObject clone() throws CloneNotSupportedException {
36          AbstractMonitorableImpl clone = (AbstractMonitorableImpl) super.clone();
37          clone.m_metrics = new SagaObjectCloner<String,Metric>().cloneMap(m_metrics);
38          return clone;
39      }
40  
41      public String[] listMetrics() throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, TimeoutException, NoSuccessException {
42          return m_metrics.keySet().toArray(new String[m_metrics.keySet().size()]);
43      }
44  
45      public Metric getMetric(String name) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, DoesNotExistException, TimeoutException, NoSuccessException {
46          Metric metric = m_metrics.get(name);
47          if (metric != null) {
48              return metric;
49          } else {
50              throw new DoesNotExistException("Metric "+name+" does not exist", this);
51          }
52      }
53  
54      public int addCallback(String name, Callback cb) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, DoesNotExistException, TimeoutException, NoSuccessException, IncorrectStateException {
55          Metric metric = m_metrics.get(name);
56          if (metric != null) {
57              return metric.addCallback(cb);
58          } else {
59              throw new DoesNotExistException("Metric "+name+" does not exist", this);
60          }
61      }
62  
63      public void removeCallback(String name, int cookie) throws NotImplementedException, DoesNotExistException, BadParameterException, TimeoutException, NoSuccessException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException {
64          Metric metric = m_metrics.get(name);
65          if (metric != null) {
66              metric.removeCallback(cookie);
67          } else {
68              throw new DoesNotExistException("Metric "+name+" does not exist", this);
69          }
70      }
71  
72      //////////////////////////////////////////// internal methods ////////////////////////////////////////////
73  
74      public void _addMetric(String name, MetricImpl<?> metric) {
75          m_metrics.put(name, metric);
76      }
77  }