Browse Source

Polishing contribution

Closes gh-34333
pull/34400/head
rstoyanchev 10 months ago
parent
commit
ccdaed594e
  1. 11
      spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserDestinationMessageHandler.java
  2. 9
      spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserDestinationResult.java
  3. 2
      spring-messaging/src/test/java/org/springframework/messaging/simp/user/UserDestinationMessageHandlerTests.java

11
spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserDestinationMessageHandler.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2024 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -280,11 +280,10 @@ public class UserDestinationMessageHandler implements MessageHandler, SmartLifec
return this.messagingTemplate; return this.messagingTemplate;
} }
public void send(UserDestinationResult destinationResult, Message<?> message) throws MessagingException { public void send(UserDestinationResult result, Message<?> message) throws MessagingException {
Iterator<String> itr = destinationResult.getSessionIds().iterator(); Iterator<String> itr = result.getSessionIds().iterator();
for (String target : result.getTargetDestinations()) {
for (String target : destinationResult.getTargetDestinations()) { String sessionId = (itr.hasNext() ? itr.next() : null);
String sessionId = (itr != null && itr.hasNext() ? itr.next() : null);
getTemplateToUse(sessionId).send(target, message); getTemplateToUse(sessionId).send(target, message);
} }
} }

9
spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserDestinationResult.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -44,7 +44,11 @@ public class UserDestinationResult {
private final Set<String> sessionIds; private final Set<String> sessionIds;
public UserDestinationResult(String sourceDestination, Set<String> targetDestinations, /**
* Main constructor.
*/
public UserDestinationResult(
String sourceDestination, Set<String> targetDestinations,
String subscribeDestination, @Nullable String user) { String subscribeDestination, @Nullable String user) {
this(sourceDestination, targetDestinations, subscribeDestination, user, null); this(sourceDestination, targetDestinations, subscribeDestination, user, null);
@ -114,7 +118,6 @@ public class UserDestinationResult {
/** /**
* Return the session id for the targetDestination. * Return the session id for the targetDestination.
*/ */
@Nullable
public Set<String> getSessionIds() { public Set<String> getSessionIds() {
return this.sessionIds; return this.sessionIds;
} }

2
spring-messaging/src/test/java/org/springframework/messaging/simp/user/UserDestinationMessageHandlerTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2024 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

Loading…
Cancel
Save