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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Java Based ThingsShape

imor
1-Visitor

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
12-Amethyst
(To:imor)

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

ibanham
12-Amethyst
(To:asinclair)

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

asinclair
12-Amethyst
(To:ibanham)

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

ngourav
1-Visitor
(To:ibanham)

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

asinclair
12-Amethyst
(To:ngourav)

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?

asinclair
12-Amethyst
(To:ngourav)

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

Announcements


Top Tags