use of org.atmosphere.config.service.Singleton 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.contains("{") && targetPath.contains("}")) {
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) 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);
}
}
}
}
}
use of org.atmosphere.config.service.Singleton 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) w.atmosphereHandler;
Servlet s = r.getServlet();
if (s == null) {
logger.warn("Invalid ReflectorServletProcessor state. Servlet is null");
return;
}
MeteorService m = s.getClass().getAnnotation(MeteorService.class);
if (m != null) {
String targetPath = m.path();
if (targetPath.contains("{") && targetPath.contains("}")) {
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) 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");
}
}
}
use of org.atmosphere.config.service.Singleton in project atmosphere by Atmosphere.
the class DefaultWebSocketProcessor method postProcessMapping.
protected WebSocketHandler postProcessMapping(WebSocket webSocket, AtmosphereRequest request, WebSocketHandlerProxy w) {
WebSocketHandlerProxy p = null;
String path = w.path();
if (wildcardMapping()) {
String pathInfo = null;
try {
pathInfo = request.getPathInfo();
} catch (IllegalStateException ex) {
// http://java.net/jira/browse/GRIZZLY-1301
}
if (pathInfo != null) {
path = request.getServletPath() + pathInfo;
} else {
path = request.getServletPath();
}
if (path == null || path.isEmpty()) {
path = "/";
}
synchronized (handlers) {
p = handlers.get(path);
if (p == null) {
// AtmosphereHandlerService
WebSocketHandlerService a = w.proxied.getClass().getAnnotation(WebSocketHandlerService.class);
if (a != null) {
String targetPath = a.path();
if (targetPath.indexOf("{") != -1 && targetPath.indexOf("}") != -1) {
try {
boolean singleton = w.proxied.getClass().getAnnotation(Singleton.class) != null;
if (!singleton) {
w = new WebSocketHandlerProxy(a.broadcaster(), framework.newClassInstance(WebSocketHandler.class, w.proxied.getClass()));
}
registerWebSocketHandler(path, new WebSocketHandlerProxy(a.broadcaster(), w));
request.localAttributes().put(Named.class.getName(), path.substring(targetPath.indexOf("{")));
p = handlers.get(path);
} catch (Throwable e) {
logger.warn("Unable to create WebSocketHandler", e);
}
}
}
}
}
}
try {
webSocket.resource().setBroadcaster(AnnotationUtil.broadcaster(framework, p != null ? p.broadcasterClazz : w.broadcasterClazz, path));
} catch (Exception e) {
logger.error("", e);
}
return p != null ? p : w;
}
use of org.atmosphere.config.service.Singleton in project atmosphere by Atmosphere.
the class ManagedServiceInterceptor method mapAnnotatedService.
protected void mapAnnotatedService(boolean reMap, String path, AtmosphereRequest request, AtmosphereFramework.AtmosphereHandlerWrapper w) {
synchronized (config.handlers()) {
if (config.handlers().get(path) == null) {
// ManagedService
if (AnnotatedProxy.class.isAssignableFrom(w.atmosphereHandler.getClass())) {
AnnotatedProxy ap = (AnnotatedProxy) w.atmosphereHandler;
ManagedAnnotation a = managed(ap, request.resource());
if (a != null) {
String targetPath = a.path();
if (targetPath.contains("{") && targetPath.contains("}")) {
try {
boolean singleton = ap.target().getClass().getAnnotation(Singleton.class) != null;
if (!singleton) {
ap = proxyHandler();
final Object o = config.framework().newClassInstance(Object.class, AnnotatedProxy.class.cast(w.atmosphereHandler).target().getClass());
ap.configure(config, o);
}
request.localAttributes().put(Named.class.getName(), path.substring(targetPath.indexOf("{")));
if (ap.pathParams()) {
request.localAttributes().put(PathParam.class.getName(), new String[] { path, targetPath });
}
((AtmosphereResourceImpl) request.resource()).atmosphereHandler(ap);
config.framework().addAtmosphereHandler(path, ap, config.getBroadcasterFactory().lookup(a.broadcaster(), 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