00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 package org.objectweb.cjdbc.common.monitor.client;
00025
00026 import java.util.ArrayList;
00027
00028 import org.objectweb.cjdbc.common.exceptions.DataCollectorException;
00029 import org.objectweb.cjdbc.common.exceptions.ExceptionTypes;
00030 import org.objectweb.cjdbc.common.monitor.AbstractDataCollector;
00031 import org.objectweb.cjdbc.controller.core.Controller;
00032 import org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabase;
00033 import org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabaseWorkerThread;
00034
00035
00036
00037
00038
00039
00040 public abstract class AbstractClientDataCollector extends AbstractDataCollector
00041 {
00042 private String virtualDatabaseName;
00043 private String clientId;
00044 private int clientIndex;
00045
00046
00047
00048
00049
00050
00051 public AbstractClientDataCollector(String virtualDatabaseName, String clientId)
00052 throws DataCollectorException
00053 {
00054 super();
00055 this.virtualDatabaseName = virtualDatabaseName;
00056 this.clientId = clientId;
00057 setClientIndex();
00058 }
00059
00060 private Object setClientIndex() throws DataCollectorException
00061 {
00062 VirtualDatabase vdb = ((Controller)controller).getVirtualDatabase(
00063 virtualDatabaseName);
00064 ArrayList activeThreads = vdb.getActiveThreads();
00065 int size = activeThreads.size();
00066 VirtualDatabaseWorkerThread client = null;
00067 int index = 0;
00068 for (index = 0; index < size; index++)
00069 {
00070 client = ((VirtualDatabaseWorkerThread) activeThreads.get(index));
00071 if (client.getUser().equals(clientId))
00072 break;
00073 else
00074 client = null;
00075 }
00076
00077 if (client == null)
00078 throw new DataCollectorException(ExceptionTypes.CLIENT_NOT_FOUND);
00079 else
00080 {
00081 this.clientIndex = index;
00082 return client;
00083 }
00084 }
00085
00086 private Object checkClientIndex() throws DataCollectorException
00087 {
00088 VirtualDatabase vdb = ((Controller)controller).getVirtualDatabase(
00089 virtualDatabaseName);
00090 ArrayList activeThreads = vdb.getActiveThreads();
00091 VirtualDatabaseWorkerThread client = (VirtualDatabaseWorkerThread) activeThreads
00092 .get(clientIndex);
00093 if (client.getUser().equals(clientId))
00094 return client;
00095 else
00096 {
00097 return setClientIndex();
00098 }
00099 }
00100
00101
00102
00103
00104 public long collectValue() throws DataCollectorException
00105 {
00106 VirtualDatabaseWorkerThread client = (VirtualDatabaseWorkerThread) checkClientIndex();
00107 return this.getValue(client);
00108 }
00109
00110
00111
00112
00113
00114
00115
00116 public abstract long getValue(Object client);
00117
00118
00119
00120
00121 public String getTargetName()
00122 {
00123 return clientId;
00124 }
00125 }