Per community requests, two methods were added into VI Java API 2.1 (GAed last summer) for changing the default connection and read timeouts. Both methods are defined in WSClient.java.
The first method setConnectTimeout() sets a specified timeout in milliseconds. It intends to be used when opening a communications link to the resource referenced by the URLConnection inside the WSClient object. If the timeout expires before the connection can be established, a java.net.SocketTimeoutException is raised. A timeout of zero is interpreted as an infinite timeout.
Lost VMs or Containers? Too Many Consoles? Too Slow GUI? Time to learn how to "Google" and manage your VMware and clouds in a fast and secure HTML5 App.
The second method setReadTimeout() sets a specified time in milliseconds. It intends to be used for reading from the server when a connection has been established. If the timeout expires before there is data available for read, a java.net.SocketTimeoutException is raised. A timeout of zero is interpreted as an infinite timeout.
Since these two methods are not commonly used, it’s only defined at WSClient.java type. To access them, you just need to get hold of the WSClient object, which may not as straight-forward as you expect it to be. But here is a quick sample:
WSClient wsc = si.getServerConnection().getVimService().getWsc(); wsc.setConnectTimeout(30*1000); wsc.setReadTimeout(10*1000);
Note that the si variable is the reference to a ServiceInstance object. Because getServerConnection() is defined in ManagedObject type, so you can use any reference to a VirtualMachine, HostSystem, etc.