GeoEvent SDK: Custom Component File Storage

480
0
06-04-2020 02:19 PM
EricIronside
Esri Regular Contributor
0 0 480

When writing a custom component for GeoEvent using the GeoEvent SDK, it is sometimes helpful to cache some information to the file system. This information could be a cache of the most recent data or configuration properties. This blog shows you how to allocate a folder within the GeoEvent file structure that will allow you create files and store data that will persist through GeoEvent Server restarts.

Step 1: OSGI Blueprint Configuration

The first step is to modify the config.xml file under your src/main/resources/OSGI-INF/blueprint/ folder.  You need to add the following property to your <bean>:

<property name="dataFolder" value="./data/yourfolder" />

For example:

<bean id="myTransportServiceBean" class="com.esri.geoevent.transport.example.MyTransportService" activation="eager">

<property name="bundleContext" ref="blueprintBundleContext" />
<property name="dataFolder" value="./data/mytransport" />

</bean>

The base directory is the install directory for GeoEvent Server (default on Windows is c:\Program Files\arcgis\server\geoevent\ ). Within the GeoEvent Server install folder there are two directories that are recommended for use:

  • ./data/: The data directory is a file cache of information such as OSGI bundles, logs, and other temporary files. The files in this folder are used for caching the state of GeoEvent Server between restarts.  If you are storing a cache of your custom component's data or configuration information, this is an ideal location.
  • ./assets/: The assets folder is a place where you can store information that will be available on the GeoEvent Server Manager's web server.  You can use this location to store any information that may potentially be accessed via a browser. This could be configuration information or a status page for your custom component.  Items in this folder can be accessed using the following URL: https://yourServerName:6143/geoevent/assets/

Step 2: Add a setDataFolder() method to your Service

After you make the config.xml file change above, OSGI will inject a folder location into your service bean.  Within your Service Java class, you need to add a setter method to allow the framework to inject this folder object.  Here's an example transport Service class:

public class MyTransportService extends TransportServiceBase {

protected static File dataFolder;
public MyTransportService() {

definition = new XmlTransportDefinition(getResourceAsStream("geotab-transport-definition.xml"));

}

public void setDataFolder(File inDataFolder) {

dataFolder = inDataFolder;
if (!dataFolder.exists()) {

dataFolder.mkdirs();

}

}

@Override
public Transport createTransport() throws ComponentException {

return new MyTransport(definition, dataFolder);

}

}

Step 3: Use the folder

After the above changes, your custom component will have access to a file folder location that can be used to store files.  As mentioned above, these files can contain configuration information, cached data, status information, or whatever you like.

About the Author
Esri Professional Services Real-Time GIS Team GeoEvent Sr. Product Enginner