diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/AttributeChange.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/AttributeChange.java deleted file mode 100644 index 48d9b2a..0000000 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/AttributeChange.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Demoiselle Framework - * Copyright (C) 2010 SERPRO - * ---------------------------------------------------------------------------- - * This file is part of Demoiselle Framework. - * - * Demoiselle Framework is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License version 3 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License version 3 - * along with this program; if not, see - * or write to the Free Software Foundation, Inc., 51 Franklin Street, - * Fifth Floor, Boston, MA 02110-1301, USA. - * ---------------------------------------------------------------------------- - * Este arquivo é parte do Framework Demoiselle. - * - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação - * do Software Livre (FSF). - * - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português - * para maiores detalhes. - * - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título - * "LICENCA.txt", junto com esse programa. Se não, acesse - * ou escreva para a Fundação do Software Livre (FSF) Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. - */ -package br.gov.frameworkdemoiselle.internal.implementation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import javax.inject.Qualifier; - -import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; -import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent; - -/** - * - * Enables {@link ManagementNotificationEvent} observers to trigger only with notifications - * of the specialized type {@link AttributeChangeNotification}. - * - * @author SERPRO - * - */ -@Qualifier -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE}) -public @interface AttributeChange { - -} diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/Generic.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/Generic.java deleted file mode 100644 index 89e62ae..0000000 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/Generic.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Demoiselle Framework - * Copyright (C) 2010 SERPRO - * ---------------------------------------------------------------------------- - * This file is part of Demoiselle Framework. - * - * Demoiselle Framework is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License version 3 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License version 3 - * along with this program; if not, see - * or write to the Free Software Foundation, Inc., 51 Franklin Street, - * Fifth Floor, Boston, MA 02110-1301, USA. - * ---------------------------------------------------------------------------- - * Este arquivo é parte do Framework Demoiselle. - * - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação - * do Software Livre (FSF). - * - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português - * para maiores detalhes. - * - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título - * "LICENCA.txt", junto com esse programa. Se não, acesse - * ou escreva para a Fundação do Software Livre (FSF) Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. - */ -package br.gov.frameworkdemoiselle.internal.implementation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import javax.inject.Qualifier; - -import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent; -import br.gov.frameworkdemoiselle.management.GenericNotification; - -/** - * - * Enables {@link ManagementNotificationEvent} observers to trigger only with notifications - * of the base type {@link GenericNotification}. - * - * @author SERPRO - * - */ -@Qualifier -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE}) -public @interface Generic { - -} diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/Management.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/Management.java index ec55a5a..7af5fa9 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/Management.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/Management.java @@ -59,12 +59,13 @@ import br.gov.frameworkdemoiselle.context.ConversationContext; import br.gov.frameworkdemoiselle.context.RequestContext; import br.gov.frameworkdemoiselle.context.SessionContext; import br.gov.frameworkdemoiselle.context.ViewContext; -import br.gov.frameworkdemoiselle.internal.implementation.ManagedType; import br.gov.frameworkdemoiselle.internal.implementation.ManagedType.MethodDetail; -import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; +import br.gov.frameworkdemoiselle.management.AttributeChangeMessage; +import br.gov.frameworkdemoiselle.management.GenericNotification; import br.gov.frameworkdemoiselle.management.ManagedAttributeNotFoundException; import br.gov.frameworkdemoiselle.management.ManagedInvokationException; import br.gov.frameworkdemoiselle.management.ManagementExtension; +import br.gov.frameworkdemoiselle.management.Notification; import br.gov.frameworkdemoiselle.management.NotificationManager; import br.gov.frameworkdemoiselle.stereotype.ManagementController; import br.gov.frameworkdemoiselle.util.Beans; @@ -280,9 +281,12 @@ public class Management implements Serializable { NotificationManager notificationManager = Beans.getReference(NotificationManager.class); Class attributeType = newValue != null ? newValue.getClass() : null; - AttributeChangeNotification notification = new AttributeChangeNotification(bundle.getString( - "management-notification-attribute-changed", propertyName, managedType.getType() - .getCanonicalName()), propertyName, attributeType, oldValue, newValue); + Notification notification = new GenericNotification( new AttributeChangeMessage( + bundle.getString("management-notification-attribute-changed", propertyName, managedType.getType().getCanonicalName()) + , propertyName + , attributeType + , oldValue + , newValue) ); notificationManager.sendNotification(notification); } catch (ConstraintViolationException ce) { diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ManagementNotificationEventImpl.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ManagementNotificationEventImpl.java index 1739b4d..c3042da 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ManagementNotificationEventImpl.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ManagementNotificationEventImpl.java @@ -36,7 +36,7 @@ */ package br.gov.frameworkdemoiselle.internal.implementation; -import br.gov.frameworkdemoiselle.management.GenericNotification; +import br.gov.frameworkdemoiselle.management.Notification; import br.gov.frameworkdemoiselle.management.NotificationManager; /** @@ -49,17 +49,17 @@ import br.gov.frameworkdemoiselle.management.NotificationManager; */ public class ManagementNotificationEventImpl implements br.gov.frameworkdemoiselle.management.ManagementNotificationEvent { - private GenericNotification notification; + private Notification notification; - public ManagementNotificationEventImpl(GenericNotification notification){ + public ManagementNotificationEventImpl(Notification notification){ this.notification = notification; } - public GenericNotification getNotification() { + public Notification getNotification() { return notification; } - public void setNotification(GenericNotification notification) { + public void setNotification(Notification notification) { this.notification = notification; } } diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/NotificationManagerImpl.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/NotificationManagerImpl.java index a438fcb..d83c585 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/NotificationManagerImpl.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/NotificationManagerImpl.java @@ -39,12 +39,10 @@ package br.gov.frameworkdemoiselle.internal.implementation; import java.io.Serializable; import javax.enterprise.event.Event; -import javax.enterprise.util.AnnotationLiteral; import javax.inject.Inject; -import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; -import br.gov.frameworkdemoiselle.management.GenericNotification; import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent; +import br.gov.frameworkdemoiselle.management.Notification; import br.gov.frameworkdemoiselle.management.NotificationManager; import br.gov.frameworkdemoiselle.util.Beans; @@ -53,45 +51,24 @@ import br.gov.frameworkdemoiselle.util.Beans; public class NotificationManagerImpl implements NotificationManager,Serializable { @Inject - @Generic - private Event genericNotificationEvent; - - @Inject - @AttributeChange - private Event attributeChangeNotificationEvent; + private Event notificationEvent; /** * Sends a generic notification to all management clients. * * @param notification The notification to send */ - public void sendNotification(GenericNotification notification) { - if (! AttributeChangeNotification.class.isInstance(notification) ){ - getGenericNotificationEvent().fire(new ManagementNotificationEventImpl(notification)); - } - else{ - getAttributeChangeNotificationEvent().fire(new ManagementNotificationEventImpl(notification)); - } + public void sendNotification(Notification notification) { + getGenericNotificationEvent().fire(new ManagementNotificationEventImpl(notification)); } @SuppressWarnings("unchecked") private Event getGenericNotificationEvent() { - if (genericNotificationEvent==null){ - genericNotificationEvent = Beans.getReference(Event.class , new AnnotationLiteral() {}); + if (notificationEvent==null){ + notificationEvent = Beans.getReference(Event.class); } - return genericNotificationEvent; + return notificationEvent; } - @SuppressWarnings("unchecked") - private Event getAttributeChangeNotificationEvent() { - if (attributeChangeNotificationEvent==null){ - attributeChangeNotificationEvent = Beans.getReference(Event.class , new AnnotationLiteral() {}); - } - - return attributeChangeNotificationEvent; - } - - - } diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/management/AttributeChangeMessage.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/management/AttributeChangeMessage.java new file mode 100644 index 0000000..ad15d45 --- /dev/null +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/management/AttributeChangeMessage.java @@ -0,0 +1,82 @@ +package br.gov.frameworkdemoiselle.management; + +/** + * Specialized message that can be used to create a {@link Notification} and be sent using {@link NotificationManager#sendNotification(Notification notification)}. + * + * This message contains information about an attribute change. + * + * @author serpro + * + */ +public class AttributeChangeMessage { + + private String description; + + private String attributeName; + + private Class attributeType; + + private Object oldValue; + + private Object newValue; + + public AttributeChangeMessage(){ + } + + public AttributeChangeMessage(String description, String attributeName, Class attributeType, + Object oldValue, Object newValue) { + this.description = description; + this.attributeName = attributeName; + this.attributeType = attributeType; + this.oldValue = oldValue; + this.newValue = newValue; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getAttributeName() { + return attributeName; + } + + + public void setAttributeName(String attributeName) { + this.attributeName = attributeName; + } + + + public Class getAttributeType() { + return attributeType; + } + + + public void setAttributeType(Class attributeType) { + this.attributeType = attributeType; + } + + + public Object getOldValue() { + return oldValue; + } + + + public void setOldValue(Object oldValue) { + this.oldValue = oldValue; + } + + + public Object getNewValue() { + return newValue; + } + + + public void setNewValue(Object newValue) { + this.newValue = newValue; + } + +} diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/management/AttributeChangeNotification.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/management/AttributeChangeNotification.java deleted file mode 100644 index b2758b2..0000000 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/management/AttributeChangeNotification.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Demoiselle Framework - * Copyright (C) 2010 SERPRO - * ---------------------------------------------------------------------------- - * This file is part of Demoiselle Framework. - * - * Demoiselle Framework is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License version 3 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License version 3 - * along with this program; if not, see - * or write to the Free Software Foundation, Inc., 51 Franklin Street, - * Fifth Floor, Boston, MA 02110-1301, USA. - * ---------------------------------------------------------------------------- - * Este arquivo é parte do Framework Demoiselle. - * - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação - * do Software Livre (FSF). - * - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português - * para maiores detalhes. - * - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título - * "LICENCA.txt", junto com esse programa. Se não, acesse - * ou escreva para a Fundação do Software Livre (FSF) Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. - */ -package br.gov.frameworkdemoiselle.management; - -/** - * Special notification to denote an attribute has changed values. - * - * @see GenericNotification - * @author SERPRO - */ -public class AttributeChangeNotification extends GenericNotification { - - private String attributeName; - - private Class attributeType; - - private Object oldValue; - - private Object newValue; - - /** - * Constructor without params. - */ - public AttributeChangeNotification() { - } - - /** - * Set all the class attibutes, according to the parameters received. - * - * @param message - * message to be displayed. - * @param attributeName - * name of the monitored attribute. - * @param attributeType - * type of the monitored attribute. - * @param oldValue - * old value of the monitored attribute. - * @param newValue - * new value for the monitored attribute. - */ - public AttributeChangeNotification(Object message, String attributeName, Class attributeType, - Object oldValue, Object newValue) { - super(message); - this.attributeName = attributeName; - this.attributeType = attributeType; - this.oldValue = oldValue; - this.newValue = newValue; - } - - public String getAttributeName() { - return attributeName; - } - - public void setAttributeName(String attributeName) { - this.attributeName = attributeName; - } - - public Class getAttributeType() { - return attributeType; - } - - public void setAttributeType(Class attributeType) { - this.attributeType = attributeType; - } - - public Object getOldValue() { - return oldValue; - } - - public void setOldValue(Object oldValue) { - this.oldValue = oldValue; - } - - public Object getNewValue() { - return newValue; - } - - public void setNewValue(Object newValue) { - this.newValue = newValue; - } - -} diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/management/GenericNotification.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/management/GenericNotification.java index a778b90..7501d5d 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/management/GenericNotification.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/management/GenericNotification.java @@ -36,13 +36,17 @@ */ package br.gov.frameworkdemoiselle.management; + /** - * Notification that can be sent by the {@link NotificationManager}. + * Notification that can be sent by the {@link NotificationManager}. This generic + * notification only has a simple message. * * @author SERPRO */ -public class GenericNotification { +public class GenericNotification implements Notification { + private static final long serialVersionUID = 4861136187996412275L; + private Object message; /** @@ -70,12 +74,12 @@ public class GenericNotification { this.message = message; } - public Class getType() { + /*public Class getType() { if (message != null) { return message.getClass(); } return null; - } + }*/ } diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/management/ManagementNotificationEvent.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/management/ManagementNotificationEvent.java index 0d10a12..e6af778 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/management/ManagementNotificationEvent.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/management/ManagementNotificationEvent.java @@ -46,6 +46,6 @@ package br.gov.frameworkdemoiselle.management; */ public interface ManagementNotificationEvent { - public GenericNotification getNotification(); + public Notification getNotification(); } diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/management/Notification.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/management/Notification.java new file mode 100644 index 0000000..fb715aa --- /dev/null +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/management/Notification.java @@ -0,0 +1,53 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +package br.gov.frameworkdemoiselle.management; + +import java.io.Serializable; + +/** + * + * A notification is a message an application can send to remote clients, usually to inform + * about events that needs special attention. + * + * @author serpro + * + */ +public interface Notification extends Serializable { + + Object getMessage(); + +} diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/management/NotificationManager.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/management/NotificationManager.java index fae0912..0618484 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/management/NotificationManager.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/management/NotificationManager.java @@ -40,8 +40,6 @@ import javax.enterprise.context.ApplicationScoped; import javax.enterprise.event.Observes; import javax.inject.Inject; -import br.gov.frameworkdemoiselle.internal.implementation.AttributeChange; -import br.gov.frameworkdemoiselle.internal.implementation.Generic; import br.gov.frameworkdemoiselle.util.Beans; /** @@ -55,9 +53,7 @@ import br.gov.frameworkdemoiselle.util.Beans; * is {@link ApplicationScoped}, so you can inject it as many times as needed and still have only one instance per application.

* *

Implementators of management protocols must observe the {@link ManagementNotificationEvent} event (using the {@link Observes} annotation), this way - * they will receive an event containing the original notification and can translate this notification to a specific protocol. Optionaly, - * the implementator can use qualifiers like the {@link Generic} and {@link AttributeChange} qualifiers - * to filter what king of notifications they will handle. One example of an implementator is the demoiselle-jmx extension.

+ * they will receive an event containing the original notification and can translate this notification to a specific protocol.

* * @author SERPRO * @@ -70,6 +66,6 @@ public interface NotificationManager { * * @param notification The notification to send */ - public void sendNotification(GenericNotification notification); + public void sendNotification(Notification notification); } diff --git a/impl/core/src/test/java/management/notification/NotificationTest.java b/impl/core/src/test/java/management/notification/NotificationTest.java index 326a576..e7291ba 100644 --- a/impl/core/src/test/java/management/notification/NotificationTest.java +++ b/impl/core/src/test/java/management/notification/NotificationTest.java @@ -52,8 +52,9 @@ import test.Tests; import br.gov.frameworkdemoiselle.annotation.Name; import br.gov.frameworkdemoiselle.internal.implementation.ManagedType; import br.gov.frameworkdemoiselle.internal.implementation.Management; -import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; +import br.gov.frameworkdemoiselle.management.AttributeChangeMessage; import br.gov.frameworkdemoiselle.management.GenericNotification; +import br.gov.frameworkdemoiselle.management.Notification; import br.gov.frameworkdemoiselle.management.NotificationManager; import br.gov.frameworkdemoiselle.util.Beans; import br.gov.frameworkdemoiselle.util.ResourceBundle; @@ -94,8 +95,9 @@ public class NotificationTest { */ @Test public void sendAttributeChangeNotification() { - manager.sendNotification(new AttributeChangeNotification("Test Message", "attribute", String.class, "old", - "new")); + Notification n = new GenericNotification( new AttributeChangeMessage("Test Message", "attribute", String.class, "old", "new") ); + manager.sendNotification(n); + DummyNotificationListener listener = Beans.getReference(DummyNotificationListener.class); Assert.assertEquals("Test Message - attribute", listener.getMessage()); } diff --git a/impl/core/src/test/java/management/testclasses/DummyNotificationListener.java b/impl/core/src/test/java/management/testclasses/DummyNotificationListener.java index 94fa38a..ee879ba 100644 --- a/impl/core/src/test/java/management/testclasses/DummyNotificationListener.java +++ b/impl/core/src/test/java/management/testclasses/DummyNotificationListener.java @@ -39,9 +39,7 @@ package management.testclasses; import javax.enterprise.context.ApplicationScoped; import javax.enterprise.event.Observes; -import br.gov.frameworkdemoiselle.internal.implementation.AttributeChange; -import br.gov.frameworkdemoiselle.internal.implementation.Generic; -import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; +import br.gov.frameworkdemoiselle.management.AttributeChangeMessage; import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent; import br.gov.frameworkdemoiselle.management.NotificationManager; @@ -56,13 +54,16 @@ public class DummyNotificationListener { private String message = null; - public void listenNotification(@Observes @Generic ManagementNotificationEvent event){ - message = event.getNotification().getMessage().toString(); - } - - public void listenAttributeChangeNotification(@Observes @AttributeChange ManagementNotificationEvent event){ - AttributeChangeNotification notification = (AttributeChangeNotification)event.getNotification(); - message = notification.getMessage().toString() + " - " + notification.getAttributeName(); + public void listenNotification(@Observes ManagementNotificationEvent event){ + Object lMessage = event.getNotification().getMessage(); + + if (AttributeChangeMessage.class.isInstance(lMessage)){ + AttributeChangeMessage lAttrMessage = (AttributeChangeMessage)lMessage; + message = lAttrMessage.getDescription() + " - " + lAttrMessage.getAttributeName(); + } + else{ + message = lMessage.toString(); + } } public String getMessage() { diff --git a/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/NotificationBroadcaster.java b/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/NotificationBroadcaster.java index db246f6..a3c1bd9 100644 --- a/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/NotificationBroadcaster.java +++ b/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/NotificationBroadcaster.java @@ -37,12 +37,14 @@ package br.gov.frameworkdemoiselle.internal.implementation; import java.io.Serializable; +import java.util.concurrent.atomic.AtomicInteger; import javax.management.AttributeChangeNotification; import javax.management.Notification; import javax.management.NotificationBroadcasterSupport; import br.gov.frameworkdemoiselle.internal.configuration.JMXConfig; +import br.gov.frameworkdemoiselle.management.AttributeChangeMessage; import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent; import br.gov.frameworkdemoiselle.management.NotificationManager; @@ -58,25 +60,26 @@ public final class NotificationBroadcaster extends NotificationBroadcasterSuppor private static final long serialVersionUID = 1L; - private int sequenceNumber = 1; + private AtomicInteger sequence = new AtomicInteger(); private static final String NOTIFICATION_TYPE_GENERIC = "jmx.message"; protected void sendNotification( ManagementNotificationEvent event , JMXConfig config ) { - br.gov.frameworkdemoiselle.management.GenericNotification demoiselleNotification = event.getNotification(); - Notification n = new Notification(NOTIFICATION_TYPE_GENERIC, config.getNotificationMBeanName(), sequenceNumber++, System.currentTimeMillis(), demoiselleNotification.getMessage().toString()); - sendNotification(n); - } - - protected void sendAttributeChangedMessage( ManagementNotificationEvent event , JMXConfig config ) { - br.gov.frameworkdemoiselle.management.AttributeChangeNotification demoiselleNotification = (br.gov.frameworkdemoiselle.management.AttributeChangeNotification)event.getNotification(); - - AttributeChangeNotification n = new AttributeChangeNotification(config.getNotificationMBeanName(), sequenceNumber++ - , System.currentTimeMillis(), demoiselleNotification.getMessage().toString() - , demoiselleNotification.getAttributeName(), demoiselleNotification.getAttributeType().getSimpleName() - , demoiselleNotification.getOldValue(), demoiselleNotification.getNewValue()); + br.gov.frameworkdemoiselle.management.Notification demoiselleNotification = event.getNotification(); + Object message = demoiselleNotification.getMessage(); + Notification n; + if (AttributeChangeMessage.class.isInstance( message )){ + AttributeChangeMessage attributeChangeMessage = (AttributeChangeMessage) message; + + n = new AttributeChangeNotification(config.getNotificationMBeanName(), sequence.incrementAndGet() + , System.currentTimeMillis(), attributeChangeMessage.getDescription() + , attributeChangeMessage.getAttributeName(), attributeChangeMessage.getAttributeType().getSimpleName() + , attributeChangeMessage.getOldValue(), attributeChangeMessage.getNewValue()); + } + else{ + n = new Notification(NOTIFICATION_TYPE_GENERIC, config.getNotificationMBeanName(), sequence.incrementAndGet(), System.currentTimeMillis(), demoiselleNotification.getMessage().toString()); + } sendNotification(n); } - } diff --git a/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/NotificationEventListener.java b/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/NotificationEventListener.java index f77bd18..492056b 100644 --- a/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/NotificationEventListener.java +++ b/impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/NotificationEventListener.java @@ -59,14 +59,10 @@ public class NotificationEventListener implements Serializable { private NotificationBroadcaster notificationBroadcaster; - public void sendNotification( @Observes @Generic ManagementNotificationEvent event , JMXConfig config ) { + public void sendNotification( @Observes ManagementNotificationEvent event , JMXConfig config ) { createNotificationBroadcaster().sendNotification(event,config); } - public void sendAttributeChangedMessage( @Observes @AttributeChange ManagementNotificationEvent event , JMXConfig config ) { - createNotificationBroadcaster().sendAttributeChangedMessage(event, config); - } - public NotificationBroadcaster createNotificationBroadcaster(){ if (notificationBroadcaster==null){ notificationBroadcaster = new NotificationBroadcaster(); @@ -74,5 +70,4 @@ public class NotificationEventListener implements Serializable { return notificationBroadcaster; } - } diff --git a/impl/extension/jmx/src/test/java/management/tests/notification/NotificationBroadcasterTest.java b/impl/extension/jmx/src/test/java/management/tests/notification/NotificationBroadcasterTest.java index d218cbf..10398bc 100644 --- a/impl/extension/jmx/src/test/java/management/tests/notification/NotificationBroadcasterTest.java +++ b/impl/extension/jmx/src/test/java/management/tests/notification/NotificationBroadcasterTest.java @@ -61,8 +61,9 @@ import br.gov.frameworkdemoiselle.internal.configuration.JMXConfig; import br.gov.frameworkdemoiselle.internal.implementation.MBeanManager; import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; import br.gov.frameworkdemoiselle.lifecycle.AfterStartupProccess; -import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; +import br.gov.frameworkdemoiselle.management.AttributeChangeMessage; import br.gov.frameworkdemoiselle.management.GenericNotification; +import br.gov.frameworkdemoiselle.management.Notification; import br.gov.frameworkdemoiselle.management.NotificationManager; import br.gov.frameworkdemoiselle.util.Beans; @@ -171,8 +172,7 @@ public class NotificationBroadcasterTest { } // Manda a notificação pelo Demoiselle - AttributeChangeNotification notification = new AttributeChangeNotification("Attribute Changed", "name", - String.class, "Demoiselle 1", "Demoiselle 2"); + Notification notification = new GenericNotification( new AttributeChangeMessage("Attribute Changed", "name", String.class, "Demoiselle 1", "Demoiselle 2") ); notificationManager.sendNotification(notification); // Se o componente funcionou, o Demoiselle propagou a notificação para o servidor MBean e o listener preencheu -- libgit2 0.21.2