Consistent SmartLifecycle implementations

Issue: SPR-14233
(cherry picked from commit f83cbff)
This commit is contained in:
Juergen Hoeller
2016-05-02 13:01:44 +02:00
parent 85faeef816
commit 85675fbe2e
11 changed files with 146 additions and 144 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -272,13 +272,6 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
return Integer.MAX_VALUE;
}
@Override
public final boolean isRunning() {
synchronized (this.lifecycleMonitor) {
return this.running;
}
}
@Override
public final void start() {
synchronized (this.lifecycleMonitor) {
@@ -303,6 +296,13 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
}
}
@Override
public final boolean isRunning() {
synchronized (this.lifecycleMonitor) {
return this.running;
}
}
protected List<HandlerMethodArgumentResolver> initArgumentResolvers() {
ConfigurableBeanFactory beanFactory = (getApplicationContext() instanceof ConfigurableApplicationContext ?

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,6 @@
package org.springframework.messaging.simp.user;
import static org.springframework.messaging.simp.SimpMessageHeaderAccessor.*;
import java.util.Arrays;
import java.util.List;
@@ -154,13 +152,6 @@ public class UserDestinationMessageHandler implements MessageHandler, SmartLifec
return true;
}
@Override
public final boolean isRunning() {
synchronized (this.lifecycleMonitor) {
return this.running;
}
}
@Override
public final void start() {
synchronized (this.lifecycleMonitor) {
@@ -187,6 +178,13 @@ public class UserDestinationMessageHandler implements MessageHandler, SmartLifec
}
}
@Override
public final boolean isRunning() {
synchronized (this.lifecycleMonitor) {
return this.running;
}
}
@Override
public void handleMessage(Message<?> message) throws MessagingException {
@@ -211,7 +209,7 @@ public class UserDestinationMessageHandler implements MessageHandler, SmartLifec
}
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.wrap(message);
initHeaders(accessor);
accessor.setNativeHeader(ORIGINAL_DESTINATION, result.getSubscribeDestination());
accessor.setNativeHeader(SimpMessageHeaderAccessor.ORIGINAL_DESTINATION, result.getSubscribeDestination());
accessor.setLeaveMutable(true);
message = MessageBuilder.createMessage(message.getPayload(), accessor.getMessageHeaders());
if (logger.isTraceEnabled()) {
@@ -242,18 +240,15 @@ public class UserDestinationMessageHandler implements MessageHandler, SmartLifec
private static final List<String> NO_COPY_LIST = Arrays.asList("subscription", "message-id");
private final MessageSendingOperations<String> messagingTemplate;
private final String broadcastDestination;
public BroadcastHandler(MessageSendingOperations<String> template, String destination) {
this.messagingTemplate = template;
this.broadcastDestination = destination;
}
public String getBroadcastDestination() {
return this.broadcastDestination;
}
@@ -263,12 +258,13 @@ public class UserDestinationMessageHandler implements MessageHandler, SmartLifec
if (!getBroadcastDestination().equals(destination)) {
return message;
}
SimpMessageHeaderAccessor accessor = getAccessor(message, SimpMessageHeaderAccessor.class);
SimpMessageHeaderAccessor accessor =
SimpMessageHeaderAccessor.getAccessor(message, SimpMessageHeaderAccessor.class);
if (accessor.getSessionId() == null) {
// Our own broadcast
return null;
}
destination = accessor.getFirstNativeHeader(ORIGINAL_DESTINATION);
destination = accessor.getFirstNativeHeader(SimpMessageHeaderAccessor.ORIGINAL_DESTINATION);
if (logger.isTraceEnabled()) {
logger.trace("Checking unresolved user destination: " + destination);
}
@@ -286,13 +282,14 @@ public class UserDestinationMessageHandler implements MessageHandler, SmartLifec
public void handleUnresolved(Message<?> message) {
MessageHeaders headers = message.getHeaders();
if (SimpMessageHeaderAccessor.getFirstNativeHeader(ORIGINAL_DESTINATION, headers) != null) {
if (SimpMessageHeaderAccessor.getFirstNativeHeader(
SimpMessageHeaderAccessor.ORIGINAL_DESTINATION, headers) != null) {
// Re-broadcast
return;
}
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.wrap(message);
String destination = accessor.getDestination();
accessor.setNativeHeader(ORIGINAL_DESTINATION, destination);
accessor.setNativeHeader(SimpMessageHeaderAccessor.ORIGINAL_DESTINATION, destination);
accessor.setLeaveMutable(true);
message = MessageBuilder.createMessage(message.getPayload(), accessor.getMessageHeaders());
if (logger.isTraceEnabled()) {