Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

AbstractClientDataCollector.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2004 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Nicolas Modrzyk.
00022  * Contributor(s): 
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  * Collects information about C-JDBC clients.
00037  * TODO: Implements proper client data collection. This is not used at the moment.
00038  * @author <a href="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk</a>
00039  */
00040 public abstract class AbstractClientDataCollector extends AbstractDataCollector
00041 {
00042   private String virtualDatabaseName;
00043   private String clientId;
00044   private int    clientIndex;
00045 
00046   /**
00047    * @param virtualDatabaseName of the virtualdatabase
00048    * @param clientId for the client
00049    * @throws DataCollectorException if cannot access client
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    * @see org.objectweb.cjdbc.common.monitor.AbstractDataCollector#collectValue()
00103    */
00104   public long collectValue() throws DataCollectorException
00105   {
00106     VirtualDatabaseWorkerThread client = (VirtualDatabaseWorkerThread) checkClientIndex();
00107     return this.getValue(client);
00108   }
00109 
00110   /**
00111    * We have the client object so let's get the value we want from ot
00112    * 
00113    * @param client as an object to allow it through RMI, but IS a <code>VirtualDatabaseWorkerThread</code>
00114    * @return the collected value
00115    */
00116   public abstract long getValue(Object client);
00117 
00118   /**
00119    * @see org.objectweb.cjdbc.common.monitor.AbstractDataCollector#getTargetName()
00120    */
00121   public String getTargetName()
00122   {
00123     return clientId;
00124   }
00125 }

Generated on Mon Apr 11 22:01:28 2005 for C-JDBC by  doxygen 1.3.9.1