@Override protected DataMessageComponent getTransformedMessage(List<DataMessageComponent> cache) throws ProcessingException { final DataMessageComponent ret = MessageUtils.mergeAll(cache); ret.putScalar("message_text", "Hello World"); return ret; }
private Map<String, String> setMotors(final MotorContainer cont, final DataMessageComponent comp) throws DataMessageException { final Map<String, String> ret = new HashMap<String, String>(cont.size()); for (MotorBean mb : cont.getExpressions()) { final String motorPath = SubstituteUtils.substitute(mb.getMotorName(), comp.getScalar()); final String baseUri = TangoUtils.getHardwareAddress(motorPath); String attribute = mb.getAttributeName(); if (attribute == null || "".equals(attribute.trim())) attribute = "Position"; DeviceAttribute value = null; if (!mb.isReadOnly()) { try { final double dbl = ExpressionUtils.evaluateExpression(mb.getExpression(), comp.getScalar()); if (Double.isNaN(dbl) || Double.isInfinite(dbl)) throw new Exception(); value = new DeviceAttribute(attribute, dbl); } catch (Exception e) { final String exp = SubstituteUtils.substitute(mb.getExpression(), comp.getScalar()); value = new DeviceAttribute(attribute, exp); } } try { final TangoConnection connection = TangoConnectionFactory.openConnection(baseUri, attribute); if (value != null) { connection.setValue(value); // Uses remote call for MockMode } try { value = connection.getValue(); } catch (Exception ne) { logger.debug("Error in TangoMotorTransformer " + getName()); logger.debug("Error message: " + ne.getMessage()); logger.debug(ne.getStackTrace().toString()); value = new DeviceAttribute(attribute, 0.0); } try { final String dblString = String.valueOf(value.extractDouble()); ret.put(connection.getName(), dblString); } catch (Exception ne) { ret.put(connection.getName(), String.valueOf(value.extractString())); } } catch (Exception e) { throw createDataMessageException("Cannot connect to " + baseUri, e); } } return ret; }
protected DataMessageComponent getTransformedMessage( List<DataMessageComponent> port1Cache, List<DataMessageComponent> port2Cache) throws ProcessingException { final List<IDataset> sets1 = MessageUtils.getDatasets(port1Cache); final List<IDataset> sets2 = MessageUtils.getDatasets(port2Cache); final Collection<IDataset> sets = new HashSet<IDataset>(7); if (sets1 != null) sets.addAll(sets1); if (sets2 != null) sets.addAll(sets2); final AbstractDataset prod = Maths.multiply(sets, isCreateClone()); try { final DataMessageComponent ret = new DataMessageComponent(); ret.setList(prod); setUpstreamValues(ret, port1Cache, port2Cache); ret.putScalar("operation_names", MessageUtils.getNames(sets)); return ret; } catch (Exception e) { throw createDataMessageException("Cannot generate multiplied data sets", e); } }
@Override protected DataMessageComponent getTransformedMessage(List<DataMessageComponent> cache) throws ProcessingException { try { final MotorContainer cont = (MotorContainer) motorsParam.getBeanFromValue(MotorContainer.class); final DataMessageComponent comp = MessageUtils.mergeAll(cache); if (cont == null) { comp.putScalar("error_messsage", "No motors configured, '" + getName() + "' did nothing."); return comp; } final Map<String, String> values = setMotors(cont, comp); if (values != null) comp.addScalar(values); return comp; } catch (Exception e) { throw createDataMessageException("Cannot set motor values!", e); } }