001/*
002 * Copyright 2002-2017 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.config;
018
019import java.util.Arrays;
020import java.util.Collection;
021import java.util.Collections;
022import java.util.List;
023
024import org.springframework.lang.Nullable;
025import org.springframework.messaging.MessageChannel;
026import org.springframework.messaging.SubscribableChannel;
027import org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler;
028import org.springframework.util.Assert;
029
030/**
031 * Base class for message broker registration classes.
032 *
033 * @author Rossen Stoyanchev
034 * @since 4.0
035 */
036public abstract class AbstractBrokerRegistration {
037
038        private final SubscribableChannel clientInboundChannel;
039
040        private final MessageChannel clientOutboundChannel;
041
042        private final List<String> destinationPrefixes;
043
044
045        public AbstractBrokerRegistration(SubscribableChannel clientInboundChannel,
046                        MessageChannel clientOutboundChannel, @Nullable String[] destinationPrefixes) {
047
048                Assert.notNull(clientOutboundChannel, "'clientInboundChannel' must not be null");
049                Assert.notNull(clientOutboundChannel, "'clientOutboundChannel' must not be null");
050
051                this.clientInboundChannel = clientInboundChannel;
052                this.clientOutboundChannel = clientOutboundChannel;
053
054                this.destinationPrefixes = (destinationPrefixes != null ?
055                                Arrays.asList(destinationPrefixes) : Collections.emptyList());
056        }
057
058
059        protected SubscribableChannel getClientInboundChannel() {
060                return this.clientInboundChannel;
061        }
062
063        protected MessageChannel getClientOutboundChannel() {
064                return this.clientOutboundChannel;
065        }
066
067        protected Collection<String> getDestinationPrefixes() {
068                return this.destinationPrefixes;
069        }
070
071
072        protected abstract AbstractBrokerMessageHandler getMessageHandler(SubscribableChannel brokerChannel);
073
074}