use of org.atmosphere.cpr.AsynchronousProcessor in project atmosphere by Atmosphere.
the class DefaultWebSocketProcessor method configure.
public WebSocketProcessor configure(AtmosphereConfig config) {
this.framework = config.framework();
this.webSocketProtocol = framework.getWebSocketProtocol();
destroyable = Boolean.parseBoolean(framework.getAtmosphereConfig().getInitParameter(RECYCLE_ATMOSPHERE_REQUEST_RESPONSE));
executeAsync = Boolean.parseBoolean(framework.getAtmosphereConfig().getInitParameter(WEBSOCKET_PROTOCOL_EXECUTION));
allow1005StatusCode = Boolean.parseBoolean(framework.getAtmosphereConfig().getInitParameter(ALLOW_WEBSOCKET_STATUS_CODE_1005_AS_DISCONNECT));
String s = framework.getAtmosphereConfig().getInitParameter(IN_MEMORY_STREAMING_BUFFER_SIZE);
if (s != null) {
byteBufferMaxSize = Integer.parseInt(s);
charBufferMaxSize = byteBufferMaxSize;
}
if (executeAsync) {
asyncExecutor = ExecutorsFactory.getAsyncOperationExecutor(config, "WebSocket");
} else {
asyncExecutor = VoidExecutorService.VOID;
}
scheduler = ExecutorsFactory.getScheduler(config);
optimizeMapping();
closingTime = Long.valueOf(config.getInitParameter(ApplicationConfig.CLOSED_ATMOSPHERE_THINK_TIME, "0"));
invokeInterceptors = Boolean.valueOf(config.getInitParameter(INVOKE_ATMOSPHERE_INTERCEPTOR_ON_WEBSOCKET_MESSAGE, "true"));
config.startupHook(framework -> {
if (AsynchronousProcessor.class.isAssignableFrom(framework.getAsyncSupport().getClass())) {
asynchronousProcessor = AsynchronousProcessor.class.cast(framework.getAsyncSupport());
} else {
asynchronousProcessor = new AsynchronousProcessor(framework.getAtmosphereConfig()) {
@Override
public Action service(AtmosphereRequest req, AtmosphereResponse res) throws IOException, ServletException {
return framework.getAsyncSupport().service(req, res);
}
};
}
});
return this;
}
use of org.atmosphere.cpr.AsynchronousProcessor in project atmosphere by Atmosphere.
the class EncoderDecoderTest method create.
@BeforeMethod
public void create() throws Throwable {
framework = new AtmosphereFramework();
framework.setDefaultBroadcasterClassName(SimpleBroadcaster.class.getName());
framework.addAnnotationPackage(ManagedMessage.class);
framework.setAsyncSupport(new AsynchronousProcessor(framework.getAtmosphereConfig()) {
@Override
public Action service(AtmosphereRequest req, AtmosphereResponse res) throws IOException, ServletException {
return suspended(req, res);
}
public void action(AtmosphereResourceImpl r) {
try {
resumed(r.getRequest(), r.getResponse());
} catch (IOException e) {
e.printStackTrace();
} catch (ServletException e) {
e.printStackTrace();
}
}
}).init(new ServletConfig() {
@Override
public String getServletName() {
return "void";
}
@Override
public ServletContext getServletContext() {
return mock(ServletContext.class);
}
@Override
public String getInitParameter(String name) {
return null;
}
@Override
public Enumeration<String> getInitParameterNames() {
return null;
}
});
latch.set(new CountDownLatch(1));
}
use of org.atmosphere.cpr.AsynchronousProcessor 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