KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > common > jmx > monitoring > backend > AbstractBackendDataCollector


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: sequoia@continuent.org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * Initial developer(s): Nicolas Modrzyk.
20  * Contributor(s):
21  */

22
23 package org.continuent.sequoia.common.jmx.monitoring.backend;
24
25 import org.continuent.sequoia.common.exceptions.DataCollectorException;
26 import org.continuent.sequoia.common.jmx.monitoring.AbstractDataCollector;
27 import org.continuent.sequoia.controller.backend.DatabaseBackend;
28 import org.continuent.sequoia.controller.core.Controller;
29 import org.continuent.sequoia.controller.monitoring.datacollector.DataCollector;
30 import org.continuent.sequoia.controller.virtualdatabase.VirtualDatabase;
31
32 /**
33  * Abstract class to factor code for collecting data from backends
34  *
35  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
36  */

37 public abstract class AbstractBackendDataCollector
38     extends AbstractDataCollector
39 {
40   private String JavaDoc backendName;
41   private String JavaDoc virtualDatabaseName;
42
43   /**
44    * Create new collector
45    *
46    * @param backendName of the backend to get data from
47    * @param virtualDatabaseName that contains reference to this backend
48    */

49   public AbstractBackendDataCollector(String JavaDoc backendName,
50       String JavaDoc virtualDatabaseName)
51   {
52     super();
53     this.backendName = backendName;
54     this.virtualDatabaseName = virtualDatabaseName;
55   }
56
57   /**
58    * @see org.continuent.sequoia.common.jmx.monitoring.AbstractDataCollector#collectValue()
59    */

60   public long collectValue() throws DataCollectorException
61   {
62     try
63     {
64       VirtualDatabase vdb = ((Controller) controller)
65           .getVirtualDatabase(virtualDatabaseName);
66       DatabaseBackend db = vdb.getAndCheckBackend(backendName,
67           VirtualDatabase.NO_CHECK_BACKEND);
68       return this.getValue(db);
69     }
70     catch (Exception JavaDoc e)
71     {
72       throw new DataCollectorException(DataCollector.BACKEND_NOT_ACCESSIBLE);
73     }
74   }
75
76   /**
77    * get the proper collected value when we have instace of the backend
78    *
79    * @param backend <code>DatabaseBackend</code> instance
80    * @return collected value
81    */

82   public abstract long getValue(Object JavaDoc backend);
83
84   /**
85    * @see org.continuent.sequoia.common.jmx.monitoring.AbstractDataCollector#getTargetName()
86    */

87   public String JavaDoc getTargetName()
88   {
89     return backendName;
90   }
91 }
92
Popular Tags