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

ConnectedThingClient : How to use in applications running for a long time

vaishnavee
13-Aquamarine

ConnectedThingClient : How to use in applications running for a long time

Hi,

 

I have a java web application that needs to connect to Thingworx foundation server and fetch data according to user's actions. One of the scenarios involves sequence of these operations -

1. Metadata creation - Fetch all ThingNames, Fetch properties of each Thing

2. Data operations - Fetch and filter historical data of Things with the help from the above fetched metadata. 

The first metadata creation is a heavy task and might be dealing with things counting in millions. This will be done in custom logic of chunks so that invokeservice request won't timeout. 

The second operations also needs to deal with huge data. 

During this time, how is the client supposed to be used? Do we disconnect/shutdown client after every invokeservice operation completes, and start client again at next service call? Or  we simply check for isConnected() before invokeservice to ensure no NullPointer and start client if needed?

 

Also, what is difference between client.shutdown() and client.disconnect() ? Can these methods be used interchangeably? 

 

Thank you!

ACCEPTED SOLUTION

Accepted Solutions

Hello @vaishnavee,

 

You can (and should) reuse ConnectedThingClient between requests, there's no need to disconnect after each operation.

 

You should call ConnectedThingClient::shutdown when you don't need the client anymore. It unbinds things gracefully (so that the platform is aware of the disconnect) and cleans up all allocated resources, and then disconnects. ConnectedThingClient::disconnect simply cuts the websocket, leaving the client unoperational until the next .connect(), so it's of little practical use. Here's what EDGE SDK JavaDocs says about disconnect():

Users will typically not use this method and will simply call the shutdown() method to close the connection to the server.

 

/ Constantine

View solution in original post

6 REPLIES 6
slangley
23-Emerald II
(To:vaishnavee)

Hi @vaishnavee.

 

Please provide additional information around your use case.  For example, how are you connecting to the ThingWorx Platform?  You indicated you may have millions of things.  Is this the current number or one you expect to grow to?

 

The answer to this question may require the assistance of our Global Services team (paid engagement) for reviewing your needs and developing a solution that will scale appropriately.

 

Regards.

 

--Sharon

slangley
23-Emerald II
(To:slangley)

Hi @vaishnavee.

 

If the previous response answered your questions, please mark it as the Accepted solution for the benefit of others with the same questions.

 

Regards.

 

--Sharon

vaishnavee
13-Aquamarine
(To:slangley)

Hi @slangley , there was a delay in response due to current pandemic situation. 

As you mentioned, we are dealing with a use case of data migration. So we want to get the data in to/out of ThingWorx platform. We will not be handling the actual object creation in ThingWorx. So for the probable case of huge data, we needed to understand if it is advisable to keep the Client open with sufficiently big timeout or keep it short and connect per api request.

 

Regards,

Vaishnavee 

slangley
23-Emerald II
(To:vaishnavee)

Hi @vaishnavee.

 

Please let us know if you have additional questions.

 

Regards.

 

--Sharon

 

 

Hello @vaishnavee,

 

You can (and should) reuse ConnectedThingClient between requests, there's no need to disconnect after each operation.

 

You should call ConnectedThingClient::shutdown when you don't need the client anymore. It unbinds things gracefully (so that the platform is aware of the disconnect) and cleans up all allocated resources, and then disconnects. ConnectedThingClient::disconnect simply cuts the websocket, leaving the client unoperational until the next .connect(), so it's of little practical use. Here's what EDGE SDK JavaDocs says about disconnect():

Users will typically not use this method and will simply call the shutdown() method to close the connection to the server.

 

/ Constantine

Thank you @Constantine for the answer. We will use shutdown instead of disconnect.

Announcements


Top Tags