1 24 25 package org.objectweb.cjdbc.common.monitor.client; 26 27 import java.util.ArrayList ; 28 29 import org.objectweb.cjdbc.common.exceptions.DataCollectorException; 30 import org.objectweb.cjdbc.common.monitor.AbstractDataCollector; 31 import org.objectweb.cjdbc.controller.core.Controller; 32 import org.objectweb.cjdbc.controller.monitoring.datacollector.DataCollector; 33 import org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabase; 34 import org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabaseWorkerThread; 35 36 42 public abstract class AbstractClientDataCollector extends AbstractDataCollector 43 { 44 private String virtualDatabaseName; 45 private String clientId; 46 private int clientIndex; 47 48 53 public AbstractClientDataCollector(String virtualDatabaseName, String clientId) 54 throws DataCollectorException 55 { 56 super(); 57 this.virtualDatabaseName = virtualDatabaseName; 58 this.clientId = clientId; 59 setClientIndex(); 60 } 61 62 private Object setClientIndex() throws DataCollectorException 63 { 64 VirtualDatabase vdb = ((Controller) controller) 65 .getVirtualDatabase(virtualDatabaseName); 66 ArrayList 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 checkClientIndex() throws DataCollectorException 89 { 90 VirtualDatabase vdb = ((Controller) controller) 91 .getVirtualDatabase(virtualDatabaseName); 92 ArrayList 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 106 public long collectValue() throws DataCollectorException 107 { 108 VirtualDatabaseWorkerThread client = (VirtualDatabaseWorkerThread) checkClientIndex(); 109 return this.getValue(client); 110 } 111 112 119 public abstract long getValue(Object client); 120 121 124 public String getTargetName() 125 { 126 return clientId; 127 } 128 } 129 | Popular Tags |