Common Use Cases

This section provides examples on how to use Unified APIs to perform the common licensing tasks, such as:

>Coding a standard license authorization request

>Coding a refresh license authorization request

>Finding the expiration date, usability status, and available usage count of a license

Coding a standard license authorization request

After creating an entitlement in EMS for the Connected mode, a developer needs to perform the following steps to allow license consumption from an end user’s machine.

1.Create an Application Context.

2.Set the license attributes for login.

3. Create an instance of the LoginSession class and call the login API.

4.After performing the required operation, call the logout API (with the logout attributes).

Sample Code

void SampleLoginCall() throws LicensingException {
		ApplicationContext appContext;
		Attribute identityAttributes;
		String identity;
		/* Initialize application context */
		
			appContext = new ApplicationContext(null);

			/* Generate Identity string */
			String customer = "NamedCustomer";
			String user = "user_1";
			String featureName = "SequencerEditorOnly";
			String featureVersion = "1.0";
			String usageCountLogin = "1";
			String vendorData = "Dummy data";

			identityAttributes = new Attribute();
			identityAttributes.set(LicensingConstants.SNTL_ATTR_IDENTITY_CUSTOMER_ID, customer);
			identityAttributes.set(LicensingConstants.SNTL_ATTR_IDENTITY_USERNAME, user);

			identity = new Identity(appContext, identityAttributes).serialize();

			/* Set Login attributes */
			Attribute loginAttributes = new Attribute();
			loginAttributes.set(LicensingConstants.SNTL_ATTR_LOGIN_IDENTITY_STRING, identity);
			loginAttributes.set(LicensingConstants.SNTL_ATTR_LOGIN_VENDOR_USAGE_DATA, vendorData);
			loginAttributes.set(LicensingConstants.SNTL_ATTR_LOGIN_FEATURE_VERSION, featureVersion);
			loginAttributes.set(LicensingConstants.SNTL_ATTR_LOGIN_USAGE_COUNT_MULTIPLIER, usageCountLogin);

			LoginSession loginSession = new LoginSession();

			/* Perform license authorization call */
			loginSession.login(appContext, featureName, loginAttributes);

			/*
			 * store session handle for reference when we will call refresh or
			 * logout API
			 */
			String sessionHandle = loginSession.serialize();
		
	}

	/*
	 * argument is session handle that we have got from the loginSession
	 * instance by calling loginSession.serialize()
	 */
	void SampleDefaultLogoutCall(String sessionHandle) {
		ApplicationContext appContext;
		LoginSession logoutSession = new LoginSession(null, sessionHandle);

		/* default logout call */
		try {
			logoutSession.logout();
		} catch (LicensingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/*
	 * argument is session handle that we have got from the loginSession
	 * instance by calling loginSession.serialize()
	 */
	void SampleLogoutCall(String sessionHandle) {
		ApplicationContext appContext;

		/* set logout attributes */
		Attribute logoutAttributes;
		try {
			logoutAttributes = new Attribute();
			logoutAttributes.set(LicensingConstants.SNTL_ATTR_LOGOUT_USAGE_COUNT_MULTIPLIER, "100");

			LoginSession logoutSession = new LoginSession(null, sessionHandle);

			/* logout call */
			logoutSession.logout(logoutAttributes);
		} catch (LicensingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

Coding a refresh license authorization request

The refresh API refreshes a license state on the Sentinel Cloud Connect server. The refresh API calls are placed between login and logout API calls to secure the license consumption state.

After creating an entitlement in EMS for the Connected mode, a developer needs to perform the following steps to allow license consumption from an end user’s machine.

1.Create an Application Context.

2.Set the license attributes for login.

3. Create an instance of the LoginSession class and call the login API.

4.Call the refresh API at appropriate intervals to refresh the license state.

NOTE   The refresh API intervals are configured in such a way that login sessions do not get killed by the background process. The refresh intervals can be configured by using the Session Timeout (with Refresh) property. You need to contact our Support Team to customize these configurations.

Sample Code

void SampleLoginCall() throws LicensingException {
		ApplicationContext appContext;
		Attribute identityAttributes;
		String identity;
		/* Initialize application context */
		appContext = new ApplicationContext(null);

		/* Generate Identity string */
		String customer = "NamedCustomer";
		String user = "user_1";
		String featureName = "SequencerEditorOnly";
		String featureVersion = "1.0";
		String usageCountLogin = "1";
		String vendorData = "Dummy data";

		identityAttributes = new Attribute();
		identityAttributes.set(LicensingConstants.SNTL_ATTR_IDENTITY_CUSTOMER_ID, customer);
		identityAttributes.set(LicensingConstants.SNTL_ATTR_IDENTITY_USERNAME, user);

		identity = new Identity(appContext, identityAttributes).serialize();

		/* Set Login attributes */
		Attribute loginAttributes = new Attribute();
		loginAttributes.set(LicensingConstants.SNTL_ATTR_LOGIN_IDENTITY_STRING, identity);
		loginAttributes.set(LicensingConstants.SNTL_ATTR_LOGIN_VENDOR_USAGE_DATA, vendorData);
		loginAttributes.set(LicensingConstants.SNTL_ATTR_LOGIN_FEATURE_VERSION, featureVersion);
		loginAttributes.set(LicensingConstants.SNTL_ATTR_LOGIN_USAGE_COUNT_MULTIPLIER, usageCountLogin);

		LoginSession loginSession = new LoginSession();

		/* Perform license authorization call */
		loginSession.login(appContext, featureName, loginAttributes);

		/*
		 * store session handle for reference when we will call refresh or
		 * logout API
		 */
		String sessionHandle = loginSession.serialize();
	}

	/*
	 * argument is session handle that we have got from the loginSession
	 * instance by calling loginSession.serialize()
	 */
	void SampleDefaultRefreshCall(String sessionHandle) throws LicensingException {
		ApplicationContext appContext;

		/* refresh call */
		LoginSession refreshSession = new LoginSession(null, sessionHandle);
		refreshSession.refresh();
	}

	/*
	 * argument is session handle that we have got from the loginSession
	 * instance by calling loginSession.serialize()
	 */
	void SampleRefreshCall(String sessionHandle) throws LicensingException {
		ApplicationContext appContext;
		/* set refresh attributes */
		Attribute refreshAttributes = new Attribute();
		refreshAttributes.set(LicensingConstants.SNTL_ATTR_REFRESH_USAGE_COUNT_MULTIPLIER, "100");
		LoginSession refreshSession = new LoginSession(null, sessionHandle);
		/* refresh call */
		refreshSession.refresh(refreshAttributes);
	}

	/*
	 * argument is session handle that we have got from the loginSession
	 * instance by calling loginSession.serialize()
	 */
	void SampleDefaultLogoutCall(String sessionHandle) throws LicensingException {
		ApplicationContext appContext;
		LoginSession logoutSession = new LoginSession(null, sessionHandle);

		/* default logout call */
		logoutSession.logout();
	}

	/*
	 * argument is session handle that we have got from the loginSession
	 * instance by calling loginSession.serialize()
	 */
	void SampleLogoutCall(String sessionHandle) throws LicensingException
	{
		Attribute logoutAttributes;
		
			logoutAttributes = new Attribute();
			logoutAttributes.set(LicensingConstants.SNTL_ATTR_LOGOUT_USAGE_COUNT_MULTIPLIER, "100");

			LoginSession logoutSession = new LoginSession(null, sessionHandle);

			/* logout call */
			logoutSession.logout(logoutAttributes);
	} 

Finding the expiration date, usability status, and available usage count of a license

Use the getInfo API to obtain license information from the cloud.

>Create an Application Context.

>Set the getInfo attributes.

>Using the Application Context created above, call the getInfo API.

Sample Code

Attribute attrIdentity;
		Identity identity = null;
		String identityLogin = null;
		String customer = "NamedCustomer";
		String user = "user_1";
		String featureName = "f1";
		String featureVersion = "SampleFeatVer";

		Attribute attrGetinfo = null;
		
			attrGetinfo = new Attribute();
			lsapiInstance = new ApplicationContext(null);
		
		String getInfoResponse = null;

		
			// Set identity attributes
			attrIdentity = new Attribute();
			attrIdentity.set(LicensingConstants.SNTL_ATTR_IDENTITY_CUSTOMER_ID, customer);
			attrIdentity.set(LicensingConstants.SNTL_ATTR_IDENTITY_USERNAME, user);
			identity = new Identity(null, attrIdentity);
			identityLogin = identity.serialize();

		String QueryFeatureInfo = "<sentinelQuery query=\"entitlementInfo\"/>";
		String scopeFeatureInfo = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<sentinelScope>"
				+ "<identity>" + identityLogin + "</identity>" + "<feature index=\"0\">" + "<name>" + featureName
				+ "</name>" + "<version>" + featureVersion + "</version>" + "</feature>" + "</sentinelScope>")
						.toString();

		getInfoResponse = lsapiInstance.getInfo(attrGetinfo, scopeFeatureInfo, QueryFeatureInfo);
		System.out.println("\n\nXML returned by getInfo: :\n\n" + getInfoResponse);
Sample Output

The sentinelInfo structure contains the XML output of getInfo.

<sentinelInfo>
	<entitlement>
		<entitlementId>bd45a39b-bb50-4a7a-beeb-4e5de62ddf49</entitlementId>
		<product>
			<productName>ruchi_P1</productName>
			<productVersion>unnamed</productVersion>
			<feature>
				<featureId>41</featureId>
				<featureName>ruchi_f1</featureName>
				<featureVersion />
				<usable>true</usable>
				<usabilityStatus>Available</usabilityStatus>
				<concurrencyLimit>unlimited</concurrencyLimit>
				<startDate>2016-08-17T00:00:00Z</startDate>
				<endDate>2017-08-17T00:00:00Z</endDate>
				<vendorInfo>vendorinfo</vendorInfo>
				<usageLimit>100</usageLimit>
				<usageCountConsumed>0</usageCountConsumed>
				<endDateGraceDuration>1</endDateGraceDuration>
			</feature>
		</product>
	</entitlement>
</sentinelInfo>

Parse the output XML to obtain the required license information, as described below: :

1. To find the expiration date of a license, use endDate.

2. To determine if the usage count is still available, use usageCount and usageCountConsumed.

In the case of licenses with a given usage limit:

Available units for consumption = (usageLimit+usageCountGrace)- usageCountConsumed

3.If the license has expired or the usage count has exhausted, the usabilityStatus will not be shown as available. In such cases, you can do one of the following (before calling the login API):

a.Reconfigure the entitlement (from EMS) to increase the end date or usage limit. You can also consider providing / increasing the grace limit.

b.Decide not to use the feature in the login call.