<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Information on ThingStart Event and constructor and destructor for a Thing in ThingWorx Developers</title>
    <link>https://community.ptc.com/t5/ThingWorx-Developers/Information-on-ThingStart-Event-and-constructor-and-destructor/m-p/543436#M27268</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN&gt;Aditya,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;ThingStart occur every time a Thing is started (not just when it is created).&amp;nbsp; This occurs each time the Thing is saved (the platform removes the current running thing from the JVM in order to load/start the newly saved structure).&amp;nbsp; It will also occur when the platform starts up, when it enters and active state (if it was de-activated) or if the RestartThing service runs.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Do keep in mind that when the platform starts there is no predefined order in which each Thing will become active.&amp;nbsp; So if you are relying on another Thing in the platform (like a DataTable) to be available at this event,&amp;nbsp; you may have errors.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;To create a Thing you can use the Resources built in to the platform.&amp;nbsp; There&amp;nbsp;is an EntityServices resource (CreateThing) that you can use to create the Thing and the ValueStream (which is just a Thing with the ValueStream template).&amp;nbsp; After creating both you use the SetValueStream service on the new Thing to assign the value stream.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You should not need to&amp;nbsp;de-assign the ValueStream from the Thing if you are deleting that Thing.&amp;nbsp; They existing independently&amp;nbsp;so you can just delete them both.&amp;nbsp; However you would need to delete the Thing before the ValueStream since there is a dependency&amp;nbsp;there.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Let me know if that makes sense or if you have additional&amp;nbsp;questions.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Adam&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 04 Apr 2018 13:47:56 GMT</pubDate>
    <dc:creator>AdamR</dc:creator>
    <dc:date>2018-04-04T13:47:56Z</dc:date>
    <item>
      <title>Information on ThingStart Event and constructor and destructor for a Thing</title>
      <link>https://community.ptc.com/t5/ThingWorx-Developers/Information-on-ThingStart-Event-and-constructor-and-destructor/m-p/543335#M27242</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I have a requirement to perform some action at startup (like filling some data tables or running some services associated with Thingworx entities), for that I am using a subscription to ThingStart Event. But I would like to have some more insights on how and when does ThingStart event occurs/triggers. I read in some documentation, that ThingStart event is fired when the Thing is created, so does that mean it occurs only once in the lifetime of a Thing? I tried to look for some detailed information for ThingStart event, but was unable to find it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another part of my question is what is the provision to have constructor and destructor feature for Thingworx entities, say for example, I would like to associate my Things with a Value Stream, when it is created (so I could do - Create a new Thing, Create a new Value Stream and assign the ValueStream to a that thing).&lt;/P&gt;
&lt;P&gt;Similarly while destroying a Thing I would like to de-assign the Value stream, delete the thing and delete the value stream.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So how can I achieve this kind of behaviour in Thingworx?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;
&lt;P&gt;Aditya Mittal&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 02:58:40 GMT</pubDate>
      <guid>https://community.ptc.com/t5/ThingWorx-Developers/Information-on-ThingStart-Event-and-constructor-and-destructor/m-p/543335#M27242</guid>
      <dc:creator>amittal-3</dc:creator>
      <dc:date>2018-04-04T02:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: Information on ThingStart Event and constructor and destructor for a Thing</title>
      <link>https://community.ptc.com/t5/ThingWorx-Developers/Information-on-ThingStart-Event-and-constructor-and-destructor/m-p/543436#M27268</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN&gt;Aditya,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;ThingStart occur every time a Thing is started (not just when it is created).&amp;nbsp; This occurs each time the Thing is saved (the platform removes the current running thing from the JVM in order to load/start the newly saved structure).&amp;nbsp; It will also occur when the platform starts up, when it enters and active state (if it was de-activated) or if the RestartThing service runs.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Do keep in mind that when the platform starts there is no predefined order in which each Thing will become active.&amp;nbsp; So if you are relying on another Thing in the platform (like a DataTable) to be available at this event,&amp;nbsp; you may have errors.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;To create a Thing you can use the Resources built in to the platform.&amp;nbsp; There&amp;nbsp;is an EntityServices resource (CreateThing) that you can use to create the Thing and the ValueStream (which is just a Thing with the ValueStream template).&amp;nbsp; After creating both you use the SetValueStream service on the new Thing to assign the value stream.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You should not need to&amp;nbsp;de-assign the ValueStream from the Thing if you are deleting that Thing.&amp;nbsp; They existing independently&amp;nbsp;so you can just delete them both.&amp;nbsp; However you would need to delete the Thing before the ValueStream since there is a dependency&amp;nbsp;there.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Let me know if that makes sense or if you have additional&amp;nbsp;questions.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Adam&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 13:47:56 GMT</pubDate>
      <guid>https://community.ptc.com/t5/ThingWorx-Developers/Information-on-ThingStart-Event-and-constructor-and-destructor/m-p/543436#M27268</guid>
      <dc:creator>AdamR</dc:creator>
      <dc:date>2018-04-04T13:47:56Z</dc:date>
    </item>
    <item>
      <title>Re: Information on ThingStart Event and constructor and destructor for a Thing</title>
      <link>https://community.ptc.com/t5/ThingWorx-Developers/Information-on-ThingStart-Event-and-constructor-and-destructor/m-p/543572#M27285</link>
      <description>&lt;P&gt;Hello Adam,&lt;/P&gt;
&lt;P&gt;Thanks for the detailed reply on the queries that I had.&lt;/P&gt;
&lt;P&gt;I think that would be all the information I would need as of now on these topics. I shall 'accept it as Solution'.&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;
&lt;P&gt;Aditya&lt;/P&gt;</description>
      <pubDate>Thu, 05 Apr 2018 02:24:56 GMT</pubDate>
      <guid>https://community.ptc.com/t5/ThingWorx-Developers/Information-on-ThingStart-Event-and-constructor-and-destructor/m-p/543572#M27285</guid>
      <dc:creator>amittal-3</dc:creator>
      <dc:date>2018-04-05T02:24:56Z</dc:date>
    </item>
    <item>
      <title>Re: Information on ThingStart Event and constructor and destructor for a Thing</title>
      <link>https://community.ptc.com/t5/ThingWorx-Developers/Information-on-ThingStart-Event-and-constructor-and-destructor/m-p/545408#M27633</link>
      <description>&lt;P&gt;Hello Adam,&lt;/P&gt;
&lt;P&gt;Related to the above topic, I think we forgot to discuss one part which is -&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Say that the thing is deleted (which had a valuestream assigned to it), now that value stream is no longer required to be kept as a Resource, how will I know that now I should delete the value stream. I mean is there a possibility that I get the event when the&amp;nbsp; thing is deleted so that I can subscribe to that event to delete value stream or carry out other tear-down process which are required after delete of any particular thing, maybe remove its references from other places.&lt;/P&gt;
&lt;P&gt;Or do we have the possibility of some sort of destructor, to which we have access&amp;nbsp; and which gets called before the memory for that thing is de-allocated. So I can remove the references of the thing before its getting deleted in its destructor.&lt;/P&gt;
&lt;P&gt;I hope&amp;nbsp;I am able to pen down my query in proper manner, so that you can guide me, if I am thinking correctly or not.&lt;/P&gt;
&lt;P&gt;Thanks in advance&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;
&lt;P&gt;Aditya&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 08:57:32 GMT</pubDate>
      <guid>https://community.ptc.com/t5/ThingWorx-Developers/Information-on-ThingStart-Event-and-constructor-and-destructor/m-p/545408#M27633</guid>
      <dc:creator>amittal-3</dc:creator>
      <dc:date>2018-04-18T08:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: Information on ThingStart Event and constructor and destructor for a Thing</title>
      <link>https://community.ptc.com/t5/ThingWorx-Developers/Information-on-ThingStart-Event-and-constructor-and-destructor/m-p/547384#M28073</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN&gt;Aditya,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Apologies&lt;SPAN&gt;&amp;nbsp;for not seeing your reply sooner.&amp;nbsp; There is not any built in descructor event or call that can be caught in a subscription or service.&amp;nbsp; You could do a periodic check (using a daily scheduler) to see if there are value steams that are no longer attached to any other entity.&amp;nbsp; There is a service on each Thing named HasIncomingDependencies which can be called to check this.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Adam&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 May 2018 12:29:58 GMT</pubDate>
      <guid>https://community.ptc.com/t5/ThingWorx-Developers/Information-on-ThingStart-Event-and-constructor-and-destructor/m-p/547384#M28073</guid>
      <dc:creator>AdamR</dc:creator>
      <dc:date>2018-05-02T12:29:58Z</dc:date>
    </item>
  </channel>
</rss>

