mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 03:39:05 +01:00
Broadcast events after committing transactions.
This commit is contained in:
@@ -1,11 +1,19 @@
|
||||
package org.briarproject.api.db;
|
||||
|
||||
import org.briarproject.api.event.Event;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A wrapper around a database transaction. Transactions are not thread-safe.
|
||||
*/
|
||||
public class Transaction {
|
||||
|
||||
private final Object txn;
|
||||
|
||||
private List<Event> events = null;
|
||||
private boolean complete = false;
|
||||
|
||||
public Transaction(Object txn) {
|
||||
@@ -20,6 +28,23 @@ public class Transaction {
|
||||
return txn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attaches an event to be broadcast when the transaction has been
|
||||
* committed.
|
||||
*/
|
||||
public void attach(Event e) {
|
||||
if (events == null) events = new ArrayList<Event>();
|
||||
events.add(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns any events attached to the transaction.
|
||||
*/
|
||||
public List<Event> getEvents() {
|
||||
if (events == null) return Collections.emptyList();
|
||||
return events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the transaction is ready to be committed.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user