The SDMConnectivity layer hides the complexity of network communication and provides easy to use APIs to the applications.
The SDMRequestManager class implements the ISDMRequestManager interface, which provides the following methods:
ISDMRequestManager void makeRequest(final ISDMRequest aRequest); void makeRequest(final ISDMBundleRequest aRequest); ConnectivityParameters getConnectivityParameter(); int getQueueSize(); Vector getAllRequests(); Object getRequest(); void setMainHandlerClassName(final String classname); void terminate(); boolean hasRequests(); void sendOnSuccess(final ISDMNetListener listener, final ISDMRequest request, finral HttpResponse response);
The number of working threads in the RequestManager class is configurable via the constructor. The number of threads is maximized by the connectivity layer because of performance related issues. If the client initializes the layer with more than the allowed threads, the implementation of the connectivity layer will decrease the thread number to the max allowed number (4).
Methods defined by the ISDMConnectivityParameters interface:
SDMConnectivityParameters void setUserName(final String aUserName); String getUserName(); void setUserPassword(final String aPassword); String getUserPassword(); void setBaseUrl(final String url); String getBaseUrl(); String getLanguage(); void setLanguage(final String language); void setServerCertificate(Certificate certificate) throws KeyStoreException; final TrustManager[] getTrustManagers();
SDMBundleRequest is a special set of SDMRequest objects. It provides serial processing of the requests when the SDMRequestManager is in multithreaded mode. Because the single SDMRequest objects are processed by multiple threads, the timing of the responses are not consistent. With SDMBundleRequest, one thread processes the bundled requests, guaranteeing that the responses are arriving in the same order as the requests are added to the bundle.
//create and fill parameters for Connectivity library SDMConnectivityParameters params = new SDMConnectivityParameters(); params.setUserName("test"); params.setUserPassword("testpwd"); mLogger = (ISDMLogger) new SDMLogger(); mPreferences = new SDMPreferences(getApplicationContext(), mLogger); //create the RequestManager mRequestManager = new SDMRequestManager(mLogger, mPreferences, params, 2); ISDMRequest testRequest = new SDMBaseRequest(); testRequest.setRequestUrl("http://test.de:8080/testpath"); testRequest.setRequestMethod(ISDMRequest.REQUEST_METHOD_GET); testRequest.setPriority(ISDMRequest.PRIORITY_NORMAL); //add the request to the connectivity layer mRequestManager.makeRequest(testRequest);
An application can have more than one SDMRequestManager instances, for example, when connecting to two different servers at the same time. To support this scenario, SDMRequestManager handles ConnectionHandler as a plugin. This kind of plugin needs to implement the ISDMConnectionHandler and implement a constructor taking three parameters: SDMRequestManager, ISDMLogger implementation and ISDMPreferences implementation.
The class name with package is set by SDMRequestManager.setMainHandlerClassName(String), or in SDMPreferences by the ISDMPreferences.SDM_CONNECTIVITY_HANDLER_CLASS_NAME preference key. The default plugin is "com.sybase.mobile.lib.client.IMOConnectionHandler", which handles connections through SUP.
An SDMRequest object wraps all the information needed by the connectivity library to be able to perform the requests. The connectivity library interacts with the request object to query the necessary information about the headers, the post data, and so on. The connectivity layer also uses the request object to notify the application about the result of the request by using the ISDMNetListener interface. The connectivity component provides an interface called ISDMRequest and a base implementation of it, called SDMBaseRequest. The applications have to extend this interface when creating new application specific requests.
ISDMRequest o void setRequestUrl(String url); o String getRequestUrl(); o void setRequestMethod(final int reqType); o int getRequestMethod(); o byte[] getData(); o Hashtable getHeaders(); o void setPriority(final int value); o int getPriority(); o boolean useCookies(); o ISDMNetListener getListener(); o void setListener(ISDMNetListener listener);
ISDMNetListener void onSuccess(ISDMRequest aRequest, HttpResponse aResponse); void onError(ISDMRequest aRequest, HttpResponse aResponse, SDMRequestStateElement aRequestStateElement);
ISDMRequestStateElement int getHttpStatusCode(); int getErrorCode(); Exception getException(); void setHttpStatusCode(final int httpStatus); void setErrorCode(final int code); void setException(final Exception aException);
Example public void onSuccess(ISDMRequest aRequest, SDMHttpResponse aResponse) { System.out.println("Http response status code:" + aResponse.getStatusCode()); System.out.println("Cookie string:" + aResponse.getCookieString()); byte[] content = aResponse.getContent(); String response = new String(content); System.out.println("Received content:" + response); //get the headers Hashtable headers = aResponse.getHeaders(); }