1 23 package com.sun.enterprise.management; 24 25 import java.util.Map ; 26 import java.io.Serializable ; 27 28 import javax.management.ObjectName ; 29 import javax.management.Notification ; 30 import javax.management.NotificationListener ; 31 import javax.management.ListenerNotFoundException ; 32 33 import com.sun.appserv.management.base.Util; 34 import com.sun.appserv.management.base.Container; 35 import com.sun.appserv.management.config.AMXConfig; 36 import com.sun.appserv.management.util.stringifier.SmartStringifier; 37 import com.sun.appserv.management.util.misc.TypeCast; 38 39 40 45 public final class CreateRemoveListener implements NotificationListener 46 { 47 private final String mNameExpected; 48 private final String mJ2EETypeExpected; 49 private final Container mSource; 50 51 private Notification mCreateNotif; 52 private Notification mRemoveNotif; 53 54 public 55 CreateRemoveListener( 56 final Container source, 57 final String j2eeTypeExpected, 58 final String nameExpected ) 59 { 60 mSource = source; 61 mNameExpected = nameExpected; 62 mJ2EETypeExpected = j2eeTypeExpected; 63 64 mSource.addNotificationListener( this, null, null ); 65 } 66 67 public void 68 handleNotification( 69 final Notification notifIn, 70 final Object handback) 71 { 72 final String type = notifIn.getType(); 73 74 final ObjectName objectName = 76 Util.getAMXNotificationValue( notifIn, AMXConfig.CONFIG_OBJECT_NAME_KEY, ObjectName .class ); 77 78 80 if ( Util.getJ2EEType( objectName ).equals( mJ2EETypeExpected ) && 81 Util.getName( objectName ).equals( mNameExpected ) ) 82 { 83 if ( type.equals( AMXConfig.CONFIG_CREATED_NOTIFICATION_TYPE ) ) 84 { 85 mCreateNotif = notifIn; 86 } 87 else if ( type.equals( AMXConfig.CONFIG_REMOVED_NOTIFICATION_TYPE ) ) 88 { 89 mRemoveNotif = notifIn; 90 } 91 } 92 } 93 protected void 94 trace( Object o ) 95 { 96 System.out.println( SmartStringifier.toString( o ) ); 97 } 98 99 public void 100 waitCreate() 101 { 102 long millis = 10; 103 104 while ( mCreateNotif == null ) 105 { 106 AMXTestBase.mySleep( millis ); 107 trace( "waiting " + millis + "ms for CONFIG_CREATED_NOTIFICATION_TYPE for " + mNameExpected); 108 millis *= 2; 109 } 110 } 111 112 public void 113 waitRemove() 114 { 115 long millis = 10; 116 while ( mRemoveNotif == null ) 117 { 118 AMXTestBase.mySleep( millis ); 119 trace( "waiting " + millis + "ms for CONFIG_REMOVED_NOTIFICATION_TYPE for " + mNameExpected); 120 millis *= 2; 121 } 122 } 123 124 125 public void 126 waitNotifs() 127 { 128 waitCreate(); 129 waitRemove(); 130 131 try 132 { 133 mSource.removeNotificationListener( (NotificationListener )this, null, null ); 134 } 135 catch( ListenerNotFoundException e ) 136 { 137 throw new RuntimeException ( e ); 138 } 139 } 140 } | Popular Tags |