use of org.atmosphere.cpr.AtmosphereResourceEventImpl in project atmosphere by Atmosphere.
the class DefaultWebSocketProcessor method notifyListener.
@Override
public void notifyListener(WebSocket webSocket, WebSocketEventListener.WebSocketEvent event) {
AtmosphereResource resource = webSocket.resource();
if (resource == null)
return;
AtmosphereResourceImpl r = AtmosphereResourceImpl.class.cast(resource);
for (AtmosphereResourceEventListener l : r.atmosphereResourceEventListener()) {
if (WebSocketEventListener.class.isAssignableFrom(l.getClass())) {
try {
switch(event.type()) {
case CONNECT:
WebSocketEventListener.class.cast(l).onConnect(event);
break;
case DISCONNECT:
WebSocketEventListener.class.cast(l).onDisconnect(event);
onDisconnect(event, l);
break;
case CONTROL:
WebSocketEventListener.class.cast(l).onControl(event);
break;
case MESSAGE:
WebSocketEventListener.class.cast(l).onMessage(event);
break;
case HANDSHAKE:
WebSocketEventListener.class.cast(l).onHandshake(event);
break;
case CLOSE:
boolean isClosedByClient = r.getAtmosphereResourceEvent().isClosedByClient();
l.onDisconnect(new AtmosphereResourceEventImpl(r, !isClosedByClient, false, isClosedByClient, null));
onDisconnect(event, l);
WebSocketEventListener.class.cast(l).onClose(event);
break;
}
} catch (Throwable t) {
logger.debug("Listener error {}", t);
try {
WebSocketEventListener.class.cast(l).onThrowable(new AtmosphereResourceEventImpl(r, false, false, t));
} catch (Throwable t2) {
logger.warn("Listener error {}", t2);
}
}
} else {
switch(event.type()) {
case CLOSE:
boolean isClosedByClient = r.getAtmosphereResourceEvent().isClosedByClient();
l.onDisconnect(new AtmosphereResourceEventImpl(r, !isClosedByClient, false, isClosedByClient, null));
break;
}
}
}
}
use of org.atmosphere.cpr.AtmosphereResourceEventImpl in project atmosphere by Atmosphere.
the class OnDisconnectInterceptor method inspect.
@Override
public Action inspect(final AtmosphereResource r) {
if (Utils.webSocketMessage(r))
return Action.CONTINUE;
AtmosphereRequest request = ((AtmosphereResourceImpl) r).getRequest(false);
String uuid = r.uuid();
if (closeMessage(request)) {
if (config.resourcesFactory() == null || uuid == null) {
logger.debug("Illegal state for uuid {} and AtmosphereResourceFactory {}", r.uuid(), config.resourcesFactory());
return Action.CANCELLED;
}
AtmosphereResource ss = config.resourcesFactory().find(uuid);
if (ss == null) {
logger.debug("No Suspended Connection found for {}. Using the AtmosphereResource associated with the close message", uuid);
ss = r;
}
logger.debug("AtmosphereResource {} disconnected", uuid);
// Block websocket closing detection
((AtmosphereResourceEventImpl) ss.getAtmosphereResourceEvent()).isClosedByClient(true);
if (AsynchronousProcessor.class.isAssignableFrom(config.framework().getAsyncSupport().getClass())) {
((AsynchronousProcessor) config.framework().getAsyncSupport()).completeLifecycle(ss, false);
}
return Action.CANCELLED;
}
return Action.CONTINUE;
}
Aggregations