use of net.iGap.request.RequestWrapper in project iGap-Android by KianIranian-STDG.
the class RequestManager method onFrameSent.
public void onFrameSent(WebSocketFrame frame) {
String id = ((RequestWrapper) frame.getRequestWrapper()).getRandomId();
RequestWrapper requestWrapper = requestQueueMap.get(id);
if (requestWrapper != null) {
requestWrapper.setTime(System.currentTimeMillis());
requestQueueMap.put(requestWrapper.getRandomId(), requestWrapper);
}
}
use of net.iGap.request.RequestWrapper in project iGap-Android by KianIranian-STDG.
the class RequestManager method requestQueuePullFunction.
private void requestQueuePullFunction() {
for (Map.Entry<String, RequestWrapper> entry : requestQueueMap.entrySet()) {
String key = entry.getKey();
RequestWrapper requestWrapper = entry.getValue();
boolean delete;
if (requestWrapper.actionId == 102) {
delete = timeDifference(requestWrapper.getTime(), (10 * DateUtils.SECOND_IN_MILLIS));
} else {
delete = timeDifference(requestWrapper.getTime(), net.iGap.Config.TIME_OUT_MS);
}
if (delete) {
requestQueueMapRemover(key);
}
}
if (requestQueueMap.size() > 0) {
G.runOnUiThread(this::requestQueuePullFunction, net.iGap.Config.TIME_OUT_DELAY_MS);
} else {
pullRequestQueueRunned.getAndSet(false);
}
}
use of net.iGap.request.RequestWrapper in project iGap-Android by KianIranian-STDG.
the class RequestManager method cancelRequestByUniqueId.
public void cancelRequestByUniqueId(int fragmentUniqueId) {
networkQueue.postRunnable(() -> {
List<RequestWrapper> requests = requestsByUId.get(fragmentUniqueId);
if (requests != null) {
for (int i = 0; i < requests.size(); i++) {
RequestWrapper req = requests.get(i);
req.canceled = true;
cancelRequest(req.randomId);
requestsByUId.remove(fragmentUniqueId);
}
}
});
}
use of net.iGap.request.RequestWrapper in project iGap-Android by KianIranian-STDG.
the class RequestManager method unpack.
public void unpack(byte[] message) {
int actionId = getId(message);
byte[] payload = getProtoInfo(message);
String className = getClassName(actionId);
Log.e("dfjshfjshfjsdhf", "unpack1: " + actionId);
if (!isSecure && !G.unSecureResponseActionId.contains(Integer.toString(actionId))) {
return;
}
final LookUpClass lookUp = LookUpClass.getInstance();
boolean isRpc = lookUp.validObject(actionId);
if (isRpc) {
AbstractObject object = lookUp.deserializeObject(actionId, payload);
if (object != null) {
String resId = object.getResId() != null && object.getResId().equals("") ? null : object.getResId();
if (resId != null) {
RequestWrapper requestWrapper = requestQueueMap.get(resId);
if (requestWrapper != null && requestWrapper.onResponse != null) {
if (actionId == 0) {
requestWrapper.onResponse.onReceived(null, object);
} else {
requestWrapper.onResponse.onReceived(object, null);
}
requestQueueMap.remove(resId);
return;
}
} else {
if (actionId != 0) {
MessageController.getInstance(AccountManager.selectedAccount).onUpdate(object);
}
}
}
}
if (className == null) {
return;
}
String protoClassName = HelperClassNamePreparation.preparationProtoClassName(className);
Object protoObject = fillProtoClassData(protoClassName, payload);
String responseId = getResponseId(protoObject);
FileLog.i("RequestManager unpack responseId -> " + responseId + " action id -> " + actionId + " class name -> " + className);
if (responseId == null) {
if (actionId == 0) {
instanceResponseClass(actionId, protoObject, null, "error");
} else {
instanceResponseClass(actionId, protoObject, null, "handler");
}
} else {
if (!requestQueueMap.containsKey(responseId)) {
return;
}
try {
RequestWrapper requestWrapper = requestQueueMap.remove(responseId);
if (actionId == 0) {
// error
if (requestWrapper != null) {
int finalAct = requestWrapper.getActionId() + net.iGap.Config.LOOKUP_MAP_RESPONSE_OFFSET;
instanceResponseClass(finalAct, protoObject, requestWrapper.identity, "error");
}
} else {
if (requestWrapper != null) {
instanceResponseClass(actionId, protoObject, requestWrapper.identity, "handler");
}
}
} catch (Exception e) {
FileLog.e(e);
}
}
}
use of net.iGap.request.RequestWrapper in project iGap-Android by KianIranian-STDG.
the class RegisterRepository method userVerify.
public void userVerify(@NotNull String verificationCode, RepositoryCallbackWithError<ErrorWithWaitTime> callback) {
try {
ProtoUserVerify.UserVerify.Builder userVerify = ProtoUserVerify.UserVerify.newBuilder();
userVerify.setCode(Integer.parseInt(verificationCode.replaceAll("[^0-9]", "").replaceAll("[\u0000-\u001f]", "")));
if (userName != null)
userVerify.setUsername(userName);
RequestWrapper requestWrapper = new RequestWrapper(101, userVerify, new OnUserVerification() {
@Override
public void onUserVerify(String tokenR, boolean newUserR) {
newUser = newUserR;
token = tokenR;
userLogin(token);
}
@Override
public void onUserVerifyError(int majorCode, int minorCode, int time) {
callback.onError(new ErrorWithWaitTime(majorCode, minorCode, time));
}
});
RequestQueue.sendRequest(requestWrapper);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
Aggregations