/** * Generate a key pair given transformation and key length which can then be used * for asymmetric en- or decryption. * * @return the generated key as a byte array */ public static KeyPair generateKeyPair() { try { KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(ASYMMETRIC_TRANSFORMATION); keyPairGenerator.initialize(ASYMMETRIC_KEY_LENGTH); return keyPairGenerator.generateKeyPair(); } catch (NoSuchAlgorithmException ex) { new FatalImplementationErrorException("Key transformation non existent", EncryptionHelper.class, ex); return null; } }
/** * Generate a key with given transformation and key length which can then be used * for symmetric en- or decryption. * * @return the generated key as a byte array */ public static byte[] generateKey() { try { KeyGenerator keyGenerator = KeyGenerator.getInstance(SYMMETRIC_ALGORITHM); keyGenerator.init(SYMMETRIC_KEY_LENGTH); SecretKey secretKey = keyGenerator.generateKey(); return secretKey.getEncoded(); } catch (NoSuchAlgorithmException ex) { new FatalImplementationErrorException("Key transformation non existent", EncryptionHelper.class, ex); return null; } }
@Override protected void bindRegistryRemoteToRemoteRegistries() { try { bindRegistryRemoteToRemoteRegistry(agentUnitConfigRemoteRegistry, unitRegistry, UnitRegistryData.AGENT_UNIT_CONFIG_FIELD_NUMBER); } catch (CouldNotPerformException ex) { new FatalImplementationErrorException("Could not bind registries", this, ex); } }
@Override protected void bindRegistryRemoteToRemoteRegistries() { try { bindRegistryRemoteToRemoteRegistry(deviceUnitConfigRemoteRegistry, unitRegistry, UnitRegistryData.DEVICE_UNIT_CONFIG_FIELD_NUMBER); } catch (CouldNotPerformException ex) { new FatalImplementationErrorException("Could not bind registries", this, ex); } }
/** * Hashes a string that has to be UTF-8 encoeded symmetrically. * * @param string String to be hashed * @return Returns a byte[] representing the hashed string */ public static byte[] hash(final String string) { try { byte[] key = string.getBytes("UTF-8"); MessageDigest sha = MessageDigest.getInstance(HASH_ALGORITHM); key = sha.digest(key); return Arrays.copyOf(key, 16); } catch (NoSuchAlgorithmException | UnsupportedEncodingException ex) { new FatalImplementationErrorException("Hashing[" + string + "] failed!", EncryptionHelper.class, ex); return null; } }
@Override protected void bindRegistryRemoteToRemoteRegistries() { try { bindRegistryRemoteToRemoteRegistry(appUnitConfigRemoteRegistry, unitRegistry, UnitRegistryData.APP_UNIT_CONFIG_FIELD_NUMBER); } catch (CouldNotPerformException ex) { new FatalImplementationErrorException("Could not bind registries", this, ex); } }
@Override public void uncaughtException(Thread t, Throwable ex) { ExceptionPrinter.printHistory(new FatalImplementationErrorException("UncaughtException found!", t, ex), LoggerFactory.getLogger(getClass())); } });
@Override protected void bindRegistryRemoteToRemoteRegistries() { try { bindRegistryRemoteToRemoteRegistry(sceneConfigRemoteRegistry, unitRegistry, UnitRegistryData.SCENE_UNIT_CONFIG_FIELD_NUMBER); } catch (CouldNotPerformException ex) { new FatalImplementationErrorException("Could not bind registries", this, ex); } }
/** * * @return * @deprecated get your own instance via the registry pool. */ @Deprecated public DeviceRegistryRemote getDeviceRegistryRemote() { try { return CachedDeviceRegistryRemote.getRegistry(); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } catch (NotAvailableException ex) { new FatalImplementationErrorException("registry not available", this, ex); } return null; }
private void verifyEnablingState() throws FatalImplementationErrorException { if (!isEnabled()) { if (JPService.testMode()) { throw new FatalImplementationErrorException("Waiting for data of a disabled unit should be avoided!", "Calling instance"); } else { logger.warn("Waiting for data of an disabled unit should be avoided! Probably this method will block forever!"); } } }
@Override public R call() throws Exception { try { internalAllOf(futureCollection, this); if (resultCallable == null) { throw new NotAvailableException("resultCallable"); } return resultCallable.call(); } catch (CouldNotPerformException | InterruptedException ex) { throw ex; } catch (Exception ex) { throw ExceptionPrinter.printHistoryAndReturnThrowable(new FatalImplementationErrorException("Task execution failed!", AbstractExecutorService.class, ex), LoggerFactory.getLogger(AbstractExecutorService.class)); } } });
private boolean checkInitialization() { try { validateInitialization(); } catch (InvalidStateException ex) { ExceptionPrinter.printHistory(new FatalImplementationErrorException(this, ex), logger); return false; } return true; }
@Override protected void bindRegistryRemoteToRemoteRegistries() { try { bindRegistryRemoteToRemoteRegistry(userConfigRemoteRegistry, unitRegistry, UnitRegistryData.USER_UNIT_CONFIG_FIELD_NUMBER); bindRegistryRemoteToRemoteRegistry(authorizationGroupConfigRemoteRegistry, unitRegistry, UnitRegistryData.AUTHORIZATION_GROUP_UNIT_CONFIG_FIELD_NUMBER); } catch (CouldNotPerformException ex) { new FatalImplementationErrorException("Could not bind registries", this, ex); } }
@Override protected void bindRegistryRemoteToRemoteRegistries() { try { bindRegistryRemoteToRemoteRegistry(locationUnitConfigRemoteRegistry, unitRegistry, UnitRegistryData.LOCATION_UNIT_CONFIG_FIELD_NUMBER); bindRegistryRemoteToRemoteRegistry(connectionUnitConfigRemoteRegistry, unitRegistry, UnitRegistryData.CONNECTION_UNIT_CONFIG_FIELD_NUMBER); } catch (CouldNotPerformException ex) { new FatalImplementationErrorException("Could not bind registries", this, ex); } }
public static void verifyServiceState(final Message serviceState) throws VerificationFailedException { try { try { detectServiceStateVerificationMethod(serviceState).invoke(null, serviceState); } catch (NotAvailableException ex) { ExceptionPrinter.printHistory("Verification of ServiceState[ " + serviceState.getClass().getSimpleName() + "] skipped because verification method not supported yet.!", ex, LOGGER, LogLevel.DEBUG); } catch (InvocationTargetException ex) { if (ex.getTargetException() instanceof VerificationFailedException) { throw (VerificationFailedException) ex.getTargetException(); } else { throw ex; } } } catch (VerificationFailedException ex) { throw ex; } catch (NullPointerException | IllegalAccessException | ExceptionInInitializerError | CouldNotPerformException | InvocationTargetException ex) { ExceptionPrinter.printHistory(new FatalImplementationErrorException("Verification of service state could no be performed!", Services.class, ex), LOGGER, LogLevel.WARN); } }
@Override protected File getPropertyDefaultValue() { // use tmp folder in test case if (JPService.testMode()) { try { return JPService.getProperty(JPTmpDirectory.class).getValue(); } catch (JPNotAvailableException ex) { // exception is already printed in constructore so no further forwarding needed. new FatalImplementationErrorException("Could not link test tmp directory as bco home path for java tests.", this, ex); } } // use bco home system variable if defined String systemDefinedHome = System.getenv(SYSTEM_VARIABLE_BCO_HOME); if (systemDefinedHome != null) { return new File(systemDefinedHome); } return new File(DEFAULT_PATH); }
/** * Method returns the unit shape of this unit. * <p> * If this unit configuration does not provide any shape information the shape of the unit host will be returned. * In case the unit host even does not provide any shape information and the unit is a device than the shape of the device class will be used. * * @return the shape representing the unit. * * @throws NotAvailableException is thrown if the unit shape is not available or the resolution has been failed. */ default Shape getUnitShape() throws NotAvailableException { try { try { return Registries.getLocationRegistry().getUnitShape(getConfig()); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); throw new FatalImplementationErrorException("getLocationRegistry should not throw InterruptedExceptions anymore!", Unit.class, ex); } } catch (final CouldNotPerformException ex) { throw new NotAvailableException("UnitShape", ex); } }
/** * Method returns the transformation leading from the root location to the given unit. * * @param unitConfig the unit where the transformation leads to. * @return a transformation future */ public static Future<Transform> getRootToUnitTransformationFuture(final UnitConfig unitConfig) { final Future<LocationRegistryDataType.LocationRegistryData> dataFuture; try { try { dataFuture = Registries.getLocationRegistry().getDataFuture(); return GlobalCachedExecutorService.allOfInclusiveResultFuture(Registries.getLocationRegistry().getRootToUnitTransformationFuture(unitConfig), dataFuture); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); throw new FatalImplementationErrorException("getLocationRegistry should not throw InterruptedExceptions anymore!", Units.class, ex); } } catch (CouldNotPerformException ex) { return FutureProcessor.canceledFuture(Transform.class, new NotAvailableException("UnitTransformation", ex)); } }
/** * Method returns the transformation leading from the given unit to the root location. * * @param unitConfig the unit where the transformation leads to. * @return a transformation future */ public static Future<Transform> getUnitToRootTransformationFuture(final UnitConfig unitConfig) { final Future<LocationRegistryDataType.LocationRegistryData> dataFuture; try { try { dataFuture = Registries.getLocationRegistry().getDataFuture(); return GlobalCachedExecutorService.allOfInclusiveResultFuture(Registries.getLocationRegistry().getUnitToRootTransformationFuture(unitConfig), dataFuture); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); throw new FatalImplementationErrorException("getLocationRegistry should not throw InterruptedExceptions anymore!", Units.class, ex); } } catch (CouldNotPerformException ex) { return FutureProcessor.canceledFuture(Transform.class, new NotAvailableException("UnitTransformation", ex)); } }
/** * Method returns the transformation between the given unit A and the given * unit B. * * @param unitConfigA the unit used as transformation base. * @param unitConfigB the unit where the transformation leads to. * @return a transformation future */ public static Future<Transform> getUnitTransformationFuture(final UnitConfig unitConfigA, final UnitConfig unitConfigB) { final Future<LocationRegistryDataType.LocationRegistryData> dataFuture; try { try { dataFuture = Registries.getLocationRegistry().getDataFuture(); return GlobalCachedExecutorService.allOfInclusiveResultFuture(Registries.getLocationRegistry().getUnitTransformationFuture(unitConfigA, unitConfigB), dataFuture); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); throw new FatalImplementationErrorException("getLocationRegistry should not throw InterruptedExceptions anymore!", Units.class, ex); } } catch (CouldNotPerformException ex) { return FutureProcessor.canceledFuture(Transform.class, new NotAvailableException("UnitTransformation", ex)); } } }