Я отправляю несколько запросов одновременно и получаю ответ в порядке запроса.
Как изменить его на получение ответа сразу после его получения?
send (1,2,3,4) receive (1,2,3,4)
пример: отправка всех запросов одновременно (можно увидеть в журналах)
только после получения первого ответа на запрос Iполучит ответ второго;
Это мой класс запросов к серверу:
открытый класс ServerRequest {
public static ServerRequest instance;
public RequestQueue requestQueue;
private JsonObjectRequest jsonObjectRequest;
private ServerRequest(Context context) {
requestQueue = Volley.newRequestQueue(context.getApplicationContext());
}
public static synchronized ServerRequest getInstance(Context context) {
if (instance == null) {
instance = new ServerRequest(context);
}
return instance;
}
/**
* this function create server response
*
* @param method the server request method (Request.Method.POST)
* @param timeOutInterval the time for time out from the volley request
* @param baseUrl the url for the call
* @param params the Json object for the call
* @param listener success response listner
* @param errListener error response listner
*/
public void jsonRequest(int method, Integer timeOutInterval, String baseUrl, JSONObject params, Response.Listener<JSONObject> listener, Response.ErrorListener errListener) {
jsonObjectRequest = new JsonObjectRequest(method, baseUrl, params, listener, errListener);
RetryPolicy policy = new DefaultRetryPolicy(timeOutInterval, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
jsonObjectRequest.setRetryPolicy(policy);
requestQueue.add(jsonObjectRequest);
}
/**
* this function create server response (with tag)
*
* @param TAG tag for the server call
* @param method the server request method (Request.Method.POST)
* @param timeOutInterval the time for time out from the volley request
* @param baseUrl the url for the call
* @param params the Json object for the call
* @param listener success response listner
* @param errListener error response listner
*/
public void jsonRequest(String TAG, int method, Integer timeOutInterval, String baseUrl, JSONObject params, Response.Listener<JSONObject> listener, Response.ErrorListener errListener) {
jsonObjectRequest = new JsonObjectRequest(method, baseUrl, params, listener, errListener);
RetryPolicy policy = new DefaultRetryPolicy(timeOutInterval, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
jsonObjectRequest.setRetryPolicy(policy);
jsonObjectRequest.setTag(TAG);
requestQueue.add(jsonObjectRequest);
}
/**
* this function create server response (witout params)
*
* @param method the server request method (Request.Method.POST)
* @param timeOutInterval the time for time out from the volley request
* @param baseUrl the url for the call
* @param listener success response listner
* @param errListener error response listner
*/
public void stringRequest(int method, Integer timeOutInterval, String baseUrl, Response.Listener<String> listener, Response.ErrorListener errListener) {
StringRequest stringRequest = new StringRequest(method, baseUrl, listener, errListener);
RetryPolicy policy = new DefaultRetryPolicy(timeOutInterval, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
stringRequest.setRetryPolicy(policy);
requestQueue.add(stringRequest);
}
}