Resolves checkstyle issues for semaphore servant serverless service-layer service-locator (#1079)
* Reduces checkstyle errors in semaphore * Reduces checkstyle errors in servant * Reduces checkstyle errors in serverless * Reduces checkstyle errors in service-layer * Reduces checkstyle errors in service-locator
This commit is contained in:
parent
37599eb48f
commit
390795154f
@ -25,18 +25,17 @@ package com.iluwatar.semaphore;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A Semaphore mediates access by a group of threads to a pool of resources.
|
* A Semaphore mediates access by a group of threads to a pool of resources.
|
||||||
* <p>
|
*
|
||||||
* In this example a group of customers are taking fruit from a fruit shop.
|
* <p>In this example a group of customers are taking fruit from a fruit shop. There is a bowl each
|
||||||
* There is a bowl each of apples, oranges and lemons. Only one customer can
|
* of apples, oranges and lemons. Only one customer can access a bowl simultaneously. A Semaphore is
|
||||||
* access a bowl simultaneously. A Semaphore is used to indicate how many
|
* used to indicate how many resources are currently available and must be acquired in order for a
|
||||||
* resources are currently available and must be acquired in order for a bowl
|
* bowl to be given to a customer. Customers continually try to take fruit until there is no fruit
|
||||||
* to be given to a customer. Customers continually try to take fruit until
|
* left in the shop.
|
||||||
* there is no fruit left in the shop.
|
|
||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* main method
|
* main method.
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
FruitShop shop = new FruitShop();
|
FruitShop shop = new FruitShop();
|
||||||
@ -47,5 +46,5 @@ public class App {
|
|||||||
new Customer("Ringo", shop).start();
|
new Customer("Ringo", shop).start();
|
||||||
new Customer("George", shop).start();
|
new Customer("George", shop).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,8 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Customer attempts to repeatedly take Fruit from the FruitShop by
|
* A Customer attempts to repeatedly take Fruit from the FruitShop by taking Fruit from FruitBowl
|
||||||
* taking Fruit from FruitBowl instances.
|
* instances.
|
||||||
*/
|
*/
|
||||||
public class Customer extends Thread {
|
public class Customer extends Thread {
|
||||||
|
|
||||||
@ -38,36 +38,35 @@ public class Customer extends Thread {
|
|||||||
* Name of the Customer.
|
* Name of the Customer.
|
||||||
*/
|
*/
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The FruitShop he is using.
|
* The FruitShop he is using.
|
||||||
*/
|
*/
|
||||||
private final FruitShop fruitShop;
|
private final FruitShop fruitShop;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Their bowl of Fruit.
|
* Their bowl of Fruit.
|
||||||
*/
|
*/
|
||||||
private final FruitBowl fruitBowl;
|
private final FruitBowl fruitBowl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Customer constructor
|
* Customer constructor.
|
||||||
*/
|
*/
|
||||||
public Customer(String name, FruitShop fruitShop) {
|
public Customer(String name, FruitShop fruitShop) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.fruitShop = fruitShop;
|
this.fruitShop = fruitShop;
|
||||||
this.fruitBowl = new FruitBowl();
|
this.fruitBowl = new FruitBowl();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Customer repeatedly takes Fruit from the FruitShop until no Fruit
|
* The Customer repeatedly takes Fruit from the FruitShop until no Fruit remains.
|
||||||
* remains.
|
*/
|
||||||
*/
|
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
while (fruitShop.countFruit() > 0) {
|
while (fruitShop.countFruit() > 0) {
|
||||||
FruitBowl bowl = fruitShop.takeBowl();
|
FruitBowl bowl = fruitShop.takeBowl();
|
||||||
Fruit fruit;
|
Fruit fruit;
|
||||||
|
|
||||||
if (bowl != null && (fruit = bowl.take()) != null) {
|
if (bowl != null && (fruit = bowl.take()) != null) {
|
||||||
LOGGER.info("{} took an {}", name, fruit);
|
LOGGER.info("{} took an {}", name, fruit);
|
||||||
fruitBowl.put(fruit);
|
fruitBowl.put(fruit);
|
||||||
@ -76,7 +75,7 @@ public class Customer extends Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOGGER.info("{} took {}", name, fruitBowl);
|
LOGGER.info("{} took {}", name, fruitBowl);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ package com.iluwatar.semaphore;
|
|||||||
public class Fruit {
|
public class Fruit {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enumeration of Fruit Types
|
* Enumeration of Fruit Types.
|
||||||
*/
|
*/
|
||||||
public enum FruitType {
|
public enum FruitType {
|
||||||
ORANGE, APPLE, LEMON
|
ORANGE, APPLE, LEMON
|
||||||
@ -46,7 +46,7 @@ public class Fruit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* toString method
|
* toString method.
|
||||||
*/
|
*/
|
||||||
public String toString() {
|
public String toString() {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
@ -23,19 +23,20 @@
|
|||||||
|
|
||||||
package com.iluwatar.semaphore;
|
package com.iluwatar.semaphore;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A FruitBowl contains Fruit.
|
* A FruitBowl contains Fruit.
|
||||||
*/
|
*/
|
||||||
public class FruitBowl {
|
public class FruitBowl {
|
||||||
|
|
||||||
private List<Fruit> fruit = new ArrayList<>();
|
private List<Fruit> fruit = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Returns the amount of fruits left in bowl.
|
||||||
* @return The amount of Fruit left in the bowl.
|
*
|
||||||
|
* @return The amount of Fruit left in the bowl.
|
||||||
*/
|
*/
|
||||||
public int countFruit() {
|
public int countFruit() {
|
||||||
return fruit.size();
|
return fruit.size();
|
||||||
@ -43,15 +44,16 @@ public class FruitBowl {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Put an item of Fruit into the bowl.
|
* Put an item of Fruit into the bowl.
|
||||||
*
|
*
|
||||||
* @param f fruit
|
* @param f fruit
|
||||||
*/
|
*/
|
||||||
public void put(Fruit f) {
|
public void put(Fruit f) {
|
||||||
fruit.add(f);
|
fruit.add(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Take an item of Fruit out of the bowl.
|
* Take an item of Fruit out of the bowl.
|
||||||
|
*
|
||||||
* @return The Fruit taken out of the bowl, or null if empty.
|
* @return The Fruit taken out of the bowl, or null if empty.
|
||||||
*/
|
*/
|
||||||
public Fruit take() {
|
public Fruit take() {
|
||||||
@ -61,15 +63,15 @@ public class FruitBowl {
|
|||||||
return fruit.remove(0);
|
return fruit.remove(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* toString method
|
* toString method.
|
||||||
*/
|
*/
|
||||||
public String toString() {
|
public String toString() {
|
||||||
int apples = 0;
|
int apples = 0;
|
||||||
int oranges = 0;
|
int oranges = 0;
|
||||||
int lemons = 0;
|
int lemons = 0;
|
||||||
|
|
||||||
for (Fruit f : fruit) {
|
for (Fruit f : fruit) {
|
||||||
switch (f.getType()) {
|
switch (f.getType()) {
|
||||||
case APPLE:
|
case APPLE:
|
||||||
@ -84,7 +86,7 @@ public class FruitBowl {
|
|||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return apples + " Apples, " + oranges + " Oranges, and " + lemons + " Lemons";
|
return apples + " Apples, " + oranges + " Oranges, and " + lemons + " Lemons";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,32 +27,32 @@ package com.iluwatar.semaphore;
|
|||||||
* A FruitShop contains three FruitBowl instances and controls access to them.
|
* A FruitShop contains three FruitBowl instances and controls access to them.
|
||||||
*/
|
*/
|
||||||
public class FruitShop {
|
public class FruitShop {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The FruitBowl instances stored in the class.
|
* The FruitBowl instances stored in the class.
|
||||||
*/
|
*/
|
||||||
private FruitBowl[] bowls = {
|
private FruitBowl[] bowls = {
|
||||||
new FruitBowl(),
|
new FruitBowl(),
|
||||||
new FruitBowl(),
|
new FruitBowl(),
|
||||||
new FruitBowl()
|
new FruitBowl()
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Access flags for each of the FruitBowl instances.
|
* Access flags for each of the FruitBowl instances.
|
||||||
*/
|
*/
|
||||||
private boolean[] available = {
|
private boolean[] available = {
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
true
|
true
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Semaphore that controls access to the class resources.
|
* The Semaphore that controls access to the class resources.
|
||||||
*/
|
*/
|
||||||
private Semaphore semaphore;
|
private Semaphore semaphore;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FruitShop constructor
|
* FruitShop constructor.
|
||||||
*/
|
*/
|
||||||
public FruitShop() {
|
public FruitShop() {
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
@ -60,30 +60,30 @@ public class FruitShop {
|
|||||||
bowls[1].put(new Fruit(Fruit.FruitType.ORANGE));
|
bowls[1].put(new Fruit(Fruit.FruitType.ORANGE));
|
||||||
bowls[2].put(new Fruit(Fruit.FruitType.LEMON));
|
bowls[2].put(new Fruit(Fruit.FruitType.LEMON));
|
||||||
}
|
}
|
||||||
|
|
||||||
semaphore = new Semaphore(3);
|
semaphore = new Semaphore(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Returns the amount of fruits left in shop.
|
||||||
|
*
|
||||||
* @return The amount of Fruit left in the shop.
|
* @return The amount of Fruit left in the shop.
|
||||||
*/
|
*/
|
||||||
public synchronized int countFruit() {
|
public synchronized int countFruit() {
|
||||||
return bowls[0].countFruit() + bowls[1].countFruit() + bowls[2].countFruit();
|
return bowls[0].countFruit() + bowls[1].countFruit() + bowls[2].countFruit();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method called by Customer to get a FruitBowl from the shop. This method
|
* Method called by Customer to get a FruitBowl from the shop. This method will try to acquire the
|
||||||
* will try to acquire the Semaphore before returning the first available
|
* Semaphore before returning the first available FruitBowl.
|
||||||
* FruitBowl.
|
*/
|
||||||
*/
|
|
||||||
public synchronized FruitBowl takeBowl() {
|
public synchronized FruitBowl takeBowl() {
|
||||||
|
|
||||||
FruitBowl bowl = null;
|
FruitBowl bowl = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
semaphore.acquire();
|
semaphore.acquire();
|
||||||
|
|
||||||
if (available[0]) {
|
if (available[0]) {
|
||||||
bowl = bowls[0];
|
bowl = bowls[0];
|
||||||
available[0] = false;
|
available[0] = false;
|
||||||
@ -94,7 +94,7 @@ public class FruitShop {
|
|||||||
bowl = bowls[2];
|
bowl = bowls[2];
|
||||||
available[2] = false;
|
available[2] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
@ -102,20 +102,19 @@ public class FruitShop {
|
|||||||
}
|
}
|
||||||
return bowl;
|
return bowl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method called by a Customer instance to return a FruitBowl to the shop.
|
* Method called by a Customer instance to return a FruitBowl to the shop. This method releases
|
||||||
* This method releases the Semaphore, making the FruitBowl available to
|
* the Semaphore, making the FruitBowl available to another Customer.
|
||||||
* another Customer.
|
*/
|
||||||
*/
|
|
||||||
public synchronized void returnBowl(FruitBowl bowl) {
|
public synchronized void returnBowl(FruitBowl bowl) {
|
||||||
if (bowl == bowls[0]) {
|
if (bowl == bowls[0]) {
|
||||||
available[0] = true;
|
available[0] = true;
|
||||||
} else if (bowl == bowls[1]) {
|
} else if (bowl == bowls[1]) {
|
||||||
available[1] = true;
|
available[1] = true;
|
||||||
} else if (bowl == bowls[2]) {
|
} else if (bowl == bowls[2]) {
|
||||||
available [2] = true;
|
available[2] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,9 +27,9 @@ package com.iluwatar.semaphore;
|
|||||||
* Lock is an interface for a lock which can be acquired and released.
|
* Lock is an interface for a lock which can be acquired and released.
|
||||||
*/
|
*/
|
||||||
public interface Lock {
|
public interface Lock {
|
||||||
|
|
||||||
void acquire() throws InterruptedException;
|
void acquire() throws InterruptedException;
|
||||||
|
|
||||||
void release();
|
void release();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,30 +33,29 @@ public class Semaphore implements Lock {
|
|||||||
* The number of concurrent resource accesses which are allowed.
|
* The number of concurrent resource accesses which are allowed.
|
||||||
*/
|
*/
|
||||||
private int counter;
|
private int counter;
|
||||||
|
|
||||||
public Semaphore(int licenses) {
|
public Semaphore(int licenses) {
|
||||||
this.licenses = licenses;
|
this.licenses = licenses;
|
||||||
this.counter = licenses;
|
this.counter = licenses;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of licenses managed by the Semaphore
|
* Returns the number of licenses managed by the Semaphore.
|
||||||
*/
|
*/
|
||||||
public int getNumLicenses() {
|
public int getNumLicenses() {
|
||||||
return licenses;
|
return licenses;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of available licenses
|
* Returns the number of available licenses.
|
||||||
*/
|
*/
|
||||||
public int getAvailableLicenses() {
|
public int getAvailableLicenses() {
|
||||||
return counter;
|
return counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method called by a thread to acquire the lock. If there are no resources
|
* Method called by a thread to acquire the lock. If there are no resources available this will
|
||||||
* available this will wait until the lock has been released to re-attempt
|
* wait until the lock has been released to re-attempt the acquire.
|
||||||
* the acquire.
|
|
||||||
*/
|
*/
|
||||||
public synchronized void acquire() throws InterruptedException {
|
public synchronized void acquire() throws InterruptedException {
|
||||||
while (counter == 0) {
|
while (counter == 0) {
|
||||||
@ -64,7 +63,7 @@ public class Semaphore implements Lock {
|
|||||||
}
|
}
|
||||||
counter = counter - 1;
|
counter = counter - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method called by a thread to release the lock.
|
* Method called by a thread to release the lock.
|
||||||
*/
|
*/
|
||||||
|
@ -23,29 +23,27 @@
|
|||||||
|
|
||||||
package com.iluwatar.servant;
|
package com.iluwatar.servant;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Servant offers some functionality to a group of classes without defining that functionality in
|
* Servant offers some functionality to a group of classes without defining that functionality in
|
||||||
* each of them. A Servant is a class whose instance provides methods that take care of a desired
|
* each of them. A Servant is a class whose instance provides methods that take care of a desired
|
||||||
* service, while objects for which the servant does something, are taken as parameters.
|
* service, while objects for which the servant does something, are taken as parameters.
|
||||||
* <p>
|
|
||||||
* In this example {@link Servant} is serving {@link King} and {@link Queen}.
|
|
||||||
*
|
*
|
||||||
|
* <p>In this example {@link Servant} is serving {@link King} and {@link Queen}.
|
||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
static Servant jenkins = new Servant("Jenkins");
|
private static Servant jenkins = new Servant("Jenkins");
|
||||||
static Servant travis = new Servant("Travis");
|
private static Servant travis = new Servant("Travis");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point
|
* Program entry point.
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
scenario(jenkins, 1);
|
scenario(jenkins, 1);
|
||||||
@ -53,7 +51,7 @@ public class App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Can add a List with enum Actions for variable scenarios
|
* Can add a List with enum Actions for variable scenarios.
|
||||||
*/
|
*/
|
||||||
public static void scenario(Servant servant, int compliment) {
|
public static void scenario(Servant servant, int compliment) {
|
||||||
King k = new King();
|
King k = new King();
|
||||||
|
@ -24,9 +24,7 @@
|
|||||||
package com.iluwatar.servant;
|
package com.iluwatar.servant;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* King.
|
||||||
* King
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class King implements Royalty {
|
public class King implements Royalty {
|
||||||
|
|
||||||
|
@ -24,9 +24,7 @@
|
|||||||
package com.iluwatar.servant;
|
package com.iluwatar.servant;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Queen.
|
||||||
* Queen
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class Queen implements Royalty {
|
public class Queen implements Royalty {
|
||||||
|
|
||||||
|
@ -24,9 +24,7 @@
|
|||||||
package com.iluwatar.servant;
|
package com.iluwatar.servant;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Royalty.
|
||||||
* Royalty
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
interface Royalty {
|
interface Royalty {
|
||||||
|
|
||||||
|
@ -26,16 +26,14 @@ package com.iluwatar.servant;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Servant.
|
||||||
* Servant
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class Servant {
|
public class Servant {
|
||||||
|
|
||||||
public String name;
|
public String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public Servant(String name) {
|
public Servant(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@ -54,7 +52,7 @@ public class Servant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if we will be hanged
|
* Check if we will be hanged.
|
||||||
*/
|
*/
|
||||||
public boolean checkIfYouWillBeHanged(List<Royalty> tableGuests) {
|
public boolean checkIfYouWillBeHanged(List<Royalty> tableGuests) {
|
||||||
boolean anotherDay = true;
|
boolean anotherDay = true;
|
||||||
|
@ -30,13 +30,13 @@ import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper;
|
|||||||
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
|
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* abstract dynamodb handler
|
* abstract dynamodb handler.
|
||||||
|
*
|
||||||
* @param <T> - serializable collection
|
* @param <T> - serializable collection
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractDynamoDbHandler<T extends Serializable> {
|
public abstract class AbstractDynamoDbHandler<T extends Serializable> {
|
||||||
@ -78,10 +78,10 @@ public abstract class AbstractDynamoDbHandler<T extends Serializable> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API Gateway response
|
* API Gateway response.
|
||||||
*
|
*
|
||||||
* @param statusCode - status code
|
* @param statusCode - status code
|
||||||
* @param body - Object body
|
* @param body - Object body
|
||||||
* @return - api gateway proxy response
|
* @return - api gateway proxy response
|
||||||
*/
|
*/
|
||||||
protected APIGatewayProxyResponseEvent apiGatewayProxyResponseEvent(Integer statusCode, T body) {
|
protected APIGatewayProxyResponseEvent apiGatewayProxyResponseEvent(Integer statusCode, T body) {
|
||||||
|
@ -28,14 +28,12 @@ import com.amazonaws.services.lambda.runtime.RequestHandler;
|
|||||||
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
|
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
|
||||||
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
|
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
|
||||||
import com.iluwatar.serverless.baas.model.Person;
|
import com.iluwatar.serverless.baas.model.Person;
|
||||||
|
import java.util.Map;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* find person from persons collection
|
* find person from persons collection Created by dheeraj.mummar on 3/5/18.
|
||||||
* Created by dheeraj.mummar on 3/5/18.
|
|
||||||
*/
|
*/
|
||||||
public class FindPersonApiHandler extends AbstractDynamoDbHandler<Person>
|
public class FindPersonApiHandler extends AbstractDynamoDbHandler<Person>
|
||||||
implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
|
implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
|
||||||
@ -44,10 +42,11 @@ public class FindPersonApiHandler extends AbstractDynamoDbHandler<Person>
|
|||||||
private static final Integer SUCCESS_STATUS_CODE = 200;
|
private static final Integer SUCCESS_STATUS_CODE = 200;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent apiGatewayProxyRequestEvent,
|
public APIGatewayProxyResponseEvent handleRequest(
|
||||||
Context context) {
|
APIGatewayProxyRequestEvent apiGatewayProxyRequestEvent, Context context) {
|
||||||
Map<String, String> pathParameters = apiGatewayProxyRequestEvent.getPathParameters();
|
Map<String, String> pathParameters = apiGatewayProxyRequestEvent.getPathParameters();
|
||||||
pathParameters.keySet().stream().map(key -> key + "=" + pathParameters.get(key)).forEach(LOG::info);
|
pathParameters.keySet().stream().map(key -> key + "=" + pathParameters.get(key))
|
||||||
|
.forEach(LOG::info);
|
||||||
|
|
||||||
Person person = this.getDynamoDbMapper().load(Person.class, apiGatewayProxyRequestEvent
|
Person person = this.getDynamoDbMapper().load(Person.class, apiGatewayProxyRequestEvent
|
||||||
.getPathParameters().get("id"));
|
.getPathParameters().get("id"));
|
||||||
|
@ -28,14 +28,12 @@ import com.amazonaws.services.lambda.runtime.RequestHandler;
|
|||||||
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
|
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
|
||||||
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
|
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
|
||||||
import com.iluwatar.serverless.baas.model.Person;
|
import com.iluwatar.serverless.baas.model.Person;
|
||||||
|
import java.io.IOException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* save person into persons collection
|
* save person into persons collection Created by dheeraj.mummar on 3/4/18.
|
||||||
* Created by dheeraj.mummar on 3/4/18.
|
|
||||||
*/
|
*/
|
||||||
public class SavePersonApiHandler extends AbstractDynamoDbHandler<Person>
|
public class SavePersonApiHandler extends AbstractDynamoDbHandler<Person>
|
||||||
implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
|
implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
|
||||||
@ -45,8 +43,8 @@ public class SavePersonApiHandler extends AbstractDynamoDbHandler<Person>
|
|||||||
private static final Integer BAD_REQUEST_STATUS_CODE = 400;
|
private static final Integer BAD_REQUEST_STATUS_CODE = 400;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent
|
public APIGatewayProxyResponseEvent handleRequest(
|
||||||
apiGatewayProxyRequestEvent, Context context) {
|
APIGatewayProxyRequestEvent apiGatewayProxyRequestEvent, Context context) {
|
||||||
APIGatewayProxyResponseEvent apiGatewayProxyResponseEvent;
|
APIGatewayProxyResponseEvent apiGatewayProxyResponseEvent;
|
||||||
Person person;
|
Person person;
|
||||||
try {
|
try {
|
||||||
|
@ -25,12 +25,10 @@ package com.iluwatar.serverless.baas.model;
|
|||||||
|
|
||||||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute;
|
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute;
|
||||||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBDocument;
|
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBDocument;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Address class
|
* Address class Created by dheeraj.mummarareddy on 3/4/18.
|
||||||
* Created by dheeraj.mummarareddy on 3/4/18.
|
|
||||||
*/
|
*/
|
||||||
@DynamoDBDocument
|
@DynamoDBDocument
|
||||||
public class Address implements Serializable {
|
public class Address implements Serializable {
|
||||||
|
@ -28,12 +28,10 @@ import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAutoGeneratedKey;
|
|||||||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey;
|
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey;
|
||||||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable;
|
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Person class
|
* Person class Created by dheeraj.mummarareddy on 3/4/18.
|
||||||
* Created by dheeraj.mummarareddy on 3/4/18.
|
|
||||||
*/
|
*/
|
||||||
@DynamoDBTable(tableName = "persons")
|
@DynamoDBTable(tableName = "persons")
|
||||||
public class Person implements Serializable {
|
public class Person implements Serializable {
|
||||||
|
@ -25,12 +25,11 @@ package com.iluwatar.serverless.faas;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Api gateway response
|
* Api gateway response.
|
||||||
*
|
*
|
||||||
* @param <T> serializable object
|
* @param <T> serializable object
|
||||||
*/
|
*/
|
||||||
@ -44,11 +43,11 @@ public class ApiGatewayResponse<T extends Serializable> implements Serializable
|
|||||||
private final Boolean isBase64Encoded;
|
private final Boolean isBase64Encoded;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* api gateway response
|
* api gateway response.
|
||||||
*
|
*
|
||||||
* @param statusCode - http status code
|
* @param statusCode - http status code
|
||||||
* @param body - response body
|
* @param body - response body
|
||||||
* @param headers - response headers
|
* @param headers - response headers
|
||||||
* @param isBase64Encoded - base64Encoded flag
|
* @param isBase64Encoded - base64Encoded flag
|
||||||
*/
|
*/
|
||||||
public ApiGatewayResponse(Integer statusCode, String body, Map<String, String> headers,
|
public ApiGatewayResponse(Integer statusCode, String body, Map<String, String> headers,
|
||||||
@ -60,7 +59,7 @@ public class ApiGatewayResponse<T extends Serializable> implements Serializable
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* http status code
|
* http status code.
|
||||||
*
|
*
|
||||||
* @return statusCode - http status code
|
* @return statusCode - http status code
|
||||||
*/
|
*/
|
||||||
@ -69,7 +68,7 @@ public class ApiGatewayResponse<T extends Serializable> implements Serializable
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* response body
|
* response body.
|
||||||
*
|
*
|
||||||
* @return string body
|
* @return string body
|
||||||
*/
|
*/
|
||||||
@ -78,7 +77,7 @@ public class ApiGatewayResponse<T extends Serializable> implements Serializable
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* response headers
|
* response headers.
|
||||||
*
|
*
|
||||||
* @return response headers
|
* @return response headers
|
||||||
*/
|
*/
|
||||||
@ -87,7 +86,7 @@ public class ApiGatewayResponse<T extends Serializable> implements Serializable
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* base64Encoded flag, API Gateway expects the property to be called "isBase64Encoded"
|
* base64Encoded flag, API Gateway expects the property to be called "isBase64Encoded".
|
||||||
*
|
*
|
||||||
* @return base64Encoded flag
|
* @return base64Encoded flag
|
||||||
*/
|
*/
|
||||||
@ -96,7 +95,8 @@ public class ApiGatewayResponse<T extends Serializable> implements Serializable
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ApiGatewayResponse Builder class
|
* ApiGatewayResponse Builder class.
|
||||||
|
*
|
||||||
* @param <T> Serializable object
|
* @param <T> Serializable object
|
||||||
*/
|
*/
|
||||||
public static class ApiGatewayResponseBuilder<T extends Serializable> {
|
public static class ApiGatewayResponseBuilder<T extends Serializable> {
|
||||||
@ -107,7 +107,8 @@ public class ApiGatewayResponse<T extends Serializable> implements Serializable
|
|||||||
private Boolean isBase64Encoded;
|
private Boolean isBase64Encoded;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* http status code
|
* http status code.
|
||||||
|
*
|
||||||
* @param statusCode - http status code
|
* @param statusCode - http status code
|
||||||
* @return ApiGatewayResponseBuilder
|
* @return ApiGatewayResponseBuilder
|
||||||
*/
|
*/
|
||||||
@ -117,7 +118,8 @@ public class ApiGatewayResponse<T extends Serializable> implements Serializable
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serializable body
|
* Serializable body.
|
||||||
|
*
|
||||||
* @param body - Serializable object
|
* @param body - Serializable object
|
||||||
* @return ApiGatewayResponseBuilder
|
* @return ApiGatewayResponseBuilder
|
||||||
*/
|
*/
|
||||||
@ -127,7 +129,8 @@ public class ApiGatewayResponse<T extends Serializable> implements Serializable
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* response headers
|
* response headers.
|
||||||
|
*
|
||||||
* @param headers - response headers
|
* @param headers - response headers
|
||||||
* @return ApiGatewayResponseBuilder
|
* @return ApiGatewayResponseBuilder
|
||||||
*/
|
*/
|
||||||
@ -137,7 +140,8 @@ public class ApiGatewayResponse<T extends Serializable> implements Serializable
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* base64Encoded glag
|
* base64Encoded flag.
|
||||||
|
*
|
||||||
* @param isBase64Encoded - base64Encoded flag
|
* @param isBase64Encoded - base64Encoded flag
|
||||||
* @return ApiGatewayResponseBuilder
|
* @return ApiGatewayResponseBuilder
|
||||||
*/
|
*/
|
||||||
@ -147,7 +151,7 @@ public class ApiGatewayResponse<T extends Serializable> implements Serializable
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* build ApiGatewayResponse
|
* build ApiGatewayResponse.
|
||||||
*
|
*
|
||||||
* @return ApiGatewayResponse
|
* @return ApiGatewayResponse
|
||||||
*/
|
*/
|
||||||
|
@ -26,7 +26,7 @@ package com.iluwatar.serverless.faas;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lambda context information
|
* Lambda context information.
|
||||||
*/
|
*/
|
||||||
public class LambdaInfo implements Serializable {
|
public class LambdaInfo implements Serializable {
|
||||||
|
|
||||||
@ -110,22 +110,28 @@ public class LambdaInfo implements Serializable {
|
|||||||
|
|
||||||
LambdaInfo that = (LambdaInfo) o;
|
LambdaInfo that = (LambdaInfo) o;
|
||||||
|
|
||||||
if (awsRequestId != null ? !awsRequestId.equals(that.awsRequestId) : that.awsRequestId != null) {
|
if (awsRequestId != null ? !awsRequestId
|
||||||
|
.equals(that.awsRequestId) : that.awsRequestId != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (logGroupName != null ? !logGroupName.equals(that.logGroupName) : that.logGroupName != null) {
|
if (logGroupName != null ? !logGroupName
|
||||||
|
.equals(that.logGroupName) : that.logGroupName != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (logStreamName != null ? !logStreamName.equals(that.logStreamName) : that.logStreamName != null) {
|
if (logStreamName != null ? !logStreamName
|
||||||
|
.equals(that.logStreamName) : that.logStreamName != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (functionName != null ? !functionName.equals(that.functionName) : that.functionName != null) {
|
if (functionName != null ? !functionName
|
||||||
|
.equals(that.functionName) : that.functionName != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (functionVersion != null ? !functionVersion.equals(that.functionVersion) : that.functionVersion != null) {
|
if (functionVersion != null ? !functionVersion
|
||||||
|
.equals(that.functionVersion) : that.functionVersion != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return memoryLimitInMb != null ? memoryLimitInMb.equals(that.memoryLimitInMb) : that.memoryLimitInMb == null;
|
return memoryLimitInMb != null ? memoryLimitInMb
|
||||||
|
.equals(that.memoryLimitInMb) : that.memoryLimitInMb == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -23,22 +23,20 @@
|
|||||||
|
|
||||||
package com.iluwatar.serverless.faas.api;
|
package com.iluwatar.serverless.faas.api;
|
||||||
|
|
||||||
import com.iluwatar.serverless.faas.ApiGatewayResponse;
|
|
||||||
|
|
||||||
import com.amazonaws.services.lambda.runtime.Context;
|
import com.amazonaws.services.lambda.runtime.Context;
|
||||||
import com.amazonaws.services.lambda.runtime.RequestHandler;
|
import com.amazonaws.services.lambda.runtime.RequestHandler;
|
||||||
|
import com.iluwatar.serverless.faas.ApiGatewayResponse;
|
||||||
import com.iluwatar.serverless.faas.LambdaInfo;
|
import com.iluwatar.serverless.faas.LambdaInfo;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LambdaInfoApiHandler - simple api to get lambda context
|
* LambdaInfoApiHandler - simple api to get lambda context Created by dheeraj.mummar on 2/5/18.
|
||||||
* Created by dheeraj.mummar on 2/5/18.
|
|
||||||
*/
|
*/
|
||||||
public class LambdaInfoApiHandler implements RequestHandler<Map<String, Object>, ApiGatewayResponse> {
|
public class LambdaInfoApiHandler
|
||||||
|
implements RequestHandler<Map<String, Object>, ApiGatewayResponse> {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(LambdaInfoApiHandler.class);
|
private static final Logger LOG = LoggerFactory.getLogger(LambdaInfoApiHandler.class);
|
||||||
private static final Integer SUCCESS_STATUS_CODE = 200;
|
private static final Integer SUCCESS_STATUS_CODE = 200;
|
||||||
@ -49,16 +47,17 @@ public class LambdaInfoApiHandler implements RequestHandler<Map<String, Object>,
|
|||||||
LOG.info("received: " + input);
|
LOG.info("received: " + input);
|
||||||
|
|
||||||
return new ApiGatewayResponse
|
return new ApiGatewayResponse
|
||||||
.ApiGatewayResponseBuilder<LambdaInfo>()
|
.ApiGatewayResponseBuilder<LambdaInfo>()
|
||||||
.headers(headers())
|
.headers(headers())
|
||||||
.statusCode(SUCCESS_STATUS_CODE)
|
.statusCode(SUCCESS_STATUS_CODE)
|
||||||
.body(lambdaInfo(context))
|
.body(lambdaInfo(context))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* lambdaInfo
|
* lambdaInfo.
|
||||||
|
*
|
||||||
* @param context - Lambda context
|
* @param context - Lambda context
|
||||||
* @return LambdaInfo
|
* @return LambdaInfo
|
||||||
*/
|
*/
|
||||||
|
@ -23,19 +23,15 @@
|
|||||||
|
|
||||||
package com.iluwatar.servicelayer.app;
|
package com.iluwatar.servicelayer.app;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.iluwatar.servicelayer.magic.MagicService;
|
import com.iluwatar.servicelayer.magic.MagicService;
|
||||||
import com.iluwatar.servicelayer.magic.MagicServiceImpl;
|
import com.iluwatar.servicelayer.magic.MagicServiceImpl;
|
||||||
import com.iluwatar.servicelayer.spell.Spell;
|
import com.iluwatar.servicelayer.spell.Spell;
|
||||||
import com.iluwatar.servicelayer.spell.SpellDao;
|
|
||||||
import com.iluwatar.servicelayer.spell.SpellDaoImpl;
|
import com.iluwatar.servicelayer.spell.SpellDaoImpl;
|
||||||
import com.iluwatar.servicelayer.spellbook.Spellbook;
|
import com.iluwatar.servicelayer.spellbook.Spellbook;
|
||||||
import com.iluwatar.servicelayer.spellbook.SpellbookDao;
|
|
||||||
import com.iluwatar.servicelayer.spellbook.SpellbookDaoImpl;
|
import com.iluwatar.servicelayer.spellbook.SpellbookDaoImpl;
|
||||||
import com.iluwatar.servicelayer.wizard.Wizard;
|
import com.iluwatar.servicelayer.wizard.Wizard;
|
||||||
import com.iluwatar.servicelayer.wizard.WizardDao;
|
|
||||||
import com.iluwatar.servicelayer.wizard.WizardDaoImpl;
|
import com.iluwatar.servicelayer.wizard.WizardDaoImpl;
|
||||||
|
import java.util.List;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -43,28 +39,27 @@ import org.slf4j.LoggerFactory;
|
|||||||
/**
|
/**
|
||||||
* Service layer defines an application's boundary with a layer of services that establishes a set
|
* Service layer defines an application's boundary with a layer of services that establishes a set
|
||||||
* of available operations and coordinates the application's response in each operation.
|
* of available operations and coordinates the application's response in each operation.
|
||||||
* <p>
|
*
|
||||||
* Enterprise applications typically require different kinds of interfaces to the data they store
|
* <p>Enterprise applications typically require different kinds of interfaces to the data they
|
||||||
* and the logic they implement: data loaders, user interfaces, integration gateways, and others.
|
* store and the logic they implement: data loaders, user interfaces, integration gateways, and
|
||||||
* Despite their different purposes, these interfaces often need common interactions with the
|
* others. Despite their different purposes, these interfaces often need common interactions with
|
||||||
* application to access and manipulate its data and invoke its business logic. The interactions may
|
* the application to access and manipulate its data and invoke its business logic. The interactions
|
||||||
* be complex, involving transactions across multiple resources and the coordination of several
|
* may be complex, involving transactions across multiple resources and the coordination of several
|
||||||
* responses to an action. Encoding the logic of the interactions separately in each interface
|
* responses to an action. Encoding the logic of the interactions separately in each interface
|
||||||
* causes a lot of duplication.
|
* causes a lot of duplication.
|
||||||
* <p>
|
|
||||||
* The example application demonstrates interactions between a client ({@link App}) and a service (
|
|
||||||
* {@link MagicService}). The service is implemented with 3-layer architecture (entity, dao,
|
|
||||||
* service). For persistence the example uses in-memory H2 database which is populated on each
|
|
||||||
* application startup.
|
|
||||||
*
|
*
|
||||||
|
* <p>The example application demonstrates interactions between a client ({@link App}) and a
|
||||||
|
* service ({@link MagicService}). The service is implemented with 3-layer architecture (entity,
|
||||||
|
* dao, service). For persistence the example uses in-memory H2 database which is populated on each
|
||||||
|
* application startup.
|
||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point
|
* Program entry point.
|
||||||
*
|
*
|
||||||
* @param args command line args
|
* @param args command line args
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@ -75,7 +70,7 @@ public class App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize data
|
* Initialize data.
|
||||||
*/
|
*/
|
||||||
public static void initData() {
|
public static void initData() {
|
||||||
// spells
|
// spells
|
||||||
@ -180,7 +175,7 @@ public class App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query the data
|
* Query the data.
|
||||||
*/
|
*/
|
||||||
public static void queryData() {
|
public static void queryData() {
|
||||||
var service =
|
var service =
|
||||||
|
@ -28,37 +28,35 @@ import javax.persistence.InheritanceType;
|
|||||||
import javax.persistence.MappedSuperclass;
|
import javax.persistence.MappedSuperclass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* Base class for entities.
|
* Base class for entities.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@MappedSuperclass
|
@MappedSuperclass
|
||||||
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
|
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
|
||||||
public abstract class BaseEntity {
|
public abstract class BaseEntity {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates the unique id of this entity
|
* Indicates the unique id of this entity.
|
||||||
*
|
*
|
||||||
* @return The id of the entity, or 'null' when not persisted
|
* @return The id of the entity, or 'null' when not persisted
|
||||||
*/
|
*/
|
||||||
public abstract Long getId();
|
public abstract Long getId();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the id of this entity
|
* Set the id of this entity.
|
||||||
*
|
*
|
||||||
* @param id The new id
|
* @param id The new id
|
||||||
*/
|
*/
|
||||||
public abstract void setId(Long id);
|
public abstract void setId(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the name of this entity
|
* Get the name of this entity.
|
||||||
*
|
*
|
||||||
* @return The name of the entity
|
* @return The name of the entity
|
||||||
*/
|
*/
|
||||||
public abstract String getName();
|
public abstract String getName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the name of this entity
|
* Set the name of this entity.
|
||||||
*
|
*
|
||||||
* @param name The new name
|
* @param name The new name
|
||||||
*/
|
*/
|
||||||
|
@ -26,11 +26,9 @@ package com.iluwatar.servicelayer.common;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* Dao interface.
|
* Dao interface.
|
||||||
*
|
*
|
||||||
* @param <E>
|
* @param <E> Type of Entity
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface Dao<E extends BaseEntity> {
|
public interface Dao<E extends BaseEntity> {
|
||||||
|
|
||||||
|
@ -23,23 +23,18 @@
|
|||||||
|
|
||||||
package com.iluwatar.servicelayer.common;
|
package com.iluwatar.servicelayer.common;
|
||||||
|
|
||||||
|
import com.iluwatar.servicelayer.hibernate.HibernateUtil;
|
||||||
import java.lang.reflect.ParameterizedType;
|
import java.lang.reflect.ParameterizedType;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.Criteria;
|
import org.hibernate.Criteria;
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
import org.hibernate.criterion.Restrictions;
|
import org.hibernate.criterion.Restrictions;
|
||||||
|
|
||||||
import com.iluwatar.servicelayer.hibernate.HibernateUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* Base class for Dao implementations.
|
* Base class for Dao implementations.
|
||||||
*
|
*
|
||||||
* @param <E>
|
* @param <E> Type of Entity
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public abstract class DaoBaseImpl<E extends BaseEntity> implements Dao<E> {
|
public abstract class DaoBaseImpl<E extends BaseEntity> implements Dao<E> {
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ package com.iluwatar.servicelayer.hibernate;
|
|||||||
import com.iluwatar.servicelayer.spell.Spell;
|
import com.iluwatar.servicelayer.spell.Spell;
|
||||||
import com.iluwatar.servicelayer.spellbook.Spellbook;
|
import com.iluwatar.servicelayer.spellbook.Spellbook;
|
||||||
import com.iluwatar.servicelayer.wizard.Wizard;
|
import com.iluwatar.servicelayer.wizard.Wizard;
|
||||||
|
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -40,7 +39,7 @@ public final class HibernateUtil {
|
|||||||
private static final Logger LOGGER = LoggerFactory.getLogger(HibernateUtil.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(HibernateUtil.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The cached session factory
|
* The cached session factory.
|
||||||
*/
|
*/
|
||||||
private static volatile SessionFactory sessionFactory;
|
private static volatile SessionFactory sessionFactory;
|
||||||
|
|
||||||
|
@ -23,17 +23,14 @@
|
|||||||
|
|
||||||
package com.iluwatar.servicelayer.magic;
|
package com.iluwatar.servicelayer.magic;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.iluwatar.servicelayer.spell.Spell;
|
import com.iluwatar.servicelayer.spell.Spell;
|
||||||
import com.iluwatar.servicelayer.spellbook.Spellbook;
|
import com.iluwatar.servicelayer.spellbook.Spellbook;
|
||||||
import com.iluwatar.servicelayer.wizard.Wizard;
|
import com.iluwatar.servicelayer.wizard.Wizard;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* Service interface.
|
* Service interface.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface MagicService {
|
public interface MagicService {
|
||||||
|
|
||||||
|
@ -23,20 +23,17 @@
|
|||||||
|
|
||||||
package com.iluwatar.servicelayer.magic;
|
package com.iluwatar.servicelayer.magic;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.iluwatar.servicelayer.spell.Spell;
|
import com.iluwatar.servicelayer.spell.Spell;
|
||||||
import com.iluwatar.servicelayer.spell.SpellDao;
|
import com.iluwatar.servicelayer.spell.SpellDao;
|
||||||
import com.iluwatar.servicelayer.spellbook.Spellbook;
|
import com.iluwatar.servicelayer.spellbook.Spellbook;
|
||||||
import com.iluwatar.servicelayer.spellbook.SpellbookDao;
|
import com.iluwatar.servicelayer.spellbook.SpellbookDao;
|
||||||
import com.iluwatar.servicelayer.wizard.Wizard;
|
import com.iluwatar.servicelayer.wizard.Wizard;
|
||||||
import com.iluwatar.servicelayer.wizard.WizardDao;
|
import com.iluwatar.servicelayer.wizard.WizardDao;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* Service implementation.
|
* Service implementation.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class MagicServiceImpl implements MagicService {
|
public class MagicServiceImpl implements MagicService {
|
||||||
|
|
||||||
@ -45,7 +42,7 @@ public class MagicServiceImpl implements MagicService {
|
|||||||
private SpellDao spellDao;
|
private SpellDao spellDao;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public MagicServiceImpl(WizardDao wizardDao, SpellbookDao spellbookDao, SpellDao spellDao) {
|
public MagicServiceImpl(WizardDao wizardDao, SpellbookDao spellbookDao, SpellDao spellDao) {
|
||||||
this.wizardDao = wizardDao;
|
this.wizardDao = wizardDao;
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
package com.iluwatar.servicelayer.spell;
|
package com.iluwatar.servicelayer.spell;
|
||||||
|
|
||||||
|
import com.iluwatar.servicelayer.common.BaseEntity;
|
||||||
|
import com.iluwatar.servicelayer.spellbook.Spellbook;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
||||||
@ -31,13 +33,8 @@ import javax.persistence.JoinColumn;
|
|||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
import com.iluwatar.servicelayer.common.BaseEntity;
|
|
||||||
import com.iluwatar.servicelayer.spellbook.Spellbook;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* Spell entity.
|
* Spell entity.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "SPELL")
|
@Table(name = "SPELL")
|
||||||
@ -54,13 +51,14 @@ public class Spell extends BaseEntity {
|
|||||||
@JoinColumn(name = "SPELLBOOK_ID_FK", referencedColumnName = "SPELLBOOK_ID")
|
@JoinColumn(name = "SPELLBOOK_ID_FK", referencedColumnName = "SPELLBOOK_ID")
|
||||||
private Spellbook spellbook;
|
private Spellbook spellbook;
|
||||||
|
|
||||||
public Spell() {}
|
public Spell() {
|
||||||
|
}
|
||||||
|
|
||||||
public Spell(String name) {
|
public Spell(String name) {
|
||||||
this();
|
this();
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@ -68,7 +66,7 @@ public class Spell extends BaseEntity {
|
|||||||
public void setId(Long id) {
|
public void setId(Long id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -26,9 +26,7 @@ package com.iluwatar.servicelayer.spell;
|
|||||||
import com.iluwatar.servicelayer.common.Dao;
|
import com.iluwatar.servicelayer.common.Dao;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* SpellDao interface.
|
* SpellDao interface.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface SpellDao extends Dao<Spell> {
|
public interface SpellDao extends Dao<Spell> {
|
||||||
|
|
||||||
|
@ -24,16 +24,11 @@
|
|||||||
package com.iluwatar.servicelayer.spell;
|
package com.iluwatar.servicelayer.spell;
|
||||||
|
|
||||||
import com.iluwatar.servicelayer.common.DaoBaseImpl;
|
import com.iluwatar.servicelayer.common.DaoBaseImpl;
|
||||||
|
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
import org.hibernate.criterion.Restrictions;
|
import org.hibernate.criterion.Restrictions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* SpellDao implementation.
|
* SpellDao implementation.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class SpellDaoImpl extends DaoBaseImpl<Spell> implements SpellDao {
|
public class SpellDaoImpl extends DaoBaseImpl<Spell> implements SpellDao {
|
||||||
|
|
||||||
|
@ -23,9 +23,11 @@
|
|||||||
|
|
||||||
package com.iluwatar.servicelayer.spellbook;
|
package com.iluwatar.servicelayer.spellbook;
|
||||||
|
|
||||||
|
import com.iluwatar.servicelayer.common.BaseEntity;
|
||||||
|
import com.iluwatar.servicelayer.spell.Spell;
|
||||||
|
import com.iluwatar.servicelayer.wizard.Wizard;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
@ -36,14 +38,8 @@ import javax.persistence.ManyToMany;
|
|||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
import com.iluwatar.servicelayer.common.BaseEntity;
|
|
||||||
import com.iluwatar.servicelayer.spell.Spell;
|
|
||||||
import com.iluwatar.servicelayer.wizard.Wizard;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* Spellbook entity.
|
* Spellbook entity.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "SPELLBOOK")
|
@Table(name = "SPELLBOOK")
|
||||||
@ -71,7 +67,7 @@ public class Spellbook extends BaseEntity {
|
|||||||
this();
|
this();
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@ -79,7 +75,7 @@ public class Spellbook extends BaseEntity {
|
|||||||
public void setId(Long id) {
|
public void setId(Long id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -26,9 +26,7 @@ package com.iluwatar.servicelayer.spellbook;
|
|||||||
import com.iluwatar.servicelayer.common.Dao;
|
import com.iluwatar.servicelayer.common.Dao;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* SpellbookDao interface.
|
* SpellbookDao interface.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface SpellbookDao extends Dao<Spellbook> {
|
public interface SpellbookDao extends Dao<Spellbook> {
|
||||||
|
|
||||||
|
@ -23,17 +23,12 @@
|
|||||||
|
|
||||||
package com.iluwatar.servicelayer.spellbook;
|
package com.iluwatar.servicelayer.spellbook;
|
||||||
|
|
||||||
import org.hibernate.Criteria;
|
import com.iluwatar.servicelayer.common.DaoBaseImpl;
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
import org.hibernate.criterion.Restrictions;
|
import org.hibernate.criterion.Restrictions;
|
||||||
|
|
||||||
import com.iluwatar.servicelayer.common.DaoBaseImpl;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* SpellbookDao implementation.
|
* SpellbookDao implementation.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class SpellbookDaoImpl extends DaoBaseImpl<Spellbook> implements SpellbookDao {
|
public class SpellbookDaoImpl extends DaoBaseImpl<Spellbook> implements SpellbookDao {
|
||||||
|
|
||||||
|
@ -23,9 +23,10 @@
|
|||||||
|
|
||||||
package com.iluwatar.servicelayer.wizard;
|
package com.iluwatar.servicelayer.wizard;
|
||||||
|
|
||||||
|
import com.iluwatar.servicelayer.common.BaseEntity;
|
||||||
|
import com.iluwatar.servicelayer.spellbook.Spellbook;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
@ -34,13 +35,8 @@ import javax.persistence.Id;
|
|||||||
import javax.persistence.ManyToMany;
|
import javax.persistence.ManyToMany;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
import com.iluwatar.servicelayer.common.BaseEntity;
|
|
||||||
import com.iluwatar.servicelayer.spellbook.Spellbook;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* Wizard entity.
|
* Wizard entity.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "WIZARD")
|
@Table(name = "WIZARD")
|
||||||
@ -64,7 +60,7 @@ public class Wizard extends BaseEntity {
|
|||||||
this();
|
this();
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@ -72,7 +68,7 @@ public class Wizard extends BaseEntity {
|
|||||||
public void setId(Long id) {
|
public void setId(Long id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -26,9 +26,7 @@ package com.iluwatar.servicelayer.wizard;
|
|||||||
import com.iluwatar.servicelayer.common.Dao;
|
import com.iluwatar.servicelayer.common.Dao;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* WizardDao interface.
|
* WizardDao interface.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface WizardDao extends Dao<Wizard> {
|
public interface WizardDao extends Dao<Wizard> {
|
||||||
|
|
||||||
|
@ -23,18 +23,15 @@
|
|||||||
|
|
||||||
package com.iluwatar.servicelayer.wizard;
|
package com.iluwatar.servicelayer.wizard;
|
||||||
|
|
||||||
|
import com.iluwatar.servicelayer.common.DaoBaseImpl;
|
||||||
|
import com.iluwatar.servicelayer.spellbook.Spellbook;
|
||||||
import org.hibernate.Criteria;
|
import org.hibernate.Criteria;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
import org.hibernate.criterion.Restrictions;
|
import org.hibernate.criterion.Restrictions;
|
||||||
|
|
||||||
import com.iluwatar.servicelayer.common.DaoBaseImpl;
|
|
||||||
import com.iluwatar.servicelayer.spellbook.Spellbook;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* WizardDao implementation.
|
* WizardDao implementation.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class WizardDaoImpl extends DaoBaseImpl<Wizard> implements WizardDao {
|
public class WizardDaoImpl extends DaoBaseImpl<Wizard> implements WizardDao {
|
||||||
|
|
||||||
|
@ -24,24 +24,22 @@
|
|||||||
package com.iluwatar.servicelocator;
|
package com.iluwatar.servicelocator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* The Service Locator pattern is a design pattern used in software development to encapsulate the
|
* The Service Locator pattern is a design pattern used in software development to encapsulate the
|
||||||
* processes involved in obtaining a service with a strong abstraction layer. This pattern uses a
|
* processes involved in obtaining a service with a strong abstraction layer. This pattern uses a
|
||||||
* central registry known as the "service locator", which on request returns the information
|
* central registry known as the "service locator", which on request returns the information
|
||||||
* necessary to perform a certain task.
|
* necessary to perform a certain task.
|
||||||
* <p>
|
*
|
||||||
* In this example we use the Service locator pattern to lookup JNDI-services and cache them for
|
* <p>In this example we use the Service locator pattern to lookup JNDI-services and cache them for
|
||||||
* subsequent requests.
|
* subsequent requests.
|
||||||
* <p>
|
* <br>
|
||||||
*
|
*
|
||||||
* @author saifasif
|
* @author saifasif
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point
|
* Program entry point.
|
||||||
*
|
*
|
||||||
* @param args command line args
|
* @param args command line args
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -25,10 +25,10 @@ package com.iluwatar.servicelocator;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This is going to be the parent service interface which we will use to create our services. All
|
* This is going to be the parent service interface which we will use to create our services. All
|
||||||
* services will have a <ul><li>service name</li> <li>unique id</li> <li>execution work flow</li></ul>
|
* services will have a <ul><li>service name</li> <li>unique id</li> <li>execution work
|
||||||
*
|
* flow</li></ul>
|
||||||
* @author saifasif
|
|
||||||
*
|
*
|
||||||
|
* @author saifasif
|
||||||
*/
|
*/
|
||||||
public interface Service {
|
public interface Service {
|
||||||
|
|
||||||
|
@ -23,11 +23,10 @@
|
|||||||
|
|
||||||
package com.iluwatar.servicelocator;
|
package com.iluwatar.servicelocator;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The service cache implementation which will cache services that are being created. On first hit,
|
* The service cache implementation which will cache services that are being created. On first hit,
|
||||||
@ -59,14 +58,14 @@ public class ServiceCache {
|
|||||||
if (serviceJndiName.equals(serviceName)) {
|
if (serviceJndiName.equals(serviceName)) {
|
||||||
cachedService = serviceCache.get(serviceJndiName);
|
cachedService = serviceCache.get(serviceJndiName);
|
||||||
LOGGER.info("(cache call) Fetched service {}({}) from cache... !",
|
LOGGER.info("(cache call) Fetched service {}({}) from cache... !",
|
||||||
cachedService.getName(), cachedService.getId());
|
cachedService.getName(), cachedService.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cachedService;
|
return cachedService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the service into the cache map
|
* Adds the service into the cache map.
|
||||||
*
|
*
|
||||||
* @param newService a {@link Service}
|
* @param newService a {@link Service}
|
||||||
*/
|
*/
|
||||||
|
@ -41,7 +41,7 @@ public class ServiceImpl implements Service {
|
|||||||
private final int id;
|
private final int id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public ServiceImpl(String serviceName) {
|
public ServiceImpl(String serviceName) {
|
||||||
// set the service name
|
// set the service name
|
||||||
|
Loading…
x
Reference in New Issue
Block a user