Application Configuration
First, you will define our WordCount application by creating a YAML configuration file. You will create an app directory called wordcount
and a config file called app.yaml
by running the following commands.
Next, you will define the name of the app, package ID, and the location of the jar file for WordCount. Add the following:
The JAR file will need to contain all the dependencies of the application. There are instructions to create the JAR further into this guide.
Grainite can manage lots of topics but for this application, you will define just one:
This defines a topic called line_topic
with the key hash
of type string
.
The topic_name
uniquely identifies a topic within the app, the key_name
provides a way for grains to subscribe to topics, while key_type
defines the type of the key. The value for key_type
is not limited to a primitive data type (string, int, long, etc) but can be anything that describes the key name (userId, username, buyerId, etc.).
Finally, you will define three tables for the application:
Line Table
Word Stats Table
Doc Stats Table
You will do this by adding the following to the configuration file.
Each table has a table_name
, key_type
, value_type
and action_handlers
.
The table_name
uniquely identifies a table, the key_type
and value_type
define the type of key and value for each grain in the table, and action_handlers
contain definitions for handlers in each grain, in the table.
Tables can also have maps
to define the type of data contained in each map. Each can have an id
, name
, key_type
and value_type
. The id
and name
are used to identify the map, while key_type
and value_type
are used to define the type of key and value for each entry in the map.
An Action Handler has a type
, actions
and some additional properties based on the provided type. The type defines the language that the action handler is written in:
Java action handlers require a class_name
which is the full class name of the defined Java class. These classes should be part of the project package (defined by package_id
).
Actions define the type of work that the action handlers are expected to handle. Each action is tied to a method in the action handler. For example, in WordCount, handleLineEvent
is the name of the action as well as the method in LineEventHandler
. It is possible to define a different method name for an action by specifying method_name
, but you will not be doing that for this application.
Subscriptions allow for action handlers to listen to a topic and stream events from it. As a result, when a new event is appended to a topic, all subscriptions for that topic are triggered and the method corresponding to the subscription is invoked. For example, in WordCount, when an event is appended to line_topic
, the event will be streamed to line_table
as part of the lineUpdates
subscription.
Last updated