121 lines
5.4 KiB
Java
121 lines
5.4 KiB
Java
package de.hsos.swa.ma.api.al;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import org.jboss.logging.Logger;
|
|
|
|
import javax.inject.Inject;
|
|
// import org.eclipse.microprofile.*;
|
|
|
|
// import org.eclipse.microprofile.openapi.annotations.OpenAPIDefinition;
|
|
// import org.eclipse.microprofile.openapi.annotations.info.Contact;
|
|
// import org.eclipse.microprofile.openapi.annotations.info.Info;
|
|
// import org.eclipse.microprofile.openapi.annotations.info.License;
|
|
// import org.eclipse.microprofile.openapi.annotations.tags.Tag;
|
|
|
|
import org.eclipse.microprofile.metrics.MetricUnits;
|
|
import org.eclipse.microprofile.metrics.annotation.Counted;
|
|
import org.eclipse.microprofile.metrics.annotation.Gauge;
|
|
import org.eclipse.microprofile.metrics.annotation.Timed;
|
|
|
|
import org.eclipse.microprofile.faulttolerance.Retry;
|
|
import org.eclipse.microprofile.faulttolerance.Timeout;
|
|
import org.eclipse.microprofile.faulttolerance.Fallback;
|
|
|
|
// import javax.ws.rs.GET;
|
|
// import javax.ws.rs.POST;
|
|
// import javax.ws.rs.PUT;
|
|
// import javax.ws.rs.DELETE;
|
|
// import javax.ws.rs.Path;
|
|
// import javax.ws.rs.Produces;
|
|
// import javax.ws.rs.Consumes;
|
|
// import javax.ws.rs.core.MediaType;
|
|
|
|
// import org.jboss.resteasy.annotations.jaxrs.PathParam;
|
|
|
|
//@Path("/mocktail")
|
|
// @OpenAPIDefinition(
|
|
// tags = {
|
|
// @Tag(name="widget", description="Widget operations."),
|
|
// @Tag(name="gasket", description="Operations related to gaskets")
|
|
// },
|
|
// info = @Info(
|
|
// title="Example API",
|
|
// version = "1.0.1",
|
|
// contact = @Contact(
|
|
// name = "Example API Support",
|
|
// url = "http://exampleurl.com/contact",
|
|
// email = "techsupport@example.com"),
|
|
// license = @License(
|
|
// name = "Apache 2.0",
|
|
// url = "http://www.apache.org/licenses/LICENSE-2.0.html"))
|
|
// )
|
|
|
|
public class Barkeeper implements BarkeeperInterface{
|
|
|
|
private static final Logger logger = Logger.getLogger(Barkeeper.class);
|
|
|
|
@Inject
|
|
StorageTransport st;
|
|
|
|
//Metrics
|
|
@Counted(name = "performedSearchesByName", description = "How many searches by name have been performed.")
|
|
@Timed(name = "searchTimer", description = "A measure of how long it takes to perform the search.", unit = MetricUnits.MILLISECONDS)
|
|
//@Gauge(name = "highestPrimeNumberSoFar", unit = MetricUnits.NONE, description = "Highest prime number so far.")
|
|
//Fault-Tolerance
|
|
@Retry(maxRetries = 3)
|
|
@Timeout(250)
|
|
@Fallback(fallbackMethod = "fallbackGetMocktailByName")
|
|
public ArrayList<Mocktail> getMocktailByName(String name) {
|
|
logger.debug(System.currentTimeMillis() + ": Barkeeper->getMocktailByName: started");
|
|
ArrayList<Mocktail> mts = st.getMocktailByName(name);
|
|
logger.trace(System.currentTimeMillis() + ": Barkeeper->getMocktailByName: get mocktail by name by REST-CLIENT");
|
|
logger.debug(System.currentTimeMillis() + ": Barkeeper->getMocktailByName: ended");
|
|
return mts;
|
|
}
|
|
|
|
public ArrayList<Mocktail> fallbackGetMocktailByName(String name) {
|
|
logger.debug(System.currentTimeMillis() + ": Barkeeper->getMocktailByName: started");
|
|
ArrayList<Mocktail> mts = st.getAllMocktails();
|
|
logger.trace(System.currentTimeMillis() + ": Barkeeper->getMocktailByName: get mocktail by name by REST-CLIENT");
|
|
logger.debug(System.currentTimeMillis() + ": Barkeeper->getMocktailByName: ended");
|
|
return mts;
|
|
}
|
|
|
|
//Metrics
|
|
@Counted(name = "performedCreates", description = "How many creates have been performed.")
|
|
@Timed(name = "createTimer", description = "A measure of how long it takes to perform the mocktail creation.", unit = MetricUnits.MILLISECONDS)
|
|
//Fault-Tolerance
|
|
@Retry(maxRetries = 3)
|
|
public void createMocktail(Mocktail m) {
|
|
logger.debug(System.currentTimeMillis() + ": Barkeeper->createMocktail: started");
|
|
this.st.addMocktail(m);
|
|
logger.trace(System.currentTimeMillis() + ": Barkeeper->createMocktail: create mocktail by REST-CLIENT");
|
|
logger.debug(System.currentTimeMillis() + ": Barkeeper->createMocktail: ended");
|
|
}
|
|
|
|
//Metrics
|
|
@Counted(name = "performedUpdates", description = "How many updates have been performed.")
|
|
@Timed(name = "updateTimer", description = "A measure of how long it takes to perform the update of a mocktail.", unit = MetricUnits.MILLISECONDS)
|
|
//Fault-Tolerance
|
|
@Retry(maxRetries = 3)
|
|
public void updateMocktail(Mocktail m, long number) {
|
|
logger.debug(System.currentTimeMillis() + ": Barkeeper->updateMocktail: started");
|
|
this.st.updateMocktail(m, number);
|
|
logger.trace(System.currentTimeMillis() + ": Barkeeper->updateMocktail: update mocktail by REST-CLIENT");
|
|
logger.debug(System.currentTimeMillis() + ": Barkeeper->updateMocktail: ended");
|
|
}
|
|
|
|
//Metrics
|
|
@Counted(name = "performedDeletions", description = "How many deletes have been performed.")
|
|
@Timed(name = "deleteTimer", description = "A measure of how long it takes to delete a mocktail.", unit = MetricUnits.MILLISECONDS)
|
|
//Fault-Tolerance
|
|
@Retry(maxRetries = 3)
|
|
public void deleteMocktail(long id) {
|
|
logger.debug(System.currentTimeMillis() + ": Barkeeper->deleteMocktail: started");
|
|
this.st.deleteMocktail(id);
|
|
logger.trace(System.currentTimeMillis() + ": Barkeeper->deleteMocktail: delete mocktail by REST-CLIENT");
|
|
logger.debug(System.currentTimeMillis() + ": Barkeeper->deleteMocktail: ended");
|
|
}
|
|
|
|
} |