kopia lustrzana https://github.com/bertrik/ttnhabbridge
Specify habitat timeout as a Duration.
rodzic
b10d84d34e
commit
493906f040
|
@ -1,5 +1,7 @@
|
||||||
package nl.sikken.bertrik;
|
package nl.sikken.bertrik;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration interface for the application.
|
* Configuration interface for the application.
|
||||||
*/
|
*/
|
||||||
|
@ -11,9 +13,9 @@ public interface ITtnHabBridgeConfig {
|
||||||
String getHabitatUrl();
|
String getHabitatUrl();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return timeout (ms) for communication with the habitat server
|
* @return timeout for communication with the habitat server
|
||||||
*/
|
*/
|
||||||
int getHabitatTimeout();
|
Duration getHabitatTimeout();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the URL of the TTN MQTT server
|
* @return the URL of the TTN MQTT server
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package nl.sikken.bertrik;
|
package nl.sikken.bertrik;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration class.
|
* Configuration class.
|
||||||
*/
|
*/
|
||||||
|
@ -10,7 +12,7 @@ final class TtnHabBridgeConfig extends BaseConfig implements ITtnHabBridgeConfig
|
||||||
*/
|
*/
|
||||||
private enum EConfigItem {
|
private enum EConfigItem {
|
||||||
HABITAT_URL("habitat.url", "http://habitat.habhub.org", "URL of the habitat server"),
|
HABITAT_URL("habitat.url", "http://habitat.habhub.org", "URL of the habitat server"),
|
||||||
HABITAT_TIMEOUT("habitat.timeout", "3000", "Timeout in milliseconds"),
|
HABITAT_TIMEOUT_MS("habitat.timeout", "3000", "Timeout in milliseconds"),
|
||||||
|
|
||||||
TTN_MQTT_URL("ttn.mqtt.url", "tcp://eu.thethings.network", "URL of the TTN MQTT server"),
|
TTN_MQTT_URL("ttn.mqtt.url", "tcp://eu.thethings.network", "URL of the TTN MQTT server"),
|
||||||
TTN_APP_ID("ttn.app.id", "habhub", "TTN Application Id (e.g. habhub, ttnmapper, etc.)"),
|
TTN_APP_ID("ttn.app.id", "habhub", "TTN Application Id (e.g. habhub, ttnmapper, etc.)"),
|
||||||
|
@ -43,8 +45,8 @@ final class TtnHabBridgeConfig extends BaseConfig implements ITtnHabBridgeConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getHabitatTimeout() {
|
public Duration getHabitatTimeout() {
|
||||||
return Integer.parseInt(get(EConfigItem.HABITAT_TIMEOUT.key));
|
return Duration.ofMillis(Integer.parseInt(get(EConfigItem.HABITAT_TIMEOUT_MS.key)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.Base64.Encoder;
|
import java.util.Base64.Encoder;
|
||||||
|
@ -11,7 +12,6 @@ import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import javax.xml.bind.DatatypeConverter;
|
import javax.xml.bind.DatatypeConverter;
|
||||||
|
|
||||||
|
@ -50,13 +50,11 @@ public final class HabitatUploader {
|
||||||
* @param timeout the connect and read timeout (ms)
|
* @param timeout the connect and read timeout (ms)
|
||||||
* @return a new REST client
|
* @return a new REST client
|
||||||
*/
|
*/
|
||||||
public static IHabitatRestApi newRestClient(String url, int timeout) {
|
public static IHabitatRestApi newRestClient(String url, Duration timeout) {
|
||||||
// create the REST client
|
// create the REST client
|
||||||
LOG.info("Creating new habitat REST client with timeout {} for {}", timeout, url);
|
LOG.info("Creating new habitat REST client with timeout {} for {}", timeout, url);
|
||||||
OkHttpClient client = new OkHttpClient().newBuilder()
|
OkHttpClient client = new OkHttpClient().newBuilder()
|
||||||
.connectTimeout(timeout, TimeUnit.MILLISECONDS)
|
.callTimeout(timeout)
|
||||||
.writeTimeout(timeout, TimeUnit.MILLISECONDS)
|
|
||||||
.readTimeout(timeout, TimeUnit.MILLISECONDS)
|
|
||||||
.build();
|
.build();
|
||||||
Retrofit retrofit = new Retrofit.Builder()
|
Retrofit retrofit = new Retrofit.Builder()
|
||||||
.baseUrl(url)
|
.baseUrl(url)
|
||||||
|
|
Ładowanie…
Reference in New Issue