org.atmosphere.plugin.jgroups.JGroupsChannel Maven / Gradle / Ivy
/*
* Copyright 2013 Jean-Francois 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.
*/
package org.atmosphere.plugin.jgroups;
import org.atmosphere.cpr.Broadcaster;
import org.jgroups.ChannelException;
import org.jgroups.JChannel;
import org.jgroups.Message;
import org.jgroups.ReceiverAdapter;
import com.vaadin.external.org.slf4j.Logger;
import com.vaadin.external.org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentLinkedQueue;
/**
* JGroupsChannel establishes a connection to a
* JGroups cluster. It sends/receives over that and forwards
* the received messages to the appropriate Broadcaster on its
* node.
*
* Best practice would have only 1 of these per Atmosphere application.
* Each JGroupsFilter instance has a reference to the
* singleton JGroupsChannel object and registers its broadcaster via
* the addBroadcaster() method.
*
* @author westraj
*
*/
public class JGroupsChannel extends ReceiverAdapter {
private static final Logger logger = LoggerFactory
.getLogger(JGroupsChannel.class);
/** JGroups JChannel object */
private final JChannel jchannel;
/** JChannel cluster name */
private final String clusterName;
/** globally unique ID for this JGroupsChannel object to tag it's messages with */
private final String id;
/** registers all the Broadcasters that are filtered via a JGroupsFilter */
private final Map broadcasters = new HashMap();
/** Holds original messages (not BroadcastMessage) received over a cluster broadcast */
private final ConcurrentLinkedQueue