com.sun.faban.driver.engine
Class MasterImpl

java.lang.Object
  extended by java.rmi.server.RemoteObject
      extended by java.rmi.server.RemoteServer
          extended by java.rmi.server.UnicastRemoteObject
              extended by com.sun.faban.driver.engine.MasterImpl
All Implemented Interfaces:
Master, Serializable, Remote

public class MasterImpl
extends UnicastRemoteObject
implements Master

This is the main Master class for running a Faban driver. The Master is instantiated on the master machine by the user wishing to run a benchmark. It is responsible for co-ordinating the work of all the Agents, setting up the benchmark test, collecting the results etc. NOTE: The registry and agents must have been brought up before starting the driver. The driver will fail otherwise.

See Also:
Agent, Registry, Serialized Form

Field Summary
protected  Agent[][] agentRefs
          Remote references for each agentImpl of each driver type.
protected  int[] agentThreads
          Threads required per agentImpl for each driver.
protected static String fs
          Convenience accessor to the file separator.
protected  int[] remainderThreads
          Remaining threads to be distributed to the first agents.
protected  RunInfo runInfo
          The RunInfo structure.
protected  Timer scheduler
          The scheduler used in the master.
protected  MasterState state
          The current state of the master.
protected  Object stateLock
          The lock object for the state.
protected  Timer timer
          The time recorder.
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Constructor Summary
protected MasterImpl()
          Creates and exports a new Master.
 
Method Summary
 void abortRun()
          Notifies the master to terminate the run immediately.
protected  void changeState(MasterState newState)
          Introduces a state change in the master.
protected  int configure()
          Contacts the registry and gets references for all agents.
protected  void configureLocal()
          Configures a local, in-process agent.
 long currentTimeMillis()
          Obtain the master's time for time adjustment.
 void generateReports(List<Map<String,Metrics>> results)
          Generates the summary and detail report.
 MasterState getCurrentState()
          Obtains the current state of the master.
 String getRunID(boolean increment)
          This method retrieves the ID for the current run, by looking in the specappplatform.seq file in the user's home directory.
static void main(String[] args)
          The main method to start the master.
 void runBenchmark()
          Runs the benchmark from begin to end.
 void setStartTime(int relTime)
          Sets the benchmark start time after all threads are started.
 void updateMetrics(RuntimeMetrics m)
          Updates the master with the latest runtime metrics so the master can dump out the stats accordingly.
 void waitForState(MasterState state)
          Wait for a certain state on the master.
 void waitForThreadStart()
          Waits for all threads in all agents to start.
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

agentRefs

protected Agent[][] agentRefs
Remote references for each agentImpl of each driver type.


agentThreads

protected int[] agentThreads
Threads required per agentImpl for each driver.


remainderThreads

protected int[] remainderThreads
Remaining threads to be distributed to the first agents.


runInfo

protected RunInfo runInfo
The RunInfo structure.


timer

protected Timer timer
The time recorder.


fs

protected static String fs
Convenience accessor to the file separator.


stateLock

protected final Object stateLock
The lock object for the state.


state

protected MasterState state
The current state of the master.


scheduler

protected Timer scheduler
The scheduler used in the master.

Constructor Detail

MasterImpl

protected MasterImpl()
              throws RemoteException
Creates and exports a new Master.

Throws:
RemoteException - if failed to export object
Method Detail

runBenchmark

public void runBenchmark()
                  throws Exception
Runs the benchmark from begin to end.

Throws:
Exception - Any error that had occurred during the run.

getRunID

public String getRunID(boolean increment)
                throws IOException
This method retrieves the ID for the current run, by looking in the specappplatform.seq file in the user's home directory. If the increment flag is set to true, the runId is incremented. Also the file will be created if it does not exist. This shall be done only maximum once in a run. Non-incrementing getRunID may be called more than once from many processes.

Parameters:
increment - Whether the file shall be incremented or not
Returns:
runId
Throws:
IOException

configure

protected int configure()
                 throws Exception
Contacts the registry and gets references for all agents. Then calculates the load distribution to each agentImpl.

Returns:
The total number of agents configured
Throws:
Exception - Any error that could happen configuring the master

configureLocal

protected void configureLocal()
                       throws Exception
Configures a local, in-process agent.

Throws:
Exception - If anything goes wrong during the configuration

generateReports

public void generateReports(List<Map<String,Metrics>> results)
                     throws IOException
Generates the summary and detail report.

Parameters:
results - List of Host-Metrics maps, one per driver type
Throws:
IOException

updateMetrics

public void updateMetrics(RuntimeMetrics m)
Description copied from interface: Master
Updates the master with the latest runtime metrics so the master can dump out the stats accordingly.

Specified by:
updateMetrics in interface Master
Parameters:
m - The runtime metrics to update

currentTimeMillis

public long currentTimeMillis()
Obtain the master's time for time adjustment.

Specified by:
currentTimeMillis in interface Master
Returns:
The current time on the master

changeState

protected void changeState(MasterState newState)
Introduces a state change in the master.

Parameters:
newState - The new state

getCurrentState

public MasterState getCurrentState()
Obtains the current state of the master.

Specified by:
getCurrentState in interface Master
Returns:
The current state of the master.

waitForState

public void waitForState(MasterState state)
Wait for a certain state on the master.

Specified by:
waitForState in interface Master
Parameters:
state - The state to wait for

waitForThreadStart

public void waitForThreadStart()
Waits for all threads in all agents to start.


setStartTime

public void setStartTime(int relTime)
Sets the benchmark start time after all threads are started.

Parameters:
relTime - The ms time from the run epoch

abortRun

public void abortRun()
Notifies the master to terminate the run immediately. This usually happens if there is a fatal error in the run.

Specified by:
abortRun in interface Master

main

public static void main(String[] args)
The main method to start the master. No arguments are required. The -noexit argument will cause the master to wait. The only actual expectation is the benchmark.properties property pointing to the properties file.

Parameters:
args - The command line arguments are ignored.