001/* 002 * Copyright 2002-2016 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 * Annotation that indicates that the return value of a message-handling method 029 * should be sent as a {@link org.springframework.messaging.Message} to the specified 030 * destination(s) 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>The annotation may also be placed at class-level in which case all methods 034 * in the class where the annotation applies will inherit it. 035 036 * @author Rossen Stoyanchev 037 * @author Sam Brannen 038 * @since 4.0 039 * @see org.springframework.messaging.simp.annotation.support.SendToMethodReturnValueHandler 040 * @see org.springframework.messaging.simp.user.UserDestinationMessageHandler 041 * @see org.springframework.messaging.simp.SimpMessageHeaderAccessor#getUser() 042 */ 043@Target({ElementType.METHOD, ElementType.TYPE}) 044@Retention(RetentionPolicy.RUNTIME) 045@Documented 046public @interface SendToUser { 047 048 /** 049 * Alias for {@link #destinations}. 050 * @see #destinations 051 */ 052 @AliasFor("destinations") 053 String[] value() default {}; 054 055 /** 056 * One or more destinations to send a message to. 057 * <p>If left unspecified, a default destination is selected based on the 058 * destination of the input message being handled. 059 * @since 4.2 060 * @see #value 061 * @see org.springframework.messaging.simp.annotation.support.SendToMethodReturnValueHandler 062 */ 063 @AliasFor("value") 064 String[] destinations() default {}; 065 066 /** 067 * Whether messages should be sent to all sessions associated with the user 068 * or only to the session of the input message being handled. 069 * <p>By default, this is set to {@code true} in which case messages are 070 * broadcast to all sessions. 071 */ 072 boolean broadcast() default true; 073 074}