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

Use interface for DI, and else.. #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,9 @@ com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Eclipse projects related
.project
.classpath
.settings/


17 changes: 17 additions & 0 deletions WebFlux/ex1/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM amd64/gradle:8.0.1-jdk19-alpine as builder

ADD ./build.gradle /home/gradle/build.gradle
ADD ./src /home/gradle/src/

RUN gradle build -x test



FROM amazoncorretto:19-alpine-jdk

# copy jar from builder stage
COPY --from=builder /home/gradle/build/libs/*.jar app.jar

EXPOSE 8080 8080

CMD ["sh", "-c", "java --enable-preview -jar app.jar " ]
53 changes: 53 additions & 0 deletions WebFlux/ex1/jsclients/callerpage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fetch API Example</title>
</head>
<body>

<button onclick="callMonoApi()">Call Mono API</button>
<textarea id="monoResult" rows="10" cols="50"></textarea>

<br><br>
<input type="text" id="paramInput" placeholder="Enter lockManagerName name">
<br><br>
<button onclick="callFluxApi()">Call Flux API</button>
<textarea id="fluxResult" rows="10" cols="50"></textarea>

<script>
function callMonoApi() {


const monoUrl = `http://localhost:8080/create?permitCount=3`;

fetch(monoUrl)
.then(response => response.json())
.then(data => {
document.getElementById('monoResult').value = JSON.stringify(data, null, 2);
})
.catch(error => {
console.error('Error calling Mono API:', error);
});
}

function callFluxApi() {
const paramInput = document.getElementById('paramInput').value;
const fluxUrl = `http://localhost:8080/acquireLocksTest?permits=3&lockManagerName=${encodeURIComponent(paramInput)}&lockManagerPermitCount=2`;

fetch(fluxUrl)
.then(response => response.json())
.then(data => {
data.forEach(item => {
document.getElementById('fluxResult').value = JSON.stringify(data, null, 2);
});
})
.catch(error => {
console.error('Error calling Flux API:', error);
});
}
</script>

</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
/**
* Constants shared by the client and server components.
*/
public class Constants {
public static final String SERVER_BASE_URL = "http://localhost:8080";
public interface Constants {
String SERVER_BASE_URL = "http://localhost:8080";

public static class Endpoints {
public static final String CREATE = "create";
public static final String ACQUIRE_LOCK = "acquireLock";
public static final String ACQUIRE_LOCKS = "acquireLocks";
public static final String RELEASE_LOCK = "releaseLock";
public static final String RELEASE_LOCKS = "releaseLocks";
}
public interface Endpoints {
String CREATE = "create", ACQUIRE_LOCK = "acquireLock", ACQUIRE_LOCKS = "acquireLocks",
RELEASE_LOCK = "releaseLock", RELEASE_LOCKS = "releaseLocks", ACQUIRE_LOCKS_TEST = "acquireLocksTest";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,71 @@
import java.util.Objects;

/**
* This class is used to keep track of allocated {@link LockManager}
* objects.
* This class is used to keep track of allocated {@link LockManager} objects.
*/
public class LockManager {
/**
* The unique name of the {@link LockManager}.
*/
public String name;
/**
* The unique name of the {@link LockManager}.
*/
public String name;

/**
* The number of permits in this {@link LockManager}.
*/
public Integer permitCount;
/**
* The number of permits in this {@link LockManager}.
*/
public Integer permitCount;

/**
* @return The unique name of the {@link LockManager}
*
public String getName() {
return mName;
}
*/
/**
* @return The unique name of the {@link LockManager}
*
* public String getName() { return mName; }
*/

/**
* Set the unique name of the {@link LockManager}.
*
* @param name The unique name of the {@link LockManager}
*/
public LockManager(String name) {
this.name = name;
}
/**
* Set the unique name of the {@link LockManager}.
*
* @param name The unique name of the {@link LockManager}
*/
public LockManager(String name) {
this.name = name;
}

public LockManager(String name,
Integer permitCount) {
this.name = name + ":[" + permitCount + "]";
}
public LockManager(String name, Integer permitCount) {
this.name = name;
this.permitCount = permitCount;
}

/**
* This class needs a default constructor.
*/
LockManager() {
name = "default";
}
/**
* This class needs a default constructor.
*/
LockManager() {
name = "default";
}

/**
* @return A {@link String} representation
*/
@Override
public String toString() {
return name;
}
/**
* @return A {@link String} representation
*/
@Override
public String toString() {
return name + ":[" + permitCount + "]";
}

/**
* Overrides the {@code equals()} method to compare two {@link
* LockManager} objects based on their {@code name}.
*
* @param object The other {@link Object} to compare with this
* object
* @return true if the object names are equal, false otherwise
*/
@Override
public boolean equals(Object object) {
return object instanceof LockManager other
&& this.name.equals(other.name);
}
/**
* Overrides the {@code equals()} method to compare two {@link LockManager}
* objects based on their {@code name}.
*
* @param object The other {@link Object} to compare with this object
* @return true if the object names are equal, false otherwise
*/
@Override
public boolean equals(Object object) {
return object instanceof LockManager other && this.name.equals(other.name);
}

/**
* @return A hash of the {@link LockManager} {@code name}
*/
@Override
public int hashCode() {
return Objects.hash(name);
}
/**
* @return A hash of the {@link LockManager} {@code name}
*/
@Override
public int hashCode() {
return Objects.hash(name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package edu.vandy.lockmanager.configuration;

import static org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME;

import java.util.concurrent.Executors;

import org.springframework.boot.web.embedded.tomcat.TomcatProtocolHandlerCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.core.task.support.TaskExecutorAdapter;

@Configuration
@Profile("default")
public class VirtualThreadsConfiguration {

/**
* Configure the use of Java virtual threads to handle all incoming HTTP
* requests.
*/
@Bean(APPLICATION_TASK_EXECUTOR_BEAN_NAME)
public AsyncTaskExecutor asyncTaskExecutor() {
return new TaskExecutorAdapter(Executors.newVirtualThreadPerTaskExecutor());
}

/**
* Customize the ProtocolHandler on the TomCat Connector to use Java virtual
* threads to handle all incoming HTTP requests.
*/
@Bean
public TomcatProtocolHandlerCustomizer<?> protocolHandlerVirtualThreadExecutorCustomizer() {
return protocolHandler -> protocolHandler.setExecutor(Executors.newVirtualThreadPerTaskExecutor());

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,16 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.tomcat.TomcatProtocolHandlerCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.core.task.support.TaskExecutorAdapter;

import java.util.concurrent.Executors;

import static org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME;

@SpringBootApplication
@ComponentScan("edu.vandy.lockmanager")
public class LockManagerApplication {
/**
* The main entry point into the LockManager microservice.
*/
public static void main(String[] args) {
SpringApplication.run(LockManagerApplication.class,
args);
}
/**
* The main entry point into the LockManager microservice.
*/
public static void main(String[] args) {
SpringApplication.run(LockManagerApplication.class, args);
}

/**
* Configure the use of Java virtual threads to handle all
* incoming HTTP requests.
*/
@Bean(APPLICATION_TASK_EXECUTOR_BEAN_NAME)
public AsyncTaskExecutor asyncTaskExecutor() {
return new TaskExecutorAdapter(Executors
.newVirtualThreadPerTaskExecutor());
}

/**
* Customize the ProtocolHandler on the TomCat Connector to
* use Java virtual threads to handle all incoming HTTP requests.
*/
@Bean
public TomcatProtocolHandlerCustomizer<?> protocolHandlerVirtualThreadExecutorCustomizer() {
return protocolHandler -> {
protocolHandler
.setExecutor(Executors.newVirtualThreadPerTaskExecutor());
};
}
}





Loading