ThingWorx Edge Java SDK > Application Details > VirtualThing Component > Defining Events
Defining Events
Event definitions describe interrupts that the ThingWorx platform can subscribe to for purposes of receiving notifications when something happens. Events require a data shape for event data. Events can be defined directly in code or by using annotations (listed below), but the data shape required by the event must be defined in code.
The examples use the following data shape (put this code in the constructor or a method called from the constructor):
FieldDefinitionCollection fields = new FieldDefinitionCollection();
new FieldDefinition("ErrorMessage", BaseTypes.STRING));
this.defineDataShapeDefinition("ErrorEventShape", fields);
ThingWorxEventDefinitions — This annotation is a collection of ThingWorxEventDefinition annotations.
ThingWorxEventDefinition — Defines an event, with the following attributes:
name — Unique identifier of an event.
description — An explanation of the event.
dataShape — The name of the data shape that defines the event data.
category — A category name for the event.
isInvocable — A Boolean, indicating whether the event can be invoked from code.
isPropertyEvent — A Boolean, indicating whether the event is associated with a property.
The example below shows how you might add a ThingWorxEventDefinition to a ThingWorxEventDefinitions collection.
@ThingWorxEventDefinitions(events = {

description="Event that sends an error",