| 1 | // jademx - JADE management using JMX |
| 2 | // Copyright 2005 Caboodle Networks, Inc. |
| 3 | // |
| 4 | // This library is free software; you can redistribute it and/or |
| 5 | // modify it under the terms of the GNU Lesser General Public |
| 6 | // License as published by the Free Software Foundation; either |
| 7 | // version 2.1 of the License, or (at your option) any later version. |
| 8 | // |
| 9 | // This library is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | // Lesser General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU Lesser General Public |
| 15 | // License along with this library; if not, write to the Free Software |
| 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
| 17 | |
| 18 | package jade.jademx.unit; |
| 19 | |
| 20 | import jade.jademx.agent.JademxAgent; |
| 21 | import jade.util.Logger; |
| 22 | |
| 23 | import javax.management.Notification; |
| 24 | import javax.management.NotificationListener; |
| 25 | |
| 26 | /** |
| 27 | * a class to listen for unit test notifications. |
| 28 | * @author David Bernstein, <a href="http://www.caboodlenetworks.com" |
| 29 | * >Caboodle Networks, Inc.</a> |
| 30 | */ |
| 31 | public class UnitTestNotificationListener implements NotificationListener { |
| 32 | |
| 33 | // use default constructor |
| 34 | |
| 35 | /** my logger */ |
| 36 | private final Logger logger = |
| 37 | Logger.getMyLogger(UnitTestNotificationListener.class.getName()); |
| 38 | |
| 39 | /** interesting notification seen, if any */ |
| 40 | private Notification notification = null; |
| 41 | |
| 42 | /* (non-Javadoc) |
| 43 | * @see javax.management.NotificationListener#handleNotification( |
| 44 | * javax.management.Notification, java.lang.Object) |
| 45 | */ |
| 46 | public void handleNotification( |
| 47 | Notification notification, Object handback ) { |
| 48 | String nType = notification.getType(); |
| 49 | logger.log( Logger.FINE, "received notification of type "+nType); |
| 50 | if ( JademxAgent.NOTIF_UNIT_TEST_FAILURE_NAME.equals( nType ) || |
| 51 | JademxAgent.NOTIF_UNIT_TEST_SUCCESS_NAME.equals( nType ) ) { |
| 52 | synchronized ( this ) { |
| 53 | this.notification = notification; |
| 54 | notify(); |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * @return Returns the notification. |
| 61 | */ |
| 62 | public synchronized Notification getNotification() { |
| 63 | return notification; |
| 64 | } |
| 65 | |
| 66 | } |