-
Notifications
You must be signed in to change notification settings - Fork 138
/
RegistrationSupport.java
711 lines (593 loc) · 26.2 KB
/
RegistrationSupport.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
/*
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package org.glassfish.admin.amx.impl.j2ee;
import com.sun.enterprise.config.serverbeans.ApplicationRef;
import com.sun.enterprise.config.serverbeans.BindableResource;
import com.sun.enterprise.config.serverbeans.Domain;
import com.sun.enterprise.config.serverbeans.Resource;
import com.sun.enterprise.config.serverbeans.ResourcePool;
import com.sun.enterprise.config.serverbeans.ResourceRef;
import com.sun.enterprise.config.serverbeans.Server;
import com.sun.enterprise.deployment.Application;
import com.sun.enterprise.deployment.ApplicationClientDescriptor;
import com.sun.enterprise.deployment.BundleDescriptor;
import com.sun.enterprise.deployment.ConnectorDescriptor;
import com.sun.enterprise.deployment.EjbBundleDescriptor;
import com.sun.enterprise.deployment.EjbDescriptor;
import com.sun.enterprise.deployment.EjbSessionDescriptor;
import com.sun.enterprise.deployment.WebBundleDescriptor;
import com.sun.enterprise.deployment.WebComponentDescriptor;
import com.sun.enterprise.deployment.archivist.Archivist;
import com.sun.enterprise.deployment.archivist.ArchivistFactory;
import com.sun.enterprise.deployment.io.DeploymentDescriptorFile;
import java.io.ByteArrayOutputStream;
import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.management.JMException;
import javax.management.MBeanServer;
import javax.management.MBeanServerNotification;
import javax.management.Notification;
import javax.management.NotificationListener;
import javax.management.ObjectName;
import org.glassfish.admin.amx.core.Util;
import org.glassfish.admin.amx.impl.config.ConfigBeanRegistry;
import org.glassfish.admin.amx.impl.j2ee.loader.J2EEInjectedValues;
import org.glassfish.admin.amx.impl.util.InjectedValues;
import org.glassfish.admin.amx.impl.util.ObjectNameBuilder;
import org.glassfish.admin.amx.j2ee.AMXEELoggerInfo;
import org.glassfish.admin.amx.j2ee.AppClientModule;
import org.glassfish.admin.amx.j2ee.EJB;
import org.glassfish.admin.amx.j2ee.EJBModule;
import org.glassfish.admin.amx.j2ee.EntityBean;
import org.glassfish.admin.amx.j2ee.J2EEApplication;
import org.glassfish.admin.amx.j2ee.J2EEManagedObject;
import org.glassfish.admin.amx.j2ee.J2EEServer;
import org.glassfish.admin.amx.j2ee.MessageDrivenBean;
import org.glassfish.admin.amx.j2ee.ResourceAdapter;
import org.glassfish.admin.amx.j2ee.ResourceAdapterModule;
import org.glassfish.admin.amx.j2ee.Servlet;
import org.glassfish.admin.amx.j2ee.SingletonSessionBean;
import org.glassfish.admin.amx.j2ee.StatefulSessionBean;
import org.glassfish.admin.amx.j2ee.StatelessSessionBean;
import org.glassfish.admin.amx.j2ee.WebModule;
import org.glassfish.admin.amx.util.ClassUtil;
import org.glassfish.admin.amx.util.MapUtil;
import org.glassfish.admin.amx.util.jmx.JMXUtil;
import org.glassfish.api.admin.config.Named;
import org.glassfish.internal.data.ApplicationInfo;
import org.glassfish.internal.data.ApplicationRegistry;
import org.jvnet.hk2.config.ConfigBean;
import org.jvnet.hk2.config.ConfigBeanProxy;
/**
* Handles registrations of resources and applications associated with a J2EEServer.
* There must be one and only one of these instances per J2EEServer.
*/
final class RegistrationSupport {
private static final Logger LOG = Logger.getLogger(RegistrationSupport.class.getName());
/**
* Associates the ObjectName of a ResourceRef or ApplicationRef with its corresponding
* top-level JSR 77 MBean. Children of those JSR 77 MBeans come and go with their parent.
*/
private final Map<ObjectName, ObjectName> mConfigRefTo77 = new HashMap<>();
private final J2EEServer mJ2EEServer;
private final MBeanServer mMBeanServer;
private final RefListener mResourceRefListener;
/** The Server config for this J2EEServer */
private final Server mServer;
/** type of any resource ref */
private final String mResourceRefType;
/** type of any application ref */
private final String mApplicationRefType;
private final Logger mLogger = AMXEELoggerInfo.getLogger();
public RegistrationSupport(final J2EEServer server) {
mJ2EEServer = server;
mMBeanServer = (MBeanServer) server.extra().mbeanServerConnection();
mResourceRefType = Util.deduceType(ResourceRef.class);
mApplicationRefType = Util.deduceType(ApplicationRef.class);
mServer = getDomain().getServers().getServer(mJ2EEServer.getName());
mResourceRefListener = new RefListener();
registerApplications();
}
protected void cleanup() {
mResourceRefListener.stopListening();
}
public void start() {
mResourceRefListener.startListening();
}
/** Maps configuration MBean type to J2EE type */
public static final Map<String, Class<? extends J2EEManagedObjectImplBase>> CONFIG_RESOURCE_TYPES = Map.of(
"jdbc-resource", JDBCResourceImpl.class,
"java-mail-resource", JavaMailResourceImpl.class,
"jca-resource", JCAResourceImpl.class,
"jms-resource", JMSResourceImpl.class,
"jndi-resource", JNDIResourceImpl.class,
"jta-resource", JTAResourceImpl.class,
"rmi-iiop-resource", RMI_IIOPResourceImpl.class,
"url-resource", URLResourceImpl.class
);
private Domain getDomain() {
return InjectedValues.getInstance().getHabitat().getService(Domain.class);
}
private ObjectName getObjectName(ConfigBeanProxy cbp) {
return ConfigBeanRegistry.getInstance().getObjectNameForProxy(cbp);
}
private String getDeploymentDescriptor(final BundleDescriptor bundleDesc) {
final ArchivistFactory archivistFactory = J2EEInjectedValues.getInstance().getArchivistFactory();
String dd = "unavailable";
ByteArrayOutputStream out = null;
try {
final Archivist<BundleDescriptor> moduleArchivist = archivistFactory
.getArchivist(bundleDesc.getModuleDescriptor().getModuleType());
final DeploymentDescriptorFile<BundleDescriptor> ddFile = moduleArchivist.getStandardDDFile();
out = new ByteArrayOutputStream();
ddFile.write(bundleDesc, out);
final String charsetName = "UTF-8";
dd = out.toString(charsetName);
} catch (final Exception e) {
dd = null;
} finally {
if (out != null) {
try {
out.close();
} catch (Exception ee) {
}
}
}
return dd;
}
private ObjectName createAppMBeans(
com.sun.enterprise.config.serverbeans.Application appConfig,
final Application application,
final MetadataImpl meta)
{
final String appLocation = appConfig.getLocation();
final boolean isStandalone = application.isVirtual();
ObjectName parentMBean = null;
ObjectName top = null;
if (isStandalone)
{
parentMBean = mJ2EEServer.objectName();
}
else
{
final String xmlDesc = getDeploymentDescriptor(application);
if ( xmlDesc != null )
{
meta.setDeploymentDescriptor(xmlDesc);
}
parentMBean = registerJ2EEChild(mJ2EEServer.objectName(), meta, J2EEApplication.class, J2EEApplicationImpl.class, application.getName());
top = parentMBean;
}
for (final EjbBundleDescriptor desc : application.getBundleDescriptors(EjbBundleDescriptor.class))
{
final ObjectName objectName = registerEjbModuleAndItsComponents(parentMBean, meta, appConfig, desc);
if (isStandalone)
{
assert (top == null);
top = objectName;
}
}
for (final WebBundleDescriptor desc : application.getBundleDescriptors(WebBundleDescriptor.class))
{
final ObjectName objectName = registerWebModuleAndItsComponents(parentMBean, meta, appConfig, desc);
if (isStandalone)
{
assert (top == null);
top = objectName;
}
}
for (final ConnectorDescriptor desc : application.getBundleDescriptors(ConnectorDescriptor.class))
{
assert top == null;
top = registerResourceAdapterModuleAndItsComponents(parentMBean, meta, appConfig, desc, appLocation);
}
for (final ApplicationClientDescriptor desc : application.getBundleDescriptors(ApplicationClientDescriptor.class))
{
assert top == null;
top = registerAppClient(parentMBean, meta, appConfig, desc);
}
mLogger.fine("Registered JSR 77 MBeans for application/module: " + top);
return top;
}
private com.sun.enterprise.config.serverbeans.Module
getModuleConfig( final com.sun.enterprise.config.serverbeans.Application appConfig, final String name)
{
if ( appConfig.getModule(name) == null )
{
throw new IllegalArgumentException( "Can't find module named " + name + " in " + appConfig );
}
return appConfig.getModule(name);
}
/* Register ejb module and its' children ejbs which is part of an application */
private ObjectName registerEjbModuleAndItsComponents(
final ObjectName parentMBean,
final MetadataImpl meta,
final com.sun.enterprise.config.serverbeans.Application appConfig,
final EjbBundleDescriptor ejbBundleDescriptor )
{
final String xmlDesc = getDeploymentDescriptor(ejbBundleDescriptor);
if ( xmlDesc != null )
{
meta.setDeploymentDescriptor( xmlDesc );
}
final String moduleName = ejbBundleDescriptor.getModuleName();
final com.sun.enterprise.config.serverbeans.Module moduleConfig = getModuleConfig(appConfig, moduleName );
meta.setCorrespondingConfig(getObjectName(moduleConfig));
final ObjectName ejbModuleObjectName = registerJ2EEChild(parentMBean, meta, EJBModule.class, EJBModuleImpl.class, moduleName);
meta.remove( Metadata.CORRESPONDING_CONFIG ); // none for an EJB MBean
meta.remove( Metadata.DEPLOYMENT_DESCRIPTOR ); // none for an EJB MBean
for (final EjbDescriptor desc : ejbBundleDescriptor.getEjbs())
{
createEJBMBean(ejbModuleObjectName, meta, desc);
}
return ejbModuleObjectName;
}
private ObjectName createEJBMBean(
final ObjectName parentMBean,
final MetadataImpl meta,
final EjbDescriptor ejbDescriptor)
{
final String ejbName = ejbDescriptor.getName();
final String ejbType = ejbDescriptor.getType();
final String ejbSessionType = ejbType.equals("Session") ? ((EjbSessionDescriptor) ejbDescriptor).getSessionType() : null;
Class<? extends EJB> intf = null;
Class<? extends EJBImplBase> impl = null;
if (ejbType.equals("Entity"))
{
intf = EntityBean.class;
impl = EntityBeanImpl.class;
}
else if (ejbType.equals("Message-driven"))
{
intf = MessageDrivenBean.class;
impl = MessageDrivenBeanImpl.class;
}
else if (ejbType.equals("Session"))
{
if (ejbSessionType.equals("Stateless"))
{
intf = StatelessSessionBean.class;
impl = StatelessSessionBeanImpl.class;
}
else if (ejbSessionType.equals("Stateful"))
{
intf = StatefulSessionBean.class;
impl = StatefulSessionBeanImpl.class;
}
else if (ejbSessionType.equals("Singleton")) // EJB 3.1
{
intf = SingletonSessionBean.class;
impl = SingletonSessionBeanImpl.class;
}
else
{
throw new IllegalArgumentException( "Unknown ejbSessionType: " + ejbSessionType + ", expected Stateless or Stateful");
}
}
return registerJ2EEChild(parentMBean, meta, intf, impl, ejbName);
}
/* Register web module and its' children which is part of an application */
private ObjectName registerWebModuleAndItsComponents(
final ObjectName parentMBean,
final MetadataImpl meta,
final com.sun.enterprise.config.serverbeans.Application appConfig,
final WebBundleDescriptor webBundleDescriptor )
{
final String xmlDesc = getDeploymentDescriptor(webBundleDescriptor);
if ( xmlDesc != null )
{
meta.setDeploymentDescriptor( xmlDesc );
}
final String moduleName = webBundleDescriptor.getModuleName();
final com.sun.enterprise.config.serverbeans.Module moduleConfig = getModuleConfig(appConfig, moduleName );
meta.setCorrespondingConfig(getObjectName(moduleConfig));
final ObjectName webModuleObjectName = registerJ2EEChild(parentMBean, meta, WebModule.class, WebModuleImpl.class, moduleName);
meta.remove( Metadata.CORRESPONDING_CONFIG ); // none for a Servlet
meta.remove( Metadata.DEPLOYMENT_DESCRIPTOR ); // none for an Servlet
for (final WebComponentDescriptor desc : webBundleDescriptor.getWebComponentDescriptors())
{
final String servletName = desc.getCanonicalName();
registerJ2EEChild(webModuleObjectName, meta, Servlet.class, ServletImpl.class, servletName);
}
return webModuleObjectName;
}
public ObjectName registerResourceAdapterModuleAndItsComponents(
final ObjectName parentMBean,
final MetadataImpl meta,
final com.sun.enterprise.config.serverbeans.Application appConfig,
final ConnectorDescriptor bundleDesc,
final String appLocation)
{
meta.setCorrespondingConfig(getObjectName(appConfig));
final ObjectName objectName = createRARModuleMBean(parentMBean, meta, appConfig, bundleDesc);
final com.sun.enterprise.config.serverbeans.Module moduleConfig = getModuleConfig(appConfig, bundleDesc.getModuleName() );
meta.setCorrespondingConfig(getObjectName(moduleConfig));
registerJ2EEChild(objectName, meta, ResourceAdapter.class, ResourceAdapterImpl.class, bundleDesc.getName());
return objectName;
}
private ObjectName createRARModuleMBean(
final ObjectName parentMBean,
final MetadataImpl meta,
final com.sun.enterprise.config.serverbeans.Application appConfig,
final ConnectorDescriptor bundleDesc )
{
final String xmlDesc = getDeploymentDescriptor(bundleDesc);
if ( xmlDesc != null )
{
meta.setDeploymentDescriptor( xmlDesc );
}
final String resAdName = bundleDesc.getModuleName();
final ObjectName objectName = registerJ2EEChild(parentMBean, meta, ResourceAdapterModule.class, ResourceAdapterModuleImpl.class, resAdName);
return objectName;
}
/* Register application client module */
public ObjectName registerAppClient(
final ObjectName parentMBean,
final MetadataImpl meta,
final com.sun.enterprise.config.serverbeans.Application appConfig,
final ApplicationClientDescriptor bundleDesc)
{
final String xmlDesc = getDeploymentDescriptor(bundleDesc);
if ( xmlDesc != null )
{
meta.setDeploymentDescriptor( xmlDesc );
}
final String moduleName = bundleDesc.getModuleDescriptor().getModuleName();
return registerJ2EEChild(parentMBean, meta, AppClientModule.class, AppClientModuleImpl.class, moduleName);
}
protected void registerApplications()
{
final List<ApplicationRef> appRefs = mServer.getApplicationRef();
for (final ApplicationRef ref : appRefs)
{
try
{
processApplicationRef(ref);
}
catch( final Exception e )
{
// log it: we want to continue with other apps, even if this one had a problem
mLogger.log( Level.INFO, AMXEELoggerInfo.registeringApplicationException,
new Object[] { ref.getRef(), e});
}
}
}
/**
Examine the MBean to see if it is a ResourceRef that should be manifested under this server,
and if so, register a JSR 77 MBean for it.
*/
public ObjectName processApplicationRef(final ApplicationRef ref)
{
// find all applications
final ApplicationRegistry appRegistry = J2EEInjectedValues.getInstance().getApplicationRegistry();
final MetadataImpl meta = new MetadataImpl();
meta.setCorrespondingRef(getObjectName(ref));
final String appName = ref.getRef();
final ApplicationInfo appInfo = appRegistry.get(appName);
if (appInfo == null)
{
mLogger.fine("Unable to get ApplicationInfo for application: " + appName);
return null;
}
final Application app = appInfo.getMetaData(Application.class);
if ( app == null )
{
if ( appInfo.isJakartaEEApp() )
{
mLogger.log(Level.WARNING, AMXEELoggerInfo.nullAppinfo, appName);
}
return null;
}
final com.sun.enterprise.config.serverbeans.Application appConfig = getDomain().getApplications().getApplication(appName);
if ( appConfig == null )
{
mLogger.log(Level.WARNING, AMXEELoggerInfo.errorGetappconfig, appName);
return null;
}
meta.setCorrespondingConfig( getObjectName(appConfig) );
final ObjectName mbean77 = createAppMBeans(appConfig, app, meta);
synchronized (mConfigRefTo77)
{
mConfigRefTo77.put(getObjectName(ref), mbean77);
}
return mbean77;
}
protected <I extends J2EEManagedObject, C extends J2EEManagedObjectImplBase> ObjectName registerJ2EEChild(
final ObjectName parent,
final Metadata metadataIn,
final Class<I> intf,
final Class<C> clazz,
final String name)
{
ObjectName objectName = null;
final String j2eeType = Util.deduceType(intf);
// must make a copy! May be an input value that is reused by caller
final Metadata metadata = new MetadataImpl(metadataIn);
try
{
final Constructor<C> c = clazz.getConstructor(ObjectName.class, Metadata.class);
final J2EEManagedObjectImplBase impl = c.newInstance(parent, metadata);
objectName = new ObjectNameBuilder(mMBeanServer, parent).buildChildObjectName(j2eeType, name);
objectName = mMBeanServer.registerMBean( impl, objectName ).getObjectName();
}
catch (final Exception e)
{
throw new RuntimeException( "Cannot register " + j2eeType + "=" + name + " as child of " + parent, e);
}
return objectName;
}
/**
* Examine the MBean to see if it is a ResourceRef that should be manifested under this server,
* and if so, register a JSR 77 MBean for it.
*/
public ObjectName processResourceRef(final ResourceRef ref) {
if (ref == null) {
throw new IllegalArgumentException("resource-ref is null");
}
if (!mServer.getName().equals(ref.getParent(Server.class).getName())) {
if (LOG.isLoggable(Level.FINEST)) {
LOG.log(Level.FINEST, "ResourceRef is not a child of server " + getObjectName(mServer));
}
return null;
}
// find the referenced resource
Resource res = null;
List<Resource> resources = getDomain().getResources().getResources();
for (Resource resource : resources) {
String name = null;
if (resource instanceof BindableResource) {
name = ((BindableResource) resource).getJndiName();
}
if (resource instanceof Named) {
name = ((Named) resource).getName();
}
if (resource instanceof ResourcePool) {
name = ((ResourcePool) resource).getName();
}
if (name != null && name.equals(ref.getRef())) {
res = resource;
}
}
if (res == null) {
throw new IllegalArgumentException("ResourceRef refers to non-existent resource: " + ref);
}
final String configType = Util.getTypeProp(getObjectName(res));
final Class<? extends J2EEManagedObjectImplBase> implClass = CONFIG_RESOURCE_TYPES.get(configType);
if (implClass == null) {
mLogger.fine("Unrecognized resource type for JSR 77 purposes: " + getObjectName(res));
return null;
}
final Class<J2EEManagedObject> intf = (Class) ClassUtil.getFieldValue(implClass, "INTF");
ObjectName mbean77 = null;
try {
final MetadataImpl meta = new MetadataImpl();
meta.setCorrespondingRef(getObjectName(ref));
meta.setCorrespondingConfig(getObjectName(res));
mbean77 = registerJ2EEChild(mJ2EEServer.objectName(), meta, intf, implClass,
Util.getNameProp(getObjectName(res)));
synchronized (mConfigRefTo77) {
mConfigRefTo77.put(getObjectName(ref), mbean77);
}
} catch (final Exception e) {
mLogger.log(Level.WARNING, AMXEELoggerInfo.cantRegisterMbean, new Object[] {getObjectName(ref), e});
}
return mbean77;
}
/**
Listen for registration/unregistration of {@link ResourceRef},
and associate them with JSR 77 MBeans for this J2EEServer.
Resources belong to a J2EEServer via ResourceRefs. So we can stay in the AMX
world by tracking registration and unregistration of AMX config MBeans of
type ResourceRef.
*/
private final class RefListener implements NotificationListener
{
public RefListener()
{
}
@Override
public void handleNotification(final Notification notifIn, final Object handback)
{
if (!(notifIn instanceof MBeanServerNotification))
{
return;
}
final MBeanServerNotification notif = (MBeanServerNotification) notifIn;
final ObjectName objectName = notif.getMBeanName();
if ( ! mJ2EEServer.objectName().getDomain().equals(objectName.getDomain()))
{
return;
}
final String type = Util.getTypeProp(objectName);
if (notif.getType().equals(MBeanServerNotification.REGISTRATION_NOTIFICATION))
{
if ( type.equals( mResourceRefType ) )
{
mLogger.fine("New ResourceRef MBEAN registered: " + objectName);
ConfigBean configBean = ConfigBeanRegistry.getInstance().getConfigBean(objectName);
if ( configBean instanceof ResourceRef ) {
final ResourceRef ref = (ResourceRef) configBean;
processResourceRef(ref);
}
}
else if ( type.equals( mApplicationRefType ) )
{
mLogger.fine( "NEW ApplicationRef MBEAN registered: " + objectName);
ConfigBean configBean = ConfigBeanRegistry.getInstance().getConfigBean(objectName);
if ( configBean instanceof ApplicationRef) {
final ApplicationRef ref = (ApplicationRef) configBean;
processApplicationRef(ref);
}
}
}
else if (notif.getType().equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION))
{
// determine if it's a config for which a JSR 77 MBean is registered
synchronized (mConfigRefTo77)
{
final ObjectName mbean77 = mConfigRefTo77.remove(objectName);
if (mbean77 != null)
{
mLogger.fine( "Unregistering MBEAN for ref: " + objectName);
try
{
mMBeanServer.unregisterMBean(mbean77);
}
catch (final Exception e)
{
mLogger.log( Level.WARNING, AMXEELoggerInfo.cantUnregisterMbean, objectName);
mLogger.log( Level.WARNING, null, e);
}
}
}
}
}
public void startListening()
{
// important: processResourceRef a listener *first* so that we don't miss anything
try
{
mMBeanServer.addNotificationListener(JMXUtil.getMBeanServerDelegateObjectName(), this, null, null);
}
catch (final JMException e)
{
throw new RuntimeException(e);
}
// register all existing
final List<ResourceRef> resourceRefs = mServer.getResourceRef();
for (final ResourceRef ref : resourceRefs)
{
processResourceRef(ref);
}
}
public void stopListening()
{
try
{
mMBeanServer.removeNotificationListener(JMXUtil.getMBeanServerDelegateObjectName(), this);
}
catch (final JMException e)
{
throw new RuntimeException(e);
}
}
}
}