1 /* 2 * Copyright 2002-2018 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 module hunt.stomp.simp.SimpAttributesContextHolder; 18 19 import hunt.stomp.Message; 20 21 // import hunt.framework.core.NamedThreadLocal; 22 23 // /** 24 // * Holder class to expose SiMP attributes associated with a session (e.g. WebSocket) 25 // * in the form of a thread-bound {@link SimpAttributes} object. 26 // * 27 // * @author Rossen Stoyanchev 28 // * @since 4.1 29 // */ 30 // abstract class SimpAttributesContextHolder { 31 32 // private static final ThreadLocal!(SimpAttributes) attributesHolder = 33 // new NamedThreadLocal<>("SiMP session attributes"); 34 35 36 // /** 37 // * Reset the SimpAttributes for the current thread. 38 // */ 39 // public static void resetAttributes() { 40 // attributesHolder.remove(); 41 // } 42 43 // /** 44 // * Bind the given SimpAttributes to the current thread. 45 // * @param attributes the RequestAttributes to expose 46 // */ 47 // public static void setAttributes(SimpAttributes attributes) { 48 // if (attributes !is null) { 49 // attributesHolder.set(attributes); 50 // } 51 // else { 52 // resetAttributes(); 53 // } 54 // } 55 56 // /** 57 // * Extract the SiMP session attributes from the given message, wrap them in 58 // * a {@link SimpAttributes} instance and bind it to the current thread. 59 // * @param message the message to extract session attributes from 60 // */ 61 // public static void setAttributesFromMessage(MessageBase message) { 62 // setAttributes(SimpAttributes.fromMessage(message)); 63 // } 64 65 // /** 66 // * Return the SimpAttributes currently bound to the thread. 67 // * @return the attributes or {@code null} if not bound 68 // */ 69 70 // public static SimpAttributes getAttributes() { 71 // return attributesHolder.get(); 72 // } 73 74 // /** 75 // * Return the SimpAttributes currently bound to the thread or raise an 76 // * {@link java.lang.IllegalStateException} if none are bound. 77 // * @return the attributes, never {@code null} 78 // * @throws java.lang.IllegalStateException if attributes are not bound 79 // */ 80 // public static SimpAttributes currentAttributes() throws IllegalStateException { 81 // SimpAttributes attributes = getAttributes(); 82 // if (attributes is null) { 83 // throw new IllegalStateException("No thread-bound SimpAttributes found. " ~ 84 // "Your code is probably not processing a client message and executing in " ~ 85 // "message-handling methods invoked by the SimpAnnotationMethodMessageHandler?"); 86 // } 87 // return attributes; 88 // } 89 90 // }