subscribeAsync get tag changed

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 :confused:

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.

Can i have an example how i can do this ?

Assuming the logger is a final variable, it should look something like this:

tagManager.subscribeAsync(Tag1,tagChangeListener).whenComplete((v, t) -> {
	if (t == null)
		logger.info("Subscribe Success");
	else
		logger.warn("Subscribe Fail", t)
});

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 have a Success subscription, but when I change the value of the tags the tagChanged function does not start.

@Override
public void tagChanged(TagChangeEvent tagChangeEvent) throws InvalidListenerException {
     logger.info("value:" + String.valueOf(tagChangeEvent.getValue()));
     logger.info("path" + String.valueOf(tagChangeEvent.getTagPath()));
    }

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.

 @Override
    public void setup(GatewayContext context) {
        try {
            this.context = context;
            GatewayTagManager tagManager = context.getTagManager();
            TagPath Tag1 = TagPathParser.parse("[test]testSDK1");
            TagListener tagChangeListener = new TagListener();
            //tagManager.subscribeAsync(Tag1,tagChangeListener).get(30, TimeUnit.SECONDS);.
            tagManager.subscribeAsync(Tag1,tagChangeListener).whenComplete((v, t) -> {
                if (t == null)
                    logger.info("Subscribe Success 1");
                else
                    logger.warn("Subscribe Fail 1", t);
            });

Here is what I do, I created a test provider and inside I have two tags testSDK1 and testSDK2 that I change manually from the designer.

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.

No it's the same behavior, I have no change, is there a specific config :confused:

I don't have any module using the manage tag provider infrastructure, so I'm out of ideas.

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.

I tried but it doesn't work thank you for your help :slight_smile:

now i have this error here is what i do

 @Override
    public void tagChanged(TagChangeEvent tagChangeEvent) {
        logger.info("test value=/%s"+tagChangeEvent.getValue().getValue());
        logger.info("test path=/%s"+tagChangeEvent.getTagPath());
    }

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.