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

Community Tip - You can change your system assigned username to something more personal in your community settings. X

Java Based ThingsShape

imor
1-Newbie

Java Based ThingsShape

Hi

I am trying to create a sophisticated Java based ThingShape, which contains several services.

In one of those services, i would like to read the value of one of the properties,

which were defined in the ThingShape, and were received their value from the implemented Thing.

The only workaround i was able to find, is to use ThreadLocalContext.getMeContext() inside the service,

which return the Thing which implements that ThingsShape, and which fire the ThingShape's service,

and then iterate over it's properties.

Can you please confirm that this is the Bast practice for getting the Thing which call the ThingShape's service?

Thank you

Ido

7 REPLIES 7
asinclair
1-Newbie
(To:imor)

I'd also be interested to know if this is the recommended method.

Hi

The best I can say is that I received code for an example ThingShape from PTC Tech Support which used that technique to get the Thing.

Regards

Ian

Thanks, Ian. I am going to give this a try.Any chance you could share the ThingShape sample from PTC?

Hey Ian Can you send the example ThingShape code to my email id rattle007@gmail.com.

The following java code sets a timestamp on the current thing but only if the property "LastMessage" is defined.

Thing me = (Thing)ThreadLocalContext.getMeContext(); // Returns the thing in whose context this service is running

Date now = new Date();

try {

me.setPropertyValue("LastMessage", new DatetimePrimitive(now.getTime()));

} catch (Exception e) {

// Don't care if the power source thing does not have a LastMessage property

}

I think if you want to iterate through the properties of the thing as suggested above you can make a call like this and then loop through the rows of the InfoTable ...

InfoTable myProperties = me.GetPropertyDefinitions(null, null, null); // Returns all thing property definitions

Thanks andy

Can I get any information or sample code for how i will create a thing or thingshape or thing template in java.?

can you help me regarding this?

Naveen, I strongly recommend that you read the Thingworx Extension Development Guide. If you have downloaded the ThingWorx Extension SDK you can find it on the PTC download page under Reference Documents. It is brief but it should get you going. -Andy

Top Tags