public final void registerUnits(final Collection<UnitConfig> unitConfigs) throws CouldNotPerformException, InterruptedException { MultiException.ExceptionStack exceptionStack = null; for (UnitConfig unitConfig : unitConfigs) { try { registerUnit(unitConfig); } catch (CouldNotPerformException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } MultiException.checkAndThrow("Could not register all hosted units of " + this, exceptionStack); }
/** * Constructor creates an continuous state change instance, which based on not manipulated state values * (literals like e.g. 17.35^^xsd:int) to store them. The information parts (input argument) will be convert * to specific data types (see getter of this class). * * @param timestamp is the timestamp at which the state change occurred. Must be parsable to OffsetDateTime. * @param stateValues is the value (literal type) of the state change. The rdf nodes must be based on literals. * @throws MultiException is thrown in case at least one input parameter is null/invalid or one state value * isn't a literal (/continuous value). */ public Continuous(final String timestamp, final List<RDFNode> stateValues) throws MultiException { final MultiException.ExceptionStack exceptionStack = Preconditions.multipleCheckNotNull(this, null, timestamp, stateValues); this.timestamp = Preconditions.Function.apply(OffsetDateTime::parse, timestamp, this, exceptionStack); this.stateValues = new ArrayList<>(); for (final RDFNode stateValue : stateValues) { // convert rdf node to literal and add to list. Invalid nodes will be stacked final Literal literal = Preconditions.Supplier.get(stateValue::asLiteral, this, exceptionStack); if (literal != null) { this.stateValues.add(literal); } } MultiException.checkAndThrow("Input argument(s) invalid. Null or no literal type!", exceptionStack); }
/** * Method executes the input function without argument and returns the result. If the input function provokes an * exception it will be stacked on the input exceptionStack object and NULL will be returned. Check the * exceptionStack in this case. * * @param function represents a function without any argument and produces an result. * @param source of the function. Can be ignored by NULL. * @param exceptionStack is used to bundle possible exception. If NULL a new exceptionStack will be created. * @param <R> is the type of the result to the function. * @return the result of the function with type R. Returns null if an exception occurs. Check exceptionStack. */ static <R> R get(final Supplier<R> function, final Object source, ExceptionStack exceptionStack) { try { exceptionStack = initializeIfNull(exceptionStack); return function.getSupplier(); } catch (Exception e) { MultiException.push(source, new Exception(e.toString()), exceptionStack); } return null; }
detectNegation(triggerQuery); } catch (MultiException ex) { throw new MultiException("Could not perform trigger with label \"" + triggerLabel + "\"", ex.getExceptionStack());
/** * Constructor creates an discrete state change instance, which based on manipulated (already aggregated) state * values (e.g. ON, OFF, ...) to store them. The information parts (input argument) will be convert to specific * data types (see getter of this class). * * @param timeWeighting is the indicator how long the unit keeps connection to the system with value range * [0..1]. E.g. an value of 0.6 means that there was connection (and observed state * changes) in 60% of the aggregated time frame. 40% of the time was not observed so that * this value is used as inaccuracy. * @param activityTime is the time how long the discrete state value was activated in the aggregated time frame. * @param quantity is the number of activation of the based state value source in the aggregated time frame. * @param stateValue is the specific discrete state value. * @throws MultiException is thrown in case at least one input parameter is null/invalid or the state value * isn't a resource (/discrete value). */ public AggregatedDiscrete(final String timeWeighting, final String activityTime, final String quantity, final RDFNode stateValue) throws MultiException { final ExceptionStack exceptionStack = Preconditions.multipleCheckNotNull(this, null, timeWeighting, activityTime, quantity, stateValue); this.timeWeighting = Optional.ofNullable(Preconditions.Function.apply(Double::parseDouble, timeWeighting, this, exceptionStack)).orElse(0.0); this.activityTime = Optional.ofNullable(Preconditions.Function.apply(Long::parseLong, activityTime, this, exceptionStack)).orElse(0L); this.quantity = Optional.ofNullable(Preconditions.Function.apply(Integer::parseInt, quantity, this, exceptionStack)).orElse(0); this.stateValue = Preconditions.Supplier.get(stateValue::asResource, this, exceptionStack); MultiException.checkAndThrow("Input is invalid.", exceptionStack); }
/** * Method executes the input function given as argument and returns the result. If an exception is provoked by * execution, it will be stacked on the input exceptionStack and NULL will be returned. Check exceptionStack. * * @param function represents a function with one argument and produces an result. * @param funcArg is the single argument of the function. * @param source is the source of the function. Can be ignored by NULL. * @param exceptionStack is used to bundle possible exception. If NULL a new exceptionStack will be created. * @param <T> is the type of the argument to the function. * @param <R> is the type of the result to the function. * @return the result of the function with type R. Returns null if an exception occurs. Check exceptionStack. */ static <T, R> R apply(final Function<T, R> function, final T funcArg, final Object source, ExceptionStack exceptionStack) { try { exceptionStack = initializeIfNull(exceptionStack); return function.applyFunction(funcArg); } catch (Exception e) { MultiException.push(source, new Exception(e.toString()), exceptionStack); } return null; }
public static String resolveVariable(final String variable, final VariableProvider... providers) throws MultiException { MultiException.ExceptionStack exceptionStack = null; for (VariableProvider provider : providers) { try { return provider.getValue(variable); } catch (NotAvailableException ex) { exceptionStack = MultiException.push(VariableProcessor.class, ex, exceptionStack); continue; } } MultiException.checkAndThrow("Could not resolve Variable[" + variable + "]!", exceptionStack); throw new AssertionError("Fatal error during variable resolving."); } }
this.stateValue = Preconditions.Supplier.get(stateValue::asLiteral, this, exceptionStack); MultiException.checkAndThrow("Input is invalid.", exceptionStack);
/** * Method executes the input function given as argument and returns the result. If an exception is provoked by * execution, it will be stacked on the input exceptionStack and NULL will be returned. Check exceptionStack. * * @param function represents a function with one argument and produces an result. * @param funcArgOne is the first argument of the function. * @param funcArgTwo is the second argument of the function. * @param source is the source of the function. Can be ignored by NULL. * @param exceptionStack is used to bundle possible exception. If NULL a new exceptionStack will be created. * @param <T> is the type of the first argument to the function. * @param <U> is the type of the second argument to the function. * @param <R> is the type of the result to the function. * @return the result of the function with type R. Returns null if an exception occurs. Check exceptionStack. */ static <T, U, R> R apply(final BiFunction<T, U, R> function, final T funcArgOne, final U funcArgTwo, final Object source, ExceptionStack exceptionStack) { try { exceptionStack = initializeIfNull(exceptionStack); return function.applyBiFunction(funcArgOne, funcArgTwo); } catch (Exception e) { MultiException.push(source, new Exception(e.toString()), exceptionStack); } return null; }
private void detectNegation(final String askQuery) throws MultiException { // official w3c sparql negation forms final String[] negationForms = new String[] {"not exists", "!exists", "minus", "not in", "not bound"}; MultiException.ExceptionStack exceptionStack = null; for (final String negationForm : negationForms) { try { if (askQuery.toLowerCase().contains(negationForm)) { throw new NotAvailableException("Found negation keyword: " + negationForm); } } catch (NotAvailableException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } MultiException.checkAndThrow("Could not parse ontologyChange from query string, because of negation phrase in query string! Certain determination of " + "trigger changes criteria can't be guarantee. Select manual criteria for this trigger!", exceptionStack); }
/** * Constructor creates an discrete state change instance, which based on not manipulated state values (e.g. * ON, OFF, ...) to store them. The information parts (input argument) will be convert to specific data types * (see getter of this class). * * @param timestamp is the timestamp at which the state change occurred. Must be parsable to OffsetDateTime. * @param stateValue is the value (resource type) of the state change. Must be based on rdf resource. * @throws MultiException is thrown in case at least one input parameter is null/invalid or the state value * isn't a resource (/discrete value). */ public Discrete(final String timestamp, final RDFNode stateValue) throws MultiException { final MultiException.ExceptionStack exceptionStack = Preconditions.multipleCheckNotNull(this, null, timestamp, stateValue); this.timestamp = Preconditions.Function.apply(OffsetDateTime::parse, timestamp, this, exceptionStack); this.stateValue = Preconditions.Supplier.get(stateValue::asResource, this, exceptionStack); MultiException.checkAndThrow("Input argument invalid. Null or no resource type!", exceptionStack); }
/** * Method ensures that one or multiple object reference(s) passed as a parameter to the calling method is/are not * null. Possible NotAvailableException is stacked and returned. By using one object reference use the single * version method to be able to specify the content if exception is thrown. * * @param source is the source of the reference(s). Can be ignored by NULL. * @param exceptionStack is used to bundle possible exception. If NULL a new exceptionStack will be created. * @param objects are the reference objects, which should be checked. * @return the exceptionStack with or without new exception entry. */ static ExceptionStack multipleCheckNotNull(final Object source, ExceptionStack exceptionStack, final Object... objects) { exceptionStack = initializeIfNull(exceptionStack); for (int i = 0; i < objects.length; i++) { try { checkNotNull(objects[i], "Parameter " + i + " in argument array is null!"); } catch (NotAvailableException e) { MultiException.push(source, e, exceptionStack); } } return exceptionStack; }
@Override public void deactivate() throws InterruptedException, CouldNotPerformException { super.deactivate(); MultiException.ExceptionStack exceptionStack = null; synchronized (unitMapLock) { for (AbstractUnitController unit : unitMap.values()) { try { unit.deactivate(); } catch (CouldNotPerformException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } } MultiException.checkAndThrow("Could not deactivate all hosted units of " + this, exceptionStack); }
private void addAggDiscrete(final OntUnits ontUnits, final String unitId, final String providerService, final RDFNode stateValue, final String timeWeighting, final String quantity, final QuerySolution querySolution, final ExceptionStack exceptionStack) throws MultiException { final String activityTime = Preconditions.BiFunction.apply(OntNodeHandler::getRDFLocalName, querySolution, ACTIVITY_TIME.getName(), this, exceptionStack); // depend on the classification the aggregated values shouldn't be null MultiException.checkAndThrow("Invalid parameters or variables in sparql query.", exceptionStack); final OntStateChange ontStateChange = OntStateChange.asAggregatedDiscrete(timeWeighting, activityTime, quantity, stateValue); // insert collected information ontUnits.addOntProviderService(unitId, providerService, ontStateChange); }
@Override public void activate() throws InterruptedException, CouldNotPerformException { super.activate(); MultiException.ExceptionStack exceptionStack = null; synchronized (unitMapLock) { for (AbstractUnitController unit : unitMap.values()) { try { unit.activate(); } catch (CouldNotPerformException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } } MultiException.checkAndThrow("Could not activate all hosted units of " + this, exceptionStack); }
private void addAggContinuous(final OntUnits ontUnits, final String unitId, final String providerService, final RDFNode stateValue, final String timeWeighting, final String quantity, final QuerySolution querySolution, final ExceptionStack exceptionStack) throws MultiException { final String variance = Preconditions.BiFunction.apply(OntNodeHandler::getRDFLocalName, querySolution, VARIANCE.getName(), this, exceptionStack); final String standardDeviation = Preconditions.BiFunction.apply(OntNodeHandler::getRDFLocalName, querySolution, STANDARD_DEVIATION.getName(), this, exceptionStack); final String mean = Preconditions.BiFunction.apply(OntNodeHandler::getRDFLocalName, querySolution, MEAN.getName(), this, exceptionStack); // depend on the classification the aggregated values shouldn't be null MultiException.checkAndThrow("Invalid parameters or variables in sparql query.", exceptionStack); final OntStateChange ontStateChange = OntStateChange.asAggregatedContinuous(mean, variance, standardDeviation, timeWeighting, quantity, stateValue); // insert collected information ontUnits.addOntProviderService(unitId, providerService, ontStateChange); }
private void initMethods(final LocalServer localServer) throws NotAvailableException, CouldNotPerformException { MultiException.ExceptionStack exceptionStack = null; synchronized (participantLock) { for (Entry<String, Callback> entry : localMethodStack.entrySet()) { try { localServer.addMethod(entry.getKey(), entry.getValue()); } catch (RSBException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } try { MultiException.checkAndThrow("Could not register all methods!", exceptionStack); } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory(ex, logger); } } }
querySolution, LAST_TIMESTAMP.getName(), this, exceptionStack); MultiException.checkAndThrow("Invalid parameters or variables in sparql query.", exceptionStack);
public Collection<GenericUnitPanel<RS>> add(final Collection<String> unitLabelList) throws InitializationException, InterruptedException { final List<GenericUnitPanel<RS>> unitPanelList = new ArrayList<>(); MultiException.ExceptionStack exceptionStack = null; try { // create and add unit panels. for (String unitLabel : unitLabelList) { try { unitPanelList.addAll(add(unitLabel)); } catch (CouldNotPerformException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } MultiException.checkAndThrow("Could not add all units!", exceptionStack); } catch (MultiException ex) { throw new InitializationException(this, ex); } return unitPanelList; }
querySolution, PROVIDER_SERVICE.getName(), this, exceptionStack); MultiException.checkAndThrow("Invalid parameters or variables in sparql query.", exceptionStack);