Javadoc, Jar and OSGi bundle downloads can be found at: Javadoc & Downloads
Initializing the Floating Client module
The floating client, as opposed to License Client SDK, is implemented as a service. More than one instance can be created, and the usage template is you need one FloatingLicenseService per product that you need to use. For most use cases this is one. This approach enables having multiple products within your application and multiple licenses per FloatingLicenseService instance.
The License identity needs to be preserved somewhere within your application, as the references to active licenses are not saved within this module.
At the minimum there are three parameters you will need to initialize the SDK:
apiKey, your company API key
sharedKey, company-specific encryption key, used when signing requests
productCode, an alphanumeric code identifying a specific product
The apiKey and sharedKey are available in the LicenseSpring Platform under "Account Setting -> Settings -> Keys tab". The productCode is tied to a specific product the license applies to and is defined while creating the product.
Optional Configuration parameters for initializing the Floating Client SDK:
addShutdownHook indicates if you want the SDK to automatically release any currently active licenses on the device before you shut down the runtime process. Default is true.
enablePeriodicCheck enables periodic calls to checkLicense method to prolong the license usage. It will be prolonged every time the license has passed half of its floating timeout time. Usage time is set through the LicenseSpring platform with the LicenseSpring platform with the floatingTimeout parameter in the product configuration.
checkSubscriber subscriber on periodic check, default implementation is DoNothingSubscriber, but you can add your own implementation to handle the onSuccess and onError of the periodic check. This, of course, isn't a parameter you need to worry about if you chose not to enable periodic checks.
requestLogging request logging for debug purposes, default is no request logging.
appName name of the application using the SDK
appVersion manually set the version of the application that's using the SDK.
identityProvider set a custom IdentityProvider which generates unique keys for a particular device. Default implementation for floating is ONCE_PER_PROCESS. More details can be found on our Java Hardware (Device) IDs page.
cacheHardwareId set to true to allow caching of hardware iDs. Default is true. You can change this to false if your hardware Id strategy isn't ONCE_PER_PROCESS.
enableNegativeConsumptions enables the option to send negative consumptions, default is false.
proxyPortand proxyHost used to setup a forward proxy, see more in Java Advanced Usage
requestTimeout set the timeout of requests make to API (in seconds), default is 10 seconds
storeMachineInfofalse by default. This toggles the collection of additional machine data, which includes:
hostname
ipAddress
macAddress
vmInfo
osInfo
infoToStore- specify what information to store, ignored if storeMachineInfo is false, defaults to ALL if left empty.
Java
|
// initialization with minimum parameterstry{FloatingConfiguration configuration =FloatingConfiguration.builder().apiKey("api-key").productCode("product-code").sharedKey("shared-key").build();}catch(LicenseSpringConfigurationException e){
log.error(e.getCause().getMessage());}// initialization with more parameterstry{FloatingConfiguration configuration =FloatingConfiguration.builder().apiKey("api-key").productCode("product-code").sharedKey("shared-key").addShutdownHook(false).requestLogging(Logger.Level.FULL).appName("MyApplication").appVersion("1.0.1").enableNegativeConsumptions(true).requestTimeout(60L).storeMachineInfo(true).infoToStore(InfoToStore.VM_INFO).infoToStore(InfoToStore.HOSTNAME).build();}catch(LicenseSpringConfigurationException e){
log.error(e.getCause().getMessage());}
FloatingLicenseService
After setting up the SDK, there are a number of methods and objects available to the app developer.
To make the FloatingLicenseService, initialize it by passing the FloatingConfiguration object you set up earlier.
Java
|
FloatingLicenseService service =newFloatingLicenseService(configuration);
Now you can use the methods that FloatingLicenseService provides.
activateLicense(ActivationLicense identity)
Attempts to activate the product using provided ActivationLicense. Returns the LicenseData object that has been activated. There are two available factory methods to make the ActivationLicense object, the method you need to use depends if your product is license key-based or user-based.
Java
|
// If your licenses are user based: (note that password is never saved in the sdk)// ActivationLicense extends the LicenseIdentity classActivationLicense identity =ActivationLicense.fromUsername("username","password");// If your licenses are key based:ActivationLicense identity =ActivationLicense.fromKey("license-key");// Activate the license, the method returns LicenseData objecttry{LicenseData data = service.activateLicense(identity);}catch(LicenseSpringException e){
log.error(e.getCause().getMessage());}// This is what LicenseData object looks like, so you can better grasp what fields of the object are at your disposal.// All fields are read only.publicclassLicenseData{String licenseSignature;LicenseType licenseType;boolean isTrial;List<LicenseFeature> productFeatures;List<CustomField> customFields;ZonedDateTime validityPeriod;ZonedDateTime maintenancePeriod;int totalConsumptions;int maxConsumptions;int maxActivations;int timesActivated;Customer customer;Product productDetails;boolean isFloatingCloud;int floatingUsers;boolean floatingInUse;int floatingTimeout;publicbooleanisExpired();publiclongdaysRemaining();}
checkLicense(LicenseIdentity data)
After you activated the license you can now use the check method to prolong the usage of the license and check its validity, since it expires after floating timeout period has passed (this can be set up in product configuration on the LicenseSpring platform). This method returns CheckResponse object that contains LicenseData, InstallationFile and flags if license is active, enabled or expired.
This method can be called periodically if you leave the enablePeriodicCheck true in the FloatingConfiguration so you don't have to worry about the floating license expiring while the user is still using it.
Java
|
// You can use the previous identity to check the licenseActivationLicense identityFromUser =ActivationLicense.fromUsername("username","password");ActivationLicense identityFromKey =ActivationLicense.fromKey("license-key");// or you can make a new LicenseIdentity object that doesn't contain the passwordLicenseIdentity identityFromUser =LicenseIdentity.builder().username("username").build();LicenseIdentity identityFromKey =LicenseIdentity.builder().licenseKey("license-key").build();try{CheckResponse response = service.checkLicense(identityFromUser);}catch(LicenseSpringException e){
log.error(e.getCause().getMessage());}// CheckResponse objectpublicclassCheckResponse{privatetransientLicenseData data;privatetransientInstallationFile file;privateboolean licenseActive;privateboolean licenseEnabled;privateboolean isExpired;}
CheckLicenseSubscriber
The check subscriber can be added as a custom handler when the check API is called (e.g. in a background thread).
Java
|
publicclassMySubscriberimplementsCheckLicenseSubscriber{@OverridepublicvoidonError(LicenseIdentity old,LicenseSpringException exception){// handle the error}@OverridepublicvoidonSuccess(CheckResponse checkResponse){// the check response recieved}}// when building the configuration add the instance on the configuration buildertry{FloatingConfiguration configuration =FloatingConfiguration.builder().apiKey("api-key").productCode("product-code").sharedKey("shared-key").checkSubscriber(newMySubscriber()).build();}catch(LicenseSpringConfigurationException e){
log.error(e.getCause().getMessage());}
addConsumption(LicenseIdentity identity, int consumptions)
If your license is the Consumption type you can increase the consumptions by the parameter provided. This method makes a request to the LicenseSpring server to increase the consumptions on the identity you provided.
Java
|
// see checkLicense method how you can build identity differentlyLicenseIdentity identityFromKey =LicenseIdentity.builder().licenseKey("license-key").build();// adds one consumption to the provided identitytry{
service.addConsumption(identity,1);}catch(LicenseSpringException e){
log.error(e.getCause().getMessage());}// if enableNegativeConsumptions is set to true in FloatingConfiguration object// you can add negative consumptionstry{
service.addConsumption(identity,-1);}catch(LicenseSpringException e){
log.error(e.getCause().getMessage());}
addFeatureConsumption(LicenseIdentity identity, int consumptions)
If your license is the Consumption type and you have certain features in your app that you want to track consumptions for separately, you can increase the consumptions of the feature by the parameter provided. This method makes a request to the LicenseSpring server to increase the feature consumptions on the identity you provided.
Java
|
// see checkLicense method how you can build identity differentlyActivationLicense identity =ActivationLicense.fromKey("license-key");// adds one consumption on feature "feature" to the identity providedtry{
service.addFeatureConsumption(identity,"feature",1);}catch(LicenseSpringException e){
log.error(e.getCause().getMessage());}// if enableNegativeConsumptions is set to true in FloatingConfiguration object// you can add negative feature consumptionstry{
service.addConsumption(identity,"feature",-1);}catch(LicenseSpringException e){
log.error(e.getCause().getMessage());
installationFile(LicenseIdentity identity
Returns the latest valid installation file, if installation files are defined in the LicenseSpring platform. For more details please see Product Versioning.
Java
|
// see checkLicense method how you can build identity differentlyActivationLicense identity =ActivationLicense.fromKey("license-key");try{InstallationFile file = service.installationFile(identity);}catch(LicenseSpringException e){
log.error(e.getCause().getMessage());}
// see checkLicense method how you can build identity differentlyActivationLicense identity =ActivationLicense.fromKey("license-key");// see checkLicense method how you can build identity differentlyActivationLicense identity =ActivationLicense.fromKey("license-key");Map<String,String> variables =newHashMap<>();
variables.put("var1","val1");
variables.put("var2","val2");try{
service.trackVariables(identity, variables);}catch(LicenseSpringException e){
log.error(e.getCause().getMessage());}try{InstallationFile file = service.installationFile(identity);}catch(LicenseSpringException e){
log.error(e.getCause().getMessage());}
versions(LicenseIdentity identity)
Returns an array of strings with all available versions.
Java
|
// see checkLicense method for more ways to build identityActivationLicense identity =ActivationLicense.fromKey("license-key");try{String[] versions = service.versions(LicenseIdentity.fromKey("license-key"));}catch(LicenseSpringException e){
log.error(e.getCause().getMessage());}
productDetails()
Gets product details from LicenseSpring servers.
Java
|
try{Product product = service.productDetails();}catch(LicenseSpringException e){
log.error(e.getCause().getMessage());}
log.info(product.getProductName());
log.info(product.getShortCode());
log.info(product.isAllowTrial());
log.info(product.getTrialDays());
log.info(product.getAuthorizationMethod());// product classpublicclassProduct{privateString productName;privateString shortCode;privateboolean allowTrial;privateint trialDays;privateString authorizationMethod;}// see checkLicense method for more ways to build identityActivationLicense identity =ActivationLicense.fromKey("license-key");try{String[] versions = service.versions(LicenseIdentity.fromKey("license-key"));}catch(LicenseSpringException e){
log.error(e.getCause().getMessage());}
releaseLicense(LicenseIdentity identity)
A floating cloud license is released from a current device. You need to supply the license identity. This is done automatically before the process shuts down normally if you leave the addShutdownHook property true in the FloatingConfiguration. Additionally, the license is also deactivated for the current device.
Java
|
// see checkLicense method for more ways to build identityActivationLicense identity =ActivationLicense.fromKey("license-key");try{
service.releaseLicense(identity);}catch(LicenseSpringException e){
log.error(e.getCause().getMessage());}
deactivateLicense(LicenseIdentity identity)
A license can be deactivated using this method, then the license can be used on another device. Returns true if deactivation was successful, false if it wasn't.
Java
|
// see checkLicense method for more ways to build identityActivationLicense identity =ActivationLicense.fromKey("license-key");try{if(service.deactivateLicense(identity){System.out.println("License successfully deactivated.");}else{System.out.println("Something went wrong.");}}catch(LicenseSpringException e){
log.error(e.getCause().getMessage());}