Search in sources :

Example 1 with TimeAbortCall

use of isf.logic.TimeAbortCall in project isf-jclient by mikrohash.

the class NodeManager method connectToNode.

private static boolean connectToNode(final String node, final int api) {
    TimeAbortCall t = new TimeAbortCall(R.STR.getString("nodes_action_connecting"), 1) {

        @Override
        public boolean onCall() {
            String protocol = node.split(":")[0];
            String host = node.split(":")[1].replace("//", "");
            String port = node.split(":")[2];
            apis[api] = (IotaAPI) new IotaAPI.Builder().protocol(protocol).host(host).port(port).localPoW(new GOldDiggerLocalPoW()).build();
            return true;
        }
    };
    if (!t.call(CONNECTING_DURATION_TOLERACE))
        return false;
    String isNodeSynced = isNodeSynced(api);
    if (isNodeSynced != null)
        uim.logDbg(String.format(R.STR.getString("nodes_action_changing"), buildNodeAddress(api), api, isNodeSynced));
    return isNodeSynced == null;
}
Also used : GOldDiggerLocalPoW(iota.GOldDiggerLocalPoW) TimeAbortCall(isf.logic.TimeAbortCall) IotaAPI(iota.IotaAPI)

Example 2 with TimeAbortCall

use of isf.logic.TimeAbortCall in project isf-jclient by mikrohash.

the class TxBroadcaster method queueTrytes.

public static void queueTrytes(final GetAttachToTangleResponse res) {
    if (res.getTrytes()[0] == null)
        return;
    final TimeAbortCall broadcastBomb = new TimeAbortCall("broadcasting tips", 10) {

        @Override
        public boolean onCall() {
            try {
                NodeManager.broadcastAndStore(res.getTrytes()[0]);
                return true;
            } catch (InterruptedException e) {
                return false;
            }
        }
    };
    new Thread() {

        @Override
        public void run() {
            amountQueued++;
            while (!broadcastBomb.call(10)) ;
            AddressManager.incrementSessionTxCount();
            amountQueued--;
        }
    }.start();
}
Also used : TimeAbortCall(isf.logic.TimeAbortCall)

Example 3 with TimeAbortCall

use of isf.logic.TimeAbortCall in project isf-jclient by mikrohash.

the class NodeManager method getNodeInfo.

public static GetNodeInfoResponse getNodeInfo(final int parApi, boolean tryMultipleTimes) {
    final ObjectWrapper api = new ObjectWrapper(parApi);
    final ObjectWrapper res = new ObjectWrapper(null);
    TimeAbortCall tb = new TimeAbortCall("requesting node info", 0) {

        @Override
        public boolean onCall() {
            try {
                res.o = apis[(int) api.o].getNodeInfo();
                return true;
            } catch (Throwable e) {
                api.o = handleThrowableFromIotaAPI("receive getNodeInfo", e, (int) api.o);
                return false;
            }
        }
    };
    do {
        tb.call(NODEINFO_DURATION_TOLERANCE);
    } while (tryMultipleTimes);
    return (GetNodeInfoResponse) res.o;
}
Also used : TimeAbortCall(isf.logic.TimeAbortCall) ObjectWrapper(isf.logic.ObjectWrapper) GetNodeInfoResponse(jota.dto.response.GetNodeInfoResponse)

Example 4 with TimeAbortCall

use of isf.logic.TimeAbortCall in project isf-jclient by mikrohash.

the class TipPool method init.

public static void init() {
    for (int i = 0; i < NodeManager.getAmountOfAPIs(); i++) {
        final int api = i;
        new Thread() {

            @Override
            public void run() {
                TimeAbortCall tb = new TimeAbortCall("requesting transactions to approve (tips)", 10) {

                    @Override
                    public boolean onCall() {
                        GetTransactionsToApproveResponse gttar = NodeManager.getTransactionsToApprove(api);
                        if (gttar != null) {
                            gttars.push(gttar);
                            REQUIRED_TIPS.o = gttarsLimit - gttars.size();
                        }
                        return gttar != null;
                    }

                    @Override
                    public void onNotToleratedFail(String failMsg) {
                        NodeManager.connectToAnyNode(api, failMsg);
                    }
                };
                while (true) {
                    do {
                        synchronized (REQUIRED_TIPS) {
                            try {
                                REQUIRED_TIPS.wait();
                            } catch (InterruptedException e) {
                            }
                        }
                    } while (!NodeManager.isAvailable(api));
                    while ((int) REQUESTED_TIPS.o < (int) REQUIRED_TIPS.o) {
                        synchronized (REQUIRED_TIPS) {
                            REQUESTED_TIPS.o = ((int) REQUESTED_TIPS.o) + 1;
                        }
                        if (!tb.call(6))
                            ;
                        synchronized (REQUIRED_TIPS) {
                            REQUESTED_TIPS.o = ((int) REQUESTED_TIPS.o) - 1;
                        }
                    }
                }
            }
        }.start();
    }
}
Also used : TimeAbortCall(isf.logic.TimeAbortCall) GetTransactionsToApproveResponse(jota.dto.response.GetTransactionsToApproveResponse)

Aggregations

TimeAbortCall (isf.logic.TimeAbortCall)4 GOldDiggerLocalPoW (iota.GOldDiggerLocalPoW)1 IotaAPI (iota.IotaAPI)1 ObjectWrapper (isf.logic.ObjectWrapper)1 GetNodeInfoResponse (jota.dto.response.GetNodeInfoResponse)1 GetTransactionsToApproveResponse (jota.dto.response.GetTransactionsToApproveResponse)1