Class Service
- java.lang.Object
-
- com.openinventor.inventor.Inventor
-
- com.openinventor.remoteviz.rendering.Service
-
public class Service extends Inventor
Defines the RemoteViz rendering service. This class uses the singleton pattern restricting its instantiation to a single unique object in the program. Use theService.instance()method to get theServiceobject.To use RemoteViz, the service must first be opened with the method
Service.open(). Create an instance ofServiceSettingsto set properties such as theServiceIP address and port.Create an implementation of class
ServiceListenerto receive notifications from theService. Register a listener using theaddListener()method.The
Serviceobject can also be used to query the current Clients and RenderAreas.Thread-safety :
All methods in the RemoteViz API are thread-safe. I.e., they are guaranteed to be free of race conditions when accessed by multiple threads simultaneously. But note this limitation with the classService:- The methods
Service.open(),Service.close()andService.dispatch()must be called from the same thread.
- See Also:
ServiceSettings,ServiceListener,Client,RenderArea
- The methods
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.openinventor.inventor.Inventor
Inventor.ConstructorCommand
-
-
Field Summary
-
Fields inherited from class com.openinventor.inventor.Inventor
VERBOSE_LEVEL, ZeroHandle
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(ServiceListener listener)Adds aServiceListener.booleanclose()Closes the rendering service.voidcreateRenderArea(java.lang.String id, int width, int height, RenderAreaHardware renderAreaHardware)Forces the creation of a renderArea.voiddispatch()This method has to be used with theServiceSettings.INVENTOR_SERVICEandServiceSettings.INDEPENDENT_SERVICEmode in a loop.ClientgetClient(int index)Gets aClientfrom index.ClientgetClient(java.lang.String id)Gets aClientfrom id.intgetNumClients()Gets the number of clients.intgetNumListeners()Gets the number ofServiceListener.intgetNumRenderAreas()Gets the number of renderAreas.RenderAreagetRenderArea(int index)Gets aRenderAreafrom index.RenderAreagetRenderArea(java.lang.String id)Gets aRenderAreafrom id.ServiceSettingsgetSettings()Gets the settings of the service.static Serviceinstance()Renderering service instance (Singleton)booleanisRunning()This method is used to know if the rendering service is running.booleanopen(ServiceSettings settings)Opens the rendering service.voidremoveAllListeners()Removes all ServiceListeners.voidremoveListener(ServiceListener listener)Removes aServiceListener.-
Methods inherited from class com.openinventor.inventor.Inventor
dispose, getNativeResourceHandle
-
-
-
-
Method Detail
-
close
public boolean close()
Closes the rendering service. If renderAreas still exist, this method will dispose them and close the rendering service.- Returns:
- true if successful, otherwise returns false.
-
getNumClients
public int getNumClients()
Gets the number of clients.- Returns:
- the number clients attached to the service.
-
isRunning
public boolean isRunning()
This method is used to know if the rendering service is running.- Returns:
- true if running; otherwise returns false.
-
getClient
public Client getClient(int index)
Gets aClientfrom index. Range is [0..getNumClients - 1].- Parameters:
index- : index identifying the client- Returns:
- the client object if the index exists, otherwise returns null.
-
instance
public static Service instance()
Renderering service instance (Singleton)- Returns:
- the service instance
-
getSettings
public ServiceSettings getSettings()
Gets the settings of the service.- Returns:
- the service settings object
-
open
public boolean open(ServiceSettings settings)
Opens the rendering service.- Parameters:
settings- : the settings of the instance. This object cannot be null.- Returns:
- true if successful, otherwise returns false.
- See Also:
Service.getSettings
-
dispatch
public void dispatch()
This method has to be used with theServiceSettings.INVENTOR_SERVICEandServiceSettings.INDEPENDENT_SERVICEmode in a loop. It processes all waiting RemoteViz events.
-
removeListener
public void removeListener(ServiceListener listener)
Removes aServiceListener.- Parameters:
listener- : object that listens to the service events
-
getRenderArea
public RenderArea getRenderArea(int index)
Gets aRenderAreafrom index. Range is [0..getNumRenderAreas - 1].- Parameters:
index- : index identifying the renderArea- Returns:
- the renderArea object if the index exists, otherwise returns null.
-
addListener
public void addListener(ServiceListener listener)
Adds aServiceListener.- Parameters:
listener- : object that listens to the service events
-
getNumRenderAreas
public int getNumRenderAreas()
Gets the number of renderAreas.- Returns:
- the renderArea number of the Instance.
-
removeAllListeners
public void removeAllListeners()
Removes all ServiceListeners.
-
createRenderArea
public void createRenderArea(java.lang.String id, int width, int height, RenderAreaHardware renderAreaHardware)Forces the creation of a renderArea.
This method is optional. The other way to create a renderArea is to return true to the callback ServiceListener.onPendingCreateRenderArea when a connection requests it.
If the renderArea already exists, the call will be ignored.- Parameters:
id- : ID identifying theRenderAreawidth- : renderArea widthheight- : renderArea heightrenderAreaHardware- : renderArea hardware settings.
-
getClient
public Client getClient(java.lang.String id)
Gets aClientfrom id. Range is [0..getNumClients - 1].- Parameters:
id- : ID identifying the client- Returns:
- the client object if the id exists, otherwise returns null.
-
getRenderArea
public RenderArea getRenderArea(java.lang.String id)
Gets aRenderAreafrom id. Range is [0..getNumRenderAreas - 1].- Parameters:
id- : ID identifying theRenderArea- Returns:
- the renderArea object if the id exists, otherwise returns null.
-
getNumListeners
public int getNumListeners()
Gets the number ofServiceListener.- Returns:
- number of
ServiceListener.
-
-