# Module licensing

**URL:** <https://forum.inductiveautomation.com/t/module-licensing/20940>\
**Category:** 3rd Party Modules\
**Created:** [November 19, 2018, 3:10pm UTC](https://forum.inductiveautomation.com/t/module-licensing/20940 "2018-11-19T15:10:47Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![INNO](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/inno/32/30161_2.png) [@INNO](https://forum.inductiveautomation.com/u/INNO)\
**Post date:** [November 19, 2018, 3:10pm UTC](https://forum.inductiveautomation.com/t/module-licensing/20940/1 "2018-11-19T15:10:48Z")

</div>

We have included the following code into the gateway hook but I’m not sure if this is sufficient to protect against a gateway that is in production but does not have license key for our module. We want to offer our module for testing (2 hour trial) without worrying that it could be used for production without purchasing.

```
@Override
public void notifyLicenseStateChanged(final LicenseState licenseState) {
    super.notifyLicenseStateChanged( licenseState );
    protectLicense( licenseState );
}

private static void protectLicense(final LicenseState licenseState) {
    if( licenseState == null || (licenseState.getLicenseMode() == LicenseMode.Trial && licenseState.isTrialExpired() ) ) {
        //Raise an exception
        throw new IllegalStateException("The module is not activated.");
    }
```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 19, 2018, 3:19pm UTC](https://forum.inductiveautomation.com/t/module-licensing/20940/2 "2018-11-19T15:19:26Z")

</div>

Raising an exception is not going to do anything to protect your module when the trial expires. You have to decide what functionality, if any, remains and actually disable it somehow. Then you need to re-enable that functionality once the trial is reset.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 19, 2018, 3:19pm UTC](https://forum.inductiveautomation.com/t/module-licensing/20940/3 "2018-11-19T15:19:28Z")

</div>

I would expect that to do bad things to the gateway’s module manager. You need to save your inactive/trial/activated state in a private variable accessible from a static method, or in some other object that all parts of your module have access to. Everything your module does should check that static method before proceeding, returning bad quality on invalid data, drawing an overlay on custom components (or replace the component content with the trial expired message), or restricting behaviour in some way that makes it obvious that the trial has expired. Don’t throw exceptions.

If checking a static variable everywhere is too much of a performance hit, you could also spawn a runnable on state change that would iterate through your module-specific objects to pass on the notice in an optimized fashion.

---

<div class="post-metadata">

**Author:** ![INNO](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/inno/32/30161_2.png) [@INNO](https://forum.inductiveautomation.com/u/INNO)\
**Post date:** [November 20, 2018, 1:30pm UTC](https://forum.inductiveautomation.com/t/module-licensing/20940/4 "2018-11-20T13:30:08Z")

</div>

Great thanks, I think we will pursue the runnable method.

Is the showcase API project working, We see our modules but when we click “add” to generate license for a particular module we get a popup with a new key but that key does not show up in the list. whats the exact procedure?

![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/9/9fd583f3ec0fa9ecb2c2bd93e786a1d7f9fd5f50.png)

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [November 20, 2018, 2:25pm UTC](https://forum.inductiveautomation.com/t/module-licensing/20940/5 "2018-11-20T14:25:53Z")

</div>

Restricting the functionality of your module, such as not updating the tags with latest values etc, is the best option, when trial expired state is true,

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 20, 2018, 2:38pm UTC](https://forum.inductiveautomation.com/t/module-licensing/20940/6 "2018-11-20T14:38:28Z")

</div>

> [@INNO](#):
>
> but that key does not show up in the list

Perhaps a bug. Are you sure your search box is completely empty?

---

<div class="post-metadata">

**Author:** ![INNO](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/inno/32/30161_2.png) [@INNO](https://forum.inductiveautomation.com/u/INNO)\
**Post date:** [November 20, 2018, 3:09pm UTC](https://forum.inductiveautomation.com/t/module-licensing/20940/7 "2018-11-20T15:09:13Z")

</div>

yes the search filter is empty.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 20, 2018, 3:19pm UTC](https://forum.inductiveautomation.com/t/module-licensing/20940/8 "2018-11-20T15:19:02Z")

</div>

Hmmm. Works for me. Showed in the list as soon as the popup was closed. Are you using the [latest project](https://api.inductiveautomation.com/showcase/module_showcase.proj)?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 20, 2018, 3:20pm UTC](https://forum.inductiveautomation.com/t/module-licensing/20940/9 "2018-11-20T15:20:16Z")

</div>

Note, new license keys are not attached to a particular module. You have to create the key first, then add modules to it.

---

<div class="post-metadata">

**Author:** ![INNO](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/inno/32/30161_2.png) [@INNO](https://forum.inductiveautomation.com/u/INNO)\
**Post date:** [November 20, 2018, 3:26pm UTC](https://forum.inductiveautomation.com/t/module-licensing/20940/10 "2018-11-20T15:26:28Z")

</div>

I guess I was not using the latest project. As soon as i used your provided project i see all the licenses.

Thank you!

---

<div class="post-metadata">

**Author:** ![Baris.kose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/baris.kose/32/18991_2.png) [@Baris.kose](https://forum.inductiveautomation.com/u/Baris.kose)\
**Post date:** [February 13, 2023, 10:03pm UTC](https://forum.inductiveautomation.com/t/module-licensing/20940/11 "2023-02-13T22:03:05Z")

</div>

Hello Phil. Sorry for this question but I am not an expert. I am just wondering that after creating license key, how can I add the license to my module? If there is documentation or some videos could be enough to understand.

Thanks in advance!
