@Override
public void exportDataSources()
throws MalformedObjectNameException, MBeanRegistrationException, InstanceAlreadyExistsException, NotCompliantMBeanException
{
for ( ServiceReference<DataSource> dataSource : dataSources ) {
String name = dataSource.identity();
Module module = ( Module ) spi.moduleOf( dataSource );
EntityDescriptor descriptor = module.entityDescriptor( DataSourceConfiguration.class.getName() );
List<MBeanAttributeInfo> attributes = new ArrayList<MBeanAttributeInfo>();
Map<String, AccessibleObject> properties = new LinkedHashMap<String, AccessibleObject>();
for ( PropertyDescriptor persistentProperty : descriptor.state().properties() ) {
if ( !persistentProperty.isImmutable() ) {
String propertyName = persistentProperty.qualifiedName().name();
String type = persistentProperty.valueType().mainType().getName();
attributes.add( new MBeanAttributeInfo( propertyName, type, propertyName, true, true, type.equals( "java.lang.Boolean" ) ) );
properties.put( propertyName, persistentProperty.accessor() );
}
}
List<MBeanOperationInfo> operations = new ArrayList<MBeanOperationInfo>();
operations.add( new MBeanOperationInfo( "restart", "Restart DataSource", new MBeanParameterInfo[ 0 ], "void", MBeanOperationInfo.ACTION_INFO ) );
MBeanInfo mbeanInfo = new MBeanInfo( DataSourceConfiguration.class.getName(), name, attributes.toArray( new MBeanAttributeInfo[ attributes.size() ] ), null, operations.toArray( new MBeanOperationInfo[ operations.size() ] ), null );
Object mbean = new ConfigurableDataSource( dataSourceService, mbeanInfo, name, properties );
ObjectName configurableDataSourceName = new ObjectName( "Zest:application=" + application.name() + ",class=Datasource,name=" + name );
server.registerMBean( mbean, configurableDataSourceName );
configurationNames.add( configurableDataSourceName );
}
}