org.fabric3.binding.web.runtime.common.ChannelBroadcaster Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fabric3-binding-web Show documentation
Show all versions of fabric3-binding-web Show documentation
Support for Comet and Websocket endpoints
/*
* Fabric3
* Copyright (c) 2009-2011 Metaform Systems
*
* Fabric3 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version, with the
* following exception:
*
* Linking this software statically or dynamically with other
* modules is making a combined work based on this software.
* Thus, the terms and conditions of the GNU General Public
* License cover the whole combination.
*
* As a special exception, the copyright holders of this software
* give you permission to link this software with independent
* modules to produce an executable, regardless of the license
* terms of these independent modules, and to copy and distribute
* the resulting executable under terms of your choice, provided
* that you also meet, for each linked independent module, the
* terms and conditions of the license of that module. An
* independent module is a module which is not derived from or
* based on this software. If you modify this software, you may
* extend this exception to your version of the software, but
* you are not obligated to do so. If you do not wish to do so,
* delete this exception statement from your version.
*
* Fabric3 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the
* GNU General Public License along with Fabric3.
* If not, see .
*/
package org.fabric3.binding.web.runtime.common;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.namespace.QName;
import org.atmosphere.cpr.AtmosphereResource;
import org.atmosphere.cpr.AtmosphereResourceEvent;
import org.atmosphere.cpr.BroadcasterFuture;
import org.atmosphere.cpr.DefaultBroadcaster;
import org.oasisopen.sca.ServiceRuntimeException;
import org.fabric3.spi.channel.EventWrapper;
import org.fabric3.spi.model.type.java.JavaClass;
import org.fabric3.spi.model.type.xsd.XSDType;
import org.fabric3.spi.transform.TransformationException;
import org.fabric3.spi.transform.Transformer;
import org.fabric3.spi.transform.TransformerRegistry;
import static org.fabric3.binding.web.runtime.common.ContentTypes.APPLICATION_XHTML_XML;
import static org.fabric3.binding.web.runtime.common.ContentTypes.APPLICATION_XML;
import static org.fabric3.binding.web.runtime.common.ContentTypes.TEXT_XML;
/**
* A synchronous Broadcaster
implementation. This class overrides the default Atmosphere asynchronous broadcast behavior as channels
* dispatch events to consumers asynchronously.
*
* This implementation transforms events from a Java type to a String using either a JSON transformer (the default) or an XML transformer according to
* the request accept header used to initiate the websocket or comet subscription. In the case of an XML transform, the broadcaster will dynamically
* request a transformer. This is necessary as the event type is not known statically and is required to create a JAXB context. To avoid creating XML
* transformers for every event, transformers are cached by event type. Care must therefore be taken to dispose of ChannelBroadcaster instances when
* an application is undeployed. Otherwise, lingering JAXB contexts containing references to application classes and classloaders may inhibit garbage
* collection.
*
* An additional performance optimization is made: string events that are contained in an EventWrapper are written directly to clients. This avoids
* deserialization and re-serialization when one client publishes an event, the event is flowed through a channel, and other clients are notified via
* the broadcaster. In this case, the serialized string representation is simply passed through without an intervening de-serialization.
*
* @version $Rev: 9763 $ $Date: 2011-01-03 00:48:06 +0000 (Mon, 03 Jan 2011) $
*/
public class ChannelBroadcaster extends DefaultBroadcaster {
private static final XSDType XSD_ANY = new XSDType(String.class, new QName(XSDType.XSD_NS, "anyType"));
private Transformer
© 2015 - 2025 Weber Informatics LLC | Privacy Policy