* perform different operations or subscribe for event notifications.
*/
public final class SimulatorRemoteResource {
-
private long mNativeHandle;
private String mUri;
private int mConnType;
private Vector<String> mResInterfaces;
private boolean mIsObservable;
- private native void dispose();
-
- private SimulatorRemoteResource(long nativeHandle) {
- mNativeHandle = nativeHandle;
- }
-
@Override
protected void finalize() throws Throwable {
try {
- dispose();
+ nativeDispose();
} catch (Throwable t) {
throw t;
} finally {
}
}
- public enum VerificationType {
- GET, PUT, POST, DELETE;
+ /**
+ * Enum to represent the verification types which can be used by the client
+ * to verify the resource model of the remote resource.
+ */
+ public enum RequestType {
+ UKNOWN, GET, PUT, POST, DELETE;
}
/**
* API to get the URI for this resource.
*
- * @return Resource URI
+ * @return Resource URI.
*/
public String getURI() {
return mUri;
}
/**
- * API to get the connectivity type for this resource.
+ * API to get the address detail of the resource.
*
- * @return Connectivity type.
+ * @return Host address.
*/
- public SimulatorConnectivityType getConnectivityType() {
- return SimulatorConnectivityType.getConnectivityType(mConnType);
+ public String getHost() {
+ return mHost;
}
/**
- * API to get the list of resource types.
+ * API to get a unique Id of the resource.
*
- * @return Array of resource types.
+ * @return Unique ID.
*/
- public Vector<String> getResourceTypes() {
- return mResTypes;
+ public String getId() {
+ return mId;
}
/**
- * API to get the list of resource interfaces.
+ * API to get the connectivity type for this resource.
*
- * @return Array of resource interfaces.
+ * @return Connectivity type.
*/
- public Vector<String> getResourceInterfaces() {
- return mResInterfaces;
+ public SimulatorConnectivityType getConnectivityType() {
+ return SimulatorConnectivityType.getConnectivityType(mConnType);
}
/**
- * API to get host address and port information of the resource.
+ * API to get the list of resource types.
*
- * @return Host address.
+ * @return Resource types.
*/
- public String getHost() {
- return mHost;
+ public Vector<String> getResourceTypes() {
+ return mResTypes;
}
/**
- * API to get a unique Id of the resource .
+ * API to get the list of resource interfaces.
*
- * @return Unique ID.
+ * @return Resource interfaces.
*/
- public String getId() {
- return mId;
+ public Vector<String> getResourceInterfaces() {
+ return mResInterfaces;
}
/**
/**
* API to send GET request to the resource. Response will be notified
- * asynchronously via callback set for {@link IGetListener}.
+ * asynchronously via callback set for {@link GetResponseListener}.
*
* @param queryParams
* Map which can have the query parameter name and value.
/**
* API to send GET request to the resource. Response will be notified
- * asynchronously via callback set for {@link IGetListener}.
+ * asynchronously via callback set for {@link GetResponseListener}.
*
* @param resourceInterface
* Interface type of the resource to operate on.
/**
* API to send PUT request to the resource. Response will be notified
- * asynchronously via callback set for {@link IPutListener}.
+ * asynchronously via callback set for {@link PutResponseListener}.
*
* @param queryParams
* Map which can have the query parameter name and value.
/**
* API to send PUT request to the resource. Response will be notified
- * asynchronously via callback set for {@link IPutListener}.
+ * asynchronously via callback set for {@link PutResponseListener}.
*
* @param resourceInterface
* Interface type of the resource to operate on.
/**
* API to send POST request to the resource. Response will be notified
- * asynchronously via callback set for {@link IPostListener}.
+ * asynchronously via callback set for {@link PostResponseListener}.
*
* @param queryParams
* Map which can have the query parameter name and value.
/**
* API to send POST request to the resource. Response will be notified
- * asynchronously via callback set for {@link IPostListener}.
+ * asynchronously via callback set for {@link PostResponseListener}.
*
* @param resourceInterface
* Interface type of the resource to operate on.
/**
* API to start observing the resource.
*
+ * @param onObserveListener
+ * The handler method which will be invoked with a map of
+ * attribute names and values whenever there is a change in
+ * resource model of the remote resource.
+ *
+ * @throws InvalidArgsException
+ * This exception will be thrown if any parameter has invalid
+ * values.
+ * @throws SimulatorException
+ * This exception will be thrown for other errors.
+ */
+ public void observe(ObserveNotificationListener onObserveListener)
+ throws InvalidArgsException, SimulatorException {
+ nativeStartObserve(null, onObserveListener);
+ }
+
+ /**
+ * API to start observing the resource.
+ *
* @param queryParams
* Map which can have the query parameter names and values.
* @param onObserveListener
* @throws SimulatorException
* This exception will be thrown for other errors.
*/
- public native void startObserve(Map<String, String> queryParams,
+ public void observe(Map<String, String> queryParams,
ObserveNotificationListener onObserveListener)
- throws InvalidArgsException, SimulatorException;
+ throws InvalidArgsException, SimulatorException {
+ if (null == queryParams)
+ throw new InvalidArgsException(
+ SimulatorResult.SIMULATOR_INVALID_PARAM,
+ "Invalid Query Parameters!");
+ nativeStartObserve(queryParams, onObserveListener);
+ }
/**
* API to stop observing the resource.
* @throws SimulatorException
* This exception will be thrown for other errors.
*/
- public native void stopObserve() throws InvalidArgsException,
- SimulatorException;
+ public void stopObserve() throws InvalidArgsException, SimulatorException {
+ nativeStopObserve();
+ }
/**
* API to provide remote resource configure information, which is required
* @param path
* Path to RAML file.
*
- * @return representation {@link SimulatorResourceModel} holding the
+ * @return Representation {@link SimulatorResourceModel} holding the
* representation of the remote resource.
*
* @throws InvalidArgsException
* @throws SimulatorException
* Thrown for other errors.
*/
- public native SimulatorResourceModel setConfigInfo(String path)
- throws InvalidArgsException, SimulatorException;
+ public Map<RequestType, SimulatorRequestModel> setConfigInfo(String path)
+ throws InvalidArgsException, SimulatorException {
+ return nativeSetConfigInfo(path);
+ }
/**
* API to send multiple requests for the resource, based on the configure
* @throws SimulatorException
* This exception will be thrown for other errors.
*/
- public int startVerification(VerificationType type,
+ public int startVerification(RequestType type,
VerificationListener onVerifyListener) throws InvalidArgsException,
NoSupportException, OperationInProgressException,
SimulatorException {
- return startVerification(type.ordinal(), onVerifyListener);
+ return nativeStartAutoRequesting(type, onVerifyListener);
}
/**
* API to stop sending requests which has been started using
- * {@link setConfigInfo}.
+ * {@link startVerification}.
*
* @param id
* Automation ID.
* @throws SimulatorException
* Thrown for other errors.
*/
- public native void stopVerification(int id) throws InvalidArgsException,
- SimulatorException;
+ public void stopVerification(int id) throws InvalidArgsException,
+ SimulatorException {
+ nativeStopAutoRequesting(id);
+ }
/**
* Listener for receiving asynchronous response for GET request.
public void onVerificationCompleted(String uid, int id);
}
+ private SimulatorRemoteResource(long nativeHandle) {
+ mNativeHandle = nativeHandle;
+ }
+
private native void nativeGet(String resourceInterface,
Map<String, String> queryParamsMap,
GetResponseListener onGetListener);
SimulatorResourceModel representation,
PostResponseListener onPostListener);
- private native int startVerification(int type,
+ private native void nativeStartObserve(Map<String, String> queryParams,
+ ObserveNotificationListener onObserveListener);
+
+ private native void nativeStopObserve();
+
+ private native Map<RequestType, SimulatorRequestModel> nativeSetConfigInfo(
+ String path);
+
+ private native int nativeStartAutoRequesting(RequestType type,
VerificationListener onVerifyListener);
+
+ private native void nativeStopAutoRequesting(int id);
+
+ private native void nativeDispose();
}