m_componentManagerCreator = new ExcaliburComponentManagerCreator( null,
new File( "../conf/logkit.xml" ), new File( "../conf/roles.xml" ),
new File( "../conf/components.xml" ), new File( "../conf/instrument.xml" ) );
// Get a reference to the service manager
ServiceManager serviceManager = m_componentManagerCreator.getServiceManager();
// Get a reference to the example component.
ExampleInstrumentable instrumentable =
(ExampleInstrumentable)serviceManager.lookup( ExampleInstrumentable.ROLE );
try
{
boolean quit = false;
while( !quit )
{
System.out.println( "Enter the number of times that exampleAction should be "
+ "called, or 'q' to quit." );
BufferedReader in = new BufferedReader( new InputStreamReader( System.in ) );
System.out.print( " : " );
String cntStr = in.readLine();
// Can get a null if CTRL-C is hit.
if( ( cntStr == null ) || ( cntStr.equalsIgnoreCase( "q" ) ) )
{
quit = true;
}
else if( ( cntStr.equalsIgnoreCase( "gc" ) ) )
{
System.gc();
}
else
{
try
{
int concurrent = 100;
CyclicBarrier barrier = new CyclicBarrier( concurrent );
int cnt = Integer.parseInt( cntStr );
int average = Math.max( cnt / concurrent, 1 );
while( cnt > 0 )
{
Thread t = new Thread( new ActionRunner( instrumentable,
Math.min( average, cnt ),
barrier ) );
t.start();
if( cnt > 0 )
{
cnt -= average;
}
if( cnt < 0 )
{
cnt = 0;
}
}
}
catch( NumberFormatException e )
{
}
}
}
}
finally
{
// Release the component
serviceManager.release( instrumentable );
instrumentable = null;
// Dispose of the ComponentManagerCreator. It will dispose all
// of its own components, including the ComponentManager
m_componentManagerCreator.dispose();