Home >

SDK Reference Guide > Java Interfaces > Re-Establishing a Connection Between Your Java Application and SafeNet Enterprise HSM

Re-Establishing a Connection Between Your Java Application and SafeNet Network HSM

The following snippet of java code re-establishes a connection between a Java Application and SafeNet Network HSM in the event of a disconnect (for example, firewall rules, network issues).

Note:  Stop all existing crypto operations before performing the reconnect.

public void reconnectHsmServer() {
     LunaSlotManager lsm = LunaSlotManager.getInstance();
     lsm.reinitialize();
     lsm.login(“<HSM partition password>”);
}
 

Note:  The reinitialize() call is a disruptive call. It unloads and reloads the dll, in order to perform a cleanup and refresh. When reinitialize() is called, there are no safe API methods that may be called and any calls in progress will result in undefined behaviour, leading, most-likely, to a JVM crash. Before calling reinitialize(), ensure that all threads making use of the API are halted or stopped, and that no other calls are made until reinitialize() has completed.