/** * Sample execution of Math services. * * @param args ignored */ public static void main(String[] args) { System.out.println("Locating service method..."); ServiceMethod method = ServiceRegistry.getDefault().findServiceMethod("math/add"); System.out.println("Service method found: " + method); System.out.println("Preparing arguments..."); Map<String, Object> arguments = new HashMap<>(); arguments.put("arg1", ValueFactory.newVDouble(1.0)); arguments.put("arg2", ValueFactory.newVDouble(2.0)); System.out.println("Arguments: " + arguments); System.out.println("Executing service..."); Map<String, Object> result = method.executeSync(arguments); System.out.println("Result: " + result); }
/** * Sample execution of Math services. * * @param args ignored */ public static void main(String[] args) { System.out.println("Locating service method..."); ServiceMethod method = ServiceRegistry.getDefault().findServiceMethod("math/add"); System.out.println("Service method found: " + method); System.out.println("Preparing arguments..."); Map<String, Object> arguments = new HashMap<>(); arguments.put("arg1", ValueFactory.newVDouble(1.0)); arguments.put("arg2", ValueFactory.newVDouble(2.0)); System.out.println("Arguments: " + arguments); System.out.println("Executing service..."); method.executeAsync(arguments, result -> { System.out.println("Result: " + result); }, ex -> { ex.printStackTrace(); }); }
@Override public Map<String, Object> syncExecImpl(Map<String, Object> parameters) { // Method implementation: this is what the service method actually does // Here we are choosing a synchronous implementation, that is the // calculation is done on the thread inside this method call. // Extract data from parameters VNumber arg1 = (VNumber) parameters.get("arg1"); VNumber arg2 = (VNumber) parameters.get("arg2"); // Check for nulls if (arg1 == null || arg2 == null) { return new HashMap<>(); } // Perform calculation VNumber result = ValueFactory.newVDouble(arg1.getValue().doubleValue() * arg2.getValue().doubleValue()); // Prepare the result Map<String, Object> resultMap = new HashMap<>(); resultMap.put("result", result); return resultMap; } }
@Override public Map<String, Object> syncExecImpl(Map<String, Object> parameters) { // Method implementation: this is what the service method actually does // Here we are choosing a synchronous implementation, that is the // calculation is done on the thread inside this method call. // Extract data from parameters VNumber arg1 = (VNumber) parameters.get("arg1"); VNumber arg2 = (VNumber) parameters.get("arg2"); // Check for nulls if (arg1 == null || arg2 == null) { return new HashMap<>(); } // Perform calculation VNumber result = ValueFactory.newVDouble(arg1.getValue().doubleValue() + arg2.getValue().doubleValue()); // Prepare the result Map<String, Object> resultMap = new HashMap<>(); resultMap.put("result", result); return resultMap; } }
@Override public final Object calculate(List<Object> args) { VNumber arg = (VNumber) args.get(0); if (arg == null) { return null; } return ValueFactory.newVDouble(calculate(arg.getValue().doubleValue()), arg, arg, ValueFactory.displayNone()); }
@Override protected Object createValue() { return newVDouble(bytesToMebiByte(Runtime.getRuntime().totalMemory()), alarmNone(), timeNow(), memoryDisplay); }
@Override protected Object createValue() { return newVDouble(bytesToMebiByte(Runtime.getRuntime().maxMemory()), alarmNone(), timeNow(), memoryDisplay); }
@Override protected Object createValue() { return newVDouble(bytesToMebiByte(Runtime.getRuntime().freeMemory()), alarmNone(), timeNow(), memoryDisplay); }
@Override public Object calculate(final List<Object> args) { VNumber value = (VNumber) args.get(0); if (value != null && value.getValue() != null) { values.add(value); } if (values.isEmpty()) { return null; } if (previousTime == null) { Instant now = Instant.now(); if (now.compareTo(values.get(0).getTimestamp()) <= 0) { previousTime = now; } else { previousTime = values.get(0).getTimestamp(); } } Instant currentTime = Instant.now(); integratedValue += integrate(previousTime, currentTime, values); previousTime = currentTime; while (values.size() > 1 && values.get(1).getTimestamp().compareTo(currentTime) <= 0) { values.remove(0); } return ValueFactory.newVDouble(integratedValue); }
@Override public Object calculate(final List<Object> args) { if (NullUtils.containsNull(args)) { return null; } VTable table = (VTable) args.get(0); VString columnName = (VString) args.get(1); VNumberArray range = (VNumberArray) args.get(2); if (range.getData().size() != 2) { throw new IllegalArgumentException("Range array must be of 2 elements"); } VTable result = VTableFactory.tableRangeFilter(table, columnName.getValue(), ValueFactory.newVDouble(range.getData().getDouble(0)), ValueFactory.newVDouble(range.getData().getDouble(1))); return result; }
@Override public final Object calculate(List<Object> args) { Object arg1 = args.get(0); Object arg2 = args.get(1); if (arg1 == null || arg2 == null) { return null; } Alarm alarm = ValueUtil.highestSeverityOf(args, false); Time time = ValueUtil.latestTimeOf(args); if (time == null) { time = ValueFactory.timeNow(); } return ValueFactory.newVDouble( calculate(((VNumber) args.get(0)).getValue().doubleValue(), ((VNumber) args.get(1)).getValue().doubleValue()) , alarm, time, ValueFactory.displayNone()); }
/** * A constant representing a double. Alarm will be none, timestamp now * and no display information. * * @param value the constant value * @return a double expression */ public static DesiredRateExpression<VDouble> vConst(double value) { return constant(newVDouble(value, alarmNone(), timeNow(), displayNone()), Double.toString(value)); }
return newVDouble(totalSum / data.size(), newAlarm(statSeverity, "NONE"), newTime(data.get(data.size() / 2).getTimestamp()), data.get(0));
/** * A list of constant expressions of type VDouble. * * @param values the list of constants * @return a list of double expression */ public static DesiredRateExpressionList<VDouble> vDoubleConstants(List<Double> values) { DesiredRateExpressionList<VDouble> list = new DesiredRateExpressionListImpl<VDouble>(); for (Double value : values) { list.and(constant(newVDouble(value, alarmNone(), timeNow(), displayNone()))); } return list; }
return ValueFactory.newVDouble(pvResult.getDoubleField(fieldName != null ? fieldName : resultName).get(), ValueFactory.alarmNone(), ValueFactory.timeNow(), ValueFactory.displayNone()); } else if (resultType.isAssignableFrom(VFloat.class)) { return ValueFactory.newVFloat(pvResult.getFloatField(fieldName != null ? fieldName : resultName).get(), ValueFactory.alarmNone(), ValueFactory.timeNow(), ValueFactory.displayNone());