Commit 6f0226752556a42b8995df65afbb9e6b75facc36
1 parent
43c92def
Exists in
master
Refatoradas classes de monitoração para melhor separar interface de
implementação.
Showing
15 changed files
with
240 additions
and
202 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/NotificationManagerImpl.java
0 → 100644
| @@ -0,0 +1,64 @@ | @@ -0,0 +1,64 @@ | ||
| 1 | +package br.gov.frameworkdemoiselle.internal.implementation; | ||
| 2 | + | ||
| 3 | +import java.io.Serializable; | ||
| 4 | + | ||
| 5 | +import javax.enterprise.event.Event; | ||
| 6 | +import javax.enterprise.util.AnnotationLiteral; | ||
| 7 | +import javax.inject.Inject; | ||
| 8 | + | ||
| 9 | +import br.gov.frameworkdemoiselle.internal.management.ManagementNotificationEventImpl; | ||
| 10 | +import br.gov.frameworkdemoiselle.internal.management.qualifier.AttributeChange; | ||
| 11 | +import br.gov.frameworkdemoiselle.internal.management.qualifier.Generic; | ||
| 12 | +import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; | ||
| 13 | +import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent; | ||
| 14 | +import br.gov.frameworkdemoiselle.management.GenericNotification; | ||
| 15 | +import br.gov.frameworkdemoiselle.management.NotificationManager; | ||
| 16 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
| 17 | + | ||
| 18 | + | ||
| 19 | +@SuppressWarnings("serial") | ||
| 20 | +public class NotificationManagerImpl implements NotificationManager,Serializable { | ||
| 21 | + | ||
| 22 | + @Inject | ||
| 23 | + @Generic | ||
| 24 | + private Event<ManagementNotificationEvent> genericNotificationEvent; | ||
| 25 | + | ||
| 26 | + @Inject | ||
| 27 | + @AttributeChange | ||
| 28 | + private Event<ManagementNotificationEvent> attributeChangeNotificationEvent; | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * Sends a generic notification to all management clients. | ||
| 32 | + * | ||
| 33 | + * @param notification The notification to send | ||
| 34 | + */ | ||
| 35 | + public void sendNotification(GenericNotification notification) { | ||
| 36 | + if (! AttributeChangeNotification.class.isInstance(notification) ){ | ||
| 37 | + getGenericNotificationEvent().fire(new ManagementNotificationEventImpl(notification)); | ||
| 38 | + } | ||
| 39 | + else{ | ||
| 40 | + getAttributeChangeNotificationEvent().fire(new ManagementNotificationEventImpl(notification)); | ||
| 41 | + } | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + @SuppressWarnings("unchecked") | ||
| 45 | + private Event<ManagementNotificationEvent> getGenericNotificationEvent() { | ||
| 46 | + if (genericNotificationEvent==null){ | ||
| 47 | + genericNotificationEvent = Beans.getReference(Event.class , new AnnotationLiteral<Generic>() {}); | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + return genericNotificationEvent; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + @SuppressWarnings("unchecked") | ||
| 54 | + private Event<ManagementNotificationEvent> getAttributeChangeNotificationEvent() { | ||
| 55 | + if (attributeChangeNotificationEvent==null){ | ||
| 56 | + attributeChangeNotificationEvent = Beans.getReference(Event.class , new AnnotationLiteral<AttributeChange>() {}); | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + return attributeChangeNotificationEvent; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + | ||
| 63 | + | ||
| 64 | +} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/management/ManagementNotificationEvent.java
| @@ -1,65 +0,0 @@ | @@ -1,65 +0,0 @@ | ||
| 1 | -/* | ||
| 2 | - * Demoiselle Framework | ||
| 3 | - * Copyright (C) 2010 SERPRO | ||
| 4 | - * ---------------------------------------------------------------------------- | ||
| 5 | - * This file is part of Demoiselle Framework. | ||
| 6 | - * | ||
| 7 | - * Demoiselle Framework is free software; you can redistribute it and/or | ||
| 8 | - * modify it under the terms of the GNU Lesser General Public License version 3 | ||
| 9 | - * as published by the Free Software Foundation. | ||
| 10 | - * | ||
| 11 | - * This program is distributed in the hope that it will be useful, | ||
| 12 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | - * GNU General Public License for more details. | ||
| 15 | - * | ||
| 16 | - * You should have received a copy of the GNU Lesser General Public License version 3 | ||
| 17 | - * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
| 18 | - * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
| 19 | - * Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 20 | - * ---------------------------------------------------------------------------- | ||
| 21 | - * Este arquivo é parte do Framework Demoiselle. | ||
| 22 | - * | ||
| 23 | - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
| 24 | - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
| 25 | - * do Software Livre (FSF). | ||
| 26 | - * | ||
| 27 | - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
| 28 | - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
| 29 | - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
| 30 | - * para maiores detalhes. | ||
| 31 | - * | ||
| 32 | - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
| 33 | - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
| 34 | - * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
| 35 | - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
| 36 | - */ | ||
| 37 | -package br.gov.frameworkdemoiselle.internal.management; | ||
| 38 | - | ||
| 39 | -import br.gov.frameworkdemoiselle.management.Notification; | ||
| 40 | -import br.gov.frameworkdemoiselle.management.NotificationManager; | ||
| 41 | - | ||
| 42 | -/** | ||
| 43 | - * Event fired when a notification is sent by {@link NotificationManager}. | ||
| 44 | - * Implementators can capture this event and be notified when the {@link NotificationManager} | ||
| 45 | - * sends notifications, so they can pass the notification to the underlying technology. | ||
| 46 | - * | ||
| 47 | - * @author serpro | ||
| 48 | - * | ||
| 49 | - */ | ||
| 50 | -public class ManagementNotificationEvent { | ||
| 51 | - | ||
| 52 | - private Notification notification; | ||
| 53 | - | ||
| 54 | - public ManagementNotificationEvent(Notification notification){ | ||
| 55 | - this.notification = notification; | ||
| 56 | - } | ||
| 57 | - | ||
| 58 | - public Notification getNotification() { | ||
| 59 | - return notification; | ||
| 60 | - } | ||
| 61 | - | ||
| 62 | - public void setNotification(Notification notification) { | ||
| 63 | - this.notification = notification; | ||
| 64 | - } | ||
| 65 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/management/ManagementNotificationEventImpl.java
0 → 100644
| @@ -0,0 +1,65 @@ | @@ -0,0 +1,65 @@ | ||
| 1 | +/* | ||
| 2 | + * Demoiselle Framework | ||
| 3 | + * Copyright (C) 2010 SERPRO | ||
| 4 | + * ---------------------------------------------------------------------------- | ||
| 5 | + * This file is part of Demoiselle Framework. | ||
| 6 | + * | ||
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
| 9 | + * as published by the Free Software Foundation. | ||
| 10 | + * | ||
| 11 | + * This program is distributed in the hope that it will be useful, | ||
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | + * GNU General Public License for more details. | ||
| 15 | + * | ||
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 20 | + * ---------------------------------------------------------------------------- | ||
| 21 | + * Este arquivo é parte do Framework Demoiselle. | ||
| 22 | + * | ||
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
| 25 | + * do Software Livre (FSF). | ||
| 26 | + * | ||
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
| 30 | + * para maiores detalhes. | ||
| 31 | + * | ||
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
| 36 | + */ | ||
| 37 | +package br.gov.frameworkdemoiselle.internal.management; | ||
| 38 | + | ||
| 39 | +import br.gov.frameworkdemoiselle.management.GenericNotification; | ||
| 40 | +import br.gov.frameworkdemoiselle.management.NotificationManager; | ||
| 41 | + | ||
| 42 | +/** | ||
| 43 | + * Event fired when a notification is sent by {@link NotificationManager}. | ||
| 44 | + * Implementators can capture this event and be notified when the {@link NotificationManager} | ||
| 45 | + * sends notifications, so they can pass the notification to the underlying technology. | ||
| 46 | + * | ||
| 47 | + * @author serpro | ||
| 48 | + * | ||
| 49 | + */ | ||
| 50 | +public class ManagementNotificationEventImpl implements br.gov.frameworkdemoiselle.management.ManagementNotificationEvent { | ||
| 51 | + | ||
| 52 | + private GenericNotification notification; | ||
| 53 | + | ||
| 54 | + public ManagementNotificationEventImpl(GenericNotification notification){ | ||
| 55 | + this.notification = notification; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + public GenericNotification getNotification() { | ||
| 59 | + return notification; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + public void setNotification(GenericNotification notification) { | ||
| 63 | + this.notification = notification; | ||
| 64 | + } | ||
| 65 | +} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/management/qualifier/AttributeChange.java
| @@ -43,8 +43,8 @@ import java.lang.annotation.Target; | @@ -43,8 +43,8 @@ import java.lang.annotation.Target; | ||
| 43 | 43 | ||
| 44 | import javax.inject.Qualifier; | 44 | import javax.inject.Qualifier; |
| 45 | 45 | ||
| 46 | -import br.gov.frameworkdemoiselle.internal.management.ManagementNotificationEvent; | ||
| 47 | import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; | 46 | import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; |
| 47 | +import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent; | ||
| 48 | 48 | ||
| 49 | /** | 49 | /** |
| 50 | * | 50 | * |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/management/qualifier/Generic.java
| @@ -43,13 +43,13 @@ import java.lang.annotation.Target; | @@ -43,13 +43,13 @@ import java.lang.annotation.Target; | ||
| 43 | 43 | ||
| 44 | import javax.inject.Qualifier; | 44 | import javax.inject.Qualifier; |
| 45 | 45 | ||
| 46 | -import br.gov.frameworkdemoiselle.internal.management.ManagementNotificationEvent; | ||
| 47 | -import br.gov.frameworkdemoiselle.management.Notification; | 46 | +import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent; |
| 47 | +import br.gov.frameworkdemoiselle.management.GenericNotification; | ||
| 48 | 48 | ||
| 49 | /** | 49 | /** |
| 50 | * | 50 | * |
| 51 | * Enables {@link ManagementNotificationEvent} observers to trigger only with notifications | 51 | * Enables {@link ManagementNotificationEvent} observers to trigger only with notifications |
| 52 | - * of the base type {@link Notification}. | 52 | + * of the base type {@link GenericNotification}. |
| 53 | * | 53 | * |
| 54 | * @author serpro | 54 | * @author serpro |
| 55 | * | 55 | * |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/AttributeChangeNotification.java
| @@ -39,12 +39,12 @@ package br.gov.frameworkdemoiselle.management; | @@ -39,12 +39,12 @@ package br.gov.frameworkdemoiselle.management; | ||
| 39 | /** | 39 | /** |
| 40 | * Special notification to denote an attribute has changed values. | 40 | * Special notification to denote an attribute has changed values. |
| 41 | * | 41 | * |
| 42 | - * @see Notification | 42 | + * @see GenericNotification |
| 43 | * | 43 | * |
| 44 | * @author serpro | 44 | * @author serpro |
| 45 | * | 45 | * |
| 46 | */ | 46 | */ |
| 47 | -public class AttributeChangeNotification extends Notification { | 47 | +public class AttributeChangeNotification extends GenericNotification { |
| 48 | 48 | ||
| 49 | private String attributeName; | 49 | private String attributeName; |
| 50 | 50 |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/GenericNotification.java
0 → 100644
| @@ -0,0 +1,77 @@ | @@ -0,0 +1,77 @@ | ||
| 1 | +/* | ||
| 2 | + * Demoiselle Framework | ||
| 3 | + * Copyright (C) 2010 SERPRO | ||
| 4 | + * ---------------------------------------------------------------------------- | ||
| 5 | + * This file is part of Demoiselle Framework. | ||
| 6 | + * | ||
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
| 9 | + * as published by the Free Software Foundation. | ||
| 10 | + * | ||
| 11 | + * This program is distributed in the hope that it will be useful, | ||
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | + * GNU General Public License for more details. | ||
| 15 | + * | ||
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 20 | + * ---------------------------------------------------------------------------- | ||
| 21 | + * Este arquivo é parte do Framework Demoiselle. | ||
| 22 | + * | ||
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
| 25 | + * do Software Livre (FSF). | ||
| 26 | + * | ||
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
| 30 | + * para maiores detalhes. | ||
| 31 | + * | ||
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
| 36 | + */ | ||
| 37 | +package br.gov.frameworkdemoiselle.management; | ||
| 38 | + | ||
| 39 | +/** | ||
| 40 | + * | ||
| 41 | + * Notification that can be sent by the {@link NotificationManager}. | ||
| 42 | + * | ||
| 43 | + * @author serpro | ||
| 44 | + * | ||
| 45 | + */ | ||
| 46 | +public class GenericNotification { | ||
| 47 | + | ||
| 48 | + private Object message; | ||
| 49 | + | ||
| 50 | + public GenericNotification(){ | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + public GenericNotification(Object message) { | ||
| 54 | + super(); | ||
| 55 | + this.message = message; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + | ||
| 59 | + public Object getMessage() { | ||
| 60 | + return message; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + | ||
| 64 | + public void setMessage(Object message) { | ||
| 65 | + this.message = message; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + | ||
| 69 | + public Class<? extends Object> getType() { | ||
| 70 | + if (message!=null){ | ||
| 71 | + return message.getClass(); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + return null; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | +} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/ManagementNotificationEvent.java
0 → 100644
| @@ -0,0 +1,15 @@ | @@ -0,0 +1,15 @@ | ||
| 1 | +package br.gov.frameworkdemoiselle.management; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * Event fired when a notification is sent by {@link NotificationManager}. | ||
| 5 | + * Implementators can capture this event and be notified when the {@link NotificationManager} | ||
| 6 | + * sends notifications, so they can pass the notification to the underlying technology. | ||
| 7 | + * | ||
| 8 | + * @author serpro | ||
| 9 | + * | ||
| 10 | + */ | ||
| 11 | +public interface ManagementNotificationEvent { | ||
| 12 | + | ||
| 13 | + public GenericNotification getNotification(); | ||
| 14 | + | ||
| 15 | +} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/Notification.java
| @@ -1,77 +0,0 @@ | @@ -1,77 +0,0 @@ | ||
| 1 | -/* | ||
| 2 | - * Demoiselle Framework | ||
| 3 | - * Copyright (C) 2010 SERPRO | ||
| 4 | - * ---------------------------------------------------------------------------- | ||
| 5 | - * This file is part of Demoiselle Framework. | ||
| 6 | - * | ||
| 7 | - * Demoiselle Framework is free software; you can redistribute it and/or | ||
| 8 | - * modify it under the terms of the GNU Lesser General Public License version 3 | ||
| 9 | - * as published by the Free Software Foundation. | ||
| 10 | - * | ||
| 11 | - * This program is distributed in the hope that it will be useful, | ||
| 12 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | - * GNU General Public License for more details. | ||
| 15 | - * | ||
| 16 | - * You should have received a copy of the GNU Lesser General Public License version 3 | ||
| 17 | - * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
| 18 | - * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
| 19 | - * Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 20 | - * ---------------------------------------------------------------------------- | ||
| 21 | - * Este arquivo é parte do Framework Demoiselle. | ||
| 22 | - * | ||
| 23 | - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
| 24 | - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
| 25 | - * do Software Livre (FSF). | ||
| 26 | - * | ||
| 27 | - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
| 28 | - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
| 29 | - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
| 30 | - * para maiores detalhes. | ||
| 31 | - * | ||
| 32 | - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
| 33 | - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
| 34 | - * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
| 35 | - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
| 36 | - */ | ||
| 37 | -package br.gov.frameworkdemoiselle.management; | ||
| 38 | - | ||
| 39 | -/** | ||
| 40 | - * | ||
| 41 | - * Notification that can be sent by the {@link NotificationManager}. | ||
| 42 | - * | ||
| 43 | - * @author serpro | ||
| 44 | - * | ||
| 45 | - */ | ||
| 46 | -public class Notification { | ||
| 47 | - | ||
| 48 | - private Object message; | ||
| 49 | - | ||
| 50 | - public Notification(){ | ||
| 51 | - } | ||
| 52 | - | ||
| 53 | - public Notification(Object message) { | ||
| 54 | - super(); | ||
| 55 | - this.message = message; | ||
| 56 | - } | ||
| 57 | - | ||
| 58 | - | ||
| 59 | - public Object getMessage() { | ||
| 60 | - return message; | ||
| 61 | - } | ||
| 62 | - | ||
| 63 | - | ||
| 64 | - public void setMessage(Object message) { | ||
| 65 | - this.message = message; | ||
| 66 | - } | ||
| 67 | - | ||
| 68 | - | ||
| 69 | - public Class<? extends Object> getType() { | ||
| 70 | - if (message!=null){ | ||
| 71 | - return message.getClass(); | ||
| 72 | - } | ||
| 73 | - | ||
| 74 | - return null; | ||
| 75 | - } | ||
| 76 | - | ||
| 77 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/NotificationManager.java
| @@ -36,23 +36,18 @@ | @@ -36,23 +36,18 @@ | ||
| 36 | */ | 36 | */ |
| 37 | package br.gov.frameworkdemoiselle.management; | 37 | package br.gov.frameworkdemoiselle.management; |
| 38 | 38 | ||
| 39 | -import java.io.Serializable; | ||
| 40 | - | ||
| 41 | import javax.enterprise.context.ApplicationScoped; | 39 | import javax.enterprise.context.ApplicationScoped; |
| 42 | -import javax.enterprise.event.Event; | ||
| 43 | import javax.enterprise.event.Observes; | 40 | import javax.enterprise.event.Observes; |
| 44 | -import javax.enterprise.util.AnnotationLiteral; | ||
| 45 | import javax.inject.Inject; | 41 | import javax.inject.Inject; |
| 46 | 42 | ||
| 47 | -import br.gov.frameworkdemoiselle.internal.management.ManagementNotificationEvent; | ||
| 48 | import br.gov.frameworkdemoiselle.internal.management.qualifier.AttributeChange; | 43 | import br.gov.frameworkdemoiselle.internal.management.qualifier.AttributeChange; |
| 49 | import br.gov.frameworkdemoiselle.internal.management.qualifier.Generic; | 44 | import br.gov.frameworkdemoiselle.internal.management.qualifier.Generic; |
| 50 | import br.gov.frameworkdemoiselle.util.Beans; | 45 | import br.gov.frameworkdemoiselle.util.Beans; |
| 51 | 46 | ||
| 52 | /** | 47 | /** |
| 53 | * | 48 | * |
| 54 | - * <p>Central class to manage sending notifications to management clients. | ||
| 55 | - * This class allows applications to send management notifications without | 49 | + * <p>Central type to manage sending notifications to management clients. |
| 50 | + * This interface allows applications to send management notifications without | ||
| 56 | * knowledge of the technology used to send those notifications.</p> | 51 | * knowledge of the technology used to send those notifications.</p> |
| 57 | * | 52 | * |
| 58 | * <p>To obtain an instance of the {@link NotificationManager} simply inject it in | 53 | * <p>To obtain an instance of the {@link NotificationManager} simply inject it in |
| @@ -68,49 +63,13 @@ import br.gov.frameworkdemoiselle.util.Beans; | @@ -68,49 +63,13 @@ import br.gov.frameworkdemoiselle.util.Beans; | ||
| 68 | * | 63 | * |
| 69 | */ | 64 | */ |
| 70 | @ApplicationScoped | 65 | @ApplicationScoped |
| 71 | -@SuppressWarnings("serial") | ||
| 72 | -public class NotificationManager implements Serializable{ | ||
| 73 | - | ||
| 74 | - @Inject | ||
| 75 | - @Generic | ||
| 76 | - private Event<ManagementNotificationEvent> genericNotificationEvent; | ||
| 77 | - | ||
| 78 | - @Inject | ||
| 79 | - @AttributeChange | ||
| 80 | - private Event<ManagementNotificationEvent> attributeChangeNotificationEvent; | 66 | +public interface NotificationManager { |
| 81 | 67 | ||
| 82 | /** | 68 | /** |
| 83 | - * Sends a generic notification to all management clients. | 69 | + * Sends a notification to all management clients. |
| 84 | * | 70 | * |
| 85 | * @param notification The notification to send | 71 | * @param notification The notification to send |
| 86 | */ | 72 | */ |
| 87 | - public void sendNotification(Notification notification) { | ||
| 88 | - if (! AttributeChangeNotification.class.isInstance(notification) ){ | ||
| 89 | - getGenericNotificationEvent().fire(new ManagementNotificationEvent(notification)); | ||
| 90 | - } | ||
| 91 | - else{ | ||
| 92 | - getAttributeChangeNotificationEvent().fire(new ManagementNotificationEvent(notification)); | ||
| 93 | - } | ||
| 94 | - } | 73 | + public void sendNotification(GenericNotification notification); |
| 95 | 74 | ||
| 96 | - @SuppressWarnings("unchecked") | ||
| 97 | - private Event<ManagementNotificationEvent> getGenericNotificationEvent() { | ||
| 98 | - if (genericNotificationEvent==null){ | ||
| 99 | - genericNotificationEvent = Beans.getReference(Event.class , new AnnotationLiteral<Generic>() {}); | ||
| 100 | - } | ||
| 101 | - | ||
| 102 | - return genericNotificationEvent; | ||
| 103 | - } | ||
| 104 | - | ||
| 105 | - @SuppressWarnings("unchecked") | ||
| 106 | - private Event<ManagementNotificationEvent> getAttributeChangeNotificationEvent() { | ||
| 107 | - if (attributeChangeNotificationEvent==null){ | ||
| 108 | - attributeChangeNotificationEvent = Beans.getReference(Event.class , new AnnotationLiteral<AttributeChange>() {}); | ||
| 109 | - } | ||
| 110 | - | ||
| 111 | - return attributeChangeNotificationEvent; | ||
| 112 | - } | ||
| 113 | - | ||
| 114 | - | ||
| 115 | - | ||
| 116 | } | 75 | } |
impl/core/src/test/java/management/NotificationTestCase.java
| @@ -57,7 +57,7 @@ import br.gov.frameworkdemoiselle.annotation.Name; | @@ -57,7 +57,7 @@ import br.gov.frameworkdemoiselle.annotation.Name; | ||
| 57 | import br.gov.frameworkdemoiselle.internal.management.ManagedType; | 57 | import br.gov.frameworkdemoiselle.internal.management.ManagedType; |
| 58 | import br.gov.frameworkdemoiselle.internal.management.Management; | 58 | import br.gov.frameworkdemoiselle.internal.management.Management; |
| 59 | import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; | 59 | import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; |
| 60 | -import br.gov.frameworkdemoiselle.management.Notification; | 60 | +import br.gov.frameworkdemoiselle.management.GenericNotification; |
| 61 | import br.gov.frameworkdemoiselle.management.NotificationManager; | 61 | import br.gov.frameworkdemoiselle.management.NotificationManager; |
| 62 | import br.gov.frameworkdemoiselle.util.Beans; | 62 | import br.gov.frameworkdemoiselle.util.Beans; |
| 63 | import br.gov.frameworkdemoiselle.util.ResourceBundle; | 63 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| @@ -98,7 +98,7 @@ public class NotificationTestCase { | @@ -98,7 +98,7 @@ public class NotificationTestCase { | ||
| 98 | */ | 98 | */ |
| 99 | @Test | 99 | @Test |
| 100 | public void testSendGenericNotification(){ | 100 | public void testSendGenericNotification(){ |
| 101 | - manager.sendNotification(new Notification("Test Message")); | 101 | + manager.sendNotification(new GenericNotification("Test Message")); |
| 102 | DummyNotificationListener listener = Beans.getReference(DummyNotificationListener.class); | 102 | DummyNotificationListener listener = Beans.getReference(DummyNotificationListener.class); |
| 103 | Assert.assertEquals("Test Message", listener.getMessage()); | 103 | Assert.assertEquals("Test Message", listener.getMessage()); |
| 104 | } | 104 | } |
impl/core/src/test/java/management/testclasses/DummyNotificationListener.java
| @@ -39,10 +39,10 @@ package management.testclasses; | @@ -39,10 +39,10 @@ package management.testclasses; | ||
| 39 | import javax.enterprise.context.ApplicationScoped; | 39 | import javax.enterprise.context.ApplicationScoped; |
| 40 | import javax.enterprise.event.Observes; | 40 | import javax.enterprise.event.Observes; |
| 41 | 41 | ||
| 42 | -import br.gov.frameworkdemoiselle.internal.management.ManagementNotificationEvent; | ||
| 43 | import br.gov.frameworkdemoiselle.internal.management.qualifier.AttributeChange; | 42 | import br.gov.frameworkdemoiselle.internal.management.qualifier.AttributeChange; |
| 44 | import br.gov.frameworkdemoiselle.internal.management.qualifier.Generic; | 43 | import br.gov.frameworkdemoiselle.internal.management.qualifier.Generic; |
| 45 | import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; | 44 | import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; |
| 45 | +import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent; | ||
| 46 | import br.gov.frameworkdemoiselle.management.NotificationManager; | 46 | import br.gov.frameworkdemoiselle.management.NotificationManager; |
| 47 | 47 | ||
| 48 | /** | 48 | /** |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/jmx/internal/NotificationBroadcaster.java
| @@ -42,8 +42,8 @@ import javax.management.AttributeChangeNotification; | @@ -42,8 +42,8 @@ import javax.management.AttributeChangeNotification; | ||
| 42 | import javax.management.Notification; | 42 | import javax.management.Notification; |
| 43 | import javax.management.NotificationBroadcasterSupport; | 43 | import javax.management.NotificationBroadcasterSupport; |
| 44 | 44 | ||
| 45 | -import br.gov.frameworkdemoiselle.internal.management.ManagementNotificationEvent; | ||
| 46 | import br.gov.frameworkdemoiselle.jmx.configuration.JMXConfig; | 45 | import br.gov.frameworkdemoiselle.jmx.configuration.JMXConfig; |
| 46 | +import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent; | ||
| 47 | import br.gov.frameworkdemoiselle.management.NotificationManager; | 47 | import br.gov.frameworkdemoiselle.management.NotificationManager; |
| 48 | 48 | ||
| 49 | /** | 49 | /** |
| @@ -67,7 +67,7 @@ final class NotificationBroadcaster extends NotificationBroadcasterSupport imple | @@ -67,7 +67,7 @@ final class NotificationBroadcaster extends NotificationBroadcasterSupport imple | ||
| 67 | private static final String NOTIFICATION_TYPE_GENERIC = "jmx.message"; | 67 | private static final String NOTIFICATION_TYPE_GENERIC = "jmx.message"; |
| 68 | 68 | ||
| 69 | protected void sendNotification( ManagementNotificationEvent event , JMXConfig config ) { | 69 | protected void sendNotification( ManagementNotificationEvent event , JMXConfig config ) { |
| 70 | - br.gov.frameworkdemoiselle.management.Notification demoiselleNotification = event.getNotification(); | 70 | + br.gov.frameworkdemoiselle.management.GenericNotification demoiselleNotification = event.getNotification(); |
| 71 | Notification n = new Notification(NOTIFICATION_TYPE_GENERIC, config.getNotificationMBeanName(), sequenceNumber++, System.currentTimeMillis(), demoiselleNotification.getMessage().toString()); | 71 | Notification n = new Notification(NOTIFICATION_TYPE_GENERIC, config.getNotificationMBeanName(), sequenceNumber++, System.currentTimeMillis(), demoiselleNotification.getMessage().toString()); |
| 72 | sendNotification(n); | 72 | sendNotification(n); |
| 73 | } | 73 | } |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/jmx/internal/NotificationEventListener.java
| @@ -41,10 +41,10 @@ import java.io.Serializable; | @@ -41,10 +41,10 @@ import java.io.Serializable; | ||
| 41 | import javax.enterprise.context.ApplicationScoped; | 41 | import javax.enterprise.context.ApplicationScoped; |
| 42 | import javax.enterprise.event.Observes; | 42 | import javax.enterprise.event.Observes; |
| 43 | 43 | ||
| 44 | -import br.gov.frameworkdemoiselle.internal.management.ManagementNotificationEvent; | ||
| 45 | import br.gov.frameworkdemoiselle.internal.management.qualifier.AttributeChange; | 44 | import br.gov.frameworkdemoiselle.internal.management.qualifier.AttributeChange; |
| 46 | import br.gov.frameworkdemoiselle.internal.management.qualifier.Generic; | 45 | import br.gov.frameworkdemoiselle.internal.management.qualifier.Generic; |
| 47 | import br.gov.frameworkdemoiselle.jmx.configuration.JMXConfig; | 46 | import br.gov.frameworkdemoiselle.jmx.configuration.JMXConfig; |
| 47 | +import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent; | ||
| 48 | import br.gov.frameworkdemoiselle.management.NotificationManager; | 48 | import br.gov.frameworkdemoiselle.management.NotificationManager; |
| 49 | 49 | ||
| 50 | /** | 50 | /** |
impl/extension/jmx/src/test/java/management/tests/internal/NotificationBroadcasterTestCase.java
| @@ -61,7 +61,7 @@ import org.junit.runner.RunWith; | @@ -61,7 +61,7 @@ import org.junit.runner.RunWith; | ||
| 61 | import br.gov.frameworkdemoiselle.jmx.configuration.JMXConfig; | 61 | import br.gov.frameworkdemoiselle.jmx.configuration.JMXConfig; |
| 62 | import br.gov.frameworkdemoiselle.jmx.internal.MBeanManager; | 62 | import br.gov.frameworkdemoiselle.jmx.internal.MBeanManager; |
| 63 | import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; | 63 | import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; |
| 64 | -import br.gov.frameworkdemoiselle.management.Notification; | 64 | +import br.gov.frameworkdemoiselle.management.GenericNotification; |
| 65 | import br.gov.frameworkdemoiselle.management.NotificationManager; | 65 | import br.gov.frameworkdemoiselle.management.NotificationManager; |
| 66 | import br.gov.frameworkdemoiselle.util.Beans; | 66 | import br.gov.frameworkdemoiselle.util.Beans; |
| 67 | 67 | ||
| @@ -122,7 +122,7 @@ public class NotificationBroadcasterTestCase { | @@ -122,7 +122,7 @@ public class NotificationBroadcasterTestCase { | ||
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | //Manda a notificação pelo Demoiselle | 124 | //Manda a notificação pelo Demoiselle |
| 125 | - Notification n = new Notification("Notification test successful"); | 125 | + GenericNotification n = new GenericNotification("Notification test successful"); |
| 126 | notificationManager.sendNotification(n); | 126 | notificationManager.sendNotification(n); |
| 127 | 127 | ||
| 128 | //Se o componente funcionou, o Demoiselle propagou a notificação para o servidor MBean e o listener preencheu | 128 | //Se o componente funcionou, o Demoiselle propagou a notificação para o servidor MBean e o listener preencheu |