Use longs to represent session capacity.

This commit is contained in:
akwizgran
2022-04-27 16:32:34 +01:00
parent 0691354952
commit e614046662
7 changed files with 23 additions and 23 deletions

View File

@@ -511,14 +511,14 @@ interface Database<T> {
* <p/>
* Read-only.
*/
Collection<MessageId> getMessagesToSend(T txn, ContactId c, int capacity,
Collection<MessageId> getMessagesToSend(T txn, ContactId c, long capacity,
long maxLatency) throws DbException;
/**
* Returns the IDs of all messages that are eligible to be sent to the
* given contact.
* <p/>
* Unlike {@link #getMessagesToSend(Object, ContactId, int, long)} this
* Unlike {@link #getMessagesToSend(Object, ContactId, long, long)} this
* method may return messages that have already been sent and are not yet
* due for retransmission.
* <p/>
@@ -612,7 +612,7 @@ interface Database<T> {
* Read-only.
*/
Collection<MessageId> getRequestedMessagesToSend(T txn, ContactId c,
int capacity, long maxLatency) throws DbException;
long capacity, long maxLatency) throws DbException;
/**
* Returns all settings in the given namespace.

View File

@@ -424,7 +424,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
@Nullable
@Override
public Collection<Message> generateBatch(Transaction transaction,
ContactId c, int capacity, long maxLatency) throws DbException {
ContactId c, long capacity, long maxLatency) throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsContact(txn, c))
@@ -479,7 +479,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
@Nullable
@Override
public Collection<Message> generateRequestedBatch(Transaction transaction,
ContactId c, int capacity, long maxLatency) throws DbException {
ContactId c, long capacity, long maxLatency) throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsContact(txn, c))
@@ -620,7 +620,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
@Override
public Collection<MessageId> getMessagesToSend(Transaction transaction,
ContactId c, int capacity, long maxLatency) throws DbException {
ContactId c, long capacity, long maxLatency) throws DbException {
T txn = unbox(transaction);
if (!db.containsContact(txn, c))
throw new NoSuchContactException();

View File

@@ -2253,7 +2253,7 @@ abstract class JdbcDatabase implements Database<Connection> {
@Override
public Collection<MessageId> getMessagesToSend(Connection txn,
ContactId c, int capacity, long maxLatency) throws DbException {
ContactId c, long capacity, long maxLatency) throws DbException {
long now = clock.currentTimeMillis();
PreparedStatement ps = null;
ResultSet rs = null;
@@ -2548,7 +2548,7 @@ abstract class JdbcDatabase implements Database<Connection> {
@Override
public Collection<MessageId> getRequestedMessagesToSend(Connection txn,
ContactId c, int capacity, long maxLatency) throws DbException {
ContactId c, long capacity, long maxLatency) throws DbException {
long now = clock.currentTimeMillis();
PreparedStatement ps = null;
ResultSet rs = null;

View File

@@ -42,7 +42,7 @@ class MailboxOutgoingSession extends SimplexOutgoingSession {
getLogger(MailboxOutgoingSession.class.getName());
private final DeferredSendHandler deferredSendHandler;
private final int initialCapacity;
private final long initialCapacity;
MailboxOutgoingSession(DatabaseComponent db,
EventBus eventBus,
@@ -52,7 +52,7 @@ class MailboxOutgoingSession extends SimplexOutgoingSession {
StreamWriter streamWriter,
SyncRecordWriter recordWriter,
DeferredSendHandler deferredSendHandler,
int capacity) {
long capacity) {
super(db, eventBus, contactId, transportId, maxLatency, streamWriter,
recordWriter);
this.deferredSendHandler = deferredSendHandler;
@@ -71,10 +71,10 @@ class MailboxOutgoingSession extends SimplexOutgoingSession {
}
private Collection<MessageId> loadMessageIdsToAck() throws DbException {
int idCapacity = (getRemainingCapacity() - RECORD_HEADER_BYTES)
long idCapacity = (getRemainingCapacity() - RECORD_HEADER_BYTES)
/ MessageId.LENGTH;
if (idCapacity <= 0) return emptyList(); // Out of capacity
int maxMessageIds = min(idCapacity, MAX_MESSAGE_IDS);
int maxMessageIds = (int) min(idCapacity, MAX_MESSAGE_IDS);
Collection<MessageId> ids = db.transactionWithResult(true, txn ->
db.getMessagesToAck(txn, contactId, maxMessageIds));
if (LOG.isLoggable(INFO)) {
@@ -83,8 +83,8 @@ class MailboxOutgoingSession extends SimplexOutgoingSession {
return ids;
}
private int getRemainingCapacity() {
return initialCapacity - (int) recordWriter.getBytesWritten();
private long getRemainingCapacity() {
return initialCapacity - recordWriter.getBytesWritten();
}
@Override
@@ -102,7 +102,7 @@ class MailboxOutgoingSession extends SimplexOutgoingSession {
}
private Collection<MessageId> loadMessageIdsToSend() throws DbException {
int capacity = getRemainingCapacity();
long capacity = getRemainingCapacity();
if (capacity < RECORD_HEADER_BYTES + MESSAGE_HEADER_LENGTH) {
return emptyList(); // Out of capacity
}