Skip to content

Commit

Permalink
- Threading model support added
Browse files Browse the repository at this point in the history
- Worker naming convention changed to service units after the new threading model support
  • Loading branch information
Areeb-Gillani committed Dec 25, 2024
1 parent 70f84d6 commit 756202c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 35 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ allprojects {
#### build.gradle
```kotlin
dependencies {
implementation ("com.github.Areeb-Gillani:vertx-boost:1.0.1")
implementation ("com.github.Areeb-Gillani:vertx-boost:1.0.2")
}
```
#### pom.xml
Expand All @@ -43,7 +43,7 @@ dependencies {
<dependency>
<groupId>com.github.Areeb-Gillani</groupId>
<artifactId>vertx-boost</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
</dependency>
</dependencies>
```
Expand All @@ -53,7 +53,7 @@ Vertx says that every class that extends AbstractVerticle will be handled by its
```json
{
{...},
"workers":{
"ServiceUnits":{
"ExampleWorker":{
"instance":5,
"poolSize":6
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/io/github/areebgillani/boost/BoostApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public void deployApplication(String folderPath, Boolean isClustered) throws Exc
booster.boost(this.getClass().getPackage().getName());
if(isClustered)
clusteredVertx = VertxClusterUtils.initClusterVertx(config, vertxOptions);
booster.getServiceWorkerList().forEach(service->{
booster.getServiceUnitList().forEach(service->{
try {
deployServices(service.getGlobalConfig(), service.getServiceSupplier(), service.getWorkerName(), service.getWorkerConfig());
deployServices(service.getGlobalConfig(), service.getServiceSupplier(), service.getServiceUnitName(), service.getServiceUnitConfig());
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -127,21 +127,21 @@ public ConfigRetrieverOptions initRetrieverConfig(String folderPath) {
.setConfig(new JsonObject().put("path", folderPath == null || folderPath.isEmpty() ? "config.json" : folderPath)))
.addStore(new ConfigStoreOptions().setType("sys"));
}
private void deployServices(JsonObject config, Supplier<Verticle> serviceSupplier, String workerName, JsonObject workerConfig) {
private void deployServices(JsonObject config, Supplier<Verticle> serviceSupplier, String serviceUnitName, JsonObject serviceUnitConfig) {
vertx.deployVerticle(serviceSupplier, new DeploymentOptions()
.setConfig(config)
.setWorkerPoolName(workerName)
.setWorkerPoolSize(workerConfig.getInteger("poolSize", 20))
.setInstances(workerConfig.getInteger("instance", 5))
.setThreadingModel(switch (workerConfig.getString("type", "W")) {
.setWorkerPoolName(serviceUnitName)
.setWorkerPoolSize(serviceUnitConfig.getInteger("poolSize", 20))
.setInstances(serviceUnitConfig.getInteger("instance", 5))
.setThreadingModel(switch (serviceUnitConfig.getString("type", "W")) {
case "EL": yield ThreadingModel.EVENT_LOOP;
case "VT": yield ThreadingModel.VIRTUAL_THREAD;
default: yield ThreadingModel.WORKER;
}), res -> {
if (res.succeeded())
logger.info(workerName+" successfully deployed.");
logger.info(serviceUnitName+" successfully deployed.");
else
logger.error(workerName+" deployment failed." + res.cause());
logger.error(serviceUnitName+" deployment failed." + res.cause());
});
}
private void deployHttpService( Supplier<Verticle> serviceSupplier, int instances, int port) {
Expand Down
17 changes: 8 additions & 9 deletions src/main/java/io/github/areebgillani/boost/Booster.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import io.github.areebgillani.boost.aspects.*;
import io.github.areebgillani.boost.pojos.EndPointController;
import io.github.areebgillani.boost.pojos.ServiceWorker;
import io.github.areebgillani.boost.pojos.ServiceUnit;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.ThreadingModel;
import io.vertx.core.Verticle;
import io.vertx.core.Vertx;
import io.vertx.core.impl.logging.Logger;
Expand All @@ -26,7 +25,7 @@ public class Booster {
Logger logger = LoggerFactory.getLogger(Booster.class);
private final HashMap<String, Object> controllerInstanceMap = new HashMap<>();
private final HashMap<String, List<EndPointController>> endPointControllerMap = new HashMap<>();
private final List<ServiceWorker> serviceWorkerList = new ArrayList<>();
private final List<ServiceUnit> serviceUnitList = new ArrayList<>();
String basePackage;
Vertx vertx;
JsonObject config;
Expand Down Expand Up @@ -68,7 +67,7 @@ private void scanServices() {
Reflections reflections = new Reflections(basePackage);
Set<Class<?>> services = reflections.getTypesAnnotatedWith(Service.class);
Set<Class<?>> repos = reflections.getTypesAnnotatedWith(Repository.class);
JsonObject workers = config.getJsonObject("workers");
JsonObject serviceUnits = config.getJsonObject("ServiceUnits");
for (Class<?> service : services) {
Supplier<Verticle> myService = () -> {
try {
Expand All @@ -84,8 +83,8 @@ private void scanServices() {
throw new RuntimeException(e);
}
};
String workerName = getWorkerName(service);
serviceWorkerList.add(new ServiceWorker(config, myService, workerName, workers.getJsonObject(workerName)));
String serviceUnitName = getServiceUnitName(service);
serviceUnitList.add(new ServiceUnit(config, myService, serviceUnitName, serviceUnits.getJsonObject(serviceUnitName)));
}
}

Expand Down Expand Up @@ -114,7 +113,7 @@ private void initRepositoryVariable(Set<Class<?>> repos, Object serviceInstance,
}
}

private String getWorkerName(Class<?> service) {
private String getServiceUnitName(Class<?> service) {
for (Annotation annotation : service.getAnnotations()) {
if (annotation instanceof Service serv)
return serv.value();
Expand All @@ -130,7 +129,7 @@ public HashMap<String, Object> getControllerInstanceMap() {
return controllerInstanceMap;
}

public List<ServiceWorker> getServiceWorkerList() {
return serviceWorkerList;
public List<ServiceUnit> getServiceUnitList() {
return serviceUnitList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@

import java.util.function.Supplier;

public class ServiceWorker {
public class ServiceUnit {
JsonObject globalConfig;
Supplier<Verticle> serviceSupplier;
String workerName;
JsonObject workerConfig;
String serviceUnitName;
JsonObject serviceUnitConfig;

public ServiceWorker(JsonObject globalConfig, Supplier<Verticle> serviceSupplier, String workerName, JsonObject workerConfig) {
public ServiceUnit(JsonObject globalConfig, Supplier<Verticle> serviceSupplier, String serviceUnitName, JsonObject serviceUnitConfig) {
this.globalConfig = globalConfig;
this.serviceSupplier = serviceSupplier;
this.workerName = workerName;
this.workerConfig = workerConfig;
this.serviceUnitName = serviceUnitName;
this.serviceUnitConfig = serviceUnitConfig;
}

public JsonObject getGlobalConfig() {
Expand All @@ -34,19 +34,19 @@ public void setServiceSupplier(Supplier<Verticle> serviceSupplier) {
this.serviceSupplier = serviceSupplier;
}

public String getWorkerName() {
return workerName;
public String getServiceUnitName() {
return serviceUnitName;
}

public void setWorkerName(String workerName) {
this.workerName = workerName;
public void setServiceUnitName(String serviceUnitName) {
this.serviceUnitName = serviceUnitName;
}

public JsonObject getWorkerConfig() {
return workerConfig;
public JsonObject getServiceUnitConfig() {
return serviceUnitConfig;
}

public void setWorkerConfig(JsonObject workerConfig) {
this.workerConfig = workerConfig;
public void setServiceUnitConfig(JsonObject serviceUnitConfig) {
this.serviceUnitConfig = serviceUnitConfig;
}
}

0 comments on commit 756202c

Please sign in to comment.