Search in sources :

Example 1 with WebSocketProcessor

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());
        }
    }
}
Also used : WebSocketProcessor(org.atmosphere.websocket.WebSocketProcessor) DefaultWebSocketProcessor(org.atmosphere.websocket.DefaultWebSocketProcessor) ExecutorService(java.util.concurrent.ExecutorService) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) UUIDBroadcasterCache(org.atmosphere.cache.UUIDBroadcasterCache)

Example 2 with WebSocketProcessor

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;
}
Also used : DefaultWebSocketProcessor(org.atmosphere.websocket.DefaultWebSocketProcessor) DefaultWebSocketProcessor(org.atmosphere.websocket.DefaultWebSocketProcessor) WebSocketProcessor(org.atmosphere.websocket.WebSocketProcessor)

Example 3 with WebSocketProcessor

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);
}
Also used : HashMap(java.util.HashMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) WebSocket(org.atmosphere.websocket.WebSocket) WebSocketProcessor(org.atmosphere.websocket.WebSocketProcessor)

Example 4 with WebSocketProcessor

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");
}
Also used : WebSocketProcessor(org.atmosphere.websocket.WebSocketProcessor) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) WebSocket(org.atmosphere.websocket.WebSocket) Test(org.testng.annotations.Test)

Example 5 with WebSocketProcessor

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");
}
Also used : WebSocketProcessor(org.atmosphere.websocket.WebSocketProcessor) Reader(java.io.Reader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) WebSocket(org.atmosphere.websocket.WebSocket) Test(org.testng.annotations.Test)

Aggregations

WebSocketProcessor (org.atmosphere.websocket.WebSocketProcessor)26 ByteArrayOutputStream (java.io.ByteArrayOutputStream)22 WebSocket (org.atmosphere.websocket.WebSocket)22 Test (org.testng.annotations.Test)21 IOException (java.io.IOException)12 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 AtmosphereRequest (org.atmosphere.runtime.AtmosphereRequest)3 DefaultWebSocketProcessor (org.atmosphere.websocket.DefaultWebSocketProcessor)3 WebSocketEventListenerAdapter (org.atmosphere.websocket.WebSocketEventListenerAdapter)3 HashMap (java.util.HashMap)2 ExecutionException (java.util.concurrent.ExecutionException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 ServletException (javax.servlet.ServletException)2 Cookie (javax.servlet.http.Cookie)2 AtmosphereRequestImpl (org.atmosphere.runtime.AtmosphereRequestImpl)2 WebSocketEventListener (org.atmosphere.websocket.WebSocketEventListener)2 Reader (java.io.Reader)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 ExecutorService (java.util.concurrent.ExecutorService)1