Propose SDK Refactor (#1821)

* Propose SDK Refactor

* Added ExecutorService for DMF Devices

* After review, Created MgmtApi inside sdk-mgmt

* Removed direct dependency to halkbit-mgmt-api all mgmt related calls now goes through hawkbit-sdk-mgmt

* Added copyright header

* Removed redundant paramters for deleteController

* Fixed File Copyright Headers
This commit is contained in:
Vasil Ilchev
2024-08-19 15:34:29 +03:00
committed by GitHub
parent d958d8e82c
commit ac34b952d9
15 changed files with 215 additions and 131 deletions

View File

@@ -9,17 +9,6 @@
*/
package org.eclipse.hawkbit.sdk.device;
import java.time.LocalTime;
import java.time.temporal.ChronoField;
import java.util.AbstractMap;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
@@ -39,6 +28,17 @@ import org.springframework.hateoas.Link;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import java.time.LocalTime;
import java.time.temporal.ChronoField;
import java.util.AbstractMap;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* Class representing DDI device connecting directly to hawkBit.
*/
@@ -84,7 +84,7 @@ public class DdiController {
* for communication to hawkBit
*/
public DdiController(final Tenant tenant, final Controller controller,
final UpdateHandler updateHandler, final HawkbitClient hawkbitClient) {
final UpdateHandler updateHandler, final HawkbitClient hawkbitClient) {
this.tenantId = tenant.getTenantId();
gatewayToken = tenant.getGatewayToken();
downloadAuthenticationEnabled = tenant.isDownloadAuthenticationEnabled();
@@ -96,13 +96,17 @@ public class DdiController {
// expects single threaded {@link java.util.concurrent.ScheduledExecutorService}
public void start(final ScheduledExecutorService executorService) {
Objects.requireNonNull(executorService, "Require non null executor!");
stop();
Objects.requireNonNull(executorService, "Require non null executor!");
this.executorService = executorService;
executorService.submit(this::poll);
}
public void stop() {
if (executorService != null) {
executorService.shutdown();
}
executorService = null;
lastActionId = null;
currentActionId = null;

View File

@@ -19,7 +19,7 @@ import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
/**
* An in-memory simulated DMF Tenant to hold the controller twins in
* An in-memory simulated DDI Tenant to hold the controller twins in
* memory and be able to retrieve them again.
*/
public class DdiTenant {
@@ -27,8 +27,9 @@ public class DdiTenant {
@Getter
private final Tenant tenant;
private final Map<String, DdiController> controllers = new ConcurrentHashMap<>();
@Getter
private final HawkbitClient hawkbitClient;
private final Map<String, DdiController> controllers = new ConcurrentHashMap<>();
public DdiTenant(final Tenant tenant, final HawkbitClient hawkbitClient) {
this.tenant = tenant;
@@ -40,17 +41,14 @@ public class DdiTenant {
controllers.clear();
}
public DdiController create(final Controller controller, final UpdateHandler updateHandler) {
public DdiController createController(final Controller controller, final UpdateHandler updateHandler) {
final DdiController ddiController = new DdiController(tenant, controller, updateHandler, hawkbitClient);
controllers.put(controller.getControllerId(), ddiController);
return ddiController;
}
public void remove(final String controllerId) {
Optional.ofNullable(controllers.remove(controllerId)).ifPresent(DdiController::stop);
}
public Optional<DdiController> getController(final String controllerId) {
return Optional.ofNullable(controllers.get(controllerId));
}
}