use of org.atmosphere.websocket.WebSocketProcessor in project atmosphere by Atmosphere.
the class AtmosphereFramework method info.
private void info() {
if (logger.isTraceEnabled()) {
Enumeration<String> e = servletConfig.getInitParameterNames();
logger.trace("Configured init-params");
String n;
while (e.hasMoreElements()) {
n = e.nextElement();
logger.trace("\t{} = {}", n, servletConfig.getInitParameter(n));
}
}
logger.info("Using EndpointMapper {}", endpointMapper.getClass());
for (String i : broadcasterFilters) {
logger.info("Using BroadcastFilter: {}", i);
}
if (broadcasterCacheClassName == null || DefaultBroadcasterCache.class.getName().equals(broadcasterCacheClassName)) {
logger.warn("No BroadcasterCache configured. Broadcasted message between client reconnection will be LOST. " + "It is recommended to configure the {}", UUIDBroadcasterCache.class.getName());
} else {
logger.info("Using BroadcasterCache: {}", broadcasterCacheClassName);
}
String s = config.getInitParameter(BROADCASTER_WAIT_TIME);
logger.info("Default Broadcaster Class: {}", broadcasterClassName);
logger.info("Broadcaster Shared List Resources: {}", config.getInitParameter(BROADCASTER_SHAREABLE_LISTENERS, false));
logger.info("Broadcaster Polling Wait Time {}", s == null ? DefaultBroadcaster.POLLING_DEFAULT : s);
logger.info("Shared ExecutorService supported: {}", sharedThreadPools);
ExecutorService executorService = ExecutorsFactory.getMessageDispatcher(config, Broadcaster.ROOT_MASTER);
if (executorService != null) {
if (ThreadPoolExecutor.class.isAssignableFrom(executorService.getClass())) {
long max = ThreadPoolExecutor.class.cast(executorService).getMaximumPoolSize();
logger.info("Messaging Thread Pool Size: {}", ThreadPoolExecutor.class.cast(executorService).getMaximumPoolSize() == 2147483647 ? "Unlimited" : max);
} else {
logger.info("Messaging ExecutorService Pool Size unavailable - Not instance of ThreadPoolExecutor");
}
}
executorService = ExecutorsFactory.getAsyncOperationExecutor(config, Broadcaster.ROOT_MASTER);
if (executorService != null) {
if (ThreadPoolExecutor.class.isAssignableFrom(executorService.getClass())) {
logger.info("Async I/O Thread Pool Size: {}", ThreadPoolExecutor.class.cast(executorService).getMaximumPoolSize());
} else {
logger.info("Async I/O ExecutorService Pool Size unavailable - Not instance of ThreadPoolExecutor");
}
}
logger.info("Using BroadcasterFactory: {}", broadcasterFactory.getClass().getName());
logger.info("Using AtmosphereResurceFactory: {}", arFactory.getClass().getName());
logger.info("Using WebSocketProcessor: {}", webSocketProcessorClassName);
if (defaultSerializerClassName != null && !defaultSerializerClassName.isEmpty()) {
logger.info("Using Serializer: {}", defaultSerializerClassName);
}
WebSocketProcessor wp = WebSocketProcessorFactory.getDefault().getWebSocketProcessor(this);
boolean b = false;
if (DefaultWebSocketProcessor.class.isAssignableFrom(wp.getClass())) {
b = DefaultWebSocketProcessor.class.cast(wp).invokeInterceptors();
}
logger.info("Invoke AtmosphereInterceptor on WebSocket message {}", b);
logger.info("HttpSession supported: {}", config.isSupportSession());
logger.info("Atmosphere is using {} for dependency injection and object creation", objectFactory);
logger.info("Atmosphere is using async support: {} running under container: {}", getAsyncSupport().getClass().getName(), asyncSupport.getContainerName());
logger.info("Atmosphere Framework {} started.", Version.getRawVersion());
logger.info("\n\n\tFor Atmosphere Framework Commercial Support, visit \n\t{} " + "or send an email to {}\n", "http://www.async-io.org/", "support@async-io.org");
if (logger.isTraceEnabled()) {
for (Entry<String, AtmosphereHandlerWrapper> e : atmosphereHandlers.entrySet()) {
logger.trace("\nConfigured AtmosphereHandler {}\n", e.getKey());
logger.trace("{}", e.getValue());
}
}
}
use of org.atmosphere.websocket.WebSocketProcessor in project atmosphere by Atmosphere.
the class WebSocketProcessorFactory method createProcessor.
private WebSocketProcessor createProcessor(AtmosphereFramework framework) {
WebSocketProcessor processor = null;
String webSocketProcessorName = framework.getWebSocketProcessorClassName();
if (!webSocketProcessorName.equalsIgnoreCase(DefaultWebSocketProcessor.class.getName())) {
try {
processor = framework.newClassInstance(WebSocketProcessor.class, (Class<WebSocketProcessor>) IOUtils.loadClass(getClass(), webSocketProcessorName));
} catch (Exception ex) {
logger.error("Unable to create {}", webSocketProcessorName);
processor = new DefaultWebSocketProcessor();
}
}
if (processor == null) {
processor = new DefaultWebSocketProcessor();
}
processor.configure(framework.getAtmosphereConfig());
return processor;
}
use of org.atmosphere.websocket.WebSocketProcessor in project atmosphere by Atmosphere.
the class TrackMessageSizeInterceptorTest method testTrackMessageSize.
private void testTrackMessageSize(boolean enabled, AtmosphereInterceptor icp, String expected) throws Exception {
ByteArrayOutputStream b = new ByteArrayOutputStream();
final WebSocket w = new ArrayBaseWebSocket(b);
final WebSocketProcessor processor = WebSocketProcessorFactory.getDefault().getWebSocketProcessor(framework);
framework.interceptor(icp);
framework.addAtmosphereHandler("/*", new AtmosphereHandler() {
@Override
public void onRequest(AtmosphereResource resource) throws IOException {
resource.getResponse().write(resource.getRequest().getReader().readLine());
}
@Override
public void onStateChange(AtmosphereResourceEvent event) throws IOException {
event.getResource().write(event.getMessage().toString().getBytes());
}
@Override
public void destroy() {
}
});
Map<String, String> reqheaders = new HashMap<String, String>();
if (enabled) {
reqheaders.put(HeaderConfig.X_ATMOSPHERE_TRACKMESSAGESIZE, "true");
}
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().destroyable(false).headers(reqheaders).body("yoComet").pathInfo("/a").build();
processor.open(w, request, AtmosphereResponseImpl.newInstance(framework.getAtmosphereConfig(), request, w));
processor.invokeWebSocketProtocol(w, "yoWebSocket");
assertEquals(b.toString(), expected);
}
use of org.atmosphere.websocket.WebSocketProcessor in project atmosphere by Atmosphere.
the class WebSocketProcessorTest method basicWorkflow.
@Test
public void basicWorkflow() throws IOException, ServletException, ExecutionException, InterruptedException {
ByteArrayOutputStream b = new ByteArrayOutputStream();
final WebSocket w = new ArrayBaseWebSocket(b);
final WebSocketProcessor processor = WebSocketProcessorFactory.getDefault().getWebSocketProcessor(framework);
framework.addAtmosphereHandler("/*", new AtmosphereHandler() {
@Override
public void onRequest(AtmosphereResource resource) throws IOException {
resource.getBroadcaster().addAtmosphereResource(resource.suspend());
resource.getResponse().write(resource.getRequest().getReader().readLine());
}
@Override
public void onStateChange(AtmosphereResourceEvent event) throws IOException {
event.getResource().write(event.getMessage().toString().getBytes());
}
@Override
public void destroy() {
}
});
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().destroyable(false).body("yoComet").pathInfo("/a").build();
processor.open(w, request, AtmosphereResponseImpl.newInstance(framework.getAtmosphereConfig(), request, w));
processor.invokeWebSocketProtocol(w, "yoWebSocket");
framework.getBroadcasterFactory().lookup("/*").broadcast("yoBroadcast").get();
assertEquals(b.toString(), "yoCometyoWebSocketyoBroadcast");
}
use of org.atmosphere.websocket.WebSocketProcessor in project atmosphere by Atmosphere.
the class WebSocketStreamingHandlerTest method multipleWebSocketAndHandler.
@Test
public void multipleWebSocketAndHandler() throws IOException, ServletException, ExecutionException, InterruptedException {
ByteArrayOutputStream b = new ByteArrayOutputStream();
final WebSocket w = new ArrayBaseWebSocket(b);
final WebSocketProcessor processor = WebSocketProcessorFactory.getDefault().getWebSocketProcessor(framework);
registerWebSocketHandler("/a", new EchoHandler());
registerWebSocketHandler("/b", new EchoHandler() {
@Override
public void onTextStream(WebSocket webSocket, Reader reader) throws IOException {
webSocket.write("2" + drainReader(reader));
}
});
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().destroyable(false).body("a").pathInfo("/a").build();
processor.open(w, request, AtmosphereResponseImpl.newInstance(framework.getAtmosphereConfig(), request, w));
processor.invokeWebSocketProtocol(w, "a");
assertEquals(b.toString(), "a");
ByteArrayOutputStream b2 = new ByteArrayOutputStream();
final WebSocket w2 = new ArrayBaseWebSocket(b2);
request = new AtmosphereRequestImpl.Builder().destroyable(false).body("b").pathInfo("/b").build();
processor.open(w2, request, AtmosphereResponseImpl.newInstance(framework.getAtmosphereConfig(), request, w));
processor.invokeWebSocketProtocol(w2, "b");
// The WebSocketHandler is shared.
assertEquals(b2.toString(), "2b");
}
Aggregations