[jboss-cvs] JBoss Messaging SVN: r4888 - in trunk: src/main/org/jboss/messaging/core/postoffice/impl and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Aug 28 10:16:43 EDT 2008
Author: jmesnil
Date: 2008-08-28 10:16:43 -0400 (Thu, 28 Aug 2008)
New Revision: 4888
Modified:
trunk/src/main/org/jboss/messaging/core/management/impl/ManagementServiceImpl.java
trunk/src/main/org/jboss/messaging/core/management/impl/MessagingServerControl.java
trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/ManagementServiceImplTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/MessagingServerControlTest.java
Log:
moved JMX Notifications sending code to ManagementServiceImpl
the JMX notifications are now sent when registering/unregistering the managed resources. This ensures that JMX Notifications will also be sent when resources are created by another way than MessagingServerControl (e.g. in ServerSession.createQueue)
Modified: trunk/src/main/org/jboss/messaging/core/management/impl/ManagementServiceImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/management/impl/ManagementServiceImpl.java 2008-08-28 12:52:59 UTC (rev 4887)
+++ trunk/src/main/org/jboss/messaging/core/management/impl/ManagementServiceImpl.java 2008-08-28 14:16:43 UTC (rev 4888)
@@ -25,8 +25,11 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
import javax.management.MBeanServer;
+import javax.management.Notification;
+import javax.management.NotificationBroadcasterSupport;
import javax.management.ObjectName;
import org.jboss.messaging.core.config.Configuration;
@@ -35,6 +38,7 @@
import org.jboss.messaging.core.management.ManagementService;
import org.jboss.messaging.core.management.MessagingServerControlMBean;
import org.jboss.messaging.core.management.QueueControlMBean;
+import org.jboss.messaging.core.management.impl.MessagingServerControl.NotificationType;
import org.jboss.messaging.core.messagecounter.MessageCounter;
import org.jboss.messaging.core.messagecounter.MessageCounterManager;
import org.jboss.messaging.core.messagecounter.impl.MessageCounterManagerImpl;
@@ -66,11 +70,15 @@
private final MBeanServer mbeanServer;
private final boolean jmxManagementEnabled;
private final Map<ObjectName, Object> registry;
+ private final NotificationBroadcasterSupport broadcaster;
+ private final AtomicLong notifSeq;
private PostOffice postOffice;
private HierarchicalRepository<Set<Role>> securityRepository;
private HierarchicalRepository<QueueSettings> queueSettingsRepository;
- private MessageCounterManager messageCounterManager = new MessageCounterManagerImpl(10000);
+ private MessageCounterManager messageCounterManager = new MessageCounterManagerImpl(
+ 10000);
+ private MessagingServerControlMBean managedServer;
// Static --------------------------------------------------------
@@ -102,6 +110,8 @@
this.mbeanServer = mbeanServer;
this.jmxManagementEnabled = jmxManagementEnabled;
this.registry = new HashMap<ObjectName, Object>();
+ this.broadcaster = new NotificationBroadcasterSupport();
+ this.notifSeq = new AtomicLong(0);
}
// Public --------------------------------------------------------
@@ -110,9 +120,9 @@
public MessageCounterManager getMessageCounterManager()
{
- return messageCounterManager;
+ return messageCounterManager;
}
-
+
public MessagingServerControlMBean registerServer(PostOffice postOffice,
StorageManager storageManager, Configuration configuration,
HierarchicalRepository<Set<Role>> securityRepository,
@@ -122,9 +132,9 @@
this.postOffice = postOffice;
this.securityRepository = securityRepository;
this.queueSettingsRepository = queueSettingsRepository;
- MessagingServerControlMBean managedServer = new MessagingServerControl(
- postOffice, storageManager, configuration, securityRepository,
- queueSettingsRepository, messagingServer, messageCounterManager);
+ managedServer = new MessagingServerControl(postOffice, storageManager,
+ configuration, securityRepository, queueSettingsRepository,
+ messagingServer, messageCounterManager, broadcaster);
ObjectName objectName = getMessagingServerObjectName();
register(objectName, managedServer);
registerInJMX(objectName, managedServer);
@@ -149,6 +159,7 @@
{
log.debug("registered address " + objectName);
}
+ sendNotification(NotificationType.ADDRESS_ADDED, address.toString());
}
public void unregisterAddress(final SimpleString address) throws Exception
@@ -156,23 +167,29 @@
ObjectName objectName = getAddressObjectName(address);
unregister(objectName);
unregisterFromJMX(objectName);
+ sendNotification(NotificationType.ADDRESS_REMOVED, address.toString());
}
public void registerQueue(final Queue queue, final SimpleString address,
final StorageManager storageManager) throws Exception
{
- MessageCounter counter = new MessageCounter(queue.getName().toString(), null, queue, false, queue.isDurable(),
- messageCounterManager.getMaxDayCount());
- messageCounterManager.registerMessageCounter(queue.getName().toString(), counter);
+ MessageCounter counter = new MessageCounter(queue.getName().toString(),
+ null, queue, false, queue.isDurable(), messageCounterManager
+ .getMaxDayCount());
+ messageCounterManager.registerMessageCounter(queue.getName().toString(),
+ counter);
ObjectName objectName = getQueueObjectName(address, queue.getName());
QueueControlMBean queueControl = new QueueControl(queue, storageManager,
postOffice, queueSettingsRepository, counter);
register(objectName, queueControl);
registerInJMX(objectName, queueControl);
+
if (log.isDebugEnabled())
{
log.debug("registered queue " + objectName);
}
+ sendNotification(NotificationType.QUEUE_CREATED, queue.getName()
+ .toString());
}
public void unregisterQueue(final SimpleString name,
@@ -182,6 +199,8 @@
unregister(objectName);
unregisterFromJMX(objectName);
messageCounterManager.unregisterMessageCounter(name.toString());
+
+ sendNotification(NotificationType.QUEUE_DESTROYED, name.toString());
}
// Package protected ---------------------------------------------
@@ -223,6 +242,17 @@
mbeanServer.unregisterMBean(objectName);
}
}
-
+
+ private void sendNotification(MessagingServerControl.NotificationType type,
+ String message)
+ {
+ if (managedServer != null)
+ {
+ Notification notif = new Notification(type.toString(), managedServer,
+ notifSeq.incrementAndGet(), message);
+ broadcaster.sendNotification(notif);
+ }
+ }
+
// Inner classes -------------------------------------------------
}
Modified: trunk/src/main/org/jboss/messaging/core/management/impl/MessagingServerControl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/management/impl/MessagingServerControl.java 2008-08-28 12:52:59 UTC (rev 4887)
+++ trunk/src/main/org/jboss/messaging/core/management/impl/MessagingServerControl.java 2008-08-28 14:16:43 UTC (rev 4888)
@@ -24,12 +24,10 @@
import java.util.List;
import java.util.Set;
-import java.util.concurrent.atomic.AtomicLong;
import javax.management.ListenerNotFoundException;
import javax.management.MBeanInfo;
import javax.management.MBeanNotificationInfo;
-import javax.management.Notification;
import javax.management.NotificationBroadcasterSupport;
import javax.management.NotificationEmitter;
import javax.management.NotificationFilter;
@@ -75,7 +73,6 @@
private final MessageCounterManager messageCounterManager;
private final NotificationBroadcasterSupport broadcaster;
- private AtomicLong notifSeq = new AtomicLong(0);
private boolean enableMessageCounters;
@@ -87,7 +84,8 @@
StorageManager storageManager, Configuration configuration,
HierarchicalRepository<Set<Role>> securityRepository,
HierarchicalRepository<QueueSettings> queueSettingsRepository,
- MessagingServer messagingServer, MessageCounterManager messageCounterManager) throws Exception
+ MessagingServer messagingServer, MessageCounterManager messageCounterManager,
+ NotificationBroadcasterSupport broadcaster) throws Exception
{
super(MessagingServerControlMBean.class);
this.postOffice = postOffice;
@@ -97,8 +95,7 @@
this.queueSettingsRepository = queueSettingsRepository;
this.server = messagingServer;
this.messageCounterManager = messageCounterManager;
-
- broadcaster = new NotificationBroadcasterSupport();
+ this.broadcaster = broadcaster;
}
// Public --------------------------------------------------------
@@ -291,7 +288,6 @@
public boolean addAddress(final String address) throws Exception
{
- sendNotification(NotificationType.ADDRESS_ADDED, address);
return postOffice.addDestination(new SimpleString(address), false);
}
@@ -304,8 +300,6 @@
{
postOffice.addBinding(sAddress, sName, null, true);
}
- sendNotification(NotificationType.ADDRESS_ADDED, address);
- sendNotification(NotificationType.QUEUE_CREATED, name);
}
public void createQueue(final String address, final String name,
@@ -325,8 +319,6 @@
{
postOffice.addBinding(sAddress, sName, filter, durable);
}
- sendNotification(NotificationType.ADDRESS_ADDED, address);
- sendNotification(NotificationType.QUEUE_CREATED, name);
}
public void destroyQueue(final String name) throws Exception
@@ -342,7 +334,6 @@
postOffice.removeBinding(queue.getName());
}
- sendNotification(NotificationType.QUEUE_DESTROYED, name);
}
public int getConnectionCount()
@@ -352,7 +343,6 @@
public boolean removeAddress(final String address) throws Exception
{
- sendNotification(NotificationType.ADDRESS_REMOVED, address);
return postOffice.removeDestination(new SimpleString(address), false);
}
@@ -482,14 +472,6 @@
messageCounterManager.resetAllCounterHistories();
}
-
- private void sendNotification(final NotificationType type,
- final String message)
- {
- Notification notif = new Notification(type.toString(), this, notifSeq
- .incrementAndGet(), message);
- broadcaster.sendNotification(notif);
- }
// Inner classes -------------------------------------------------
Modified: trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java 2008-08-28 12:52:59 UTC (rev 4887)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java 2008-08-28 14:16:43 UTC (rev 4888)
@@ -304,8 +304,6 @@
Binding binding = new BindingImpl(address, queue);
- managementService.registerQueue(queue, address, storageManager);
-
return binding;
}
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/ManagementServiceImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/ManagementServiceImplTest.java 2008-08-28 12:52:59 UTC (rev 4887)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/ManagementServiceImplTest.java 2008-08-28 14:16:43 UTC (rev 4888)
@@ -159,7 +159,6 @@
expect(
mbeanServer.registerMBean(isA(AddressControlMBean.class),
eq(objectName))).andReturn(objectInstance);
-
replay(mbeanServer);
ManagementService service = new ManagementServiceImpl(mbeanServer, true);
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/MessagingServerControlTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/MessagingServerControlTest.java 2008-08-28 12:52:59 UTC (rev 4887)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/MessagingServerControlTest.java 2008-08-28 14:16:43 UTC (rev 4888)
@@ -22,7 +22,6 @@
package org.jboss.messaging.tests.unit.core.management.impl;
-import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expect;
@@ -34,24 +33,17 @@
import static org.jboss.messaging.tests.util.RandomUtil.randomLong;
import static org.jboss.messaging.tests.util.RandomUtil.randomString;
-import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
-import java.util.concurrent.CountDownLatch;
-import javax.management.MBeanServer;
-import javax.management.Notification;
-import javax.management.NotificationListener;
-import javax.management.ObjectName;
+import javax.management.NotificationBroadcasterSupport;
import junit.framework.TestCase;
import org.jboss.messaging.core.config.Configuration;
import org.jboss.messaging.core.filter.Filter;
-import org.jboss.messaging.core.management.impl.ManagementServiceImpl;
import org.jboss.messaging.core.management.impl.MessagingServerControl;
-import org.jboss.messaging.core.management.impl.MessagingServerControl.NotificationType;
import org.jboss.messaging.core.messagecounter.MessageCounterManager;
import org.jboss.messaging.core.persistence.StorageManager;
import org.jboss.messaging.core.postoffice.Binding;
@@ -75,8 +67,6 @@
*/
public class MessagingServerControlTest extends TestCase
{
- private MBeanServer mbeanServer;
- private ObjectName serverON;
private PostOffice postOffice;
private StorageManager storageManager;
private Configuration configuration;
@@ -91,17 +81,6 @@
// Static --------------------------------------------------------
- private static void assertGotNotification(NotificationType expectedType,
- NotificationListenerWithLatch listener, CountDownLatch latch)
- throws Exception
- {
- boolean gotNotification = latch.await(500, MILLISECONDS);
- assertTrue(gotNotification);
- Notification notification = listener.getNotification();
- assertNotNull(notification);
- assertEquals(expectedType.toString(), notification.getType());
- }
-
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@@ -359,22 +338,10 @@
replayMockedAttributes();
MessagingServerControl control = createControl();
- mbeanServer.registerMBean(control, serverON);
- final CountDownLatch latch = new CountDownLatch(1);
- NotificationListenerWithLatch listener = new NotificationListenerWithLatch(
- latch);
- mbeanServer.addNotificationListener(serverON, listener, null, null);
-
assertEquals(added, control.addAddress(address));
- assertGotNotification(
- MessagingServerControl.NotificationType.ADDRESS_ADDED, listener,
- latch);
-
verifyMockedAttributes();
-
- mbeanServer.removeNotificationListener(serverON, listener);
}
public void testRemoveAddress() throws Exception
@@ -387,22 +354,9 @@
replayMockedAttributes();
MessagingServerControl control = createControl();
- mbeanServer.registerMBean(control, serverON);
-
- final CountDownLatch latch = new CountDownLatch(1);
- NotificationListenerWithLatch listener = new NotificationListenerWithLatch(
- latch);
- mbeanServer.addNotificationListener(serverON, listener, null, null);
-
assertEquals(removed, control.removeAddress(address));
- assertGotNotification(
- MessagingServerControl.NotificationType.ADDRESS_REMOVED, listener,
- latch);
-
verifyMockedAttributes();
-
- mbeanServer.removeNotificationListener(serverON, listener);
}
public void testCreateQueue() throws Exception
@@ -425,39 +379,6 @@
verify(newBinding);
}
- public void testCreateQueueAndReceiveNotification() throws Exception
- {
- String address = randomString();
- String name = randomString();
-
- expect(postOffice.getBinding(new SimpleString(address))).andReturn(null);
- Binding newBinding = createMock(Binding.class);
- expect(
- postOffice.addBinding(new SimpleString(address), new SimpleString(
- name), null, true)).andReturn(newBinding);
- replayMockedAttributes();
- replay(newBinding);
-
- MessagingServerControl control = createControl();
- mbeanServer.registerMBean(control, serverON);
-
- final CountDownLatch latch = new CountDownLatch(1);
- NotificationListenerWithLatch listener = new NotificationListenerWithLatch(
- latch);
-
- mbeanServer.addNotificationListener(serverON, listener, null, null);
- control.createQueue(address, name);
-
- assertGotNotification(
- MessagingServerControl.NotificationType.QUEUE_CREATED, listener,
- latch);
-
- mbeanServer.removeNotificationListener(serverON, listener);
-
- verify(newBinding);
- verifyMockedAttributes();
- }
-
public void testCreateQueueWithAllParameters() throws Exception
{
String address = randomString();
@@ -541,23 +462,10 @@
replay(binding, queue);
MessagingServerControl control = createControl();
- mbeanServer.registerMBean(control, serverON);
-
- final CountDownLatch latch = new CountDownLatch(1);
- NotificationListenerWithLatch listener = new NotificationListenerWithLatch(
- latch);
-
- mbeanServer.addNotificationListener(serverON, listener, null, null);
control.destroyQueue(name);
- assertGotNotification(
- MessagingServerControl.NotificationType.QUEUE_DESTROYED, listener,
- latch);
-
verify(binding, queue);
verifyMockedAttributes();
-
- mbeanServer.removeNotificationListener(serverON, listener);
}
public void testGetConnectionCount() throws Exception
@@ -582,9 +490,6 @@
{
super.setUp();
- mbeanServer = ManagementFactory.getPlatformMBeanServer();
- serverON = ManagementServiceImpl.getMessagingServerObjectName();
-
postOffice = createMock(PostOffice.class);
storageManager = createMock(StorageManager.class);
configuration = createMock(Configuration.class);
@@ -597,14 +502,6 @@
@Override
protected void tearDown() throws Exception
{
- if (mbeanServer.isRegistered(serverON))
- {
- mbeanServer.unregisterMBean(serverON);
- }
-
- serverON = null;
- mbeanServer = null;
-
postOffice = null;
storageManager = null;
configuration = null;
@@ -622,7 +519,7 @@
{
MessagingServerControl control = new MessagingServerControl(postOffice,
storageManager, configuration, securityRepository,
- queueSettingsRepository, server, messageCounterManager);
+ queueSettingsRepository, server, messageCounterManager, new NotificationBroadcasterSupport());
return control;
}
@@ -639,28 +536,4 @@
}
// Inner classes -------------------------------------------------
-
- private final class NotificationListenerWithLatch implements
- NotificationListener
- {
- private final CountDownLatch latch;
- private Notification notification;
-
- private NotificationListenerWithLatch(CountDownLatch latch)
- {
- this.latch = latch;
- }
-
- public void handleNotification(Notification notification, Object handback)
- {
- this.notification = notification;
- latch.countDown();
- }
-
- public Notification getNotification()
- {
- return notification;
- }
- }
-
}
More information about the jboss-cvs-commits
mailing list