1
1
/*
2
- * Copyright 2002-2024 the original author or authors.
2
+ * Copyright 2002-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -243,29 +243,28 @@ public void afterSingletonsInstantiated() {
243
243
244
244
this .singletonsInstantiated = true ;
245
245
}
246
- catch (RuntimeException e ) {
246
+ catch (RuntimeException ex ) {
247
247
unregisterBeans ();
248
- throw e ;
248
+ throw ex ;
249
249
}
250
250
}
251
251
252
252
private void populateMessageHandlers () {
253
253
Map <String , MessageHandler > messageHandlers = this .applicationContext .getBeansOfType (MessageHandler .class );
254
254
for (Entry <String , MessageHandler > entry : messageHandlers .entrySet ()) {
255
-
256
255
String beanName = entry .getKey ();
257
256
MessageHandler bean = entry .getValue ();
258
- if (this . handlerInAnonymousWrapper (bean ) != null ) {
257
+ if (handlerInAnonymousWrapper (bean ) != null ) {
259
258
if (logger .isDebugEnabled ()) {
260
259
logger .debug ("Skipping " + beanName + " because it wraps another handler" );
261
260
}
262
261
continue ;
263
262
}
264
263
// If the handler is proxied, we have to extract the target to expose as an MBean.
265
264
// The MetadataMBeanInfoAssembler does not support JDK dynamic proxies.
266
- MessageHandler monitor = ( MessageHandler ) extractTarget (bean );
267
- if (monitor instanceof IntegrationManagement ) {
268
- this .handlers .put (beanName , ( IntegrationManagement ) monitor );
265
+ MessageHandler monitor = extractTarget (bean );
266
+ if (monitor instanceof IntegrationManagement management ) {
267
+ this .handlers .put (beanName , management );
269
268
}
270
269
}
271
270
}
@@ -316,15 +315,15 @@ public Object postProcessAfterInitialization(Object bean, String beanName) throw
316
315
if (this .singletonsInstantiated ) {
317
316
try {
318
317
if (bean instanceof MessageChannel ) {
319
- MessageChannel monitor = ( MessageChannel ) extractTarget (bean );
320
- if (monitor instanceof IntegrationManagement ) {
321
- this .channels .put (beanName , ( IntegrationManagement ) monitor );
322
- registerChannel (( IntegrationManagement ) monitor );
318
+ MessageChannel monitor = extractTarget (bean );
319
+ if (monitor instanceof IntegrationManagement management ) {
320
+ this .channels .put (beanName , management );
321
+ registerChannel (management );
323
322
this .runtimeBeans .add (bean );
324
323
}
325
324
}
326
- else if (bean instanceof MessageProducer && bean instanceof Lifecycle ) {
327
- registerProducer (( MessageProducer ) bean );
325
+ else if (bean instanceof MessageProducer producer && bean instanceof Lifecycle ) {
326
+ registerProducer (producer );
328
327
this .runtimeBeans .add (bean );
329
328
}
330
329
else if (bean instanceof AbstractEndpoint ) {
@@ -341,19 +340,18 @@ else if (bean instanceof AbstractEndpoint) {
341
340
private void postProcessAbstractEndpoint (Object bean ) {
342
341
if (bean instanceof IntegrationConsumer integrationConsumer ) {
343
342
MessageHandler handler = integrationConsumer .getHandler ();
344
- MessageHandler monitor = (MessageHandler ) extractTarget (handler );
345
- if (monitor instanceof IntegrationManagement ) {
346
- registerHandler ((IntegrationManagement ) monitor , integrationConsumer );
347
- this .handlers .put (((IntegrationManagement ) monitor ).getComponentName (),
348
- (IntegrationManagement ) monitor );
343
+ MessageHandler monitor = extractTarget (handler );
344
+ if (monitor instanceof IntegrationManagement management ) {
345
+ registerHandler (management , integrationConsumer );
346
+ this .handlers .put (management .getComponentName (), management );
349
347
this .runtimeBeans .add (monitor );
350
348
}
351
349
return ;
352
350
}
353
351
else if (bean instanceof SourcePollingChannelAdapter pollingChannelAdapter ) {
354
352
MessageSource <?> messageSource = pollingChannelAdapter .getMessageSource ();
355
353
if (messageSource instanceof IntegrationInboundManagement ) {
356
- IntegrationInboundManagement monitor = ( IntegrationInboundManagement ) extractTarget (messageSource );
354
+ IntegrationInboundManagement monitor = extractTarget (messageSource );
357
355
registerSource (monitor );
358
356
this .sourceLifecycles .put (monitor , pollingChannelAdapter );
359
357
this .runtimeBeans .add (monitor );
@@ -366,7 +364,7 @@ else if (bean instanceof SourcePollingChannelAdapter pollingChannelAdapter) {
366
364
}
367
365
368
366
private void registerProducer (MessageProducer messageProducer ) {
369
- Lifecycle target = ( Lifecycle ) extractTarget (messageProducer );
367
+ Lifecycle target = extractTarget (messageProducer );
370
368
if (!(target instanceof AbstractMessageProducingHandler )) {
371
369
this .inboundLifecycleMessageProducers .add (target );
372
370
}
@@ -387,22 +385,22 @@ public void postProcessBeforeDestruction(Object bean, String beanName) throws Be
387
385
ObjectName objectName = this .objectNames .remove (bean );
388
386
if (objectName != null ) {
389
387
doUnregister (objectName );
390
- if (bean instanceof AbstractEndpoint ) {
391
- this .endpointNames .remove ((( AbstractEndpoint ) bean ) .getComponentName ());
388
+ if (bean instanceof AbstractEndpoint endpoint ) {
389
+ this .endpointNames .remove (endpoint .getComponentName ());
392
390
}
393
391
else {
394
392
395
393
this .endpointsByMonitor .remove (bean );
396
- if (bean instanceof IntegrationManagement && bean instanceof MessageChannel ) {
397
- this .channels .remove ((( NamedComponent ) bean ) .getComponentName ());
394
+ if (bean instanceof IntegrationManagement management && management instanceof MessageChannel ) {
395
+ this .channels .remove (management .getComponentName ());
398
396
}
399
- else if (bean instanceof IntegrationManagement && bean instanceof MessageHandler ) {
400
- this .handlers .remove ((( NamedComponent ) bean ) .getComponentName ());
401
- this .endpointNames .remove ((( NamedComponent ) bean ) .getComponentName ());
397
+ else if (bean instanceof IntegrationManagement management && management instanceof MessageHandler ) {
398
+ this .handlers .remove (management .getComponentName ());
399
+ this .endpointNames .remove (management .getComponentName ());
402
400
}
403
- else if (bean instanceof IntegrationInboundManagement && bean instanceof MessageSource ) {
404
- this .sources .remove ((( NamedComponent ) bean ) .getComponentName ());
405
- this .endpointNames .remove ((( NamedComponent ) bean ) .getComponentName ());
401
+ else if (bean instanceof IntegrationInboundManagement management && bean instanceof MessageSource ) {
402
+ this .sources .remove (management .getComponentName ());
403
+ this .endpointNames .remove (management .getComponentName ());
406
404
}
407
405
}
408
406
}
@@ -553,7 +551,7 @@ public void stopInboundMessageProducers() {
553
551
554
552
@ ManagedOperation
555
553
public void stopActiveChannels () {
556
- // Stop any "active" channels (JMS etc).
554
+ // Stop any "active" channels (JMS etc.)
557
555
for (IntegrationManagement metrics : this .channels .values ()) {
558
556
if (metrics instanceof Lifecycle ) {
559
557
if (logger .isInfoEnabled ()) {
@@ -759,15 +757,16 @@ private boolean matches(String[] patterns, String name) {
759
757
return match != null && match ;
760
758
}
761
759
762
- private Object extractTarget (Object bean ) {
760
+ @ SuppressWarnings ("unchecked" )
761
+ private <T > T extractTarget (Object bean ) {
763
762
if (!(bean instanceof Advised advised )) {
764
- return bean ;
763
+ return ( T ) bean ;
765
764
}
766
765
try {
767
766
return extractTarget (advised .getTargetSource ().getTarget ());
768
767
}
769
- catch (Exception e ) {
770
- logger .error ("Could not extract target" , e );
768
+ catch (Exception ex ) {
769
+ logger .error ("Could not extract target" , ex );
771
770
return null ;
772
771
}
773
772
}
@@ -979,11 +978,11 @@ private IntegrationInboundManagement buildMessageSourceMetricsIfAny(
979
978
}
980
979
981
980
MessageChannel outputChannel = null ;
982
- if (target instanceof MessagingGatewaySupport ) {
983
- outputChannel = (( MessagingGatewaySupport ) target ) .getRequestChannel ();
981
+ if (target instanceof MessagingGatewaySupport gatewaySupport ) {
982
+ outputChannel = gatewaySupport .getRequestChannel ();
984
983
}
985
- else if (target instanceof SourcePollingChannelAdapter ) {
986
- outputChannel = (( SourcePollingChannelAdapter ) target ) .getOutputChannel ();
984
+ else if (target instanceof SourcePollingChannelAdapter pollingChannelAdapter ) {
985
+ outputChannel = pollingChannelAdapter .getOutputChannel ();
987
986
}
988
987
989
988
if (outputChannel != null ) {
0 commit comments