Show a status screen when opening the database or applying migrations

This commit is contained in:
Torsten Grote
2018-02-26 18:15:00 -03:00
committed by akwizgran
parent dac3de24e7
commit 21956f2627
22 changed files with 282 additions and 31 deletions

View File

@@ -43,7 +43,7 @@ public interface DatabaseComponent {
* @throws DataTooOldException if the data uses an older schema than the
* current code and cannot be migrated
*/
boolean open() throws DbException;
boolean open(@Nullable MigrationListener listener) throws DbException;
/**
* Waits for any open transactions to finish and closes the database.

View File

@@ -0,0 +1,9 @@
package org.briarproject.bramble.api.db;
import org.briarproject.bramble.api.event.Event;
/**
* An event that is broadcast before database migrations are being applied.
*/
public class DatabaseMigrationEvent extends Event {
}

View File

@@ -0,0 +1,11 @@
package org.briarproject.bramble.api.db;
public interface MigrationListener {
/**
* This is called when a migration is started while opening the database.
* It will be called once for each migration being applied.
*/
void onMigrationRun();
}

View File

@@ -24,6 +24,14 @@ public interface LifecycleManager {
ALREADY_RUNNING, DB_ERROR, SERVICE_ERROR, SUCCESS
}
/**
* The state the lifecycle can be in.
* Returned by {@link #getLifecycleState()}
*/
enum LifecycleState {
STARTING, MIGRATING, RUNNING
}
/**
* Registers a {@link Service} to be started and stopped.
*/
@@ -71,4 +79,10 @@ public interface LifecycleManager {
* the {@link DatabaseComponent} to be closed before returning.
*/
void waitForShutdown() throws InterruptedException;
/**
* Returns the current state of the lifecycle.
*/
LifecycleState getLifecycleState();
}

View File

@@ -0,0 +1,10 @@
package org.briarproject.bramble.api.lifecycle.event;
import org.briarproject.bramble.api.event.Event;
/**
* An event that is broadcast when the app is starting.
* This happens after the database was opened and services were started.
*/
public class StartupEvent extends Event {
}