mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 11:49:04 +01:00
Create local state for clients at startup. #279
This commit is contained in:
12
briar-api/src/org/briarproject/api/clients/Client.java
Normal file
12
briar-api/src/org/briarproject/api/clients/Client.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package org.briarproject.api.clients;
|
||||
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.db.Transaction;
|
||||
|
||||
public interface Client {
|
||||
|
||||
/**
|
||||
* Called at startup to create any local state needed by the client.
|
||||
*/
|
||||
void createLocalState(Transaction txn) throws DbException;
|
||||
}
|
||||
@@ -6,6 +6,9 @@ import org.briarproject.api.sync.Group;
|
||||
|
||||
public interface PrivateGroupFactory {
|
||||
|
||||
/** Creates a group that is not shared with any contacts. */
|
||||
Group createLocalGroup(ClientId clientId);
|
||||
|
||||
/** Creates a group for the given client to share with the given contact. */
|
||||
Group createPrivateGroup(ClientId clientId, Contact contact);
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ public interface DatabaseComponent {
|
||||
* <p/>
|
||||
* This method acquires locks, so it must not be called while holding a
|
||||
* lock.
|
||||
*
|
||||
* @param readOnly true if the transaction will only be used for reading.
|
||||
*/
|
||||
Transaction startTransaction(boolean readOnly) throws DbException;
|
||||
@@ -90,13 +91,27 @@ public interface DatabaseComponent {
|
||||
void addTransportKeys(Transaction txn, ContactId c, TransportKeys k)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Returns true if the database contains the given contact for the given
|
||||
* local pseudonym.
|
||||
*/
|
||||
boolean containsContact(Transaction txn, AuthorId remote, AuthorId local)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Returns true if the database contains the given group.
|
||||
*/
|
||||
boolean containsGroup(Transaction txn, GroupId g) throws DbException;
|
||||
|
||||
/**
|
||||
* Deletes the message with the given ID. The message ID and any other
|
||||
* associated data are not deleted.
|
||||
*/
|
||||
void deleteMessage(Transaction txn, MessageId m) throws DbException;
|
||||
|
||||
/** Deletes any metadata associated with the given message. */
|
||||
/**
|
||||
* Deletes any metadata associated with the given message.
|
||||
*/
|
||||
void deleteMessageMetadata(Transaction txn, MessageId m) throws DbException;
|
||||
|
||||
/**
|
||||
@@ -162,13 +177,6 @@ public interface DatabaseComponent {
|
||||
Collection<ContactId> getContacts(Transaction txn, AuthorId a)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Returns true if the database contains the given contact for the given
|
||||
* local pseudonym.
|
||||
*/
|
||||
boolean containsContact(Transaction txn, AuthorId remote, AuthorId local)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the unique ID for this device.
|
||||
* <p/>
|
||||
@@ -359,7 +367,7 @@ public interface DatabaseComponent {
|
||||
* Marks the given contact as active or inactive.
|
||||
*/
|
||||
void setContactActive(Transaction txn, ContactId c, boolean active)
|
||||
throws DbException;
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Marks the given message as shared or unshared.
|
||||
|
||||
@@ -1,32 +1,49 @@
|
||||
package org.briarproject.api.lifecycle;
|
||||
|
||||
import org.briarproject.api.clients.Client;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
/**
|
||||
* Manages the lifecycle of the app, starting and stopping {@link Service
|
||||
* Services}, shutting down {@link java.util.concurrent.ExecutorService
|
||||
* Manages the lifecycle of the app, starting {@link
|
||||
* org.briarproject.api.clients.Client Clients}, starting and stopping {@link
|
||||
* Service Services}, shutting down {@link java.util.concurrent.ExecutorService
|
||||
* ExecutorServices}, and opening and closing the {@link
|
||||
* org.briarproject.api.db.DatabaseComponent DatabaseComponent}.
|
||||
*/
|
||||
public interface LifecycleManager {
|
||||
|
||||
/** The result of calling {@link LifecycleManager#startServices()}. */
|
||||
enum StartResult { ALREADY_RUNNING, DB_ERROR, SERVICE_ERROR, SUCCESS }
|
||||
/**
|
||||
* The result of calling {@link LifecycleManager#startServices()}.
|
||||
*/
|
||||
enum StartResult {
|
||||
ALREADY_RUNNING, DB_ERROR, SERVICE_ERROR, SUCCESS
|
||||
}
|
||||
|
||||
/** Registers a {@link Service} to be started and stopped. */
|
||||
public void register(Service s);
|
||||
/**
|
||||
* Registers a {@link Service} to be started and stopped.
|
||||
*/
|
||||
void registerService(Service s);
|
||||
|
||||
/**
|
||||
* Registers a {@link org.briarproject.api.clients.Client Client} to be
|
||||
* started.
|
||||
*/
|
||||
void registerClient(Client c);
|
||||
|
||||
/**
|
||||
* Registers an {@link java.util.concurrent.ExecutorService ExecutorService}
|
||||
* to be shut down.
|
||||
*/
|
||||
public void registerForShutdown(ExecutorService e);
|
||||
void registerForShutdown(ExecutorService e);
|
||||
|
||||
/**
|
||||
* Starts any registered {@link Service Services} and opens the {@link
|
||||
* org.briarproject.api.db.DatabaseComponent DatabaseComponent}.
|
||||
* Opens the {@link org.briarproject.api.db.DatabaseComponent
|
||||
* DatabaseComponent} and starts any registered {@link
|
||||
* org.briarproject.api.clients.Client Clients} and {@link Service
|
||||
* Services}.
|
||||
*/
|
||||
public StartResult startServices();
|
||||
StartResult startServices();
|
||||
|
||||
/**
|
||||
* Stops any registered {@link Service Services}, shuts down any
|
||||
@@ -34,20 +51,21 @@ public interface LifecycleManager {
|
||||
* and closes the {@link org.briarproject.api.db.DatabaseComponent
|
||||
* DatabaseComponent}.
|
||||
*/
|
||||
public void stopServices();
|
||||
void stopServices();
|
||||
|
||||
/**
|
||||
* Waits for the {@link org.briarproject.api.db.DatabaseComponent
|
||||
* DatabaseComponent} to be opened before returning.
|
||||
*/
|
||||
public void waitForDatabase() throws InterruptedException;
|
||||
void waitForDatabase() throws InterruptedException;
|
||||
|
||||
/**
|
||||
* Waits for the {@link org.briarproject.api.db.DatabaseComponent
|
||||
* DatabaseComponent} to be opened and all registered {@link Service
|
||||
* DatabaseComponent} to be opened and all registered {@link
|
||||
* org.briarproject.api.clients.Client Clients} and {@link Service
|
||||
* Services} to start before returning.
|
||||
*/
|
||||
public void waitForStartup() throws InterruptedException;
|
||||
void waitForStartup() throws InterruptedException;
|
||||
|
||||
/**
|
||||
* Waits for all registered {@link Service Services} to stop, all
|
||||
@@ -55,5 +73,5 @@ public interface LifecycleManager {
|
||||
* to shut down, and the {@link org.briarproject.api.db.DatabaseComponent
|
||||
* DatabaseComponent} to be closed before returning.
|
||||
*/
|
||||
public void waitForShutdown() throws InterruptedException;
|
||||
void waitForShutdown() throws InterruptedException;
|
||||
}
|
||||
Reference in New Issue
Block a user