Search in sources :

Example 1 with AtmosphereHandlerService

use of org.atmosphere.config.service.AtmosphereHandlerService in project atmosphere by Atmosphere.

the class AtmosphereHandlerServiceProcessor method handle.

@Override
public void handle(AtmosphereFramework framework, Class<AtmosphereHandler> annotatedClass) {
    try {
        AtmosphereHandlerService a = annotatedClass.getAnnotation(AtmosphereHandlerService.class);
        atmosphereConfig(a.atmosphereConfig(), framework);
        filters(a.broadcastFilters(), framework);
        Class<?>[] interceptors = a.interceptors();
        LinkedList<AtmosphereInterceptor> l = new LinkedList<AtmosphereInterceptor>();
        for (Class i : interceptors) {
            try {
                AtmosphereInterceptor ai = (AtmosphereInterceptor) framework.newClassInstance(AtmosphereHandler.class, i);
                l.add(ai);
            } catch (Throwable e) {
                logger.warn("", e);
            }
        }
        AtmosphereInterceptor aa = listeners(a.listeners(), framework);
        if (aa != null) {
            l.add(aa);
        }
        if (a.path().contains("{")) {
            l.addFirst(framework.newClassInstance(AtmosphereInterceptor.class, AtmosphereHandlerServiceInterceptor.class));
        }
        framework.sessionSupport(a.supportSession());
        AtmosphereHandler handler = framework.newClassInstance(AtmosphereHandler.class, annotatedClass);
        for (String s : a.properties()) {
            String[] nv = s.split("=");
            IntrospectionUtils.setProperty(handler, nv[0], nv[1]);
            IntrospectionUtils.addProperty(handler, nv[0], nv[1]);
        }
        AnnotationUtil.interceptorsForHandler(framework, Arrays.asList(a.interceptors()), l);
        framework.addAtmosphereHandler(a.path(), handler, broadcaster(framework, a.broadcaster(), a.path()), l);
        framework.setBroadcasterCacheClassName(a.broadcasterCache().getName());
    } catch (Throwable e) {
        logger.warn("", e);
    }
}
Also used : AtmosphereInterceptor(org.atmosphere.runtime.AtmosphereInterceptor) AtmosphereHandlerService(org.atmosphere.config.service.AtmosphereHandlerService) AtmosphereHandlerServiceInterceptor(org.atmosphere.config.managed.AtmosphereHandlerServiceInterceptor) AtmosphereHandler(org.atmosphere.runtime.AtmosphereHandler) LinkedList(java.util.LinkedList)

Example 2 with AtmosphereHandlerService

use of org.atmosphere.config.service.AtmosphereHandlerService in project atmosphere by Atmosphere.

the class AtmosphereHandlerServiceInterceptor method mapAnnotatedService.

protected void mapAnnotatedService(boolean reMap, String path, AtmosphereRequest request, AtmosphereHandlerWrapper w) {
    synchronized (config.handlers()) {
        if (config.handlers().get(path) == null) {
            // AtmosphereHandlerService
            AtmosphereHandlerService m = w.atmosphereHandler.getClass().getAnnotation(AtmosphereHandlerService.class);
            if (m != null) {
                try {
                    String targetPath = m.path();
                    if (targetPath.indexOf("{") != -1 && targetPath.indexOf("}") != -1) {
                        boolean singleton = w.atmosphereHandler.getClass().getAnnotation(Singleton.class) != null;
                        AtmosphereHandler newW = w.atmosphereHandler;
                        if (!singleton) {
                            newW = config.framework().newClassInstance(AtmosphereHandler.class, w.atmosphereHandler.getClass());
                        }
                        request.localAttributes().put(Named.class.getName(), path.substring(targetPath.indexOf("{")));
                        AtmosphereResourceImpl.class.cast(request.resource()).atmosphereHandler(newW);
                        config.framework().addAtmosphereHandler(path, newW, config.getBroadcasterFactory().lookup(w.broadcaster.getClass(), path, true), w.interceptors);
                        request.setAttribute(FrameworkConfig.NEW_MAPPING, "true");
                    }
                } catch (Throwable e) {
                    logger.warn("Unable to create AtmosphereHandler", e);
                }
            }
        }
    }
}
Also used : AtmosphereHandlerService(org.atmosphere.config.service.AtmosphereHandlerService) Named(javax.inject.Named) AtmosphereHandler(org.atmosphere.runtime.AtmosphereHandler) Singleton(org.atmosphere.config.service.Singleton) AtmosphereResourceImpl(org.atmosphere.runtime.AtmosphereResourceImpl)

Aggregations

AtmosphereHandlerService (org.atmosphere.config.service.AtmosphereHandlerService)2 AtmosphereHandler (org.atmosphere.runtime.AtmosphereHandler)2 LinkedList (java.util.LinkedList)1 Named (javax.inject.Named)1 AtmosphereHandlerServiceInterceptor (org.atmosphere.config.managed.AtmosphereHandlerServiceInterceptor)1 Singleton (org.atmosphere.config.service.Singleton)1 AtmosphereInterceptor (org.atmosphere.runtime.AtmosphereInterceptor)1 AtmosphereResourceImpl (org.atmosphere.runtime.AtmosphereResourceImpl)1