# Java Advanced Usage

### Detecting Virtual Machines

In case your `License` is using the `Prevent virtual machine` feature, the Java SDK will try to detect a Virtual Machine (VM) by comparing common VM signatures in hardware components of a node (computer).

If any of the mentioned components match a VM component signature and the feature is active, the License activation will fail!

{% hint style="info" %}
If you come across a Virtual Machine that's not properly detected, [**please submit a ticket**](https://licensespring.zendesk.com/hc/en-us/requests/new) with information about the VM used so we can add it to the detector.
{% endhint %}

#### Virtual Machines Currently Detected Using the Java SDK

The detection process compares the hardware signatures of the current node (computer) against a list of the following known VM signatures:

* bhyve
* Docker Container
* FreeBSD Jail
* KVM
* LXC
* Lguest
* Linux-VServer
* Microsoft Hyper-V
* OpenVZ
* Parallels
* Project ACRN
* QEMU
* QNX Hypervisor
* VMware
* Windows Virtual PC
* Xen/Oracle
* Virtual Iron
* VirtualBox

### Multiple Licenses on Same Device in LicenseClient

By default, the `LicenseManager` is used as a singleton - but if there is a need for multiple `LicenseManagers`, each with its own configuration - you can use the `LicenseManagerFactory` to create additional managers or use the singleton like before.

```java
// creates a new LicenseManager object, there can be multiple ones using this method
LicenseManager multipleLicences = LicenseManagerFactory.createLicenseManager();

// uses the singleton variant, only 1 manager can be initialized using this method
LicesneManager singleton = LicenseManagerFactory.getLicenseManager();
```

### Custom License Storage in License Client

By default the license is stored on the local disk - encrypted when storing. The location of the license can be changed via the `Configuration` object. A custom `LicenseRepository` can also be implemented, see sample below:

```java
// another way to initialize the manager
// is to pass it an additional field which is
// your own implementation of the LicenseRepository interface
public class MyLicenseRepository implements LicenseRepository {
    void save(License license) {
        // save the license
    }
    void delete() {
        // delete the license 
    }
    License load() {
        // load the license
    }
    // add any additional methods you need
}

try {
    licenseManager.initialize(configuration, new MyLicenseRepository());
} catch (LicenseSpringException e) {
    log.error(e.getCause().getMessage());
}
```

### Implementing Your Own LicenseSpring using LicenseSpring Core

This is possible to do, where you get to reuse most of the DTOs and authorization that was built. Feel free to contact us, if you require help of implementing your own SDK, with the boilerplate and authorization layers already finished.

### Forward Proxy

All Java SDK modules support a forward proxy. Set `proxyPort` and `proxyHost` in the relevant configuration.\n+\n+If you’re choosing between modules, see [**Java Modules**](/sdks/java-sdk/java-modules.md).\n+\n+For on-prem floating, see [**Floating Server V1**](/floating-server/floating-server-v1.md).

There is also support for Basic Auth, by setting the `proxyUser` and `proxyPass` fields in any of the configurations.

Here is an example setup for the `License Client` module:

```java
LicenseSpringConfiguration configuration = LicenseSpringConfiguration.builder()
                        .apiKey("api_key")
                        .productCode("product_code")
                        .sharedKey("shared-key")
                        .proxyHost("192.168.0.254")
                        .proxyPort(1337)
                        .proxyUser("SampleUser")
                        .proxyPass("SamplePass")
                        .build();
```

### Disable SSL

{% hint style="info" %}
disableSsl() still uses SSL traffic; it just trusts all certificates.
{% endhint %}

In rare cases, some clients using a forward proxy cannot verify the public certificate of LicenseSpring servers. For these cases, there is an option in the `License Client`, `Floating Client` and `Management SDK` called `disableSsl`.

Here is an example setup for the `License Client` module:

```java
LicenseSpringConfiguration configuration = LicenseSpringConfiguration.builder()
                        .apiKey("api_key")
                        .productCode("product_code")
                        .sharedKey("shared-key")
                        .disableSsl(true)
                        .build();
```

### Shutdown Scheduled Executors

License Client (`LicenseManager`), Floating Client (`FloatingLicenseService`) and Proxy Floating Client (`ProxyFloatingService`) have the method `shutdownScheduler()`, which calls `shutdownNow()` for their scheduled executors. The executors are used in making periodic checks (if it's enabled) and in some cases will leave threads running indefinitely - when no shutdown signal is received.

### Offline Mode Toggle

`LicenseManager` can dynamically toggle offline/online mode with `setOfflineMode(boolean)`.

For detecting if the user has access to internet: The connection type is "com.licensespring.model.exceptions.infrastructure.ConnectionException", with the message: "<http://api.licensespring.com/>: nodename nor servname provided, or not known" or message "timeout" - depending if the internet was available at some point during app running ("timeout" message if internet was available at some point and later disabled)

### Custom Service URL

License Client and Floating client can have alternate serviceUrls (when base domain is not <http://licensespring.com/>) — to override, use the `serviceURL` and `serviceUrlCertPath` configuration params. The certificate needs to be a `.pem` file (on disk or a resource).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.licensespring.com/sdks/java-sdk/java-advanced-usage.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
