use of org.atmosphere.handler.AbstractReflectorAtmosphereHandler in project atmosphere by Atmosphere.
the class AtmosphereResourceListenerTest method testListenersCallback.
@Test
public void testListenersCallback() throws IOException, ServletException {
framework.addAtmosphereHandler("/a", new AbstractReflectorAtmosphereHandler() {
@Override
public void onRequest(AtmosphereResource resource) throws IOException {
}
@Override
public void destroy() {
}
});
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().pathInfo("/a").build();
final AtomicReference<Boolean> suspended = new AtomicReference<Boolean>();
final AtomicReference<Boolean> resumed = new AtomicReference<Boolean>();
final AtomicReference<Boolean> disconnected = new AtomicReference<Boolean>();
final AtomicReference<Boolean> preSuspended = new AtomicReference<Boolean>();
final AtomicReference<Boolean> broadcasted = new AtomicReference<Boolean>();
final AtmosphereResourceEventListener listener = new AtmosphereResourceEventListener() {
@Override
public void onPreSuspend(AtmosphereResourceEvent event) {
preSuspended.set(true);
}
@Override
public void onSuspend(AtmosphereResourceEvent event) {
suspended.set(true);
}
@Override
public void onResume(AtmosphereResourceEvent event) {
resumed.set(true);
}
@Override
public void onHeartbeat(AtmosphereResourceEvent event) {
}
@Override
public void onDisconnect(AtmosphereResourceEvent event) {
disconnected.set(true);
}
@Override
public void onBroadcast(AtmosphereResourceEvent event) {
broadcasted.set(true);
}
@Override
public void onThrowable(AtmosphereResourceEvent event) {
}
@Override
public void onClose(AtmosphereResourceEvent event) {
}
};
framework.interceptor(new AtmosphereInterceptor() {
@Override
public void configure(AtmosphereConfig config) {
}
@Override
public void destroy() {
}
@Override
public Action inspect(AtmosphereResource r) {
r.addEventListener(listener).suspend();
try {
r.getBroadcaster().broadcast("void").get();
} catch (InterruptedException e) {
} catch (ExecutionException e) {
}
return Action.CONTINUE;
}
@Override
public void postInspect(AtmosphereResource r) {
r.resume();
}
});
framework.doCometSupport(request, AtmosphereResponseImpl.newInstance());
assertTrue(preSuspended.get());
assertTrue(suspended.get());
assertTrue(resumed.get());
assertTrue(broadcasted.get());
}
use of org.atmosphere.handler.AbstractReflectorAtmosphereHandler in project atmosphere by Atmosphere.
the class AtmosphereResourceListenerTest method testOnClose.
@Test
public void testOnClose() throws IOException, ServletException {
framework.addAtmosphereHandler("/a", new AbstractReflectorAtmosphereHandler() {
@Override
public void onRequest(AtmosphereResource resource) throws IOException {
}
@Override
public void destroy() {
}
});
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().pathInfo("/a").build();
final AtomicReference<Boolean> closed = new AtomicReference<Boolean>();
final AtmosphereResourceEventListener listener = new AtmosphereResourceEventListenerAdapter() {
@Override
public void onClose(AtmosphereResourceEvent event) {
closed.set(true);
}
};
framework.interceptor(new AtmosphereInterceptor() {
@Override
public void configure(AtmosphereConfig config) {
}
@Override
public void destroy() {
}
@Override
public Action inspect(AtmosphereResource r) {
r.addEventListener(listener).suspend();
try {
r.getBroadcaster().broadcast("void").get();
} catch (InterruptedException e) {
} catch (ExecutionException e) {
}
return Action.CONTINUE;
}
@Override
public void postInspect(AtmosphereResource r) {
try {
r.close();
} catch (IOException e) {
e.printStackTrace();
}
}
});
framework.doCometSupport(request, AtmosphereResponseImpl.newInstance());
assertTrue(closed.get());
}
Aggregations