Atmosphere Framework

Atmosphere:

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.

Maven Tool:

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:

  1. Generates source code (if auto-generated code is used).
  2. Generates documentation from source code.
  3. Compiles source code.
  4. Packages compiled code into JAR or ZIP file.
  5. 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:

  1. Used Atmosphere Framework
  2. Used runtime-native as atmosphere dependency for maven tool
  3. 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.

The Flow:

  1. A request is sent to the server.
  2. The server doesn’t close the connection until it has a message to send.
  3. When a message appears – the server responds to the request with it.

Server:

Broadcasting the messages to clients-

BroadcasterFactory.getDefault().lookup(“URL to broadcast”, true).scheduleFixedBroadcast(message, 2, TimeUnit.SECONDS);

Client:

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:

 1.

<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>2.4.21</version>
</dependency

 2.

<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-spring</artifactId>
<version>2.4.3</version>
</dependency>

Benefits of Atmosphere:

  1. Provide High Availability.
  2. Scalability.
  3. Fault Tolerance.

Conclusion:

The Atmosphere framework makes the development easier to build applications. The Atmosphere Framework is portable and can be deployed to any web server.

vijaya-surve

Jr. Software Developer