ObjectName serviceName = new ObjectName("examples", "mbean", "legacy");
DynamicLegacyService dynamicService = new DynamicLegacyService(legacyService);
server.registerMBean(dynamicService, serviceName);
// Now register a listener: we want to be able to know when the service starts and stops
server.addNotificationListener(serviceName, new NotificationListener()
{
public void handleNotification(Notification notification, Object handback)
{
System.out.println(notification);
}