The Atmosphere Framework runtime providing comprehensive support for building real-time, event-driven web applications with transparent transport protocol support including WebSockets, Server Sent Events, Long-Polling, HTTP Streaming, and JSONP.
npx @tessl/cli install tessl/maven-org-atmosphere--atmosphere-runtime@3.0.0The Atmosphere Framework runtime provides comprehensive support for building real-time, event-driven web applications with transparent transport protocol support including WebSockets, Server Sent Events, Long-Polling, HTTP Streaming, and JSONP. It enables scalable real-time applications with automatic protocol fallback and cross-platform compatibility across all Servlet-based servers.
pom.xml:
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>3.0.13</version>
</dependency>import org.atmosphere.cpr.*;
import org.atmosphere.config.service.*;
import org.atmosphere.websocket.*;Common patterns:
import org.atmosphere.cpr.AtmosphereFramework;
import org.atmosphere.cpr.AtmosphereResource;
import org.atmosphere.cpr.AtmosphereHandler;
import org.atmosphere.cpr.Broadcaster;
import org.atmosphere.config.service.AtmosphereHandlerService;
import org.atmosphere.config.service.ManagedService;import org.atmosphere.cpr.*;
import org.atmosphere.config.service.AtmosphereHandlerService;
@AtmosphereHandlerService(path = "/chat")
public class ChatHandler implements AtmosphereHandler {
@Override
public void onRequest(AtmosphereResource resource) throws IOException {
// Suspend the connection for real-time updates
resource.suspend();
}
@Override
public void onStateChange(AtmosphereResourceEvent event) throws IOException {
// Handle broadcast messages
if (event.getMessage() != null) {
event.getResource().write(event.getMessage().toString());
}
}
@Override
public void destroy() {
// Cleanup resources
}
}import org.atmosphere.config.service.*;
@ManagedService(path = "/managed-chat")
public class ManagedChatService {
@Get
public void onOpen(AtmosphereResource resource) {
resource.suspend();
}
@Message
public void onMessage(String message) {
// Handle incoming message
// Broadcast to other connected clients
}
@Disconnect
public void onDisconnect(AtmosphereResourceEvent event) {
// Handle client disconnection
}
}import org.atmosphere.cpr.*;
// Get broadcaster factory and create/lookup broadcaster
BroadcasterFactory factory = BroadcasterFactory.getDefault();
Broadcaster broadcaster = factory.lookup("/chat", true);
// Broadcast message to all connected resources
broadcaster.broadcast("Hello, everyone!");
// Broadcast to specific resource
broadcaster.broadcast("Private message", atmosphereResource);The Atmosphere Framework is built around several core components:
Central framework management including configuration, resource handling, and the primary AtmosphereResource interface for managing suspended connections and broadcasting.
public class AtmosphereFramework {
public AtmosphereFramework init();
public void destroy();
public AtmosphereFramework addAtmosphereHandler(String mapping, AtmosphereHandler handler);
public BroadcasterFactory getBroadcasterFactory();
public AtmosphereConfig getAtmosphereConfig();
}
public interface AtmosphereResource {
public AtmosphereResource suspend();
public AtmosphereResource suspend(long timeout);
public AtmosphereResource resume();
public boolean isSuspended();
public Broadcaster getBroadcaster();
public AtmosphereResource setBroadcaster(Broadcaster broadcaster);
public AtmosphereRequest getRequest();
public AtmosphereResponse getResponse();
public TRANSPORT transport();
}Message distribution system with support for multiple scopes, policies, and targeted broadcasting. Includes factory management and meta-broadcasting capabilities.
public interface Broadcaster {
public Future<Object> broadcast(Object msg);
public Future<Object> broadcast(Object msg, AtmosphereResource resource);
public Broadcaster addAtmosphereResource(AtmosphereResource resource);
public Broadcaster removeAtmosphereResource(AtmosphereResource resource);
public void destroy();
public Broadcaster setScope(SCOPE scope);
}
public interface BroadcasterFactory {
public Broadcaster lookup(Object id, boolean createIfNull);
public void destroy();
public Collection<Broadcaster> lookupAll();
}Declarative service configuration using annotations for HTTP method mapping, event handling, parameter injection, and component registration.
@AtmosphereHandlerService(path = "/example")
@ManagedService(path = "/managed")
@Get @Post @Put @Delete
@Message @Ready @Disconnect @Resume @Heartbeat
@PathParam("param")
@BroadcasterService @AtmosphereInterceptorServiceComplete WebSocket integration including connection management, protocol handling, message processing, and custom protocol implementations.
public interface WebSocket {
public WebSocket write(String data);
public void close();
public boolean isOpen();
public AtmosphereResource resource();
}
public interface WebSocketHandler {
public void onOpen(WebSocket webSocket);
public void onClose(WebSocket webSocket);
public void onTextMessage(WebSocket webSocket, String message);
public void onByteMessage(WebSocket webSocket, byte[] message);
}Message caching and replay capabilities for connection recovery, with multiple cache implementations and inspection utilities.
public interface BroadcasterCache {
public void addToCache(String broadcasterId, String uuid, BroadcastMessage message);
public List<Object> retrieveFromCache(String broadcasterId, String uuid);
public void clearCache(String broadcasterId, String uuid);
}Request/response processing pipeline with built-in interceptors for CORS, heartbeat, protocol handling, and custom processing logic.
public interface AtmosphereInterceptor {
public Action intercept(AtmosphereResource resource);
public void postInspect(AtmosphereResource resource);
public int priority();
}public enum TRANSPORT {
POLLING,
LONG_POLLING,
STREAMING,
WEBSOCKET,
JSONP,
SSE,
AJAX,
HTMLFILE,
CLOSE,
UNDEFINED
}public enum SCOPE {
REQUEST, // Current request only
APPLICATION, // Current web application
VM // Entire JVM
}
public enum POLICY {
FIFO, // First In, First Out
REJECT // Reject new resources when limit reached
}