Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X
Hello,
I keep banging my head against a very straightforward question -- what is the Thing's lifecycle?
I'm implementing my custom Thing Template in Java (let's say "MyThing extends Thing"), and have a number of very specific questions:
Thank you for any suggestions!
Can anybody provide update on this?
This is maintained in the Javadoc for the Thing class, so you can see it in your editor of choice.
For ease of use I'm pasting here the 7.3 information (please check your javadoc as it might differ based on version).
Each of the methods also have their own Javadoc btw, so you can see which are the objects to which you have access there.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
An entity containing services, properties, events, and subscriptions representing an instance of a thing based on a specified template.
Thing entities are one of the fundamental entity types in Thingworx. They are used to represent an instance of an object that is actionable (services), declarative (properties), reactive (events), and observable (subscriptions). Things must define a single ThingTemplate
to inherit shared functionality, as well as any number of ThingShape
s that add additional functionality that is independent of the ThingTemplate
hierarchy. The consolidation of all inherited functionality must not have any name collisions within the same behavioral type (i.e., a property and service can share the same name, but two services cannot).
All Things have the following lifecycle:
ThingState | OFF | → | ON | → | OFF | → | N/A |
Events | Inactive → Preinitializing (Entity) → Validating → Initializing (Entity) → Initializing (Thing) → Starting | → | Notifying → Active → Stopping | → | Cleaning Up → Deactivated | → | Disposing |
These lifecycle events correspond to the following methods:
State | Method | Description |
---|---|---|
Preinitialize (Entity) 1 | RootEntity#preInitializeEntity() | Occurs only during the entity import process. |
Validate1 | Thing#validateConfiguration(ImportedEntityCollection) | Occurs only during the entity import process. Validates all requirements of the entity. |
Initialize (Entity) | Thing#initializeEntity() | Initializes the entity. Should be used to initialize anything needed by thing initialization. |
Initialize (Thing) | Thing#initializeThing() | Initializes the thing. Should be used to construct the initial state of the thing. |
Start | Thing#startThing() | Brings the thing into an active state. Initialization should finish at this step. |
Notify | Thing#processStartNotification() | Thing has entered active state and is about to run. Any final processing must occur here. |
Stop | Thing#stopThing() | Thing has received a stop request. Any back-end processing should be torn down. |
Cleanup | Thing#cleanupThing() | Thing has stopped and needs to clean up its resources. Any managed resources should be cleaned up. |
Dispose | Thing#dispose() | Removes any remaining references of this entity (e.g., networks). |
Note 1: The preinitialization and validation states only execute when a Thing is imported. They are skipped when the entity is created from the persistence store.
When developing extensions, you must extend from the Thing
class for any classes that are assigned to a com.thingworx.thingpackages.ThingPackage entity. If the package is assigned to a thing in the extension, then the code will execute in the context of that entity. If the package is assigned to a thing template, then the code will execute in the context of the things that have been created with the thing template in its hierarchy.
Thing
is not thread-safe nor is it designed to be mutated by multiple threads simultaneously.