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);
}
}
}
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());
}
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());
}
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();
}
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();
}
Aggregations