Add more lifecycle states, merge lifecycle events.

This commit is contained in:
akwizgran
2018-03-01 14:29:35 +00:00
parent af1fc6f095
commit 0a70c2d44d
10 changed files with 69 additions and 59 deletions

View File

@@ -1,9 +0,0 @@
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

@@ -29,7 +29,12 @@ public interface LifecycleManager {
* Returned by {@link #getLifecycleState()}
*/
enum LifecycleState {
STARTING, MIGRATING, RUNNING
STARTING, MIGRATING_DATABASE, STARTING_SERVICES, RUNNING, STOPPING;
public boolean isAfter(LifecycleState state) {
return ordinal() > state.ordinal();
}
}
/**

View File

@@ -0,0 +1,20 @@
package org.briarproject.bramble.api.lifecycle.event;
import org.briarproject.bramble.api.event.Event;
import org.briarproject.bramble.api.lifecycle.LifecycleManager.LifecycleState;
/**
* An event that is broadcast when the app enters a new lifecycle state.
*/
public class LifecycleEvent extends Event {
private final LifecycleState state;
public LifecycleEvent(LifecycleState state) {
this.state = state;
}
public LifecycleState getLifecycleState() {
return state;
}
}

View File

@@ -1,9 +0,0 @@
package org.briarproject.bramble.api.lifecycle.event;
import org.briarproject.bramble.api.event.Event;
/**
* An event that is broadcast when the app is shutting down.
*/
public class ShutdownEvent extends Event {
}

View File

@@ -1,10 +0,0 @@
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 {
}