001/* 002 * Copyright 2002-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.messaging.simp.annotation; 018 019import java.lang.annotation.Documented; 020import java.lang.annotation.ElementType; 021import java.lang.annotation.Retention; 022import java.lang.annotation.RetentionPolicy; 023import java.lang.annotation.Target; 024 025import org.springframework.core.annotation.AliasFor; 026 027/** 028 * Indicates the return value of a message-handling method should be sent as a 029 * {@link org.springframework.messaging.Message} to the specified destination(s) 030 * further prepended with <code>"/user/{username}"</code> where the user name 031 * is extracted from the headers of the input message being handled. 032 * 033 * <p>Both {@code @SendTo} and {@code @SendToUser} may be used on the same method 034 * in which case a message is sent to the destinations of both annotations. 035 * 036 * <p>This annotation may be placed class-level in which case it is inherited 037 * by methods of the class. At the same time, method-level {@code @SendTo} or 038 * {@code @SendToUser} annotations override any such at the class level. 039 040 * @author Rossen Stoyanchev 041 * @author Sam Brannen 042 * @since 4.0 043 * @see org.springframework.messaging.simp.annotation.support.SendToMethodReturnValueHandler 044 * @see org.springframework.messaging.simp.user.UserDestinationMessageHandler 045 * @see org.springframework.messaging.simp.SimpMessageHeaderAccessor#getUser() 046 */ 047@Target({ElementType.TYPE, ElementType.METHOD}) 048@Retention(RetentionPolicy.RUNTIME) 049@Documented 050public @interface SendToUser { 051 052 /** 053 * Alias for {@link #destinations}. 054 * @see #destinations 055 */ 056 @AliasFor("destinations") 057 String[] value() default {}; 058 059 /** 060 * One or more destinations to send a message to. 061 * <p>If left unspecified, a default destination is selected based on the 062 * destination of the input message being handled. 063 * @since 4.2 064 * @see #value 065 * @see org.springframework.messaging.simp.annotation.support.SendToMethodReturnValueHandler 066 */ 067 @AliasFor("value") 068 String[] destinations() default {}; 069 070 /** 071 * Whether messages should be sent to all sessions associated with the user 072 * or only to the session of the input message being handled. 073 * <p>By default, this is set to {@code true} in which case messages are 074 * broadcast to all sessions. 075 */ 076 boolean broadcast() default true; 077 078}