Search in sources :

Example 1 with CommonTimer

use of im.actor.runtime.threading.CommonTimer in project actor-platform by actorapp.

the class ApiBroker method cancelRequest.

private void cancelRequest(long randomId) {
    CommonTimer timer = timeouts.get(randomId);
    if (timer != null) {
        timer.cancel();
        timeouts.remove(randomId);
    }
    RequestHolder holder = requests.get(randomId);
    if (holder != null) {
        requests.remove(randomId);
        if (holder.protoId != 0 && proto != null) {
            idMap.remove(holder.protoId);
            proto.cancelRpc(holder.protoId);
        }
    }
}
Also used : CommonTimer(im.actor.runtime.threading.CommonTimer)

Example 2 with CommonTimer

use of im.actor.runtime.threading.CommonTimer in project actor-platform by actorapp.

the class ManagedConnection method sendPingMessage.

private synchronized void sendPingMessage() {
    if (isClosed) {
        return;
    }
    final long pingId = RANDOM.nextLong();
    DataOutput dataOutput = new DataOutput();
    dataOutput.writeInt(8);
    synchronized (RANDOM) {
        dataOutput.writeLong(pingId);
    }
    CommonTimer pingTimeoutTask = new CommonTimer(new TimeoutRunnable());
    schedulledPings.put(pingId, pingTimeoutTask);
    pingTimeoutTask.schedule(RESPONSE_TIMEOUT);
    // Log.d(TAG, "Performing ping #" + pingId + "... " + pingTimeoutTask);
    rawPost(HEADER_PING, dataOutput.toByteArray());
}
Also used : DataOutput(im.actor.runtime.bser.DataOutput) CommonTimer(im.actor.runtime.threading.CommonTimer)

Example 3 with CommonTimer

use of im.actor.runtime.threading.CommonTimer in project actor-platform by actorapp.

the class ManagedConnection method rawPost.

private synchronized void rawPost(int header, byte[] data, int offset, int len) {
    // Log.w(TAG, "rawPost");
    int packageId = sentPackages++;
    DataOutput dataOutput = new DataOutput();
    dataOutput.writeInt(packageId);
    dataOutput.writeByte(header);
    dataOutput.writeInt(data.length);
    dataOutput.writeBytes(data, offset, len);
    CRC32_ENGINE.reset();
    CRC32_ENGINE.update(data, offset, len);
    dataOutput.writeInt((int) CRC32_ENGINE.getValue());
    if (header == HEADER_PROTO) {
        CommonTimer timeoutTask = new CommonTimer(new TimeoutRunnable());
        packageTimers.put(packageId, timeoutTask);
        timeoutTask.schedule(RESPONSE_TIMEOUT);
    }
    rawConnection.doSend(dataOutput.toByteArray());
}
Also used : DataOutput(im.actor.runtime.bser.DataOutput) CommonTimer(im.actor.runtime.threading.CommonTimer)

Example 4 with CommonTimer

use of im.actor.runtime.threading.CommonTimer in project actor-platform by actorapp.

the class ManagedConnection method onPongPackage.

private synchronized void onPongPackage(byte[] data) throws IOException {
    DataInput dataInput = new DataInput(data);
    int size = dataInput.readInt();
    if (size != 8) {
        Log.w(TAG, "Received incorrect pong");
        throw new IOException("Incorrect pong payload size");
    }
    long pingId = dataInput.readLong();
    // Log.d(TAG, "Received pong #" + pingId + "...");
    CommonTimer timeoutTask = schedulledPings.remove(pingId);
    if (timeoutTask == null) {
        return;
    }
    timeoutTask.cancel();
    refreshTimeouts();
}
Also used : DataInput(im.actor.runtime.bser.DataInput) CommonTimer(im.actor.runtime.threading.CommonTimer) IOException(java.io.IOException)

Example 5 with CommonTimer

use of im.actor.runtime.threading.CommonTimer in project actor-platform by actorapp.

the class ManagedConnection method onAckPackage.

// Ack
private synchronized void onAckPackage(byte[] data) throws IOException {
    DataInput ackContent = new DataInput(data);
    int frameId = ackContent.readInt();
    CommonTimer timerCompat = packageTimers.remove(frameId);
    if (timerCompat == null) {
        return;
    }
    timerCompat.cancel();
    refreshTimeouts();
}
Also used : DataInput(im.actor.runtime.bser.DataInput) CommonTimer(im.actor.runtime.threading.CommonTimer)

Aggregations

CommonTimer (im.actor.runtime.threading.CommonTimer)7 DataInput (im.actor.runtime.bser.DataInput)2 DataOutput (im.actor.runtime.bser.DataOutput)2 IOException (java.io.IOException)2 ProtoStruct (im.actor.core.network.mtp.entity.ProtoStruct)1 RpcError (im.actor.core.network.mtp.entity.rpc.RpcError)1 RpcFloodWait (im.actor.core.network.mtp.entity.rpc.RpcFloodWait)1 RpcInternalError (im.actor.core.network.mtp.entity.rpc.RpcInternalError)1 RpcOk (im.actor.core.network.mtp.entity.rpc.RpcOk)1 RpcRequest (im.actor.core.network.mtp.entity.rpc.RpcRequest)1 Response (im.actor.core.network.parser.Response)1