ThingWorx Edge Java SDK Edge Extensions > Defining Services for an ETS
Defining Services for an ETS
The EdgeThingShape supports service definitions through its EdgeThingShapeServices interface. You can create service definitions using the defineService method or an annotation. When creating a service definition for an ETS, make sure that you do it the same way as when defining services for a VirtualThing.
Each Edge Thing Shape (ETS) extends EdgeThingShape. When it extends this class, an ETS has access to protected member functions that provide required services that all ETS instances can depend on. The member functions of the EdgeThingShapeServices interface that the ETS base class is required to implement are shown in the following UML diagram:
list of methods for the EdgeThingShapeServices interface
getIdentifier() Method
This method returns the identifier string from the annotation of this class. It provides a unique name
getThingInstance() Method
This method returns a reference to the EdgeThingTemplate instance that constructed this ETS. Ue this method in conjunction with the ETT function getShapeInstances() to enumerate all of the ETS instances inside the given ETT.
Other Methods
All other methods are convenience methods, providing services that you can access directly by calling getThingInstance().<servicename>.
The following example is taken from the InventoryEdgeShape in the section, Examples of Creating an ETT and an ETS. It shows how to create a service that returns the inventory table as an infotable:
/**
* Returns the entire inventory as an InfoTable
* @return current inventory
*/
@ThingworxServiceDefinition( name="currentInventory",
description="displays the Inventory")
@ThingworxServiceResult( name = CommonPropertyNames.PROP_RESULT,
description="The inventory", baseType="INFOTABLE" )
public InfoTable currentInventory( ){
InfoTablePrimitive inventoryTable = (InfoTablePrimitive)
getProperty("inventory").getValue();
InfoTable inventoryTableVal = inventoryTable.getValue();
return inventoryTableVal;
}
The inventory example also has a service that adds items to the infotable.
Was this helpful?