org.cometd.bayeux.server.ConfigurableServerChannel Maven / Gradle / Ivy
/*
* Copyright (c) 2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.cometd.bayeux.server;
import java.util.List;
import org.cometd.bayeux.Bayeux;
import org.cometd.bayeux.Channel;
/**
* A {@link ConfigurableServerChannel} offers an API that can be used to
* configure {@link ServerChannel}s at creation time.
* {@link ServerChannel}s may be created concurrently via
* {@link BayeuxServer#createChannelIfAbsent(String, ConfigurableServerChannel.Initializer...)}
* and it is important that the creation of a channel is atomic so that its
* configuration is executed only once, and so that it is guaranteed that
* it happens before any message can be published or received by the channel.
*/
public interface ConfigurableServerChannel extends Channel {
/**
* @param listener the listener to add
* @see #removeListener(ServerChannelListener)
*/
public void addListener(ServerChannelListener listener);
/**
* @param listener the listener to remove
* @see #addListener(ServerChannelListener)
*/
public void removeListener(ServerChannelListener listener);
/**
* @return an immutable list of listeners
* @see #addListener(ServerChannelListener)
*/
public List getListeners();
/**
* @return whether the channel is lazy
* @see #setLazy(boolean)
*/
public boolean isLazy();
/**
* A lazy channel marks all messages published to it as lazy.
*
* @param lazy whether the channel is lazy
* @see #isLazy()
*/
public void setLazy(boolean lazy);
/**
* @return the lazy timeout for this channel
* @see #setLazyTimeout(long)
*/
public long getLazyTimeout();
/**
* Sets the lazy timeout for this channel.
* A positive value makes the channel lazy, a negative value makes the channel non-lazy.
*
* @param lazyTimeout the lazy timeout for this channel
* @see #setLazy(boolean)
*/
public void setLazyTimeout(long lazyTimeout);
/**
* @return whether the channel is persistent
* @see #setPersistent(boolean)
*/
public boolean isPersistent();
/**
* A persistent channel is not removed when the last subscription is removed
*
* @param persistent whether the channel is persistent
* @see #isPersistent()
*/
public void setPersistent(boolean persistent);
/**
* @return whether the channel broadcasts messages back to the publisher
*/
public boolean isBroadcastToPublisher();
/**
* Sets whether a publisher that is also a subscriber to the channel
* will receive the messages it publishes on that channel.
*
* @param broadcastToPublisher whether the channel broadcasts messages back to the publisher
*/
public void setBroadcastToPublisher(boolean broadcastToPublisher);
/**
* Adds the given {@link Authorizer} that grants or denies operations on this channel.
* Operations must be granted by at least one Authorizer and must not be denied by any.
*
* @param authorizer the Authorizer to add
* @see #removeAuthorizer(Authorizer)
* @see Authorizer
*/
public void addAuthorizer(Authorizer authorizer);
/**
* Removes the given {@link Authorizer}.
*
* @param authorizer the Authorizer to remove
* @see #addAuthorizer(Authorizer)
*/
public void removeAuthorizer(Authorizer authorizer);
/**
* @return an immutable list of authorizers for this channel
*/
public List getAuthorizers();
/**
* A listener interface by means of which listeners can atomically
* set the initial configuration of a channel.
*/
public interface Initializer {
/**
* Callback invoked when a channel is created and needs to be configured
*
* @param channel the channel to configure
*/
public void configureChannel(ConfigurableServerChannel channel);
/**
* Utility class that initializes channels to be persistent
*/
public static class Persistent implements Initializer {
@Override
public void configureChannel(ConfigurableServerChannel channel) {
channel.setPersistent(true);
}
}
}
/**
* Common interface for {@link ServerChannel} listeners.
* Specific sub-interfaces define what kind of event listeners will be notified.
*/
public interface ServerChannelListener extends Bayeux.BayeuxListener {
/**
* Tag interface that marks {@link ServerChannelListener}s as "weak".
* {@link ServerChannel}s that are not {@link ServerChannel#isPersistent() persistent},
* that have no subscribers and that only have weak listeners are eligible to be
* {@link ServerChannel#remove() removed}.
*/
public interface Weak extends ServerChannelListener {
}
}
}