protected void handlePerformNotifyDataChange ( final Variant value, final Map<String, Variant> attributes, final boolean cache ) final DataItemValue.Builder newValue = new Builder ( this.value ); newValue.setAttributes ( new HashMap<String, Variant> ( attributes ) ); AttributesHelper.mergeAttributes ( newValue.getAttributes (), attributes ); newValue.setValue ( value ); this.value = newValue.build ();
protected DataItemValue processHandler ( DataItemValue value ) { logger.debug ( "Processing handlers" ); final ArrayList<HandlerEntry> handler; synchronized ( this.itemHandler ) { handler = new ArrayList<HandlerEntry> ( this.itemHandler ); } final Map<String, Object> context = new HashMap<String, Object> (); final DataItemValue.Builder builder = new Builder ( value ); for ( final HandlerEntry entry : handler ) { logger.debug ( "Process: {} -> {}", new Object[] { entry.getPriority (), entry.getHandler () } ); entry.getHandler ().dataUpdate ( context, builder ); } if ( this.debug ) { builder.setAttribute ( "master.debug.handlerCount", Variant.valueOf ( handler.size () ) ); value = builder.build (); } return builder.build (); }
protected void handlePerformNotifySubscriptionChange ( final SubscriptionState subscriptionState, final Throwable subscriptionError ) { final DataItemValue.Builder newValue = new DataItemValue.Builder ( this.value ); newValue.setSubscriptionState ( subscriptionState ); newValue.setSubscriptionError ( subscriptionError ); final DataItemValue oldValue = this.value; this.value = newValue.build (); setChanged (); try { notifyObservers ( this.value ); this.propertySupport.firePropertyChange ( PROP_VALUE, oldValue, this.value ); } catch ( final Throwable e ) { logger.warn ( "Failed to notify subscription change", e ); } }
@Override protected void processDataUpdate ( final Map<String, Object> context, final DataItemValue.Builder builder ) throws Exception final Variant originalValue = builder.getValue (); builder.setSubscriptionState ( SubscriptionState.CONNECTED ); builder.setSubscriptionError ( null ); builder.setAttribute ( this.attrValueOriginal, originalValue ); builder.setAttribute ( this.attrActive, Variant.TRUE ); builder.setAttribute ( getPrefixed ( null, null ), Variant.TRUE ); builder.setValue ( this.state.getValue () ); builder.setAttribute ( this.attrUser, Variant.valueOf ( state.getUser () ) ); builder.setAttribute ( this.attrReason, Variant.valueOf ( state.getReason () ) );
builder.setAttribute ( this.attributeActive, Variant.valueOf ( this.active ) ); builder.setAttribute ( this.attributeState, Variant.valueOf ( this.state ) ); builder.setAttribute ( this.attributeUnsafe, Variant.valueOf ( this.unsafe ) ); builder.setAttribute ( this.attributeInfo, Variant.valueOf ( this.alarm ) ); builder.setAttribute ( this.attributeInfoAckRequired, Variant.valueOf ( this.akn ) ); break; case WARNING: builder.setAttribute ( this.attributeWarning, Variant.valueOf ( this.alarm ) ); builder.setAttribute ( this.attributeWarningAckRequired, Variant.valueOf ( this.akn ) ); break; case ALARM: builder.setAttribute ( this.attributeAlarm, Variant.valueOf ( this.alarm ) ); builder.setAttribute ( this.attributeAlarmAckRequired, Variant.valueOf ( this.akn ) ); break; case ERROR: builder.setAttribute ( this.attributeError, Variant.valueOf ( this.alarm ) ); builder.setAttribute ( this.attributeErrorAckRequired, Variant.valueOf ( this.akn ) ); break;
protected void handlePerformNotifyDataChange ( final Variant value, final Map<String, Variant> attributes, final boolean cache ) final DataItemValue.Builder newValue = new Builder ( this.value ); newValue.setAttributes ( new HashMap<String, Variant> ( attributes ) ); AttributesHelper.mergeAttributes ( newValue.getAttributes (), attributes ); newValue.setValue ( value ); this.value = newValue.build ();
@Override protected void performDataUpdate ( final Map<String, Object> context, final Builder builder ) { if ( builder.getSubscriptionState () != SubscriptionState.CONNECTED ) { setUnsafe (); return; } final Variant value = builder.getValue (); if ( value == null || value.isNull () ) { setUnsafe (); return; } if ( builder.getAttributes () != null ) { final Variant errorAttr = builder.getAttributes ().get ( "error" ); if ( errorAttr != null && errorAttr.asBoolean () ) { // error attribute set to "true" setUnsafe (); return; } } performValueUpdate ( context, builder, value ); }
@Override protected synchronized void stateChanged ( final DataItemValue value ) { logger.debug ( "state change: {}", value ); if ( value != null ) { if ( value.isConnected () || this.dontOverrideSubscription ) { this.sourceValue = value; } else { final Builder builder = new Builder ( value ); builder.setSubscriptionState ( SubscriptionState.CONNECTED ); this.sourceValue = builder.build (); } } else { final Builder builder = new Builder (); builder.setAttribute ( "master.source.error", Variant.TRUE ); builder.setAttribute ( "master.datasource.id", Variant.valueOf ( this.dataSourceId ) ); this.sourceValue = builder.build (); } reprocess (); }
@Override public void dataUpdate ( final Map<String, Object> context, final DataItemValue.Builder builder ) { // convert source errors convertSource ( builder ); for ( final Entry entry : this.entries ) { entry.start ( context, builder ); } // sum up for ( final Map.Entry<String, Variant> valueEntry : builder.getAttributes ().entrySet () ) { final Variant pValue = valueEntry.getValue (); final String name = valueEntry.getKey (); for ( final Entry entry : this.entries ) { entry.check ( name, pValue ); } } for ( final Entry entry : this.entries ) { entry.end ( context, builder ); } }
private DataItemValue applyAutoTimestamp ( DataItemValue value ) { if ( value != null && value.getTimestamp () == null ) { try { if ( !this.lastValue.equals ( value.getValue () ) ) { this.lastTimestamp = Calendar.getInstance (); } } catch ( final Exception e ) { // nothing logger.info ( "Failed to update timestamp", e ); } final DataItemValue.Builder builder = new DataItemValue.Builder ( value ); builder.setTimestamp ( this.lastTimestamp ); value = builder.build (); } return value; }
private DataItemValue applyAutoTimestamp ( DataItemValue value ) { if ( value != null && value.getTimestamp () == null ) { try { if ( !this.lastValue.equals ( value.getValue () ) ) { this.lastTimestamp = Calendar.getInstance (); } } catch ( final Exception e ) { // nothing logger.info ( "Failed to update timestamp", e ); } final DataItemValue.Builder builder = new DataItemValue.Builder ( value ); builder.setTimestamp ( this.lastTimestamp ); value = builder.build (); } return value; }
public void convertSource ( final Builder builder ) { Variant sourceValue; sourceValue = builder.getAttributes ().remove ( this.tag ); if ( sourceValue != null ) { builder.setAttribute ( this.attributeName, sourceValue ); } sourceValue = builder.getAttributes ().remove ( this.attributeCountName ); if ( sourceValue != null && this.debug ) { builder.setAttribute ( String.format ( "%s.%s.count", this.prefix, this.tag ), sourceValue ); } sourceValue = builder.getAttributes ().remove ( this.tag + ".items" ); if ( sourceValue != null && this.debug ) { builder.setAttribute ( String.format ( "%s.%s.items", this.prefix, this.tag ), sourceValue ); } }
@Override public void dataUpdate ( final Map<String, Object> context, final DataItemValue.Builder builder ) { if ( builder == null ) { return; } try { processDataUpdate ( context, builder ); } catch ( final Throwable e ) { builder.setAttribute ( getPrefixed ( "error", Activator.getStringInterner () ), Variant.TRUE ); builder.setAttribute ( getPrefixed ( "error.message", Activator.getStringInterner () ), Variant.valueOf ( e.getMessage () ) ); } }
protected void injectAttributes ( final Map<String, Object> context, final Builder builder ) { if ( this.configuration == null ) { return; } if ( this.configuration.active ) { context.putAll ( this.configuration.markers ); } if ( this.configuration.exportAttribute ) { if ( this.configuration.active || this.configuration.alwaysExport ) { builder.setAttribute ( this.attrActive, Variant.valueOf ( this.configuration.active ) ); } } }
protected void handlePerformNotifySubscriptionChange ( final SubscriptionState subscriptionState, final Throwable subscriptionError ) { final DataItemValue.Builder newValue = new DataItemValue.Builder ( this.value ); newValue.setSubscriptionState ( subscriptionState ); newValue.setSubscriptionError ( subscriptionError ); final DataItemValue oldValue = this.value; this.value = newValue.build (); setChanged (); try { notifyObservers ( this.value ); this.propertySupport.firePropertyChange ( PROP_VALUE, oldValue, this.value ); } catch ( final Throwable e ) { logger.warn ( "Failed to notify subscription change", e ); } }
public Calendar getTimestamp () { return getAsTimestamp ( "timestamp" ); }
@Override protected void processDataUpdate ( final Map<String, Object> context, final DataItemValue.Builder builder ) throws Exception { injectAttributes ( builder ); if ( this.active ) { builder.setAttribute ( this.attrValueOriginal, builder.getValue () ); } final Variant val = builder.getValue (); if ( val == null || val.isNull () ) { return; } builder.setValue ( handleDataUpdate ( builder.getValue () ) ); }
public void start ( final Map<String, Object> context, final Builder builder ) { this.contextSet = getContextSet ( context, this.contextAttribute ); if ( this.debug ) { builder.setAttribute ( this.prefix + ".before", Variant.valueOf ( StringHelper.join ( this.contextSet, "," ) ) ); } this.matches = 0; }
protected void injectAttributes ( final Builder builder ) { builder.setAttribute ( this.attrActive, this.active ? Variant.TRUE : Variant.FALSE ); }
public static Long getTimestamp ( final Builder builder ) { if ( builder == null || builder.getAttributes () == null ) { return null; } final Variant attr = builder.getAttributes ().get ( "timestamp" ); if ( attr == null ) { return null; } return attr.asLong ( null ); }