void configureResumeOnBroadcast(Broadcaster b) { Iterator<AtmosphereResource> i = b.getAtmosphereResources().iterator(); while (i.hasNext()) { HttpServletRequest r = i.next().getRequest(); r.setAttribute(RESUME_ON_BROADCAST, true); } }
@Override protected void disconnect() { if (broadcaster.getAtmosphereResources().size() == 0) { onClose(); } else { for (AtmosphereResource r : broadcaster.getAtmosphereResources()) { r.resume(); try { r.close(); } catch (IOException e) { throw new RuntimeException(e); } } } }
logger.info("Connecting to comet with: " +resource.getRequest().getRequestURI()); Broadcaster broadcaster = BroadcasterFactory.getDefault().lookup(YOUR_CONNECTION_ID, true); if(broadcaster.getAtmosphereResources().size()>0){ logger.debug("Broadcaster recovered with name: " + broadcaster.getID());
/** * Check to see if this atmosphere resource is still in use by the system. * It will query the associated broadcaster if it is still referenced. * * @return */ @Override public boolean isAlive() { if (writer.isTerminated()) { return false; } if ((System.currentTimeMillis() - startTime) < WARMUP_TIME) { return true; } if (atmResource.getBroadcaster() == null) { return false; } Collection<AtmosphereResource> res = atmResource.getBroadcaster().getAtmosphereResources(); for (AtmosphereResource ar : res) { if (ar == atmResource) { return true; } } return suspended; }
/** * Check to see if this atmosphere resource is still in use by the system. * It will query the associated broadcaster if it is still referenced. * * @return */ @Override public boolean isAlive() { if (writer.isTerminated()) { return false; } if ((System.currentTimeMillis() - startTime) < WARMUP_TIME) { return true; } if (atmResource.getBroadcaster() == null) { return false; } Collection<AtmosphereResource> res = atmResource.getBroadcaster().getAtmosphereResources(); for (AtmosphereResource ar : res) { if (ar == atmResource) { return true; } } return suspended; }
/** * Post an event to all pages that have a suspended connection. This will invoke the event * handlers on components, annotated with {@link Subscribe}. The resulting AJAX updates are * pushed to the clients. * * @param event */ public void post(Object event) { ThreadContext oldContext = ThreadContext.get(false); try { for (AtmosphereResource resource : ImmutableList.copyOf(getBroadcaster().getAtmosphereResources())) { postToSingleResource(event, resource); } } finally { ThreadContext.restore(oldContext); } }
Broadcaster broadcaster = BroadcasterFactory.getDefault().lookup( YOUR_CLIENT_ID, true); if (broadcaster.getAtmosphereResources().size() > 0) { logger.debug("Broadcaster recovered with name: " + broadcaster.getID());
/** * Post an event to all pages that have a suspended connection. This will invoke the event * handlers on components, annotated with {@link Subscribe}. The resulting AJAX updates are * pushed to the clients. * * @param event */ public void post(Object event) { ThreadContext oldContext = ThreadContext.get(false); try { for (AtmosphereResource resource : broadcaster.getAtmosphereResources()) { postToSingleResource(event, resource); } } finally { ThreadContext.restore(oldContext); } }
@PathParam("topic") Broadcaster broadcaster; @Suspend(contentType = "application/json") @GET public SuspendResponse<String> search() { if (broadcaster.getAtmosphereResources().size() == 0) { broadcaster.scheduleFixedBroadcast(new Callable<String>() { public String call() throws Exception { // Wait for the connection to be suspended. broadcaster.broadcast("broadcast"); return null; } }, 5000, TimeUnit.MILLISECONDS); } return new SuspendResponse.SuspendResponseBuilder<String>() .broadcaster(broadcaster) .outputComments(true) .addListener(new EventsLogger() { @Override public void onSuspend( AtmosphereResourceEvent event) { super.onSuspend(event); } }).build(); }
@Disconnect public final void onDisconnect(final AtmosphereResourceEvent event){ Collection<AtmosphereResource> atmosphereResources = event.getResource().getBroadcaster().getAtmosphereResources(); if (atmosphereResources.size() < 2 && subscription != null) { synchronized (subscription) { subscription.unsubscribe(); subscription = null; } LOG.debug("[websocket {}] [broadcaster:#{}] unsubscribed !", scopeAsAString, event.getResource().getBroadcaster().getID()); } if (event.isCancelled()) { LOG.info("[websocket {}] Client {} cancelled the connection", scopeAsAString, event.getResource().uuid()); } else if(event.isClosedByClient()) { LOG.info("[websocket {}] Client {} closed the connection", scopeAsAString, event.getResource().uuid()); } }
throw new WebApplicationException(authorizationException); if (feed.getAtmosphereResources().size() == 0) {
logger.info("Atmo Resource Size: " + bc.getAtmosphereResources().size());