cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

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

What is the Thing lifecycle?

ckulak
12-Amethyst

What is the Thing lifecycle?

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:

  1. When MyThing class is loaded by the classloader?
  2. When is MyThing constructor called?
  3. How many instances of MyThing are in memory at the same time?
  4. When startThing() / stopThing() are called?
  5. What happens when I EnableThing / DisableThing / RestartThing?
  6. When MyThing instances get garbage-collected?

Thank you for any suggestions!

2 REPLIES 2

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  ThingShapes 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: 

ThingStateOFF→ON→OFF→N/A
EventsInactive → Preinitializing (Entity) → Validating → Initializing (Entity) → Initializing (Thing) → Starting→Notifying → Active → Stopping→Cleaning Up → Deactivated→Disposing

  These lifecycle events correspond to the following methods: 

StateMethodDescription
Preinitialize (Entity) 1RootEntity#preInitializeEntity()Occurs only during the entity import process.
Validate1Thing#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.
StartThing#startThing()Brings the thing into an active state. Initialization should finish at this step.
NotifyThing#processStartNotification()Thing has entered active state and is about to run. Any final processing must occur here.
StopThing#stopThing()Thing has received a stop request. Any back-end processing should be torn down.
CleanupThing#cleanupThing()Thing has stopped and needs to clean up its resources. Any managed resources should be cleaned up.
DisposeThing#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.

Announcements


Top Tags