Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2017 Async-IO.org
*
* 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.cpr;
import java.net.URI;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
/**
* A Broadcaster is responsible for delivering messages to its subscribed {@link AtmosphereResource}s, which are
* representing suspended responses. {@link AtmosphereResource} can be added using {@link Broadcaster#addAtmosphereResource},
* so when {@link #broadcast(java.lang.Object)} is executed, {@link AtmosphereHandler#onStateChange(org.atmosphere.cpr.AtmosphereResourceEvent)}
* will be invoked and the suspended connection will have a chance to write the message available using {@link AtmosphereResourceEvent#getMessage()}.
*
* A {@link Broadcaster} will by default use an {@link ExecutorService}, and the number of Threads will be computed
* based on the number of cores/CPUs of the OS under which the application runs. Thus invoking
* {@link org.atmosphere.cpr.Broadcaster#broadcast(Object)} will be executed asynchronously so this is
* important to wait for the {@link Future#get} to awake/unblock to be guaranteed that the operation has completed.
*
* One final word on Broadcaster: by default, a Broadcaster will broadcast using
* all {@link AtmosphereResource} on which the response has been suspended, e.g. {AtmosphereResource#suspend()}
* has been invoked. This behavior is configurable and you can configure it by invoking the
* {@link Broadcaster#setScope(org.atmosphere.cpr.Broadcaster.SCOPE)} ):
*
REQUEST: broadcast events only to the AtmosphereResourceEvent associated with the current request.
*
APPLICATION: broadcast events to all AtmosphereResourceEvent created for the current web application.
*
VM: broadcast events to all AtmosphereResourceEvent created inside the current virtual machine.
*
*
* @author Jeanfrancois Arcand
*/
public interface Broadcaster {
public final static String ROOT_MASTER = "/*";
enum SCOPE {
REQUEST, APPLICATION, VM
}
enum POLICY {
FIFO, REJECT
}
/**
* Configure a Broadcaster.
* @param name
* @param uri
* @param config an {@link AtmosphereConfig}
* @return a usable Broadcaster.
*/
public Broadcaster initialize(String name, URI uri, AtmosphereConfig config);
/**
* Set the maximum number of suspended {@link AtmosphereResource}s. If the maximum is reached, Atmosphere will either
* resume {@link AtmosphereResource} using {@link org.atmosphere.cpr.Broadcaster.POLICY#FIFO} (first in first out)
* or {@link org.atmosphere.cpr.Broadcaster.POLICY#REJECT} the {@link AtmosphereResource}.
*
* By default the number is unlimited.
*
* @param maxSuspended maximum number of suspended AtmosphereResource
* @oaram policy the {@link org.atmosphere.cpr.Broadcaster.POLICY}
*/
void setSuspendPolicy(long maxSuspended, POLICY policy);
/**
* Broadcast the {@link Object} to all suspended responses, eg. invoke {@link AtmosphereHandler#onStateChange}.
*
* @param o the {@link Object} to be broadcasted
* @return a {@link Future} that can be used to synchronize using the {@link Future#get()}
*/
Future