Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves checkstyle errors for remaining m #1090

Merged
merged 12 commits into from
Nov 16, 2019
Merged
Prev Previous commit
Next Next commit
Reduces checkstyle errors in monostate
  • Loading branch information
anuragagarwal561994 committed Nov 15, 2019
commit 99768307712ac792278158f625aaffe8badf2322
16 changes: 5 additions & 11 deletions monostate/src/main/java/com/iluwatar/monostate/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,22 @@
package com.iluwatar.monostate;



/**
*
* The MonoState pattern ensures that all instances of the class will have the same state. This can
* be used a direct replacement of the Singleton pattern.
*
* <p>
* In the following example, The {@link LoadBalancer} class represents the app's logic. It contains
* a series of Servers, which can handle requests of type {@link Request}. Two instances of
*
* <p>In the following example, The {@link LoadBalancer} class represents the app's logic. It
* contains a series of Servers, which can handle requests of type {@link Request}. Two instances of
* LoadBalacer are created. When a request is made to a server via the first LoadBalancer the state
* change in the first load balancer affects the second. So if the first LoadBalancer selects the
* Server 1, the second LoadBalancer on a new request will select the Second server. If a third
* LoadBalancer is created and a new request is made to it, then it will select the third server as
* the second load balancer has already selected the second server.
* <p>
* .
*
*/
public class App {
/**
* Program entry point
*
* Program entry point.
*
* @param args command line args
*/
public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
* receiving a new Request, it delegates the call to the servers in a Round Robin Fashion. Since all
* instances of the class share the same state, all instances will delegate to the same server on
* receiving a new Request.
*
*/

public class LoadBalancer {
Expand All @@ -40,13 +39,13 @@ public class LoadBalancer {

static {
int id = 0;
for (int port : new int[] {8080, 8081, 8082, 8083, 8084}) {
for (int port : new int[]{8080, 8081, 8082, 8083, 8084}) {
SERVERS.add(new Server("localhost", port, ++id));
}
}

/**
* Add new server
* Add new server.
*/
public final void addServer(Server server) {
synchronized (SERVERS) {
Expand All @@ -64,7 +63,7 @@ public int getLastServedId() {
}

/**
* Handle request
* Handle request.
*/
public synchronized void serverRequest(Request request) {
if (lastServedId >= SERVERS.size()) {
Expand All @@ -73,5 +72,5 @@ public synchronized void serverRequest(Request request) {
Server server = SERVERS.get(lastServedId++);
server.serve(request);
}

}
2 changes: 0 additions & 2 deletions monostate/src/main/java/com/iluwatar/monostate/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
package com.iluwatar.monostate;

/**
*
* The Request class. A {@link Server} can handle an instance of a Request.
*
*/

public class Request {
Expand Down
6 changes: 2 additions & 4 deletions monostate/src/main/java/com/iluwatar/monostate/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@
import org.slf4j.LoggerFactory;

/**
*
* The Server class. Each Server sits behind a LoadBalancer which delegates the call to the servers
* in a simplistic Round Robin fashion.
*
*/
public class Server {

Expand All @@ -41,7 +39,7 @@ public class Server {
public final int id;

/**
* Constructor
* Constructor.
*/
public Server(String host, int port, int id) {
this.host = host;
Expand All @@ -59,6 +57,6 @@ public int getPort() {

public void serve(Request request) {
LOGGER.info("Server ID {} associated to host : {} and port {}. Processed request with value {}",
id, host, port, request.value);
id, host, port, request.value);
}
}