The Atmosphere Framework contains client and server-side components for building Asynchronous Web Applications. Realtime client-server framework for the JVM, supporting WebSocket and cross-browser fallbacks support. The Atmosphere Framework supports all major Browsers and Servers. The Atmosphere framework is the most popular asynchronous application development framework for enterprise Java.
Atmosphere’s Java Client is called wAsync.
Why to choose Atmosphere Framework?
Based on the requirement we need a framework that supports bi-directional communication so, we have selected Atmosphere Framework. The main advantage is that it provides two-way communication between client and server over a single TCP connection. Generally, a client will send a request to the server then the server returns the response. For every request from the same client to the same server, a new connection needs to be opened. WebSocket will maintain a single connection between the client and the server. It also keeps the connection alive with all it’s clients until they disconnect.
Tomcat Configuration Steps:
Used runtime – native as atmosphere dependency for maven tool and tomcat -v9 as a server
Step 1: Download and Install Tomcat.
Step 2: Create an Environment Variable JAVA_HOME.
Step 3: Configure the Tomcat Server.
Step 4: Start Tomcat Server.
Step 5: Develop and Deploy an App.
A maven is a build tool that provides different dependencies. Here dependency means the external libraries required to build a project.
It does the following:
- Generates source code (if auto-generated code is used).
- Generates documentation from source code.
- Compiles source code.
- Packages compiled code into JAR or ZIP file.
- Installs the packaged code in a local repository, server repository, or central repository.
How to Broadcast Message from JAVA server to JAVA Client in Atmosphere Framework:
- Used Atmosphere Framework
- Used runtime-native as atmosphere dependency for maven tool
- Tomcat-v9 as a server
Long polling :
Long polling is the simplest way of having a persistent connection with a server that doesn’t use any specific protocol like WebSocket or Server Side Events. Easy to implement, and delivers messages without delays.
- A request is sent to the server.
- The server doesn’t close the connection until it has a message to send.
- When a message appears – the server responds to the request with it.
Broadcasting the messages to clients-
BroadcasterFactory.getDefault().lookup(“URL to broadcast”, true).scheduleFixedBroadcast(message, 2, TimeUnit.SECONDS);
We have used the AsyncHttpProvider library to establish a connection with the Server in async mode.
AtmosphereRequest request = atmosphereResource.getRequest();
String IncomingMessage = request.getReader().readLine();
To use Atmosphere, add the following dependency:
Benefits of Atmosphere:
- Provide High Availability.
- Fault Tolerance.
The Atmosphere framework makes the development easier to build applications. The Atmosphere Framework is portable and can be deployed to any web server.