/** {@inheritDoc} */ public void setScope(SCOPE scope) { this.scope = scope; if (scope != SCOPE.REQUEST) { return; } try { for (AtmosphereResource<?, ?> resource : resources) { Broadcaster b = BroadcasterFactory.getDefault() .get(getClass(), getClass().getSimpleName() + "/" + UUID.randomUUID()); if (DefaultBroadcaster.class.isAssignableFrom(this.getClass())) { BroadcasterCache cache = bc.getBroadcasterCache().getClass().newInstance(); InjectorProvider.getInjector().inject(cache); DefaultBroadcaster.class.cast(b).broadcasterCache = cache; } resource.setBroadcaster(b); if (resource.getAtmosphereResourceEvent().isSuspended()) { b.addAtmosphereResource(resource); } } if (!resources.isEmpty()) { destroy(); } } catch (Exception e) { logger.error("failed to set request scope for current resources", e); } }
private Broadcaster createBroadcaster(Class<? extends Broadcaster> c, Object id) throws BroadcasterCreationException { try { Broadcaster b = c.getConstructor(String.class, AtmosphereConfig.class).newInstance(id.toString(), config); InjectorProvider.getInjector().inject(b); if (b.getBroadcasterConfig() == null) { b.setBroadcasterConfig( new BroadcasterConfig(config.framework().broadcasterFilters, config)); } b.setBroadcasterLifeCyclePolicy(policy); if (DefaultBroadcaster.class.isAssignableFrom(clazz)) { DefaultBroadcaster.class.cast(b).start(); } for (BroadcasterListener l : broadcasterListeners) { b.addBroadcasterListener(l); } notifyOnPostCreate(b); return b; } catch (Throwable t) { throw new BroadcasterCreationException(t); } }