// Loop over the Instruments published by this Instrumentable
Instrument[] instruments = instrumentable.getInstruments();
for( int i = 0; i < instruments.length; i++ )
{
Instrument instrument = instruments[ i ];
String instrumentName = instrument.getInstrumentName();
String fullInstrumentName = instrumentableName + "." + instrumentName;
getLogger().debug( "Registering Instrument: " + fullInstrumentName );
// See if a proxy exists for the Instrument yet.
InstrumentProxy proxy = instrumentableProxy.getInstrumentProxy( fullInstrumentName );
if( proxy == null )
{
proxy = new InstrumentProxy(
instrumentableProxy, fullInstrumentName, instrumentName );
proxy.enableLogging( getLogger() );
incrementInstrumentCount();
// Set the type of the new InstrumentProxy depending on the
// class of the actual Instrument.
if( instrument instanceof CounterInstrument )
{
proxy.setType( DefaultInstrumentManager.INSTRUMENT_TYPE_COUNTER );
}
else if( instrument instanceof ValueInstrument )
{
proxy.setType( DefaultInstrumentManager.INSTRUMENT_TYPE_VALUE );
}
else
{
throw new ServiceException( fullInstrumentName, "Encountered an unknown "
+ "Instrument type for the Instrument with key, "
+ fullInstrumentName + ": " + instrument.getClass().getName() );
}
// Mark the instrument proxy as registered.
proxy.setRegistered();
// Store a reference to the proxy in the Instrument.
( (AbstractInstrument)instrument ).setInstrumentProxy( proxy );
instrumentableProxy.addInstrumentProxy( proxy );
}
else
{
// Register the existing proxy with the Instrument. Make sure that the
// type didn't change on us.
if( instrument instanceof CounterInstrument )
{
switch( proxy.getType() )
{
case DefaultInstrumentManager.INSTRUMENT_TYPE_COUNTER:
// Type is the same.
// Store a reference to the proxy in the Instrument.
( (AbstractInstrument)instrument ).setInstrumentProxy( proxy );
break;
case DefaultInstrumentManager.INSTRUMENT_TYPE_NONE:
// Not yet set. Created in configuration.
proxy.setType( DefaultInstrumentManager.INSTRUMENT_TYPE_COUNTER );
// Store a reference to the proxy in the Instrument.
( (AbstractInstrument)instrument ).setInstrumentProxy( proxy );
break;
default:
throw new ServiceException( instrumentName,
"Instruments of more than one type are assigned to name: "
+ instrumentName );
}
}
else if( instrument instanceof ValueInstrument )
{
switch( proxy.getType() )
{
case DefaultInstrumentManager.INSTRUMENT_TYPE_VALUE:
// Type is the same.
// Store a reference to the proxy in the Instrument.
( (AbstractInstrument)instrument ).setInstrumentProxy( proxy );
break;
case DefaultInstrumentManager.INSTRUMENT_TYPE_NONE:
// Not yet set. Created in configuration.
proxy.setType( DefaultInstrumentManager.INSTRUMENT_TYPE_VALUE );
// Store a reference to the proxy in the Instrument.
( (AbstractInstrument)instrument ).setInstrumentProxy( proxy );
break;
default:
throw new ServiceException( instrumentName,
"Instruments of more than one type are assigned to name: "
+ instrumentName );
}
}
else
{
throw new ServiceException( instrumentName, "Encountered an unknown Instrument "
+ "type for the Instrument with name, " + instrumentName + ": "
+ instrument.getClass().getName() );
}
// Mark the instrument proxy as registered.
proxy.setRegistered();
}