DataModel.java revision 9a70fc3be3b1e966bf78825cdb8d509963a6f0a1
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2001 by Sun Microsystems, Inc.
* All rights reserved.
*
*/
/**
* Aggregation of all users, projects, and sets metrics data.
* Implements the singleton pattern
* @author Sun Microsystems, Inc.
*/
class DataModel {
private static SRMDataReader dr;
private static boolean doAlive;
/**
* syncObject guards the calls of SRMDataReader methods between the
* current data model thread and the KeepAlive thread.
*/
private static Object syncObject;
/**
* rdsKeepAliveTimeout: how long the KeepAlive thread should keep
* the connection opened.
*/
private static boolean kaError;
private static boolean msacct = false;
private static final int PROCESSESHASHSIZE = 500;
private static final int USERPROCSHASHSIZE = 200;
private static final int PROJPROCSHASHSIZE = 100;
private static final int USERSHASHSIZE = 200;
private static final int PROJSHASHSIZE = 100;
private static final int L_PRC_SI = 1;
private static final int L_USR_SI = 2;
private static final int L_PRJ_SI = 3;
private static final int L_AC_USR = 4;
private static final int L_AC_PRJ = 5;
private static final int L_SYSTEM = 6;
private static final int L_ALL = 20;
// RDS exec command
private static final int TIMEOUTIDX = 3;
private static final int INTERVALIDX = 5;
// RDS commands
private static boolean updating; // set if udpdateing is in progress
private static boolean running; // set if the rds is running
private int rdsTimeout;
private int rdsInterval;
/**
* Default constructor
*/
private DataModel() {
}
/**
* Should be used to obtain the singleton instance of this class
* @return the singleton instance of this class
*/
try {
}
}
} catch (Exception e) { };
}
return dm;
}
/**
* Initialize the rds timeouts, the actually opening is deleted
* until the first update call.
*/
this.rdsTimeout = rdsTimeout;
this.rdsInterval = rdsInterval;
}
}
}
} // end open
/**
* Close the rds communication pipe.
*/
void close() {
if (running) {
doAlive = false;
synchronized (syncObject) {
/*
* check again, since AliveThread could already close RDS
* when this thread was waiting on syncObject
*/
if (running) {
running = false;
}
}
}
} // end close
/**
* Close the rds communication pipe after an error has raised. In this
* case the rds will be shutdown instead of gently closed.
*/
void closeONError() {
doAlive = false;
dr.shutdownRDS();
running = false;
}
/**
* Get a provider data model object identified by id from the list defined
* by listt.
* @return the provider data model object or null if other the list type
* or the provider object id are unsupported.
*/
try {
switch (listt) {
default: return null;
}
} catch (NumberFormatException e) {
return null;
}
}
/**
* Get process metrics object.
* @param pid the process id
* @return metrics object with process metrics or new empty
* object at first call.
*/
if (updating == false)
return null;
}
if (updating == true)
pdm.setUpdated(true);
return pdm;
}
/**
* Get user metrics object.
* @param uid the user id
* @return metrics object with process metrics or new empty object at
* first call.
*/
if ((padm = (UserProcessAggregateDataModel)
if (updating == false)
return null;
}
if (updating == true)
padm.setUpdated(true);
return padm;
}
/**
* Get project metrics object.
* @return metrics object with process metrics or new empty
* object at first call.
*/
if ((padm = (ProjectProcessAggregateDataModel)
if (updating == false)
return null;
}
if (updating == true)
padm.setUpdated(true);
return padm;
}
/**
* Get active user object.
* @param name the user id as string
* @return active user object.
*/
if (updating == false)
return null;
}
if (updating == true)
aum.setUpdated(true);
return aum;
}
/**
* Get active project object.
* @param name the project
* @return project object.
*/
if (updating == false)
return null;
}
if (updating == true)
apm.setUpdated(true);
return apm;
}
/**
* Returns an iterator over the Processes.
* @return iterator
*/
}
/**
* Returns an iterator over the Users.
* @return iterator
*/
}
/**
* Returns an iterator over the Projects.
* @return iterator
*/
}
/**
* Returns an iterator over the user process aggregation.
* @return iterator
*/
}
/**
* Returns an iterator over the project process aggregation.
* @return iterator
*/
}
/**
* Update the metrics data.
* @exception SRMProtocolException
*/
void update() throws SRMProtocolException {
int tries = 2;
while (tries-- > 0) {
if (!running) {
running = true;
}
try {
synchronized (syncObject) {
/* check if AliveThread has set error flag */
if (kaError) {
closeONError();
continue;
/*
* check if rds is still running, since AliveThread
* could already close RDS when this thread was waiting
* on syncObject
*/
} else if (running) {
updating = true;
} else {
tries = 2;
continue;
}
}
ka.resetTimeout();
updating = false;
tries = 0;
} catch (SRMProtocolException e) {
closeONError();
if (tries == 0)
throw e;
}
}
cleanUp();
} // end update
/**
* Remove all dead processes, users or projects.
*/
private void cleanUp() {
}
/**
* Remove all elements that heven't been updated in last update.
*/
Iterator i;
i.remove();
} else {
pdm.setUpdated(false);
}
}
}
/**
* This thread keeps the rds and the communication with it alive by
* sending the alive message to rds.
*/
int keepAliveTimeout, save;
/**
* Constructor
* @param timeout how long to run at all
*/
super("KeepAlive");
kaError = false;
}
synchronized public void run() {
int myTimeout = 0;
doAlive = true;
while (doAlive) {
/*
* the keepAliveTimeout value is set in constructor and
* in the resetTimeout() method. If its value is reseted
* the internal timer myTimeout value will be wind up.
*/
if (keepAliveTimeout > 0) {
keepAliveTimeout = 0;
}
try {
synchronized (syncObject) {
/*
* this thread has gained the sync object, but it
* also should check the doAlive flag since
* the dataModel thread could already removed it
* because of a protocol error
*/
if (doAlive) {
kaError = true;
if (myTimeout <= 0) {
running = false;
return;
} else {
}
kaError = false;
} else {
return;
}
}
} catch (InterruptedException e) {
return;
} catch (SRMProtocolException e) {
return;
}
}
}
/**
* Reset the absolute timeout
*/
public void resetTimeout() {
}
} // end class KeepAlive
class ProjectProcessAggregateDataModel extends ProcessAggregateDataModel {
super(id);
}
protected void setCIMInstance(boolean newInstance) {
super.setCIMInstance(newInstance);
}
}
class UserProcessAggregateDataModel extends ProcessAggregateDataModel {
super(id);
}
protected void setCIMInstance(boolean newInstance) {
super.setCIMInstance(newInstance);
}
}
} // end class DataModel