use of com.google.j2objc.annotations.AutoreleasePool in project actor-platform by actorapp.
the class ManagerActor method onInMessage.
@AutoreleasePool
private void onInMessage(byte[] data, int offset, int len) {
// Log.d(TAG, "Received package");
DataInput bis = new DataInput(data, offset, len);
try {
long authId = bis.readLong();
long sessionId = bis.readLong();
if (authId != this.authId || sessionId != this.sessionId) {
throw new IOException("Incorrect header");
}
if (authKey != null) {
EncryptedPackage encryptedPackage = new EncryptedPackage(bis);
int seq = (int) encryptedPackage.getSeqNumber();
if (seq != inSeq) {
throw new IOException("Expected " + inSeq + ", got: " + seq);
}
inSeq++;
// long start = Runtime.getActorTime();
EncryptedCBCPackage usEncryptedPackage = new EncryptedCBCPackage(new DataInput(encryptedPackage.getEncryptedPackage()));
byte[] ruPackage = serverUSDecryptor.decryptPackage(ByteStrings.longToBytes(seq), usEncryptedPackage.getIv(), usEncryptedPackage.getEncryptedContent());
EncryptedCBCPackage ruEncryptedPackage = new EncryptedCBCPackage(new DataInput(ruPackage));
byte[] plainText = serverRUDecryptor.decryptPackage(ByteStrings.longToBytes(seq), ruEncryptedPackage.getIv(), ruEncryptedPackage.getEncryptedContent());
// Log.d(TAG, "Package decrypted in " + (Runtime.getActorTime() - start) + " ms, size: " + len);
DataInput ptInput = new DataInput(plainText);
long messageId = ptInput.readLong();
byte[] ptPayload = ptInput.readProtoBytes();
receiver.send(new ProtoMessage(messageId, ptPayload));
} else {
long messageId = bis.readLong();
byte[] payload = bis.readProtoBytes();
receiver.send(new ProtoMessage(messageId, payload));
}
} catch (IOException e) {
Log.w(TAG, "Closing connection: incorrect package");
Log.e(TAG, e);
if (currentConnection != null) {
try {
currentConnection.close();
} catch (Exception e2) {
e2.printStackTrace();
}
currentConnection = null;
currentConnectionId = 0;
outSeq = 0;
inSeq = 0;
// Log.d(TAG, "Set connection #" + 0);
}
checkConnection();
}
}
use of com.google.j2objc.annotations.AutoreleasePool in project actor-platform by actorapp.
the class AsyncStorageActor method loadHead.
@AutoreleasePool
public void loadHead(LoadItemCallback<T> callback) {
List<ListEngineRecord> records = storage.loadForward(null, 1);
if (records.size() != 1) {
callback.onLoaded(null);
return;
}
ListEngineRecord record = records.get(0);
try {
callback.onLoaded(Bser.parse(creator.createInstance(), record.getData()));
} catch (IOException e) {
e.printStackTrace();
callback.onLoaded(null);
}
}
use of com.google.j2objc.annotations.AutoreleasePool in project actor-platform by actorapp.
the class AsyncStorageActor method loadItem.
@AutoreleasePool
public void loadItem(long key, LoadItemCallback<T> callback) {
ListEngineRecord record = storage.loadItem(key);
if (record != null) {
try {
T res = Bser.parse(creator.createInstance(), record.getData());
callback.onLoaded(res);
} catch (IOException e) {
e.printStackTrace();
callback.onLoaded(null);
}
} else {
callback.onLoaded(null);
}
}
use of com.google.j2objc.annotations.AutoreleasePool in project actor-platform by actorapp.
the class AsyncStorageActor method addOrUpdate.
@AutoreleasePool
public void addOrUpdate(List<T> items) {
if (items.size() == 1) {
T item = items.get(0);
storage.updateOrAdd(new ListEngineRecord(item.getEngineId(), item.getEngineSort(), item.getEngineSearch(), item.toByteArray()));
} else if (items.size() > 0) {
List<ListEngineRecord> updated = new ArrayList<>();
for (T i : items) {
updated.add(new ListEngineRecord(i.getEngineId(), i.getEngineSort(), i.getEngineSearch(), i.toByteArray()));
}
storage.updateOrAdd(updated);
}
}
use of com.google.j2objc.annotations.AutoreleasePool in project actor-platform by actorapp.
the class AsyncStorageActor method replace.
@AutoreleasePool
public void replace(List<T> items) {
List<ListEngineRecord> updated = new ArrayList<>();
for (T i : items) {
updated.add(new ListEngineRecord(i.getEngineId(), i.getEngineSort(), i.getEngineSearch(), i.toByteArray()));
}
storage.clear();
storage.updateOrAdd(updated);
}
Aggregations