For overview of using License Keys to consume licenses, see following sections in 10Duke Scale Documentation:
See also client concepts.
Workflow description
First, the client application either prompts the user to enter a license key or reads the license key from e.g. configuration. Next the client application requests information about the license(s) the license key entitles to use. This information may be used to communicate further with the user. The client application then makes a license checkout using the license key. The workflow continues with optional periodic heartbeat calls and finally a call to release the license.
Configuration
The minimum viable configuration includes the licensing API URL. HTTP request timeout is an optional configuration.
For more configuration options, see the configuration guide.
Example
First, lets start with looking at the main program of this example. The main program is a Java cli application, which implements the following flow:
- initialize the application and the 10Duke Scale SDK
- prompt user to enter a license key
- query information about the license(s) that the key entitles to use
- checkout a seat
- release the checkout
public static void main(final String[] args)
throws IOException, InterruptedException, URISyntaxException {
CliLicenseKeyExample example = new CliLicenseKeyExample();
example.initClientApp();
example.promptLicenseKey();
if (example.licenseKey == null) {
System.out.println("No license key given, bye bye...");
return;
}
LicenseKeyLicensesStatus licenseInfo = example.describeLicenseKey();
example.selectedLicense = licenseInfo.getLicenses().get(0);
LicenseToken licenseToken = example.checkoutLicense();
System.out.println(
"License checkout made for product "
+ licenseToken.getProductName()
+ " with status: "
+ licenseToken.getStatus());
LicenseReleaseResult releaseResult
= example.releaseLicense(licenseToken);
if (releaseResult != null) {
System.out.println(
"License release made for product "
+ releaseResult.getProductName()
+ " with status: "
+ (releaseResult.getErrorCode() == null
? " success"
: releaseResult.getErrorCode()));
}
System.out.println("All done, bye bye...");
}
Initialize the client application to use the 10Duke Scale SDK. The following example shows how to set up a client application utilize license keys.
private void initClientApp() throws IOException, URISyntaxException {
String configResource = "tenduke.conf";
String userAgent
= "tenduke-scale-sdk-java-cli-example/1.0.0";
clientBuilder = new DesktopAppClientBuilder(
configResource,
userAgent);
try {
client = clientBuilder.initForLicenseKeyBasedLicensing();
} catch (SdkException ex) {
Logger
.getLogger("CliLicenseKeyExample")
.log(
Level.SEVERE,
"""
Startup error, tip: check config file
and that APIs can be reached""",
ex);
throw ex;
}
}
Query which information about License(s) the license key entitles to use.
private LicenseKeyLicensesStatus describeLicenseKey() {
LicenseKeyLicensesStatus result = client.getLicenseCheckoutClient()
.describeLicenseKeyLicenses(licenseKey, true);
if (result == null || result.getLicenses().isEmpty()) {
throw ExceptionBuilder.internalError(
"""
Expecting information about one license from
call to describe license key, got none.""");
}
return result;
}
Checkout license based on selecting the first license returned from the information query.
private LicenseToken checkoutLicense() {
long qty = 1;
if (!QuantityDimension.SEATS.equals(
selectedLicense.getQtyDimension())) {
System.out.println(
"Enter quantity to consume,"
+ " mind that license has:"
+ selectedLicense.getQty()
+ " remaining.");
qty = scanner.nextLong();
}
Map<String, String> claims = new HashMap<>();
claims.put("cliHwId", hwId());
LicenseCheckoutArguments checkoutArguments
= LicenseCheckoutArguments
.builder()
.productName(
selectedLicense.getProductName())
.qty(qty)
.qtyDimension(
selectedLicense.getQtyDimension())
.build();
List<LicenseToken> result = client.getLicenseCheckoutClient()
.checkoutLicenseByKey(
licenseKey,
claims,
Collections.singletonList(
checkoutArguments));
if (result.size() != 1) {
throw ExceptionBuilder.internalError(
"Expecting 1 license token from"
+ " checkout 1 license, got "
+ result.size()
+ " instead");
} else {
return result.get(0);
}
}
Finally, release the license based on current checkout
private LicenseReleaseResult releaseLicense(
final LicenseToken licenseToken) {
if (licenseToken.getLeaseId() == null) {
System.out.println(
"Null lease id, nothing to release.");
return null;
}
long qty = 1;
if (!QuantityDimension.SEATS.equals(
selectedLicense.getQtyDimension())) {
System.out.println(
"Enter final quantity that was consumed:");
qty = scanner.nextLong();
}
Map<String, String> claims = new HashMap<>();
LicenseReleaseArguments releaseArguments
= LicenseReleaseArguments
.builder()
.finalUsedQty(qty)
.leaseId(licenseToken.getLeaseId())
.build();
List<LicenseReleaseResult> result = client
.getLicenseCheckoutClient()
.releaseLicense(
claims,
licenseKey,
Collections.singletonList(
releaseArguments));
if (result.size() != 1) {
throw ExceptionBuilder.internalError(
"Expecting 1 license release result"
+ " from release 1 license, got "
+ result.size()
+ " instead");
} else {
return result.get(0);
}
}