mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
[daikin] Use createHttpClient (#14481)
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
parent
20ac69725a
commit
e7b0fc6c14
@ -30,7 +30,7 @@ import org.openhab.core.thing.ThingTypeUID;
|
||||
@NonNullByDefault
|
||||
public class DaikinBindingConstants {
|
||||
|
||||
private static final String BINDING_ID = "daikin";
|
||||
public static final String BINDING_ID = "daikin";
|
||||
|
||||
// List of all Thing Type UIDs
|
||||
public static final ThingTypeUID THING_TYPE_AC_UNIT = new ThingTypeUID(BINDING_ID, "ac_unit");
|
||||
|
@ -16,8 +16,11 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
import org.openhab.core.io.net.http.HttpClientFactory;
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Deactivate;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -39,37 +42,32 @@ public class DaikinHttpClientFactoryImpl implements DaikinHttpClientFactory {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(DaikinHttpClientFactoryImpl.class);
|
||||
|
||||
private @Nullable HttpClient httpClient;
|
||||
private HttpClient httpClient;
|
||||
|
||||
@Activate
|
||||
public DaikinHttpClientFactoryImpl(@Reference HttpClientFactory httpClientFactory) {
|
||||
this.httpClient = httpClientFactory.createHttpClient(DaikinBindingConstants.BINDING_ID,
|
||||
new SslContextFactory.Client(true));
|
||||
try {
|
||||
httpClient.start();
|
||||
logger.debug("Daikin http client started");
|
||||
} catch (Exception e) {
|
||||
logger.warn("Could not start Daikin http client", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Deactivate
|
||||
protected void deactivate() {
|
||||
if (httpClient != null) {
|
||||
try {
|
||||
httpClient.stop();
|
||||
logger.debug("Daikin http client stopped");
|
||||
} catch (Exception e) {
|
||||
logger.debug("error while stopping Daikin http client", e);
|
||||
}
|
||||
httpClient = null;
|
||||
try {
|
||||
httpClient.stop();
|
||||
logger.debug("Daikin http client stopped");
|
||||
} catch (Exception e) {
|
||||
logger.debug("error while stopping Daikin http client", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable HttpClient getHttpClient() {
|
||||
initialize();
|
||||
return httpClient;
|
||||
}
|
||||
|
||||
private synchronized void initialize() {
|
||||
if (httpClient == null) {
|
||||
httpClient = new HttpClient(new SslContextFactory.Client(true));
|
||||
try {
|
||||
httpClient.start();
|
||||
logger.debug("Daikin http client started");
|
||||
} catch (Exception e) {
|
||||
logger.warn("Could not start Daikin http client", e);
|
||||
httpClient = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user