Search in sources :

Example 1 with MeteorService

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

the class MeteorServiceProcessor method handle.

@Override
public void handle(AtmosphereFramework framework, Class<Servlet> annotatedClass) {
    try {
        ReflectorServletProcessor r = framework.newClassInstance(ReflectorServletProcessor.class, ReflectorServletProcessor.class);
        r.setServletClassName(annotatedClass.getName());
        LinkedList<AtmosphereInterceptor> l = new LinkedList<AtmosphereInterceptor>();
        MeteorService m = annotatedClass.getAnnotation(MeteorService.class);
        framework.setBroadcasterCacheClassName(m.broadcasterCache().getName());
        String mapping = m.path();
        atmosphereConfig(m.atmosphereConfig(), framework);
        filters(m.broadcastFilters(), framework);
        AtmosphereInterceptor aa = listeners(m.listeners(), framework);
        if (aa != null) {
            l.add(aa);
        }
        AnnotationUtil.interceptorsForHandler(framework, Arrays.asList(m.interceptors()), l);
        if (m.path().contains("{")) {
            l.addFirst(framework.newClassInstance(AtmosphereInterceptor.class, MeteorServiceInterceptor.class));
        }
        framework.addAtmosphereHandler(mapping, r, broadcaster(framework, m.broadcaster(), m.path()), l);
    } catch (Throwable e) {
        logger.warn("", e);
    }
}
Also used : AtmosphereInterceptor(org.atmosphere.runtime.AtmosphereInterceptor) MeteorService(org.atmosphere.config.service.MeteorService) ReflectorServletProcessor(org.atmosphere.handler.ReflectorServletProcessor) MeteorServiceInterceptor(org.atmosphere.config.managed.MeteorServiceInterceptor) LinkedList(java.util.LinkedList)

Example 2 with MeteorService

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

the class MeteorServiceInterceptor method mapAnnotatedService.

protected void mapAnnotatedService(boolean reMap, String path, AtmosphereRequest request, AtmosphereFramework.AtmosphereHandlerWrapper w) {
    synchronized (config.handlers()) {
        if (config.handlers().get(path) == null) {
            // MeteorService
            if (ReflectorServletProcessor.class.isAssignableFrom(w.atmosphereHandler.getClass())) {
                ReflectorServletProcessor r = ReflectorServletProcessor.class.cast(w.atmosphereHandler);
                Servlet s = r.getServlet();
                MeteorService m = s.getClass().getAnnotation(MeteorService.class);
                if (m != null) {
                    String targetPath = m.path();
                    if (targetPath.indexOf("{") != -1 && targetPath.indexOf("}") != -1) {
                        try {
                            boolean singleton = s.getClass().getAnnotation(Singleton.class) != null;
                            if (!singleton) {
                                r = config.framework().newClassInstance(ReflectorServletProcessor.class, ReflectorServletProcessor.class);
                                r.setServlet(config.framework().newClassInstance(Servlet.class, s.getClass()));
                                r.init(config);
                            }
                            request.localAttributes().put(Named.class.getName(), path.substring(targetPath.indexOf("{")));
                            AtmosphereResourceImpl.class.cast(request.resource()).atmosphereHandler(r);
                            config.framework().addAtmosphereHandler(path, r, 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);
                        }
                    }
                }
            }
        } else if (reMap) {
            request.setAttribute(FrameworkConfig.NEW_MAPPING, "true");
        }
    }
}
Also used : MeteorService(org.atmosphere.config.service.MeteorService) Named(javax.inject.Named) Singleton(org.atmosphere.config.service.Singleton) Servlet(javax.servlet.Servlet) ReflectorServletProcessor(org.atmosphere.handler.ReflectorServletProcessor) AtmosphereResourceImpl(org.atmosphere.runtime.AtmosphereResourceImpl)

Aggregations

MeteorService (org.atmosphere.config.service.MeteorService)2 ReflectorServletProcessor (org.atmosphere.handler.ReflectorServletProcessor)2 LinkedList (java.util.LinkedList)1 Named (javax.inject.Named)1 Servlet (javax.servlet.Servlet)1 MeteorServiceInterceptor (org.atmosphere.config.managed.MeteorServiceInterceptor)1 Singleton (org.atmosphere.config.service.Singleton)1 AtmosphereInterceptor (org.atmosphere.runtime.AtmosphereInterceptor)1 AtmosphereResourceImpl (org.atmosphere.runtime.AtmosphereResourceImpl)1