@Override public Class<T> getType() { return valueCache.getType(); }
@Override @SuppressWarnings("unchecked") public boolean updateCache(ValueCache cache, Object connection, Object message) { Object oldValue = cache.readValue(); cache.writeValue(message); if ((message == oldValue) || (message != null && message.equals(oldValue))) return false; return true; } };
@Override public void writeValue(T newValue) { synchronized(forwardFunction) { valueCache.writeValue(newValue); R forwardValue = forwardFunction.readValue(); forwardWriter.writeValue(forwardValue); } }
@Override public T readValue() { return valueCache.readValue(); }
/** * Creates a constant expression that always return that object, with the * given name for the expression. * This is useful to test expressions or to introduce data that is available * at connection time at that will not change. * * @param <T> type of the value * @param value the actual value * @param name the name of the expression * @return an expression that is always going to return the given value */ public static <T> DesiredRateExpression<T> constant(T value, String name) { Class<?> clazz = Object.class; if (value != null) clazz = value.getClass(); @SuppressWarnings("unchecked") ValueCache<T> cache = (ValueCache<T>) new ValueCacheImpl(clazz); if (value != null) cache.writeValue(value); return new DesiredRateExpressionImpl<T>(new DesiredRateExpressionListImpl<T>(), cache, name); }
@Override @SuppressWarnings("unchecked") public boolean updateCache(ValueCache cache, JCAConnectionPayload connPayload, JCAMessagePayload message) { Channel channel = connPayload.getChannel(); // If metadata is required and not present, no update if (epicsMetaType != null && message.getMetadata() == null) return false; // If value is not present, no update if (message.getEvent() == null) return false; Object value = createValue(message.getEvent().getDBR(), message.getMetadata(), connPayload); cache.writeValue(value); return true; }
/** * Formats the error message in case of not unique match. This * allows data sources to give more specific error messages. * * @param cache the cache used for the match * @param connection the connection payload used for the match * @param match the result of the match * @param matchedConverters the matched converters; will either be 0 (no match) * or more than 1 (non unique match) * @return the message to be passed with the exception */ protected String formatMessage(ValueCache<?> cache, Object connection, int match, List<? extends DataSourceTypeAdapter<?, ?>> matchedConverters) { if (matchedConverters.isEmpty()) { return "DataSource misconfiguration: no match found to convert payload to type. (" + cache.getType() + " - " + connection + ")"; } else { return "DataSource misconfiguration: multiple matches found to convert payload to type. (" + cache.getType() + " - " + connection + ": " + matchedConverters + ")"; } } }
@Override @SuppressWarnings("unchecked") public boolean updateCache(@SuppressWarnings("rawtypes") ValueCache cache, PVAChannelHandler channel, PVStructure message) { PVField valueField = null; String extractFieldName = channel.getExtractFieldName(); if (extractFieldName != null) { if (channel.getChannelType().getType() == Type.structure) message = message.getStructureField(extractFieldName); else // this avoids problem when scalars/scalar arrays needs to be passed as PVStructure message valueField = message.getSubField(extractFieldName); } Object value = createValue(message, valueField, !channel.isConnected()); cache.writeValue(value); return true; }
@Override public int match(ValueCache<?> cache, JCAConnectionPayload connPayload) { Channel channel = connPayload.getChannel(); // If the generated type can't be put in the cache, no match if (!cache.getType().isAssignableFrom(typeClass)) return 0; // If the type of the channel does not match, no match if (!dbrTypeMatch(epicsValueType, connPayload.getFieldType())) return 0; // If processes array, but count is 1, no match if (array != null &&array && channel.getElementCount() == 1) return 0; // If processes scalar, but the count is not 1, no match if (array != null && !array && channel.getElementCount() != 1) return 0; // Everything matches return 1; }
if (!cache.getType().isAssignableFrom(typeClass)) return 0;