com.google.sitebricks.channel.ChannelModule Maven / Gradle / Ivy
package com.google.sitebricks.channel;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import com.google.common.collect.ImmutableSet;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
import com.google.inject.servlet.ServletModule;
/**
* Install to set up sitebricks channel support for websocket (or other available
* transports, such as Google AppEngine's Channel API).
*
* @author [email protected] (Dhanji R. Prasanna)
*/
public abstract class ChannelModule extends ServletModule {
static final String CHANNEL_URL_NAME = "__SB:CHANNEL_URL";
private final String channelUrl;
private static final Set SUPPORTED_SYSTEMS =
ImmutableSet.of(
"jetty-websocket",
"jetty-continuation"
);
private final Map handlers = new HashMap();
public ChannelModule(String channelUrl) {
if (channelUrl == null || channelUrl.isEmpty()
|| !channelUrl.startsWith("/"))
addError("ChannelModule URL must begin with '/' but found: " + channelUrl);
else if (channelUrl.endsWith("/") && channelUrl.length() > 1)
channelUrl = channelUrl.substring(0, channelUrl.length() - 1);
this.channelUrl = channelUrl;
}
@Override
protected final void configureServlets() {
configureChannels();
bind(Switchboard.class).to(ChannelSwitchboard.class);
bind(new TypeLiteral