Search in sources :

Example 1 with ManagedService

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);
    }
}
Also used : ManagedService(org.atmosphere.config.service.ManagedService) AtmosphereInterceptor(org.atmosphere.runtime.AtmosphereInterceptor) BroadcasterConfig(org.atmosphere.runtime.BroadcasterConfig) LinkedList(java.util.LinkedList) ManagedAtmosphereHandler(org.atmosphere.config.managed.ManagedAtmosphereHandler) ManagedAtmosphereHandler(org.atmosphere.config.managed.ManagedAtmosphereHandler) AtmosphereHandler(org.atmosphere.runtime.AtmosphereHandler) BroadcastFilter(org.atmosphere.runtime.BroadcastFilter)

Aggregations

LinkedList (java.util.LinkedList)1 ManagedAtmosphereHandler (org.atmosphere.config.managed.ManagedAtmosphereHandler)1 ManagedService (org.atmosphere.config.service.ManagedService)1 AtmosphereHandler (org.atmosphere.runtime.AtmosphereHandler)1 AtmosphereInterceptor (org.atmosphere.runtime.AtmosphereInterceptor)1 BroadcastFilter (org.atmosphere.runtime.BroadcastFilter)1 BroadcasterConfig (org.atmosphere.runtime.BroadcasterConfig)1