KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > base > ListenerTest


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.management.base;
24
25 import java.util.Set JavaDoc;
26
27 import javax.management.Notification JavaDoc;
28 import javax.management.NotificationListener JavaDoc;
29 import javax.management.NotificationFilter JavaDoc;
30 import javax.management.NotificationFilterSupport JavaDoc;
31
32 import com.sun.appserv.management.config.Enabled;
33 import com.sun.appserv.management.base.AMX;
34
35 import com.sun.enterprise.management.AMXTestBase;
36
37
38 /**
39  */

40 public final class ListenerTest extends AMXTestBase
41 {
42     public ListenerTest()
43     {
44     }
45
46     private static class DummyListener implements NotificationListener JavaDoc
47     {
48         public DummyListener() {}
49         
50             public void
51         handleNotification(
52             final Notification JavaDoc notif,
53             final Object JavaDoc handback )
54         {
55         }
56     }
57     
58         public void
59     testAddRemoveNotificationListener()
60         throws Exception JavaDoc
61     {
62         final long start = now();
63         final Set JavaDoc<AMX> all = getAllAMX();
64         
65         final NotificationListener JavaDoc listener1 = new DummyListener();
66         final NotificationListener JavaDoc listener2 = new DummyListener();
67         
68         final NotificationFilter JavaDoc filter = new NotificationFilterSupport JavaDoc();
69         final Object JavaDoc handback = "handback";
70         
71         for( final AMX amx : all )
72         {
73             amx.getNotificationInfo();
74             amx.addNotificationListener( listener1, null, null );
75             amx.addNotificationListener( listener2, filter, handback );
76         }
77         
78         for( final AMX amx : all )
79         {
80             amx.removeNotificationListener( listener1 );
81             amx.removeNotificationListener( listener2, filter, handback );
82         }
83         
84         printElapsed( "Added/removed NotificationListener", all.size(), start );
85     }
86     
87     
88  
89 }
90
91
92
Popular Tags