Search in sources :

Example 6 with RequestWrapper

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);
    }
}
Also used : RequestWrapper(net.iGap.request.RequestWrapper) HelperString(net.iGap.helper.HelperString)

Example 7 with 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);
    }
}
Also used : RequestWrapper(net.iGap.request.RequestWrapper) HelperString(net.iGap.helper.HelperString) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 8 with RequestWrapper

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);
            }
        }
    });
}
Also used : RequestWrapper(net.iGap.request.RequestWrapper)

Example 9 with RequestWrapper

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);
        }
    }
}
Also used : RequestWrapper(net.iGap.request.RequestWrapper) HelperString(net.iGap.helper.HelperString) GeneralSecurityException(java.security.GeneralSecurityException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 10 with RequestWrapper

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();
    }
}
Also used : ProtoUserVerify(net.iGap.proto.ProtoUserVerify) RequestWrapper(net.iGap.request.RequestWrapper) OnUserVerification(net.iGap.observers.interfaces.OnUserVerification) HelperString(net.iGap.helper.HelperString)

Aggregations

RequestWrapper (net.iGap.request.RequestWrapper)10 HelperString (net.iGap.helper.HelperString)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 GeneralSecurityException (java.security.GeneralSecurityException)2 ByteString (com.google.protobuf.ByteString)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 PublicKey (java.security.PublicKey)1 RSAPublicKey (java.security.interfaces.RSAPublicKey)1 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)1 RSAPublicKeySpec (java.security.spec.RSAPublicKeySpec)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 OnResponse (net.iGap.observers.interfaces.OnResponse)1 OnUserRegistration (net.iGap.observers.interfaces.OnUserRegistration)1 OnUserVerification (net.iGap.observers.interfaces.OnUserVerification)1 ProtoConnectionSecuring (net.iGap.proto.ProtoConnectionSecuring)1