How to save Tags with SimpleTagProvider?


I’m developing a module using SimpleTagProvider. I’m adding tags using SimpleTagProvider.configureTag().

I was just wondering if there is a straightforward way to:

  • Save these tags to the internal database, so that when the server is restarted these are automatically reloaded
  • Browse these tags and/or check if a given tag exists.

I guess this could be done with PersistentRecords, I’m wondering if there are wrapper classes that already take care of the details.

Our driver dynamically creates tags when we receive data from an RTU, but we are loosing the configuration if there is a re-start.


You’re right that there aren’t currently facilities for storing tags, per se. The SimpleTagProvider is built with the idea that the module would be configuring sets of tags each time it ran. When those tags are edited by the user (turning on alerting or history, for example), an “extension” is stored, but that’s about it. The extensions are a little special anyhow- they get paired up with the tags that are registered by the provider, and removed after a while if the module no longer registers those tags.

On one hand, I can see why you’re asking for this, but on the other hand, I’m not sure the SimpleTagProvider is the appropriate place for it. I would say for now, your best bet is to store it yourself either in the internal db with the persistent records, or simply in an external file, stored under GatewayContext.getHome().

In regards to browsing and/or checking, you can just browse the SQLTags system using GatewayContext.getTagManager() and the browse(…)/getTag(…) functions, with tag paths using your provider name as the source (for example, made with something like [tt]TagPathParser.parse(“MyProvider”,“Path/To/Tag”)[/tt])

Hope this helps,

Hi Colby,

Many thanks for your reply, it helps clarify things.

I’ve been browsing the javadocs now and looking at context.getTagManager(), I see that the SQLTagsManager object offers the createTagStore(long id) method. Do you think this could be suitable? I’m assuming that the CustomTagStore created would be based on whatever the default for the gateway is, i.e. internal database or external SQL.

If I persist the provided id for the CustomTagStore, would this still be valid after a module restart? (so I can recover the configuration)

Thanks again,


I suppose you might be able to do something with that, but it might be a bit clunky. That function is actually used by the SimpleTagProvider system to create a store for the extensions, but you don’t have access to the one it makes. You would be creating one in order to organize your tag objects, but it would really just be a storage mechanism- the objects in the tag store don’t show up anywhere. That is, you would still need to use the SimpleTagProvider to expose them.

The tag stores made by that function are only internal. In terms of how they work, the tag store is wrapped up in a tag provider, which watches it, and then actually executes the tags. If you were going to use one, you would call that create method (first with an id of 0, and then subsequently with the id that was created by that- it will be valid after restart, like you thought), then register a config listener, and then call startup. After calling startup, all items will be delivered through the config listener.

Ultimately though, I’m afraid that going this route will be a bit cumbersome. It seems that perhaps what you really should be doing is creating an OPC-UA driver, where the user would then create SQLTags on their own, which would persist forever. Unfortunately, that system is a bit more complex that this one.


Thanks again Colby.

The UA Driver route does not seem to match our concept that well. I’ll probably release a version of the module based on UA driver, but it will be limited in functionality and mostly as a compatibility option.

I think I need to implement a TagProvider “from scratch”, and possibly the TagStore as well, since using CustomTagStore seems like a little bit redundant path.

I searched the API for Record types but couldn’t find anything like a SQLTagRecord class. Is there something like that? Or should I just implement my own?