Is it possible to create a listener/callback for a Tag Provider for when the properties of a tag are updated?
I know you can create listeners for a GatewayTagProvider via the addTagStructureListener for tag creation, removal and movement (although from my experimentation moving a tag within the designer seems to trigger an added tag event, not a moved tag event - unclear when a tag move is triggered).
GatewayTagManager manager = context.getTagManager();
manager.addTagStructureListener("Sample_Tags", new TagStructureListener() {
public void tagStructureChanged(TagStructureEvent event){
event.getAddedTags().forEach((tag)->{
//process tag added
});
event.getMovedTags().forEach((pair) -> {
TagPath path = pair.getLeft();
NodeBrowseInfo info = pair.getRight();
//process tag moved
});
event.getRemovedTagsInfo().forEach((tag) -> {
//process tag removed
});
}
});
But from what I can find there does not seem to be a way to add a similar callback for configuration changes/updates to tags within any provider (GatewayTagProvider, TagProvider, ManagedTagProvider etc.). Is there a way I am missing/are there other approaches that are viable for this?
Thanks so much!
Found my answer shortly after posting lol. Seems like the approach is to use:
TagPath path; //path of desired tag
manager.subscribeAsync(path, new TagChangeListener(){
public void tagChanged(TagChangeEvent event) throws InvalidListenerException{
// handle tag change event
}
})
However a limitation of this approach is that this is triggered by all events including value updates which causes a lot of redundant work filtering out all non-value updates from the subscription. Ideally there would be a more efficient mechanism.
Please correct me if I’m mistaken.
Consider using the tag actor subsystem and registering properties of interest. (And having the resulting actors simply pass value changes along, while processing all conditional configuration changes.)
2 Likes
I’ve been playing around with them and TagActors seem fantastic for my use case! One wrinkle I’ve encountered is I can’t seem to figure out how to get attemptConfiguration to trigger for custom properties (both adding and updating don’t do anything - although the values are accessible via VersionedPropertySet.getExtension(). I assume it has to do with with the monitored properties and/or the ActorClassification of the TagActorFactory, but can’t seem to figure out.
Did you define these properties and inject them into tag models from your factory upon request? If not in the model, you cannot monitor them.
By “custom properties” I mean properties I injected into the property model using:
context.getTagManager().getConfigManager().registerTagPropertyContributor(...). Not the “Custom Properties” key-value pairs. Are these also not trackable via actor models?
That should do, I think, but that functionality is also part of registered tag actor factories. The key is that the factory needs to list its properties of interest.