use of org.atmosphere.config.service.ManagedService in project atmosphere by Atmosphere.
the class ManagedServiceProcessor method handle.
@Override
public void handle(AtmosphereFramework framework, Class<Object> annotatedClass) {
try {
Class<?> aClass = annotatedClass;
ManagedService a = aClass.getAnnotation(ManagedService.class);
framework.setBroadcasterCacheClassName(a.broadcasterCache().getName());
List<AtmosphereInterceptor> l = new LinkedList<AtmosphereInterceptor>();
AnnotationUtil.defaultManagedServiceInterceptors(framework, l);
atmosphereConfig(a.atmosphereConfig(), framework);
filters(a.broadcastFilters(), framework);
AtmosphereInterceptor aa = listeners(a.listeners(), framework);
if (aa != null) {
l.add(aa);
}
Object c = framework.newClassInstance(Object.class, aClass);
AtmosphereHandler handler = framework.newClassInstance(ManagedAtmosphereHandler.class, ManagedAtmosphereHandler.class).configure(framework.getAtmosphereConfig(), c);
framework.filterManipulator(new BroadcasterConfig.FilterManipulator() {
@Override
public Object unwrap(Object o) {
if (o != null && ManagedAtmosphereHandler.Managed.class.isAssignableFrom(o.getClass())) {
o = ManagedAtmosphereHandler.Managed.class.cast(o).object();
}
return o;
}
@Override
public BroadcastFilter.BroadcastAction wrap(BroadcastFilter.BroadcastAction a, boolean wasWrapped) {
if (wasWrapped) {
return new BroadcastFilter.BroadcastAction(a.action(), new ManagedAtmosphereHandler.Managed(a.message()));
} else {
return a;
}
}
});
AnnotationUtil.interceptorsForManagedService(framework, Arrays.asList(a.interceptors()), l);
framework.addAtmosphereHandler(a.path(), handler, broadcaster(framework, a.broadcaster(), a.path()), l);
} catch (Throwable e) {
logger.warn("", e);
}
}
Aggregations