mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-26 15:21:41 +01:00
[volvooncall] Adjust thread name for HTTP client (#14469)
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
parent
cb160bdf63
commit
8c56a0f0b3
@ -18,7 +18,6 @@ import java.time.ZonedDateTime;
|
|||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.eclipse.jetty.client.HttpClient;
|
|
||||||
import org.openhab.binding.volvooncall.internal.handler.VehicleHandler;
|
import org.openhab.binding.volvooncall.internal.handler.VehicleHandler;
|
||||||
import org.openhab.binding.volvooncall.internal.handler.VehicleStateDescriptionProvider;
|
import org.openhab.binding.volvooncall.internal.handler.VehicleStateDescriptionProvider;
|
||||||
import org.openhab.binding.volvooncall.internal.handler.VolvoOnCallBridgeHandler;
|
import org.openhab.binding.volvooncall.internal.handler.VolvoOnCallBridgeHandler;
|
||||||
@ -55,13 +54,13 @@ public class VolvoOnCallHandlerFactory extends BaseThingHandlerFactory {
|
|||||||
private final Logger logger = LoggerFactory.getLogger(VolvoOnCallHandlerFactory.class);
|
private final Logger logger = LoggerFactory.getLogger(VolvoOnCallHandlerFactory.class);
|
||||||
private final VehicleStateDescriptionProvider stateDescriptionProvider;
|
private final VehicleStateDescriptionProvider stateDescriptionProvider;
|
||||||
private final Gson gson;
|
private final Gson gson;
|
||||||
private final HttpClient httpClient;
|
private final HttpClientFactory httpClientFactory;
|
||||||
|
|
||||||
@Activate
|
@Activate
|
||||||
public VolvoOnCallHandlerFactory(@Reference VehicleStateDescriptionProvider provider,
|
public VolvoOnCallHandlerFactory(@Reference VehicleStateDescriptionProvider provider,
|
||||||
@Reference HttpClientFactory httpClientFactory) {
|
@Reference HttpClientFactory httpClientFactory) {
|
||||||
this.stateDescriptionProvider = provider;
|
this.stateDescriptionProvider = provider;
|
||||||
this.httpClient = httpClientFactory.createHttpClient(BINDING_ID);
|
this.httpClientFactory = httpClientFactory;
|
||||||
this.gson = new GsonBuilder()
|
this.gson = new GsonBuilder()
|
||||||
.registerTypeAdapter(ZonedDateTime.class,
|
.registerTypeAdapter(ZonedDateTime.class,
|
||||||
(JsonDeserializer<ZonedDateTime>) (json, type, jsonDeserializationContext) -> ZonedDateTime
|
(JsonDeserializer<ZonedDateTime>) (json, type, jsonDeserializationContext) -> ZonedDateTime
|
||||||
@ -87,7 +86,7 @@ public class VolvoOnCallHandlerFactory extends BaseThingHandlerFactory {
|
|||||||
protected @Nullable ThingHandler createHandler(Thing thing) {
|
protected @Nullable ThingHandler createHandler(Thing thing) {
|
||||||
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
|
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
|
||||||
if (APIBRIDGE_THING_TYPE.equals(thingTypeUID)) {
|
if (APIBRIDGE_THING_TYPE.equals(thingTypeUID)) {
|
||||||
return new VolvoOnCallBridgeHandler((Bridge) thing, gson, httpClient);
|
return new VolvoOnCallBridgeHandler((Bridge) thing, gson, httpClientFactory);
|
||||||
} else if (VEHICLE_THING_TYPE.equals(thingTypeUID)) {
|
} else if (VEHICLE_THING_TYPE.equals(thingTypeUID)) {
|
||||||
return new VehicleHandler(thing, stateDescriptionProvider);
|
return new VehicleHandler(thing, stateDescriptionProvider);
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ import org.openhab.binding.volvooncall.internal.dto.PostResponse;
|
|||||||
import org.openhab.binding.volvooncall.internal.dto.VocAnswer;
|
import org.openhab.binding.volvooncall.internal.dto.VocAnswer;
|
||||||
import org.openhab.core.cache.ExpiringCacheMap;
|
import org.openhab.core.cache.ExpiringCacheMap;
|
||||||
import org.openhab.core.id.InstanceUUID;
|
import org.openhab.core.id.InstanceUUID;
|
||||||
|
import org.openhab.core.io.net.http.HttpClientFactory;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -61,12 +62,12 @@ public class VocHttpApi {
|
|||||||
private final HttpClient httpClient;
|
private final HttpClient httpClient;
|
||||||
private final ApiBridgeConfiguration configuration;
|
private final ApiBridgeConfiguration configuration;
|
||||||
|
|
||||||
public VocHttpApi(ApiBridgeConfiguration configuration, Gson gson, HttpClient httpClient)
|
public VocHttpApi(String clientName, ApiBridgeConfiguration configuration, Gson gson,
|
||||||
throws VolvoOnCallException {
|
HttpClientFactory httpClientFactory) throws VolvoOnCallException {
|
||||||
this.gson = gson;
|
this.gson = gson;
|
||||||
this.cache = new ExpiringCacheMap<>(120 * 1000);
|
this.cache = new ExpiringCacheMap<>(120 * 1000);
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
this.httpClient = httpClient;
|
this.httpClient = httpClientFactory.createHttpClient(clientName);
|
||||||
|
|
||||||
httpClient.setUserAgentField(new HttpField(HttpHeader.USER_AGENT, "openhab/voc_binding/" + InstanceUUID.get()));
|
httpClient.setUserAgentField(new HttpField(HttpHeader.USER_AGENT, "openhab/voc_binding/" + InstanceUUID.get()));
|
||||||
try {
|
try {
|
||||||
|
@ -17,18 +17,19 @@ import java.util.Collections;
|
|||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.eclipse.jetty.client.HttpClient;
|
|
||||||
import org.openhab.binding.volvooncall.internal.VolvoOnCallException;
|
import org.openhab.binding.volvooncall.internal.VolvoOnCallException;
|
||||||
import org.openhab.binding.volvooncall.internal.api.VocHttpApi;
|
import org.openhab.binding.volvooncall.internal.api.VocHttpApi;
|
||||||
import org.openhab.binding.volvooncall.internal.config.ApiBridgeConfiguration;
|
import org.openhab.binding.volvooncall.internal.config.ApiBridgeConfiguration;
|
||||||
import org.openhab.binding.volvooncall.internal.discovery.VolvoVehicleDiscoveryService;
|
import org.openhab.binding.volvooncall.internal.discovery.VolvoVehicleDiscoveryService;
|
||||||
import org.openhab.binding.volvooncall.internal.dto.CustomerAccounts;
|
import org.openhab.binding.volvooncall.internal.dto.CustomerAccounts;
|
||||||
|
import org.openhab.core.io.net.http.HttpClientFactory;
|
||||||
import org.openhab.core.thing.Bridge;
|
import org.openhab.core.thing.Bridge;
|
||||||
import org.openhab.core.thing.ChannelUID;
|
import org.openhab.core.thing.ChannelUID;
|
||||||
import org.openhab.core.thing.ThingStatus;
|
import org.openhab.core.thing.ThingStatus;
|
||||||
import org.openhab.core.thing.ThingStatusDetail;
|
import org.openhab.core.thing.ThingStatusDetail;
|
||||||
import org.openhab.core.thing.binding.BaseBridgeHandler;
|
import org.openhab.core.thing.binding.BaseBridgeHandler;
|
||||||
import org.openhab.core.thing.binding.ThingHandlerService;
|
import org.openhab.core.thing.binding.ThingHandlerService;
|
||||||
|
import org.openhab.core.thing.util.ThingWebClientUtil;
|
||||||
import org.openhab.core.types.Command;
|
import org.openhab.core.types.Command;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -46,14 +47,14 @@ public class VolvoOnCallBridgeHandler extends BaseBridgeHandler {
|
|||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(VolvoOnCallBridgeHandler.class);
|
private final Logger logger = LoggerFactory.getLogger(VolvoOnCallBridgeHandler.class);
|
||||||
private final Gson gson;
|
private final Gson gson;
|
||||||
private final HttpClient httpClient;
|
private final HttpClientFactory httpClientFactory;
|
||||||
|
|
||||||
private @Nullable VocHttpApi api;
|
private @Nullable VocHttpApi api;
|
||||||
|
|
||||||
public VolvoOnCallBridgeHandler(Bridge bridge, Gson gson, HttpClient httpClient) {
|
public VolvoOnCallBridgeHandler(Bridge bridge, Gson gson, HttpClientFactory httpClientFactory) {
|
||||||
super(bridge);
|
super(bridge);
|
||||||
this.gson = gson;
|
this.gson = gson;
|
||||||
this.httpClient = httpClient;
|
this.httpClientFactory = httpClientFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -62,7 +63,8 @@ public class VolvoOnCallBridgeHandler extends BaseBridgeHandler {
|
|||||||
ApiBridgeConfiguration configuration = getConfigAs(ApiBridgeConfiguration.class);
|
ApiBridgeConfiguration configuration = getConfigAs(ApiBridgeConfiguration.class);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
VocHttpApi vocApi = new VocHttpApi(configuration, gson, httpClient);
|
String clientName = ThingWebClientUtil.buildWebClientConsumerName(thing.getUID(), null);
|
||||||
|
VocHttpApi vocApi = new VocHttpApi(clientName, configuration, gson, httpClientFactory);
|
||||||
CustomerAccounts account = vocApi.getURL("customeraccounts/", CustomerAccounts.class);
|
CustomerAccounts account = vocApi.getURL("customeraccounts/", CustomerAccounts.class);
|
||||||
if (account.username != null) {
|
if (account.username != null) {
|
||||||
updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE, account.username);
|
updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE, account.username);
|
||||||
|
Loading…
Reference in New Issue
Block a user