ScheduledFuture<?> scheduleHeartbeat() { return getBroadcaster().getBroadcasterConfig().getScheduledExecutorService() .schedule(heartBeatTask, heartBeatInterval, TimeUnit.MILLISECONDS); }
ScheduledFuture<?> scheduleHeartbeat() { return getBroadcaster().getBroadcasterConfig().getScheduledExecutorService() .schedule(heartBeatTask, heartBeatInterval, TimeUnit.MILLISECONDS); }
void configureFilter(Broadcaster bc){ BroadcasterConfig c = bc.getBroadcasterConfig(); // Always the first one, before any transformation/filtering for (ClusterBroadcastFilter cbf: clusters){ cbf.setBroadcaster(bc); c.addFilter(cbf); } org.atmosphere.cpr.BroadcastFilter f = null; if (filters != null){ for (Class<org.atmosphere.cpr.BroadcastFilter> filter: filters){ try{ f = filter.newInstance(); } catch (Throwable t){ logger.warning("Invalid @BroadcastFilter: " + filter); } c.addFilter(f); } } }
private void delayBatchBroadcast(final AtmosphereResource r, Long delay) { String uuid = r.uuid(); r.getBroadcaster().getBroadcasterConfig().getScheduledExecutorService().schedule(new Runnable() { @Override public void run() { synchronized (getMutex(uuid)) { List<JSONObject> messages = messagesForUuid.get(uuid); if (messages != null) { JSONObject batchMessage = new JSONObject(); JSONArray jsonMessages = new JSONArray(messages); batchMessage.put("data", jsonMessages); batchMessage.put("type", "batch"); r.getBroadcaster().broadcast(batchMessage.toString(), r); broadcastScheduledForUuid.remove(uuid); messages.clear(); } } } }, delay, TimeUnit.MILLISECONDS); broadcastScheduledForUuid.put(uuid, true); }
void configureFilter(Broadcaster bc) { if (bc == null) throw new WebApplicationException(new IllegalStateException("Broadcaster cannot be null")); /** * Here we can't predict if it's the same set of filter shared across all Broadcaster as * Broadcaster can have their own BroadcasterConfig instance. */ BroadcasterConfig c = bc.getBroadcasterConfig(); // Already configured if (c.hasFilters()) { return; } // Always the first one, before any transformation/filtering for (ClusterBroadcastFilter cbf : clusters) { cbf.setBroadcaster(bc); c.addFilter(cbf); } BroadcastFilter f = null; if (filters != null) { for (Class<BroadcastFilter> filter : filters) { try { f = filter.newInstance(); } catch (Throwable t) { logger.warn("Invalid @BroadcastFilter: " + filter, t); } c.addFilter(f); } } }
String method = request.getMethod(); resource.getBroadcaster().getBroadcasterConfig().addFilter(injectEndpoint ? onPerMessageFilter : onMessageFilter);
@Override public void sendMessage(List<SocketIOPacketImpl> messages) throws SocketIOException { if (messages != null) { for (SocketIOPacketImpl msg : messages) { switch (msg.getFrameType()) { case MESSAGE: case JSON: case EVENT: case ACK: case ERROR: msg.setPadding(messages.size() > 1); try { sendMessage(msg.toString()); } catch (Exception e) { AtmosphereResourceImpl resource = session.getAtmosphereResourceImpl(); // if BroadcastCache is available, add the message to the cache if (resource != null && DefaultBroadcaster.class.isAssignableFrom(resource.getBroadcaster().getClass())) { resource.getBroadcaster().getBroadcasterConfig().getBroadcasterCache(). addToCache(resource.getBroadcaster().getID(), resource.uuid(), new BroadcastMessage(msg)); } } break; default: logger.error("Unknown SocketIOEvent msg = " + msg); } } } }
List<Object> cachedMessages = resource.getBroadcaster().getBroadcasterConfig().getBroadcasterCache() .retrieveFromCache(resource.getBroadcaster().getID(), resource.uuid());
/** * Creates and registers an {@code EventBus} for the given application and broadcaster * * @param application * @param broadcaster */ public EventBus(WebApplication application, Broadcaster broadcaster) { this.application = application; this.broadcaster = broadcaster; application.setMetaData(EVENT_BUS_KEY, this); application.mount(new AtmosphereRequestMapper(createEventSubscriptionInvoker())); application.getComponentPostOnBeforeRenderListeners().add( createEventSubscriptionCollector()); application.getSessionStore().registerUnboundListener(this); checkEnabledAnalytics(getBroadcaster().getBroadcasterConfig().getAtmosphereConfig()); }