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);
}
}
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");
}
}
}
Aggregations