org.atmosphere.cache.UUIDBroadcasterCache Java Examples

The following examples show how to use org.atmosphere.cache.UUIDBroadcasterCache. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebConfigurer.java    From springboot-angular-atmosphere-quickstart with Apache License 2.0 5 votes vote down vote up
private void configureAthmosphere(AtmosphereServlet servlet, ServletContext servletContext) {
  ServletRegistration.Dynamic atmosphereServlet = servletContext.addServlet("atmosphereServlet", servlet);
  atmosphereServlet.setInitParameter(ApplicationConfig.ANNOTATION_PACKAGE, ToastService.class.getPackage().getName());
  atmosphereServlet.setInitParameter(ApplicationConfig.BROADCASTER_CACHE, UUIDBroadcasterCache.class.getName());
  atmosphereServlet.setInitParameter(ApplicationConfig.BROADCASTER_SHARABLE_THREAD_POOLS, "true");
  atmosphereServlet.setInitParameter(ApplicationConfig.BROADCASTER_MESSAGE_PROCESSING_THREADPOOL_MAXSIZE, "10");
  atmosphereServlet.setInitParameter(ApplicationConfig.BROADCASTER_ASYNC_WRITE_THREADPOOL_MAXSIZE, "10");
  servletContext.addListener(new org.atmosphere.cpr.SessionSupport());
  atmosphereServlet.addMapping("/websocket/*");
  atmosphereServlet.setLoadOnStartup(0);
  atmosphereServlet.setAsyncSupported(true);
}
 
Example #2
Source File: AtmosphereModule.java    From joynr with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {

    params.put("suspend.seconds", "20");
    params.put("org.atmosphere.cpr.broadcasterClass", BounceProxyBroadcaster.class.getName());
    params.put("org.atmosphere.cpr.broadcasterCacheClass", UUIDBroadcasterCache.class.getName());
    params.put("org.atmosphere.useBlocking", "false");
    params.put("org.atmosphere.cpr.broadcasterLifeCyclePolicy", "NEVER");
    params.put("org.atmosphere.cpr.broadcaster.shareableThreadPool", "true");
    params.put("com.sun.jersey.config.feature.DisableWADL", "true");
    params.put("org.atmosphere.cpr.BroadcasterCache.strategy", "beforeFilter");

    bind(new TypeLiteral<Map<String, String>>() {
    }).annotatedWith(Names.named("org.atmosphere.guice.AtmosphereGuiceServlet.properties")).toInstance(params);
}
 
Example #3
Source File: BounceProxyBroadcaster.java    From joynr with Apache License 2.0 5 votes vote down vote up
public BounceProxyBroadcaster(String name, AtmosphereConfig config) {
    super(name, config);

    UUIDBroadcasterCache broadcasterCache = (UUIDBroadcasterCache) bc.getBroadcasterCache();
    broadcasterCache.setClientIdleTime(TimeUnit.DAYS.toMillis(7));

    // order of filters matters
    bc.addFilter(new ExpirationFilter());
    bc.addFilter(new MessageSerializationFilter());

}
 
Example #4
Source File: LongPollingMessagingDelegate.java    From joynr with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a long polling channel.
 *
 * @param ccid
 *            the identifier of the channel
 * @param atmosphereTrackingId
 *            the tracking ID of the channel
 * @return the path segment for the channel. The path, appended to the base
 *         URI of the channel service, can be used to post messages to the
 *         channel.
 */
public String createChannel(String ccid, String atmosphereTrackingId) {

    throwExceptionIfTrackingIdnotSet(atmosphereTrackingId);

    log.info("CREATE channel for cluster controller: {} trackingId: {} ", ccid, atmosphereTrackingId);
    Broadcaster broadcaster = null;
    // look for an existing broadcaster

    BroadcasterFactory defaultBroadcasterFactory = BroadcasterFactory.getDefault();
    if (defaultBroadcasterFactory == null) {
        throw new JoynrHttpException(500, 10009, "broadcaster was null");
    }

    broadcaster = defaultBroadcasterFactory.lookup(Broadcaster.class, ccid, false);
    // create a new one if none already exists
    if (broadcaster == null) {
        broadcaster = defaultBroadcasterFactory.get(BounceProxyBroadcaster.class, ccid);

    }

    // avoids error where previous long poll from browser got message
    // destined for new long poll
    // especially as seen in js, where every second refresh caused a fail
    for (AtmosphereResource resource : broadcaster.getAtmosphereResources()) {
        if (resource.uuid() != null && resource.uuid().equals(atmosphereTrackingId)) {
            resource.resume();
        }
    }

    UUIDBroadcasterCache broadcasterCache = (UUIDBroadcasterCache) broadcaster.getBroadcasterConfig()
                                                                              .getBroadcasterCache();
    broadcasterCache.activeClients().put(atmosphereTrackingId, System.currentTimeMillis());

    // BroadcasterCacheInspector is not implemented corrected in Atmosphere
    // 1.1.0RC4
    // broadcasterCache.inspector(new MessageExpirationInspector());

    return "/channels/" + ccid + "/";
}
 
Example #5
Source File: PushRequestHandler.java    From flow with Apache License 2.0 4 votes vote down vote up
/**
 * Initializes Atmosphere for the given ServletConfiguration.
 *
 * @param vaadinServletConfig
 *            The servlet configuration for the servlet which should have
 *            Atmosphere support
 */
static AtmosphereFramework initAtmosphere(
        final ServletConfig vaadinServletConfig) {
    AtmosphereFramework atmosphere = new AtmosphereFramework(false, false) {
        @Override
        protected void analytics() {
            // Overridden to disable version number check
        }

        @Override
        public AtmosphereFramework addInitParameter(String name,
                String value) {
            if (vaadinServletConfig.getInitParameter(name) == null) {
                super.addInitParameter(name, value);
            }
            return this;
        }
    };

    atmosphere.addAtmosphereHandler("/*", new PushAtmosphereHandler());
    atmosphere.addInitParameter(ApplicationConfig.BROADCASTER_CACHE,
            UUIDBroadcasterCache.class.getName());
    atmosphere.addInitParameter(ApplicationConfig.ANNOTATION_PROCESSOR,
            VoidAnnotationProcessor.class.getName());
    atmosphere.addInitParameter(ApplicationConfig.PROPERTY_SESSION_SUPPORT,
            "true");
    atmosphere.addInitParameter(ApplicationConfig.MESSAGE_DELIMITER,
            String.valueOf(PushConstants.MESSAGE_DELIMITER));
    atmosphere.addInitParameter(
            ApplicationConfig.DROP_ACCESS_CONTROL_ALLOW_ORIGIN_HEADER,
            "false");
    // Disable heartbeat (it does not emit correct events client side)
    // https://github.com/Atmosphere/atmosphere-javascript/issues/141
    atmosphere.addInitParameter(
            ApplicationConfig.DISABLE_ATMOSPHEREINTERCEPTORS,
            HeartbeatInterceptor.class.getName());

    final String bufferSize = String
            .valueOf(PushConstants.WEBSOCKET_BUFFER_SIZE);
    atmosphere.addInitParameter(ApplicationConfig.WEBSOCKET_BUFFER_SIZE,
            bufferSize);
    atmosphere.addInitParameter(ApplicationConfig.WEBSOCKET_MAXTEXTSIZE,
            bufferSize);
    atmosphere.addInitParameter(ApplicationConfig.WEBSOCKET_MAXBINARYSIZE,
            bufferSize);
    atmosphere.addInitParameter(
            ApplicationConfig.PROPERTY_ALLOW_SESSION_TIMEOUT_REMOVAL,
            "false");
    // This prevents Atmosphere from recreating a broadcaster after it has
    // already been destroyed when the servlet is being undeployed
    // (see #20026)
    atmosphere.addInitParameter(ApplicationConfig.RECOVER_DEAD_BROADCASTER,
            "false");
    // Disable Atmosphere's message about commercial support
    atmosphere.addInitParameter("org.atmosphere.cpr.showSupportMessage",
            "false");

    try {
        atmosphere.init(vaadinServletConfig);

        // Ensure the client-side knows how to split the message stream
        // into individual messages when using certain transports
        AtmosphereInterceptor trackMessageSize = new TrackMessageSizeInterceptor();
        trackMessageSize.configure(atmosphere.getAtmosphereConfig());
        atmosphere.interceptor(trackMessageSize);

    } catch (ServletException e) {
        throw new RuntimeException("Atmosphere init failed", e);
    }
    return atmosphere;
}