001/*
002 * Copyright 2002-2013 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.web.socket.client.standard;
018
019import javax.websocket.ContainerProvider;
020import javax.websocket.WebSocketContainer;
021
022import org.springframework.beans.factory.FactoryBean;
023
024/**
025 * A FactoryBean for creating and configuring a {@link javax.websocket.WebSocketContainer}
026 * through Spring XML configuration. In Java configuration, ignore this class and use
027 * {@code ContainerProvider.getWebSocketContainer()} instead.
028 *
029 * @author Rossen Stoyanchev
030 * @since 4.0
031 */
032public class WebSocketContainerFactoryBean implements FactoryBean<WebSocketContainer> {
033
034        private final WebSocketContainer webSocketContainer = ContainerProvider.getWebSocketContainer();
035
036
037        public void setAsyncSendTimeout(long timeoutInMillis) {
038                this.webSocketContainer.setAsyncSendTimeout(timeoutInMillis);
039        }
040
041        public long getAsyncSendTimeout() {
042                return this.webSocketContainer.getDefaultAsyncSendTimeout();
043        }
044
045        public void setMaxSessionIdleTimeout(long timeoutInMillis) {
046                this.webSocketContainer.setDefaultMaxSessionIdleTimeout(timeoutInMillis);
047        }
048
049        public long getMaxSessionIdleTimeout() {
050                return this.webSocketContainer.getDefaultMaxSessionIdleTimeout();
051        }
052
053        public void setMaxTextMessageBufferSize(int bufferSize) {
054                this.webSocketContainer.setDefaultMaxTextMessageBufferSize(bufferSize);
055        }
056
057        public int getMaxTextMessageBufferSize() {
058                return this.webSocketContainer.getDefaultMaxTextMessageBufferSize();
059        }
060
061        public void setMaxBinaryMessageBufferSize(int bufferSize) {
062                this.webSocketContainer.setDefaultMaxBinaryMessageBufferSize(bufferSize);
063        }
064
065        public int getMaxBinaryMessageBufferSize() {
066                return this.webSocketContainer.getDefaultMaxBinaryMessageBufferSize();
067        }
068
069        @Override
070        public WebSocketContainer getObject() throws Exception {
071                return this.webSocketContainer;
072        }
073
074        @Override
075        public Class<?> getObjectType() {
076                return WebSocketContainer.class;
077        }
078
079        @Override
080        public boolean isSingleton() {
081                return true;
082        }
083
084}