Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update pom.xml and add HostConfig class #17

Merged
merged 4 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
<artifactId>jna</artifactId>
<version>5.10.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.14.2</version>
</dependency>
</dependencies>

<distributionManagement>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/cryptlex/lexfloatclient/HostConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.cryptlex.lexfloatclient;

public class HostConfig {
public String maxOfflineLeaseDuration;
}
49 changes: 49 additions & 0 deletions src/main/java/com/cryptlex/lexfloatclient/LexFloatClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.nio.CharBuffer;
import java.io.UnsupportedEncodingException;
import com.sun.jna.ptr.IntByReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -156,6 +158,53 @@ public static String GetFloatingClientLibraryVersion() throws LexFloatClientExce
throw new LexFloatClientException(status);
}

/**
* Gets the host configuration.
* This function sends a network request to LexFloatServer to get the configuration details.

* @return Returns host configuration.
* @throws LexFloatClientException
* @throws UnsupportedEncodingException
*/
public static HostConfig GetHostConfig() throws LexFloatClientException, UnsupportedEncodingException {
int status;
int bufferSize = 1024;
if (Platform.isWindows()) {
CharBuffer buffer = CharBuffer.allocate(bufferSize);
status = LexFloatClientNative.GetHostConfigInternal(buffer, bufferSize);
if (LF_OK == status) {
String hostConfigJson = buffer.toString().trim();
if (!hostConfigJson.isEmpty()) {
HostConfig hostConfig = null;
ObjectMapper objectMapper = new ObjectMapper();
try {
hostConfig = objectMapper.readValue(hostConfigJson, HostConfig.class);
} catch (JsonProcessingException e) {}
return hostConfig;
} else {
return null;
}
}
} else {
ByteBuffer buffer = ByteBuffer.allocate(bufferSize);
status = LexFloatClientNative.GetHostConfigInternal(buffer, bufferSize);
if (LF_OK == status) {
String hostConfigJson = new String(buffer.array(), "UTF-8").trim();
if (!hostConfigJson.isEmpty()) {
HostConfig hostConfig = null;
ObjectMapper objectMapper = new ObjectMapper();
try {
hostConfig = objectMapper.readValue(hostConfigJson, HostConfig.class);
} catch (JsonProcessingException e) {}
return hostConfig;
} else {
return null;
}
}
}
throw new LexFloatClientException(status);
}

/**
* Gets the product version name.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public interface CallbackType extends Callback {

public static native int SetFloatingClientMetadata(WString key, WString value);

public static native int GetHostConfigInternal(ByteBuffer hostConfig, int length);

public static native int GetHostConfigInternal(CharBuffer hostConfig, int length);

public static native int GetFloatingClientLeaseExpiryDate(IntByReference expiryDate);

public static native int GetFloatingClientLibraryVersion(ByteBuffer libraryVersion, int length);
Expand Down