SDKs
...
Java SDK
Java Modules
Floating Client
20min
floating client is a module that has everything related to floating licenses see floating licenses docid 4aunypial8i2te4nyppx7 for more information about floating licenses to include floating client into your maven/gradle project add this snippet \<dependencies> \<dependency> \<groupid>com licensespring\</groupid> \<artifactid>licensespring floating client\</artifactid> \<version>2 16 1\</version> \</dependency> \</dependencies> \<repositories> \<repository> \<id>jdk java\</id> \<url>https //licensespring maven s3 eu central 1 amazonaws com/\</url> \</repository> \</repositories>repositories { mavenlocal() maven { url = 'https //licensespring maven s3 eu central 1 amazonaws com/' } } dependencies { implementation 'com licensespring\ licensespring floating client 2 16 1' } javadoc, jar and osgi bundle downloads can be found at javadoc & downloads docid\ dm ksn9s vvhglpywsm5x 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 to initialize the sdk, you must supply authentication credentials and product information you can choose one of two authentication methods 1\ api key authentication apikey your company api key sharedkey a company specific encryption key used when signing requests 2\ oauth authorization clientid your client identifier clientsecret your client secret in addition to the authentication credentials, you must provide the productcode , an alphanumeric code identifying the specific product the apikey and sharedkey are available in the licensespring platform under "settings > settings > keys " for oauth authorization docid\ xhyzaual9qy4jerxkilmk , your clientid and clientsecret are available here oauth configuration docid\ q1yeced3kghzmwcsx2moj the productcode is defined when creating the product and ties the license to that specific 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 docid\ kinndeo4bghcv3azyvchm 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 proxyport and proxyhost used to setup a forward proxy, see more in java advanced usage docid\ mqlrngvkrepj5ivdgupt0 requesttimeout set the timeout of requests make to api (in seconds), default is 10 seconds storemachineinfo false 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 // initialization with minimum parameters try { 	floatingconfiguration configuration = floatingconfiguration builder() apikey("api key") sharedkey("shared key") productcode("product code") build(); } catch (licensespringconfigurationexception e) { log error(e getcause() getmessage()); } // oauth minimum parameters try { 	floatingconfiguration configuration = floatingconfiguration builder() clientid("client id") clientsecret("client secret") productcode("product code") build(); } catch (licensespringconfigurationexception e) { log error(e getcause() getmessage()); } licensespringconfiguration configuration = licensespringconfiguration builder() sharedkey("shared key") build(); // initialization with more parameters try { 	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 floatinglicenseservice service = new floatinglicenseservice(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 // if your licenses are user based (note that password is never saved in the sdk) // activationlicense extends the licenseidentity class activationlicense identity = activationlicense fromusername("username", "password"); // if your licenses are key based activationlicense identity = activationlicense fromkey("license key"); // activate the license, the method returns licensedata object try { 	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 public class licensedata { 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; public boolean isexpired(); public long daysremaining(); } 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 // you can use the previous identity to check the license activationlicense identityfromuser = activationlicense fromusername("username", "password"); activationlicense identityfromkey = activationlicense fromkey("license key"); // or you can make a new licenseidentity object that doesn't contain the password licenseidentity 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 object public class checkresponse { private transient licensedata data; private transient installationfile file; private boolean licenseactive; private boolean licenseenabled; private boolean isexpired; } checklicensesub scriber the check subscriber can be added as a custom handler when the check api is called (e g in a background thread) public class mysubscriber implements checklicensesubscriber{ @override public void onerror(licenseidentity old, licensespringexception exception) { // handle the error } @override public void onsuccess(checkresponse checkresponse) { // the check response recieved } } // when building the configuration add the instance on the configuration builder try { 	floatingconfiguration configuration = floatingconfiguration builder() apikey("api key") productcode("product code") sharedkey("shared key") checksubscriber(new mysubscriber()) build(); } catch (licensespringconfigurationexception e) { log error(e getcause() getmessage()); } borrowedlicenseexpirationsubscriber the borrowed license expiration subscriber can be added as a custom handler when the borrowed license borrow time expires public class mysubscriber implements borrowedlicenseexpirationsubscriber{ @override public void onborrowedlicenseexpiration(licenseborrowresponse response) { // your custom handler } } // when building the configuration add the instance on the configuration builder try { 	floatingconfiguration configuration = floatingconfiguration builder() apikey("api key") productcode("product code") sharedkey("shared key") borrowedlicenseexpirationsubscriber(new mysubscriber()) 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 // see checklicense method how you can build identity differently licenseidentity identityfromkey = licenseidentity builder() licensekey("license key") build(); // adds one consumption to the provided identity try { 	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 consumptions try { 	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 // see checklicense method how you can build identity differently activationlicense identity = activationlicense fromkey("license key"); // adds one consumption on feature "feature" to the identity provided try { 	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 consumptions try { 	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 docid\ sz5imovmj5qjawhelsoxt // see checklicense method how you can build identity differently activationlicense identity = activationlicense fromkey("license key"); try { 	installationfile file = service installationfile(identity); } catch (licensespringexception e) { log error(e getcause() getmessage()); } trackvariables(licenseidentity identity, map\<string, string> variables) tracks device based variables for end uses // see checklicense method how you can build identity differently activationlicense identity = activationlicense fromkey("license key"); // see checklicense method how you can build identity differently activationlicense identity = activationlicense fromkey("license key"); map\<string, string> variables = new hashmap<>(); 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 // see checklicense method for more ways to build identity activationlicense 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 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 class public class product { private string productname; private string shortcode; private boolean allowtrial; private int trialdays; private string authorizationmethod; }// see checklicense method for more ways to build identity activationlicense 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 // see checklicense method for more ways to build identity activationlicense 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 // see checklicense method for more ways to build identity activationlicense 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()); } borrowlicense(licenseidentity identity) a license can be borrowed using this method // see checklicense method for more ways to build identity activationlicense identity = activationlicense fromkey("license key"); try { service borrowlicense(identity, zoneddatetime now() plushours(1)); } catch (licensespringexception e) { log error(e getcause() getmessage()); } changeoauthclientsecret changes the oauth client secret used for auth > in case you have a rotating secret service changeoauthclientsecret("otherclientsecret");