
org.atmosphere.util.ExcludeSessionBroadcaster Maven / Gradle / Ivy
/*
* Copyright 2013 Jeanfrancois Arcand
*
* 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.
*/
/*
* Copyright 2013 Kagilum - Vincent Barrier - [email protected]
*
* 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.atmosphere.util;
import org.atmosphere.cpr.AtmosphereConfig;
import org.atmosphere.cpr.AtmosphereResource;
import org.atmosphere.cpr.BroadcasterFuture;
import org.atmosphere.cpr.DefaultBroadcaster;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpSession;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Future;
/**
* An implementation of {@link DefaultBroadcaster} that exclude one or more {@link AtmosphereResource}
*
* @author Jeanfrancois Arcand
*/
public class ExcludeSessionBroadcaster
extends DefaultBroadcaster {
private static final Logger logger = LoggerFactory.getLogger(ExcludeSessionBroadcaster.class);
public ExcludeSessionBroadcaster(String id, AtmosphereConfig config) {
super(id, config);
}
/**
* the AtmosphereResource r will be exclude for this broadcast
*
* @param msg
* @param r
* @param
* @return
*/
@Override
public Future broadcast(T msg, AtmosphereResource r) {
if (destroyed.get()) {
throw new IllegalStateException("This Broadcaster has been destroyed and cannot be used");
}
Set sub = new HashSet();
sub.addAll(resources);
sub.remove(r);
start();
Object newMsg = filter(msg);
if (newMsg == null) {
return null;
}
BroadcasterFuture
© 2015 - 2025 Weber Informatics LLC | Privacy Policy