Commit b1e021f07a954fe1e91d3a9bd0b029bddfd853d2

Authored by Luciano Borges
2 parents 598113c0 e742f58b
Exists in master

Merge branch 'master' of git@github.com:demoiselle/framework.git

documentation/reference/pt-BR/gerenciamento.xml
... ... @@ -177,11 +177,7 @@ public class MonitorLogin{
177 177  
178 178 <para>
179 179 É comum que aplicações monitoradas permaneçam em estado de espera - é função do cliente de monitoração acessar a aplicação e obter
180   - as informações necessárias.
181   - </para>
182   -
183   - <para>
184   - No entanto existem casos onde é necessário que a aplicação comunique clientes de eventos ocorridos no sistema. Um exemplo é um monitor
  180 + as informações necessárias. No entanto existem casos onde é necessário que a aplicação comunique clientes de eventos ocorridos no sistema. Um exemplo é um monitor
185 181 de espaço em disco que envia um alerta quando esse espaço for menor que 20% do total.
186 182 </para>
187 183  
... ... @@ -202,16 +198,37 @@ public class DiskWritter{
202 198 // ... implementação da escrita de arquivo
203 199  
204 200 if (fileToWrite.getUsableSpace() / (float)fileToWrite.getTotalSpace() <= 0.2f){
205   - Notification notification = new GenericNotification("O espaço disponível no disco é inferior a 20% do total");
  201 + Notification notification = new DefaultNotification("O espaço disponível no disco é inferior a 20% do total");
206 202 notificationManager.sendNotification( notification );
207 203 }
208 204 }
209 205 }]]></programlisting>
210 206  
211 207 <para>
212   - Nesse exemplo podemos ver como enviar uma notificação em decorrência de um evento gerado pela aplicação. Dessa forma
213   - a aplicação pode comunicar a um agente de monitoração sobre o espaço disponível no disco, ao invés de aguardar que o agente
214   - conecte-se à aplicação para solicitar essa informação explicitamente.
  208 + Como é possível ver no exemplo, o utilitário <emphasis>NotificationManager</emphasis> é usado para enviar notificações em decorrência
  209 + de eventos ocorridos na sua aplicação. O uso mais comum é notificar avisos ou problemas para que ações sejam tomadas, mas é possível também
  210 + usar essa técnica para tomar ações preventivas ou informativas - uma notificação que o backup noturno foi feito com sucesso por exemplo.
  211 + </para>
  212 +
  213 + <para>
  214 + A interface <emphasis>Notification</emphasis> é a base das notificações enviadas e possui apenas um método:
  215 + <emphasis>Object getMessage()</emphasis>. A API de monitoração não força o tipo específico da mensagem e usualmente essa mensagem
  216 + será uma <emphasis>String</emphasis> (como no exemplo acima), mas algumas extensões podem utilizar tipos específicos de mensagem
  217 + capazes de carregar mais informações.
  218 + </para>
  219 +
  220 + <para>
  221 + O <emphasis>demoiselle-core</emphasis> disponibiliza por padrão o tipo concreto de notificação <emphasis>DefaultNotification</emphasis> - uma
  222 + implementação direta da interface <emphasis>Notification</emphasis> que permite definir a mensagem a ser retornada por <emphasis>getMessage()</emphasis>.
  223 + Além disso o <emphasis>demoiselle-core</emphasis> disponibiliza o tipo especial de mensagem <emphasis>AttributeChangeMessage</emphasis>, que permite
  224 + especificar além do texto da mensagem enviada, dados sobre a mudança de valor de um atributo, como o nome do atributo alterado, o valor antigo e o novo.
  225 + </para>
  226 + <para>
  227 + Notificações contendo mensagens do tipo <emphasis>AttributeChangeMessage</emphasis> são automaticamente enviadas por padrão pelo framework quando um
  228 + agente de monitoração altera o valor de uma propriedade anotada com <emphasis>@ManagedProperty</emphasis>, mas você também pode enviar mensagens desse tipo
  229 + quando propriedades de sua aplicação são alteradas. Extensões e componentes compatíveis com a API de monitoração do <emphasis>Demoiselle Framework</emphasis>
  230 + (por exemplo, a extensão <emphasis>demoiselle-jmx</emphasis>) podem fornecer implementações específicas da interface <emphasis>Notification</emphasis> e
  231 + tipos especializados de mensagem. Consulte a documentação desses componentes para aprender sobre seus usos.
215 232 </para>
216 233 </section>
217 234  
... ...
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/Management.java
... ... @@ -61,7 +61,7 @@ import br.gov.frameworkdemoiselle.context.SessionContext;
61 61 import br.gov.frameworkdemoiselle.context.ViewContext;
62 62 import br.gov.frameworkdemoiselle.internal.implementation.ManagedType.MethodDetail;
63 63 import br.gov.frameworkdemoiselle.management.AttributeChangeMessage;
64   -import br.gov.frameworkdemoiselle.management.GenericNotification;
  64 +import br.gov.frameworkdemoiselle.management.DefaultNotification;
65 65 import br.gov.frameworkdemoiselle.management.ManagedAttributeNotFoundException;
66 66 import br.gov.frameworkdemoiselle.management.ManagedInvokationException;
67 67 import br.gov.frameworkdemoiselle.management.ManagementExtension;
... ... @@ -281,7 +281,7 @@ public class Management implements Serializable {
281 281 NotificationManager notificationManager = Beans.getReference(NotificationManager.class);
282 282 Class<? extends Object> attributeType = newValue != null ? newValue.getClass() : null;
283 283  
284   - Notification notification = new GenericNotification( new AttributeChangeMessage(
  284 + Notification notification = new DefaultNotification( new AttributeChangeMessage(
285 285 bundle.getString("management-notification-attribute-changed", propertyName, managedType.getType().getCanonicalName())
286 286 , propertyName
287 287 , attributeType
... ...
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/DefaultNotification.java 0 → 100644
... ... @@ -0,0 +1,85 @@
  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}. This generic
  42 + * notification only has a simple message.
  43 + *
  44 + * @author SERPRO
  45 + */
  46 +public class DefaultNotification implements Notification {
  47 +
  48 + private static final long serialVersionUID = 4861136187996412275L;
  49 +
  50 + private Object message;
  51 +
  52 + /**
  53 + * Constructor without params.
  54 + */
  55 + public DefaultNotification() {
  56 + }
  57 +
  58 + /**
  59 + * Constructor with message to notification.
  60 + *
  61 + * @param message
  62 + * message to notification.
  63 + */
  64 + public DefaultNotification(Object message) {
  65 + super();
  66 + this.message = message;
  67 + }
  68 +
  69 + public Object getMessage() {
  70 + return message;
  71 + }
  72 +
  73 + public void setMessage(Object message) {
  74 + this.message = message;
  75 + }
  76 +
  77 + /*public Class<? extends Object> getType() {
  78 + if (message != null) {
  79 + return message.getClass();
  80 + }
  81 +
  82 + return null;
  83 + }*/
  84 +
  85 +}
... ...
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/GenericNotification.java
... ... @@ -1,85 +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}. This generic
42   - * notification only has a simple message.
43   - *
44   - * @author SERPRO
45   - */
46   -public class GenericNotification implements Notification {
47   -
48   - private static final long serialVersionUID = 4861136187996412275L;
49   -
50   - private Object message;
51   -
52   - /**
53   - * Constructor without params.
54   - */
55   - public GenericNotification() {
56   - }
57   -
58   - /**
59   - * Constructor with message to notification.
60   - *
61   - * @param message
62   - * message to notification.
63   - */
64   - public GenericNotification(Object message) {
65   - super();
66   - this.message = message;
67   - }
68   -
69   - public Object getMessage() {
70   - return message;
71   - }
72   -
73   - public void setMessage(Object message) {
74   - this.message = message;
75   - }
76   -
77   - /*public Class<? extends Object> getType() {
78   - if (message != null) {
79   - return message.getClass();
80   - }
81   -
82   - return null;
83   - }*/
84   -
85   -}
impl/core/src/test/java/management/notification/NotificationTest.java
... ... @@ -53,7 +53,7 @@ import br.gov.frameworkdemoiselle.annotation.Name;
53 53 import br.gov.frameworkdemoiselle.internal.implementation.ManagedType;
54 54 import br.gov.frameworkdemoiselle.internal.implementation.Management;
55 55 import br.gov.frameworkdemoiselle.management.AttributeChangeMessage;
56   -import br.gov.frameworkdemoiselle.management.GenericNotification;
  56 +import br.gov.frameworkdemoiselle.management.DefaultNotification;
57 57 import br.gov.frameworkdemoiselle.management.Notification;
58 58 import br.gov.frameworkdemoiselle.management.NotificationManager;
59 59 import br.gov.frameworkdemoiselle.util.Beans;
... ... @@ -85,7 +85,7 @@ public class NotificationTest {
85 85 */
86 86 @Test
87 87 public void sendGenericNotification() {
88   - manager.sendNotification(new GenericNotification("Test Message"));
  88 + manager.sendNotification(new DefaultNotification("Test Message"));
89 89 DummyNotificationListener listener = Beans.getReference(DummyNotificationListener.class);
90 90 Assert.assertEquals("Test Message", listener.getMessage());
91 91 }
... ... @@ -95,7 +95,7 @@ public class NotificationTest {
95 95 */
96 96 @Test
97 97 public void sendAttributeChangeNotification() {
98   - Notification n = new GenericNotification( new AttributeChangeMessage("Test Message", "attribute", String.class, "old", "new") );
  98 + Notification n = new DefaultNotification( new AttributeChangeMessage("Test Message", "attribute", String.class, "old", "new") );
99 99 manager.sendNotification(n);
100 100  
101 101 DummyNotificationListener listener = Beans.getReference(DummyNotificationListener.class);
... ...
impl/extension/jmx/src/test/java/management/tests/notification/NotificationBroadcasterTest.java
... ... @@ -62,7 +62,7 @@ import br.gov.frameworkdemoiselle.internal.implementation.MBeanManager;
62 62 import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess;
63 63 import br.gov.frameworkdemoiselle.lifecycle.AfterStartupProccess;
64 64 import br.gov.frameworkdemoiselle.management.AttributeChangeMessage;
65   -import br.gov.frameworkdemoiselle.management.GenericNotification;
  65 +import br.gov.frameworkdemoiselle.management.DefaultNotification;
66 66 import br.gov.frameworkdemoiselle.management.Notification;
67 67 import br.gov.frameworkdemoiselle.management.NotificationManager;
68 68 import br.gov.frameworkdemoiselle.util.Beans;
... ... @@ -128,7 +128,7 @@ public class NotificationBroadcasterTest {
128 128 }
129 129  
130 130 // Manda a notificação pelo Demoiselle
131   - GenericNotification n = new GenericNotification("Notification test successful");
  131 + DefaultNotification n = new DefaultNotification("Notification test successful");
132 132 notificationManager.sendNotification(n);
133 133  
134 134 // Se o componente funcionou, o Demoiselle propagou a notificação para o servidor MBean e o listener preencheu
... ... @@ -172,7 +172,7 @@ public class NotificationBroadcasterTest {
172 172 }
173 173  
174 174 // Manda a notificação pelo Demoiselle
175   - Notification notification = new GenericNotification( new AttributeChangeMessage("Attribute Changed", "name", String.class, "Demoiselle 1", "Demoiselle 2") );
  175 + Notification notification = new DefaultNotification( new AttributeChangeMessage("Attribute Changed", "name", String.class, "Demoiselle 1", "Demoiselle 2") );
176 176 notificationManager.sendNotification(notification);
177 177  
178 178 // Se o componente funcionou, o Demoiselle propagou a notificação para o servidor MBean e o listener preencheu
... ...