/** * Method shutdown the cached registry instances. * <p> * Please use method with care! * Make sure no other instances are using the cached remote instances before shutdown. * <p> * Note: This method takes only effect in unit tests, otherwise this call is ignored. During normal operation there is not need for a manual registry shutdown because each registry takes care of its shutdown. */ public static void shutdown() { // check if externally called. if (shutdown == false && !JPService.testMode()) { LOGGER.warn("This manual registry shutdown is only available during unit tests and not allowed during normal operation!"); return; } synchronized (REMOTE_LOCK) { if (registryRemote != null) { try { registryRemote.unlock(REMOTE_LOCK); } catch (final CouldNotPerformException ex) { ExceptionPrinter.printHistory(new FatalImplementationErrorException("Internal remote was locked by an external instance!", CachedUserActivityRegistryRemote.class, ex), LOGGER); } registryRemote.shutdown(); registryRemote = null; } } } }
/** * @return @throws InterruptedException * * @throws NotAvailableException */ public synchronized static UserActivityRegistryRemote getRegistry() throws InterruptedException, NotAvailableException { try { if (shutdown) { throw new InvalidStateException("Remote service is shutting down!"); } if (registryRemote == null) { try { registryRemote = new UserActivityRegistryRemote(); registryRemote.init(); registryRemote.activate(); registryRemote.lock(REMOTE_LOCK); } catch (Exception ex) { if (registryRemote != null) { registryRemote.unlock(REMOTE_LOCK); registryRemote.shutdown(); registryRemote = null; } throw ExceptionPrinter.printHistoryAndReturnThrowable(new CouldNotPerformException("Could not start cached user activity registry remote!", ex), LOGGER); } } return registryRemote; } catch (CouldNotPerformException ex) { throw new NotAvailableException("cached user activity registry", ex); } }