Skip to content

NHaystack as a server

esanderson edited this page May 22, 2021 · 4 revisions

1. Using NHaystack as a server

To get started with exposing a Niagara 4 station as a Haystack server, install nhaystack-rt.jar into a Niagara 4 station. Then open the nhaystack palette in Workbench, and drag-and-drop the NHaystackService onto the "/Services" folder of your station.

This is all you need to do to get rolling. Your station is now automatically serving up all its ControlPoint objects and Histories as haystack point [recs][rec], via the Haystack REST Api. Many of the tags that are defined as being associated with points, like kind, unit, tz, his, cur, etc. are automatically generated for you.

1.1 The Cache

The NHaystackService maintains an in-memory cache of all the Haystack records it finds in your Niagara Station. When you first add the NHaystackService to your station it needs to be enabled. This can be done from the Property Sheet of the NHaystackService. When the service initialises it builds the in-memory cache of the Haystack records it finds.

This process also happens when the station is started or restarted. If you examine the output from the Application Director of your station you will see a number of messages logged there advising of the status of the cache building process.

If at anytime whilst the station is running you make a change to any tags or site/equipment entities then it you must make sure you execute a cache rebuild. This can be done by finding the NHaystackService in your station and right-clicking on the service. From the context menu that appears select Actions->Rebuild Cache. If you do not do this then your changes will not appear in any queries to the NHaystackService from either internal or external clients.

1.2 The Haystack Servlet

When using the NHaystack module in Niagara and configuring your station as a Haystack server you will most likely want to enable the servlet. The NHaystackService comes with a built-in, fully compliant implementation of the Project Haystack REST API specification. This servlet enables external Haystack clients to interact with your Niagara Station.

To enable the built-in servlet that implements the Project Haystack REST API navigate to the Property Sheet of the NHaystackService in your station and you will find the property that enables the servlet. Additionally there is an opportunity to provide a custom name for the servlet. By default the servlet name is haystack and it is recommended that this default name remains unchanged as other clients will be expecting this servlet name as a defacto standard.

It is recommended to enable the servlet immediately after installing the NHaystackService so that other clients are able to interact with your station.