author | emcmanus |
Fri, 07 Nov 2008 11:48:07 +0100 | |
changeset 1570 | 4165709c91e3 |
permissions | -rw-r--r-- |
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
1 |
/* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
2 |
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
4 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
8 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
13 |
* accompanied this code). |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
14 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
18 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
21 |
* have any questions. |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
22 |
*/ |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
23 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
24 |
/* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
25 |
* @test |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
26 |
* @bug 5072267 |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
27 |
* @summary Test that an MBean can handle localized Notification messages. |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
28 |
* @author Eamonn McManus |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
29 |
*/ |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
30 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
31 |
import java.util.Collections; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
32 |
import java.util.ListResourceBundle; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
33 |
import java.util.Locale; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
34 |
import java.util.Map; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
35 |
import java.util.MissingResourceException; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
36 |
import java.util.ResourceBundle; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
37 |
import java.util.concurrent.ArrayBlockingQueue; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
38 |
import java.util.concurrent.BlockingQueue; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
39 |
import java.util.concurrent.Callable; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
40 |
import java.util.concurrent.ConcurrentHashMap; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
41 |
import java.util.concurrent.ConcurrentMap; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
42 |
import java.util.concurrent.TimeUnit; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
43 |
import javax.management.ClientContext; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
44 |
import javax.management.JMX; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
45 |
import javax.management.ListenerNotFoundException; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
46 |
import javax.management.MBeanNotificationInfo; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
47 |
import javax.management.MBeanServer; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
48 |
import javax.management.MBeanServerConnection; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
49 |
import javax.management.MBeanServerFactory; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
50 |
import javax.management.Notification; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
51 |
import javax.management.NotificationBroadcasterSupport; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
52 |
import javax.management.NotificationEmitter; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
53 |
import javax.management.NotificationFilter; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
54 |
import javax.management.NotificationListener; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
55 |
import javax.management.ObjectName; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
56 |
import javax.management.SendNotification; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
57 |
import javax.management.remote.JMXConnector; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
58 |
import javax.management.remote.JMXConnectorFactory; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
59 |
import javax.management.remote.JMXConnectorServer; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
60 |
import javax.management.remote.JMXConnectorServerFactory; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
61 |
import javax.management.remote.JMXServiceURL; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
62 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
63 |
public class LocaleAwareBroadcasterTest { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
64 |
static final ObjectName mbeanName = ObjectName.valueOf("d:type=LocaleAware"); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
65 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
66 |
static final String |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
67 |
messageKey = "broken.window", |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
68 |
defaultMessage = "broken window", |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
69 |
frenchMessage = "fen\u00eatre bris\u00e9e", |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
70 |
irishMessage = "fuinneog briste"; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
71 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
72 |
public static class Bundle extends ListResourceBundle { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
73 |
@Override |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
74 |
protected Object[][] getContents() { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
75 |
return new Object[][] { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
76 |
{messageKey, defaultMessage}, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
77 |
}; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
78 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
79 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
80 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
81 |
public static class Bundle_fr extends ListResourceBundle { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
82 |
@Override |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
83 |
protected Object[][] getContents() { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
84 |
return new Object[][] { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
85 |
{messageKey, frenchMessage}, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
86 |
}; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
87 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
88 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
89 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
90 |
public static class Bundle_ga extends ListResourceBundle { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
91 |
@Override |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
92 |
protected Object[][] getContents() { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
93 |
return new Object[][] { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
94 |
{messageKey, irishMessage}, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
95 |
}; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
96 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
97 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
98 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
99 |
static volatile String failure; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
100 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
101 |
public static interface LocaleAwareMBean { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
102 |
public void sendNotification(Notification n); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
103 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
104 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
105 |
public static class LocaleAware |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
106 |
implements LocaleAwareMBean, NotificationEmitter, SendNotification { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
107 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
108 |
private final ConcurrentMap<Locale, NotificationBroadcasterSupport> |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
109 |
localeToEmitter = newConcurrentMap(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
110 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
111 |
public void sendNotification(Notification n) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
112 |
for (Map.Entry<Locale, NotificationBroadcasterSupport> entry : |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
113 |
localeToEmitter.entrySet()) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
114 |
Notification localizedNotif = |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
115 |
localizeNotification(n, entry.getKey()); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
116 |
entry.getValue().sendNotification(localizedNotif); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
117 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
118 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
119 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
120 |
public void addNotificationListener( |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
121 |
NotificationListener listener, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
122 |
NotificationFilter filter, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
123 |
Object handback) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
124 |
throws IllegalArgumentException { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
125 |
Locale locale = ClientContext.getLocale(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
126 |
NotificationBroadcasterSupport broadcaster; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
127 |
broadcaster = localeToEmitter.get(locale); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
128 |
if (broadcaster == null) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
129 |
broadcaster = new NotificationBroadcasterSupport(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
130 |
NotificationBroadcasterSupport old = |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
131 |
localeToEmitter.putIfAbsent(locale, broadcaster); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
132 |
if (old != null) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
133 |
broadcaster = old; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
134 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
135 |
broadcaster.addNotificationListener(listener, filter, handback); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
136 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
137 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
138 |
public void removeNotificationListener(NotificationListener listener) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
139 |
throws ListenerNotFoundException { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
140 |
Locale locale = ClientContext.getLocale(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
141 |
NotificationBroadcasterSupport broadcaster = |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
142 |
localeToEmitter.get(locale); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
143 |
if (broadcaster == null) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
144 |
throw new ListenerNotFoundException(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
145 |
broadcaster.removeNotificationListener(listener); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
146 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
147 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
148 |
public void removeNotificationListener( |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
149 |
NotificationListener listener, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
150 |
NotificationFilter filter, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
151 |
Object handback) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
152 |
throws ListenerNotFoundException { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
153 |
Locale locale = ClientContext.getLocale(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
154 |
NotificationBroadcasterSupport broadcaster = |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
155 |
localeToEmitter.get(locale); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
156 |
if (broadcaster == null) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
157 |
throw new ListenerNotFoundException(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
158 |
broadcaster.removeNotificationListener(listener, filter, handback); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
159 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
160 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
161 |
public MBeanNotificationInfo[] getNotificationInfo() { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
162 |
return new MBeanNotificationInfo[0]; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
163 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
164 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
165 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
166 |
// Localize notif using the convention that the message looks like |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
167 |
// [resourcebundlename:resourcekey]defaultmessage |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
168 |
// for example [foo.bar.Resources:unknown.problem] |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
169 |
static Notification localizeNotification(Notification n, Locale locale) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
170 |
String msg = n.getMessage(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
171 |
if (!msg.startsWith("[")) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
172 |
return n; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
173 |
int close = msg.indexOf(']'); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
174 |
if (close < 0) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
175 |
throw new IllegalArgumentException("Bad notification message: " + msg); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
176 |
int colon = msg.indexOf(':'); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
177 |
if (colon < 0 || colon > close) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
178 |
throw new IllegalArgumentException("Bad notification message: " + msg); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
179 |
String bundleName = msg.substring(1, colon); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
180 |
String key = msg.substring(colon + 1, close); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
181 |
ClassLoader loader = LocaleAwareBroadcasterTest.class.getClassLoader(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
182 |
ResourceBundle bundle = |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
183 |
ResourceBundle.getBundle(bundleName, locale, loader); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
184 |
try { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
185 |
msg = bundle.getString(key); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
186 |
} catch (MissingResourceException e) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
187 |
msg = msg.substring(close + 1); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
188 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
189 |
n = (Notification) n.clone(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
190 |
n.setMessage(msg); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
191 |
return n; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
192 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
193 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
194 |
public static void main(String[] args) throws Exception { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
195 |
Locale.setDefault(new Locale("en")); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
196 |
testLocal(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
197 |
testRemote(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
198 |
if (failure == null) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
199 |
System.out.println("TEST PASSED"); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
200 |
else |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
201 |
throw new Exception("TEST FAILED: " + failure); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
202 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
203 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
204 |
static interface AddListenerInLocale { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
205 |
public void addListenerInLocale( |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
206 |
MBeanServerConnection mbsc, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
207 |
NotificationListener listener, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
208 |
Locale locale) throws Exception; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
209 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
210 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
211 |
private static void testLocal() throws Exception { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
212 |
System.out.println("Test local MBeanServer using doWithContext"); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
213 |
MBeanServer mbs = makeMBS(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
214 |
AddListenerInLocale addListener = new AddListenerInLocale() { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
215 |
public void addListenerInLocale( |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
216 |
final MBeanServerConnection mbsc, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
217 |
final NotificationListener listener, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
218 |
Locale locale) throws Exception { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
219 |
Map<String, String> localeContext = Collections.singletonMap( |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
220 |
ClientContext.LOCALE_KEY, locale.toString()); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
221 |
ClientContext.doWithContext( |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
222 |
localeContext, new Callable<Void>() { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
223 |
public Void call() throws Exception { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
224 |
mbsc.addNotificationListener( |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
225 |
mbeanName, listener, null, null); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
226 |
return null; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
227 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
228 |
}); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
229 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
230 |
}; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
231 |
test(mbs, addListener); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
232 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
233 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
234 |
private static void testRemote() throws Exception { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
235 |
System.out.println("Test remote MBeanServer using withLocale"); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
236 |
MBeanServer mbs = makeMBS(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
237 |
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://"); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
238 |
JMXConnectorServer cs = |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
239 |
JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
240 |
cs.start(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
241 |
JMXServiceURL addr = cs.getAddress(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
242 |
JMXConnector cc = JMXConnectorFactory.connect(addr); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
243 |
MBeanServerConnection mbsc = cc.getMBeanServerConnection(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
244 |
AddListenerInLocale addListenerInLocale = new AddListenerInLocale() { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
245 |
public void addListenerInLocale( |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
246 |
MBeanServerConnection mbsc, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
247 |
NotificationListener listener, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
248 |
Locale locale) throws Exception { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
249 |
mbsc = ClientContext.withLocale(mbsc, locale); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
250 |
mbsc.addNotificationListener(mbeanName, listener, null, null); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
251 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
252 |
}; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
253 |
try { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
254 |
test(mbsc, addListenerInLocale); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
255 |
} finally { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
256 |
try { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
257 |
cc.close(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
258 |
} catch (Exception e) {} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
259 |
cs.stop(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
260 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
261 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
262 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
263 |
static class QueueListener implements NotificationListener { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
264 |
final BlockingQueue<Notification> queue = |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
265 |
new ArrayBlockingQueue<Notification>(10); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
266 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
267 |
public void handleNotification(Notification notification, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
268 |
Object handback) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
269 |
queue.add(notification); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
270 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
271 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
272 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
273 |
private static void test( |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
274 |
MBeanServerConnection mbsc, AddListenerInLocale addListener) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
275 |
throws Exception { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
276 |
QueueListener defaultListener = new QueueListener(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
277 |
QueueListener frenchListener = new QueueListener(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
278 |
QueueListener irishListener = new QueueListener(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
279 |
mbsc.addNotificationListener(mbeanName, defaultListener, null, null); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
280 |
addListener.addListenerInLocale(mbsc, frenchListener, new Locale("fr")); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
281 |
addListener.addListenerInLocale(mbsc, irishListener, new Locale("ga")); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
282 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
283 |
LocaleAwareMBean proxy = |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
284 |
JMX.newMBeanProxy(mbsc, mbeanName, LocaleAwareMBean.class); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
285 |
String notifMsg = "[" + Bundle.class.getName() + ":" + messageKey + "]" + |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
286 |
"broken window (default message that should never be seen)"; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
287 |
Notification notif = new Notification( |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
288 |
"notif.type", mbeanName, 0L, notifMsg); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
289 |
proxy.sendNotification(notif); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
290 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
291 |
final Object[][] expected = { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
292 |
{defaultListener, defaultMessage}, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
293 |
{frenchListener, frenchMessage}, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
294 |
{irishListener, irishMessage}, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
295 |
}; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
296 |
for (Object[] exp : expected) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
297 |
QueueListener ql = (QueueListener) exp[0]; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
298 |
String msg = (String) exp[1]; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
299 |
System.out.println("Checking: " + msg); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
300 |
Notification n = ql.queue.poll(1, TimeUnit.SECONDS); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
301 |
if (n == null) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
302 |
fail("Did not receive expected notif: " + msg); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
303 |
if (!n.getMessage().equals(msg)) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
304 |
fail("Received notif with wrong message: got " + |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
305 |
n.getMessage() + ", expected " + msg); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
306 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
307 |
n = ql.queue.poll(2, TimeUnit.MILLISECONDS); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
308 |
if (n != null) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
309 |
fail("Received unexpected extra notif: " + n); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
310 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
311 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
312 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
313 |
private static MBeanServer makeMBS() throws Exception { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
314 |
MBeanServer mbs = MBeanServerFactory.newMBeanServer(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
315 |
LocaleAware aware = new LocaleAware(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
316 |
mbs.registerMBean(aware, mbeanName); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
317 |
return mbs; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
318 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
319 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
320 |
static <K, V> ConcurrentMap<K, V> newConcurrentMap() { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
321 |
return new ConcurrentHashMap<K, V>(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
322 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
323 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
324 |
static void fail(String why) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
325 |
System.out.println("FAIL: " + why); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
326 |
failure = why; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
327 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
diff
changeset
|
328 |
} |