1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package nginx.unit.websocket.server; 18 19 import java.util.List; 20 import java.util.Map; 21 import java.util.concurrent.ConcurrentHashMap; 22 23 import javax.websocket.Decoder; 24 import javax.websocket.Encoder; 25 import javax.websocket.Extension; 26 import javax.websocket.server.ServerEndpointConfig; 27 28 /** 29 * Wraps the provided {@link ServerEndpointConfig} and provides a per session 30 * view - the difference being that the map returned by {@link 31 * #getUserProperties()} is unique to this instance rather than shared with the 32 * wrapped {@link ServerEndpointConfig}. 33 */ 34 class WsPerSessionServerEndpointConfig implements ServerEndpointConfig { 35 36 private final ServerEndpointConfig perEndpointConfig; 37 private final Map<String,Object> perSessionUserProperties = 38 new ConcurrentHashMap<>(); 39 WsPerSessionServerEndpointConfig(ServerEndpointConfig perEndpointConfig)40 WsPerSessionServerEndpointConfig(ServerEndpointConfig perEndpointConfig) { 41 this.perEndpointConfig = perEndpointConfig; 42 perSessionUserProperties.putAll(perEndpointConfig.getUserProperties()); 43 } 44 45 @Override getEncoders()46 public List<Class<? extends Encoder>> getEncoders() { 47 return perEndpointConfig.getEncoders(); 48 } 49 50 @Override getDecoders()51 public List<Class<? extends Decoder>> getDecoders() { 52 return perEndpointConfig.getDecoders(); 53 } 54 55 @Override getUserProperties()56 public Map<String,Object> getUserProperties() { 57 return perSessionUserProperties; 58 } 59 60 @Override getEndpointClass()61 public Class<?> getEndpointClass() { 62 return perEndpointConfig.getEndpointClass(); 63 } 64 65 @Override getPath()66 public String getPath() { 67 return perEndpointConfig.getPath(); 68 } 69 70 @Override getSubprotocols()71 public List<String> getSubprotocols() { 72 return perEndpointConfig.getSubprotocols(); 73 } 74 75 @Override getExtensions()76 public List<Extension> getExtensions() { 77 return perEndpointConfig.getExtensions(); 78 } 79 80 @Override getConfigurator()81 public Configurator getConfigurator() { 82 return perEndpointConfig.getConfigurator(); 83 } 84 } 85