KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > common > jmx > monitoring > client > AbstractClientDataCollector


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.client;
24
25 import java.util.ArrayList JavaDoc;
26
27 import org.continuent.sequoia.common.exceptions.DataCollectorException;
28 import org.continuent.sequoia.common.jmx.monitoring.AbstractDataCollector;
29 import org.continuent.sequoia.controller.core.Controller;
30 import org.continuent.sequoia.controller.monitoring.datacollector.DataCollector;
31 import org.continuent.sequoia.controller.virtualdatabase.VirtualDatabase;
32 import org.continuent.sequoia.controller.virtualdatabase.VirtualDatabaseWorkerThread;
33
34 /**
35  * Collects information about Sequoia clients.
36  * <p>
37  * TODO: Implements proper client data collection. This is not used at the
38  * moment.
39  *
40  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
41  */

42 public abstract class AbstractClientDataCollector extends AbstractDataCollector
43 {
44   private String JavaDoc virtualDatabaseName;
45   private String JavaDoc clientId;
46   private int clientIndex;
47
48   /**
49    * @param virtualDatabaseName of the virtualdatabase
50    * @param clientId for the client
51    * @throws DataCollectorException if cannot access client
52    */

53   public AbstractClientDataCollector(String JavaDoc virtualDatabaseName, String JavaDoc clientId)
54       throws DataCollectorException
55   {
56     super();
57     this.virtualDatabaseName = virtualDatabaseName;
58     this.clientId = clientId;
59     setClientIndex();
60   }
61
62   private Object JavaDoc setClientIndex() throws DataCollectorException
63   {
64     VirtualDatabase vdb = ((Controller) controller)
65         .getVirtualDatabase(virtualDatabaseName);
66     ArrayList JavaDoc activeThreads = vdb.getActiveThreads();
67     int size = activeThreads.size();
68     VirtualDatabaseWorkerThread client = null;
69     int index = 0;
70     for (index = 0; index < size; index++)
71     {
72       client = ((VirtualDatabaseWorkerThread) activeThreads.get(index));
73       if (client.getUser().equals(clientId))
74         break;
75       else
76         client = null;
77     }
78
79     if (client == null)
80       throw new DataCollectorException(DataCollector.CLIENT_NOT_FOUND);
81     else
82     {
83       this.clientIndex = index;
84       return client;
85     }
86   }
87
88   private Object JavaDoc checkClientIndex() throws DataCollectorException
89   {
90     VirtualDatabase vdb = ((Controller) controller)
91         .getVirtualDatabase(virtualDatabaseName);
92     ArrayList JavaDoc activeThreads = vdb.getActiveThreads();
93     VirtualDatabaseWorkerThread client = (VirtualDatabaseWorkerThread) activeThreads
94         .get(clientIndex);
95     if (client.getUser().equals(clientId))
96       return client;
97     else
98     {
99       return setClientIndex();
100     }
101   }
102
103   /**
104    * @see org.continuent.sequoia.common.jmx.monitoring.AbstractDataCollector#collectValue()
105    */

106   public long collectValue() throws DataCollectorException
107   {
108     VirtualDatabaseWorkerThread client = (VirtualDatabaseWorkerThread) checkClientIndex();
109     return this.getValue(client);
110   }
111
112   /**
113    * We have the client object so let's get the value we want from ot
114    *
115    * @param client as an object to allow it through RMI, but IS a
116    * <code>VirtualDatabaseWorkerThread</code>
117    * @return the collected value
118    */

119   public abstract long getValue(Object JavaDoc client);
120
121   /**
122    * @see org.continuent.sequoia.common.jmx.monitoring.AbstractDataCollector#getTargetName()
123    */

124   public String JavaDoc getTargetName()
125   {
126     return clientId;
127   }
128 }
129
Popular Tags