ThingWorx Edge Java SDK > Application Details > VirtualThing Component > Binding to ThingWorx Platform
Binding to ThingWorx Platform
For the ThingWorx platform to interact with a virtual thing, the websocket over which the virtual thing connects to ThingWorx platform must be bound to the corresponding remote thing on the server instance. Use the ConnectedThingClient.bind() method to tell the platform to make this binding. The platform can then send request messages to your virtual thing, over the websocket. The bind action also changes the value of the isConnected property (to true) and the time value of the lastConnection property for the newly bound virtual thing. Your application can also call ConnectedThingClient.unbind() to tell the platform to remove the association between the remote thing and the websocket. The platform changes the value of the isConnected property to false.
Identifiers provide an alternate way to associate a virtual thing with a remote thing in the ThingWorx platform and at the device. It is important to remember that if you assign an identifier to the remote thing at the server, you must use that identifier in your client application because the server uses the identifier instead of the name to match a virtual thing connection to a remote thing. If you do not use the identifier in the client application, the server returns an error. It cannot match the client to the remote thing by the thing name once an identifier is configured for the remote thing on the server.
Using Overrides After Binding
To customize a client application, you can take advantage of overridable callback methods for a virtual thing. These callback methods are not required; rather you may want to use them to add custom processes to your application. The following callback methods are available:
afterBinding() — Called after the binding of the virtual thing is complete.
afterUnbinding() — Called after the unbinding of the virtual thing is complete.
afterEnable() — Called after the virtual thing has been enabled.
afterDisable() — Called after the virtual thing has been disabled.
processScanRequest() — This method performs no operations and is empty (a “no-op”). It provides a common interface for a callback method for customizing the scan cycle of a virtual thing. You can then set up a thread to execute this function periodically and drive scheduled activities. One example would be reading a sensor value, setting a property with the new value, and then pushing the updated property to the server. See the file in the samples directory for an example.
synchronizedState() — Called when the client first connects to the ThingWorx platform, as well as whenever changes are made to the associated remote thing on the server. This method is useful for sending initial data (if it does not change regularly) or when a reconnect occurs.