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.
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:
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);
}
}
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.