org.eclipse.hawkbit.sdk.device.DdiTenant Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hawkbit-sdk-device Show documentation
Show all versions of hawkbit-sdk-device Show documentation
Device SDK that could be used for development of devices on JVM based languages
The newest version!
/**
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.sdk.device;
import lombok.Getter;
import org.eclipse.hawkbit.sdk.Controller;
import org.eclipse.hawkbit.sdk.HawkbitClient;
import org.eclipse.hawkbit.sdk.Tenant;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
/**
* An in-memory simulated DDI Tenant to hold the controller twins in
* memory and be able to retrieve them again.
*/
public class DdiTenant {
@Getter
private final Tenant tenant;
@Getter
private final HawkbitClient hawkbitClient;
private final Map controllers = new ConcurrentHashMap<>();
public DdiTenant(final Tenant tenant, final HawkbitClient hawkbitClient) {
this.tenant = tenant;
this.hawkbitClient = hawkbitClient;
}
public void destroy() {
controllers.values().forEach(DdiController::stop);
controllers.clear();
}
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 Optional getController(final String controllerId) {
return Optional.ofNullable(controllers.get(controllerId));
}
}