use of org.aion.api.server.types.TxPendingStatus in project aion by aionnetwork.
the class HdlrZmq method getTxWait.
void getTxWait() {
TxWaitingMappingUpdate txWait = null;
try {
txWait = this.api.takeTxWait();
if (txWait.isDummy()) {
// shutdown process
return;
}
} catch (Exception e) {
// TODO Auto-generated catch block
LOGGER.error("zmq takeTxWait failed! ", e);
}
Map.Entry<ByteArrayWrapper, ByteArrayWrapper> entry = null;
if (txWait != null) {
entry = this.api.getMsgIdMapping().get(txWait.getTxHash());
}
if (entry != null) {
this.api.getPendingStatus().add(new TxPendingStatus(txWait.getTxHash(), entry.getValue(), entry.getKey(), txWait.getState(), txWait.getTxResult(), txWait.getTxReceipt().getError()));
// INCLUDED(3);
if (txWait.getState() == 1 || txWait.getState() == 2) {
this.api.getPendingReceipts().put(txWait.getTxHash(), txWait.getTxReceipt());
} else {
this.api.getPendingReceipts().remove(txWait.getTxHash());
this.api.getMsgIdMapping().remove(txWait.getTxHash());
}
}
}
use of org.aion.api.server.types.TxPendingStatus in project aion by aionnetwork.
the class ProtocolProcessor method callbackRun.
private void callbackRun(Context ctx) {
Socket sock = ctx.socket(ZMQ.DEALER);
sock.connect(AION_ZMQ_CB_TH);
while (!shutDown.get()) {
TxPendingStatus tps;
try {
tps = ((HdlrZmq) this.handler).getTxStatusQueue().take();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
if (LOG.isErrorEnabled()) {
LOG.error("queue take exception - [{}]", e1.getMessage());
}
continue;
}
if (tps.isEmpty()) {
continue;
}
byte[] rsp = tps.toTxReturnCode() != 105 ? ((HdlrZmq) this.handler).toRspMsg(tps.getMsgHash(), tps.toTxReturnCode(), tps.getError()) : ((HdlrZmq) this.handler).toRspMsg(tps.getMsgHash(), tps.toTxReturnCode(), tps.getError(), tps.getTxResult());
if (LOG.isTraceEnabled()) {
LOG.trace("callbackRun send. socketID: [{}], msgHash: [{}], txReturnCode: [{}]/n rspMsg: [{}]", Hex.toHexString(tps.getSocketId()), Hex.toHexString(tps.getMsgHash()), tps.toTxReturnCode(), Hex.toHexString(rsp));
}
try {
sock.send(tps.getSocketId(), ZMQ.SNDMORE);
sock.send(rsp, ZMQ.DONTWAIT);
} catch (Exception e) {
if (LOG.isErrorEnabled()) {
LOG.error("ProtocolProcessor.callbackRun sock.send exception: " + e.getMessage());
}
}
}
sock.close();
if (LOG.isDebugEnabled()) {
LOG.debug("close callbackRun sockets...");
}
}
use of org.aion.api.server.types.TxPendingStatus in project aion by aionnetwork.
the class HdlrZmq method shutdown.
public void shutdown() {
this.getTxStatusQueue().add(new TxPendingStatus(null, null, null, 0, null, ""));
this.api.getTxWait().add(new TxWaitingMappingUpdate(null, 0, null));
}
use of org.aion.api.server.types.TxPendingStatus in project aion by aionnetwork.
the class ApiAion0 method pendingTxUpdate.
@Override
protected void pendingTxUpdate(AionTxReceipt _txRcpt, int _state) {
ByteArrayWrapper txHashW = ByteArrayWrapper.wrap(_txRcpt.getTransaction().getTransactionHash());
LOG.trace("ApiAion0.onPendingTransactionUpdate - txHash: [{}], state: [{}]", txHashW.toString(), _state);
if (getMsgIdMapping().get(txHashW) != null) {
if (pendingStatus.remainingCapacity() == 0) {
pendingStatus.poll();
LOG.warn("ApiAion0.onPendingTransactionUpdate - txPend ingStatus queue full, drop the first message.");
}
LOG.trace("ApiAion0.onPendingTransactionUpdate - the pending Tx state : [{}]", _state);
pendingStatus.add(new TxPendingStatus(txHashW, getMsgIdMapping().get(txHashW).getValue(), getMsgIdMapping().get(txHashW).getKey(), _state, ByteArrayWrapper.wrap(_txRcpt.getTransactionOutput() == null ? EMPTY_BYTE_ARRAY : _txRcpt.getTransactionOutput()), _txRcpt.getError()));
if (_state == PendingTransactionState.NEW_PENDING.getValue() || _state == PendingTransactionState.PENDING.getValue()) {
pendingReceipts.put(txHashW, _txRcpt);
} else {
pendingReceipts.remove(txHashW);
getMsgIdMapping().remove(txHashW);
}
} else {
if (txWait.remainingCapacity() == 0) {
txWait.poll();
LOG.trace("ApiAion0.onPendingTransactionUpdate - txWait queue full, drop the first message.");
}
// waiting origin Api call status been callback
try {
txWait.put(new TxWaitingMappingUpdate(txHashW, _state, _txRcpt));
} catch (InterruptedException e) {
LOG.error("ApiAion0.onPendingTransactionUpdate txWait.put exception", e);
}
}
}
Aggregations