I try to get changed value of a tag with subscribe Async :
I have this in setup(GatewayContext context) GatewayHook :
GatewayTagManager tagManager = context.getTagManager();
TagPath Tag1 = TagPathParser.parse("[Default]test1");
TagListener tagChangeListener = new TagListener();
tagManager.subscribeAsync(Tag1,tagChangeListener);
And in TagListener implements TagChangeListener :
public void tagChanged(TagChangeEvent tagChangeEvent) throws InvalidListenerException {
logger.info("value:"+String.valueOf(tagChangeEvent.getValue()));
logger.info("path"+String.valueOf(tagChangeEvent.getTagPath()));
}
But I don't see anything in the gateway when I change the value of the tag
You aren't doing anything with the return value of .subscribeAsync(), so you'll miss any exceptions that would have been reported to the CompletableFuture. You should use .whenComplete() to provide a handler that can log success or exception from the subscribe operation itself.
In the lambda above, v is a placeholder for the CompletableFuture's result, but that is void for this interface, so not used. t is the placeholder for the CompletableFuture's exception result, which you log if not null.
I noticed that you are implementing a managed tag provider. I don't know enough about them to help much, but if the tag in question is yours (inside the managed provider), it matters how you are changing the value. Something must initiate the tag change notification. I suspect when implementing a managed provider, that would be you.
Try subscribing to a tag path that is in the default provider, and changing that tag.
I figured that out. I'm suggesting you try a variation that will isolate your problem to either the managed provider machinery or the listener machinery. Please add a listener to a tag that isn't in your provider and see if you get change events from it.
Actually, consider variable lifetimes. I don't know if the tag manager holds a direct reference to listeners or weak references to listeners. If the latter, your listener would no longer have a reference after your .setup() method exits, and would be garbage collected shortly thereafter. Try using a listener that has a lifetime anchored by a field in your hook class.
Examine the reported error line numbers. Add more logging until you narrow down which element is null when you aren't expecting a null. Then try to understand why it is null.