Executors and Services register themselves with the LifecycleManager.

Fixes issue #3612607.
This commit is contained in:
akwizgran
2013-05-15 12:26:56 +01:00
parent dddd15cd10
commit 630cfde81e
30 changed files with 301 additions and 189 deletions

View File

@@ -1,6 +1,7 @@
package net.sf.briar.api.crypto;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@@ -11,6 +12,6 @@ import com.google.inject.BindingAnnotation;
/** Annotation for injecting the executor for long-running crypto tasks. */
@BindingAnnotation
@Target({ FIELD, PARAMETER })
@Target({ FIELD, METHOD, PARAMETER })
@Retention(RUNTIME)
public @interface CryptoExecutor {}

View File

@@ -2,19 +2,11 @@ package net.sf.briar.api.crypto;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.TransportId;
import net.sf.briar.api.lifecycle.Service;
import net.sf.briar.api.transport.ConnectionContext;
import net.sf.briar.api.transport.Endpoint;
public interface KeyManager {
/**
* Starts the key manager and returns true if it started successfully. This
* method must be called after the database has been opened.
*/
boolean start();
/** Stops the key manager. */
void stop();
public interface KeyManager extends Service {
/**
* Returns a connection context for connecting to the given contact over

View File

@@ -1,6 +1,7 @@
package net.sf.briar.api.db;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@@ -11,6 +12,6 @@ import com.google.inject.BindingAnnotation;
/** Annotation for injecting the executor for database tasks. */
@BindingAnnotation
@Target({ FIELD, PARAMETER })
@Target({ FIELD, METHOD, PARAMETER })
@Retention(RUNTIME)
public @interface DatabaseExecutor {}

View File

@@ -1,19 +1,37 @@
package net.sf.briar.api.lifecycle;
import java.util.concurrent.ExecutorService;
public interface LifecycleManager {
/** Starts any services that need to be started at startup. */
/** Registers a {@link Service} to be started and stopped. */
public void register(Service s);
/**
* Registers an {@link java.util.concurrent.ExecutorService ExecutorService}
* to be shut down.
*/
public void registerForShutdown(ExecutorService e);
/** Starts any registered {@link Service}s. */
public void startServices();
/** Stops any services that need to be stopped at shutdown. */
/**
* Stops any registered {@link Service}s and shuts down any registered
* {@link java.util.concurrent.ExecutorService ExecutorService}s.
*/
public void stopServices();
/** Waits for the database to be opened before returning. */
public void waitForDatabase() throws InterruptedException;
/** Waits for all services to start before returning. */
/** Waits for all registered {@link Service}s to start before returning. */
public void waitForStartup() throws InterruptedException;
/** Waits for all services to stop before returning. */
/**
* Waits for all registered {@link Service}s to stop and all registered
* {@link java.util.concurrent.ExecutorService ExecutorService}s to shut
* down before returning.
*/
public void waitForShutdown() throws InterruptedException;
}
}

View File

@@ -0,0 +1,10 @@
package net.sf.briar.api.lifecycle;
public interface Service {
/** Starts the service and returns true if it started successfully. */
public boolean start();
/** Stops the service and returns true if it stopped successfully. */
public boolean stop();
}

View File

@@ -1,5 +1,7 @@
package net.sf.briar.api.plugins;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@@ -10,6 +12,6 @@ import com.google.inject.BindingAnnotation;
/** Annotation for injecting the executor used by transport plugins. */
@BindingAnnotation
@Target({ PARAMETER })
@Target({ FIELD, METHOD, PARAMETER })
@Retention(RUNTIME)
public @interface PluginExecutor {}

View File

@@ -2,25 +2,14 @@ package net.sf.briar.api.plugins;
import java.util.Collection;
import net.sf.briar.api.lifecycle.Service;
import net.sf.briar.api.plugins.duplex.DuplexPlugin;
/**
* Responsible for starting transport plugins at startup, stopping them at
* shutdown, and providing access to plugins for exchanging invitations.
*/
public interface PluginManager {
/**
* Starts the plugins and returns the number of plugins successfully
* started. This method must not be called until the database has been
* opened.
*/
int start();
/**
* Stops the plugins and returns the number of plugins successfully stopped.
*/
int stop();
public interface PluginManager extends Service {
/** Returns any running duplex plugins that support invitations. */
Collection<DuplexPlugin> getInvitationPlugins();

View File

@@ -1,5 +1,7 @@
package net.sf.briar.api.reliability;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@@ -10,6 +12,6 @@ import com.google.inject.BindingAnnotation;
/** Annotation for injecting the executor used by reliability layers. */
@BindingAnnotation
@Target({ PARAMETER })
@Target({ FIELD, METHOD, PARAMETER })
@Retention(RUNTIME)
public @interface ReliabilityExecutor {}

View File

@@ -1,5 +1,7 @@
package net.sf.briar.api.transport;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@@ -12,6 +14,6 @@ import com.google.inject.BindingAnnotation;
* Annotation for injecting the executor for recognising incoming connections.
*/
@BindingAnnotation
@Target({ PARAMETER })
@Target({ FIELD, METHOD, PARAMETER })
@Retention(RUNTIME)
public @interface IncomingConnectionExecutor {}