Record when the latest subscription/transport update was sent.

This commit is contained in:
akwizgran
2011-09-26 18:13:48 +01:00
parent 266048a815
commit a40c081815
3 changed files with 34 additions and 6 deletions

View File

@@ -452,6 +452,15 @@ interface Database<T> {
void setSubscriptions(T txn, ContactId c, Map<Group, Long> subs,
long timestamp) throws DbException;
/**
* Records the time at which a subscription update was last sent to the
* given contact.
* <p>
* Locking: contacts read, subscriptions write.
*/
void setSubscriptionTimestamp(T txn, ContactId c, long timestamp)
throws DbException;
/**
* Sets the configuration for the transport with the given name, replacing
* any existing configuration for that transport.
@@ -481,6 +490,15 @@ interface Database<T> {
Map<String, Map<String, String>> transports, long timestamp)
throws DbException;
/**
* Records the time at which a transport update was last sent to the given
* contact.
* <p>
* Locking: contacts read, transports write.
*/
void setTransportTimestamp(T txn, ContactId c, long timestamp)
throws DbException;
/**
* Makes the given group visible to the given set of contacts and invisible
* to any other contacts.

View File

@@ -596,26 +596,29 @@ DatabaseCleaner.Callback {
public void generateSubscriptionUpdate(ContactId c, SubscriptionWriter s)
throws DbException, IOException {
Map<Group, Long> subs;
long timestamp;
contactLock.readLock().lock();
try {
if(!containsContact(c)) throw new NoSuchContactException();
subscriptionLock.readLock().lock();
subscriptionLock.writeLock().lock();
try {
T txn = db.startTransaction();
try {
subs = db.getVisibleSubscriptions(txn, c);
timestamp = System.currentTimeMillis();
db.setSubscriptionTimestamp(txn, c, timestamp);
db.commitTransaction(txn);
} catch(DbException e) {
db.abortTransaction(txn);
throw e;
}
} finally {
subscriptionLock.readLock().unlock();
subscriptionLock.writeLock().unlock();
}
} finally {
contactLock.readLock().unlock();
}
s.writeSubscriptions(subs, System.currentTimeMillis());
s.writeSubscriptions(subs, timestamp);
if(LOG.isLoggable(Level.FINE))
LOG.fine("Added " + subs.size() + " subscriptions to update");
}
@@ -623,26 +626,29 @@ DatabaseCleaner.Callback {
public void generateTransportUpdate(ContactId c, TransportWriter t)
throws DbException, IOException {
Map<String, Map<String, String>> transports;
long timestamp;
contactLock.readLock().lock();
try {
if(!containsContact(c)) throw new NoSuchContactException();
transportLock.readLock().lock();
transportLock.writeLock().lock();
try {
T txn = db.startTransaction();
try {
transports = db.getTransports(txn);
timestamp = System.currentTimeMillis();
db.setTransportTimestamp(txn, c, timestamp);
db.commitTransaction(txn);
} catch(DbException e) {
db.abortTransaction(txn);
throw e;
}
} finally {
transportLock.readLock().unlock();
transportLock.writeLock().unlock();
}
} finally {
contactLock.readLock().unlock();
}
t.writeTransports(transports, System.currentTimeMillis());
t.writeTransports(transports, timestamp);
if(LOG.isLoggable(Level.FINE))
LOG.fine("Added " + transports.size() + " transports to update");
}