Resolves checkstyle errors for remaining m (#1090)
* Reduces checkstyle errors in marker * Reduces checkstyle errors in master-worker-pattern * Reduces checkstyle errors in mediator * Reduces checkstyle errors in memento * Reduces checkstyle errors in model-view-controller * Reduces checkstyle errors in model-view-presenter * Reduces checkstyle errors in module * Reduces checkstyle errors in monad * Reduces checkstyle errors in monostate * Reduces checkstyle errors in multiton * Reduces checkstyle errors in mute-idiom * Reduces checkstyle errors in mutex
This commit is contained in:
committed by
Ilkka Seppälä
parent
3ccc9baa1a
commit
1fdc650545
@ -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) {
|
||||
|
@ -31,7 +31,6 @@ import java.util.List;
|
||||
* 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 {
|
||||
@ -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) {
|
||||
@ -64,7 +63,7 @@ public class LoadBalancer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle request
|
||||
* Handle request.
|
||||
*/
|
||||
public synchronized void serverRequest(Request request) {
|
||||
if (lastServedId >= SERVERS.size()) {
|
||||
@ -73,5 +72,5 @@ public class LoadBalancer {
|
||||
Server server = SERVERS.get(lastServedId++);
|
||||
server.serve(request);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -24,9 +24,7 @@
|
||||
package com.iluwatar.monostate;
|
||||
|
||||
/**
|
||||
*
|
||||
* The Request class. A {@link Server} can handle an instance of a Request.
|
||||
*
|
||||
*/
|
||||
|
||||
public class Request {
|
||||
|
@ -27,10 +27,8 @@ import org.slf4j.Logger;
|
||||
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 {
|
||||
|
||||
@ -41,7 +39,7 @@ public class Server {
|
||||
public final int id;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Constructor.
|
||||
*/
|
||||
public Server(String host, int port, int id) {
|
||||
this.host = host;
|
||||
@ -59,6 +57,6 @@ public class Server {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user