-
Notifications
You must be signed in to change notification settings - Fork 39
Networking with janeway
Janeway communicates with the server by using the Network library, which consists of four key classes:
- Network
- NetworkConfiguration
- Request
- RequestObserver
The Network class is a singleton class designed to allow Janeway modules to easily create Requests using the default NetworkConfiguration
, as well as access and change the default NetworkConfiguration
. Network
's makeRequest
method will construct and return a Request
which uses the default NetworkConfiguration
. The getDefaultNetworkConfiguration
method returns the default NetworkConfiguration
. This allows you to get the configuration information necessary to construct your own Request
.
The NetworkConfiguration class stores information on how Requests should be made. Each instance of NetworkConfiguration stores the URL to the WPISuite API, a set of default request headers, and a set of RequestObservers. Request headers in a NetworkConfiguration, such as cookies, will be sent to the server by any Request using that NetworkConfiguration.
The Request class is used for setting up and initiating a request to the server. By default, all Requests are made asynchronously. This means that Janeway will continue to operate and accept input from the user while the Request is made. A request will be sent to the server after the send method is called.
The RequestObserver class is used for taking action when a Request completes or fails. They can be added to a Request via the Request#addObserver(RequestObserver)
method. If a Request is completed successfully, the responseSuccess method of all RequestObservers in that Request will be called. If the Request gets an error from the server, the responseError method will be called. Finally, if the Request is unable to be sent to the server due to a timeout or some other error, the fail method of the RequestObservers attached to the Request will be called.