Skip to content

Commit

Permalink
Provide io.deephaven.appmode.ApplicationState.Factory via a Set (#3037)
Browse files Browse the repository at this point in the history
This allows integrators to Bind their own factories if service loader is not appropriate (for example, if the factory has other dependencies).
  • Loading branch information
devinrsmith authored Nov 15, 2022
1 parent af0a58b commit bf22c8e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@

import dagger.Binds;
import dagger.Module;
import dagger.Provides;
import dagger.multibindings.ElementsIntoSet;
import dagger.multibindings.IntoSet;
import io.deephaven.appmode.ApplicationState;
import io.deephaven.appmode.ApplicationState.Factory;
import io.deephaven.engine.util.ScriptSession;
import io.deephaven.server.session.TicketResolver;
import io.grpc.BindableService;

import java.util.LinkedHashSet;
import java.util.Set;

@Module
public interface AppModeModule {
@Binds
Expand All @@ -29,4 +35,12 @@ public interface AppModeModule {

@Binds
ApplicationStates bindApplicationStates(ApplicationTicketResolver resolver);

@Provides
@ElementsIntoSet
static Set<Factory> providesFactoriesFromServiceLoader() {
final Set<Factory> set = new LinkedHashSet<>();
ApplicationState.Factory.loadFromServiceFactory().forEach(set::add);
return set;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import io.deephaven.appmode.ApplicationConfig;
import io.deephaven.appmode.ApplicationState;
import io.deephaven.appmode.ApplicationState.Factory;
import io.deephaven.engine.liveness.LivenessScopeStack;
import io.deephaven.engine.util.ScriptSession;
import io.deephaven.internal.log.LoggerFactory;
Expand All @@ -19,6 +20,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Set;

public class ApplicationInjector {

Expand All @@ -27,19 +29,22 @@ public class ApplicationInjector {
private final Provider<ScriptSession> scriptSessionProvider;
private final ApplicationTicketResolver ticketResolver;
private final ApplicationState.Listener applicationListener;
private final Set<Factory> factories;

@Inject
public ApplicationInjector(
final Provider<ScriptSession> scriptSessionProvider,
final ApplicationTicketResolver ticketResolver,
final ApplicationState.Listener applicationListener) {
final ApplicationState.Listener applicationListener,
final Set<Factory> factories) {
this.scriptSessionProvider = Objects.requireNonNull(scriptSessionProvider);
this.ticketResolver = ticketResolver;
this.applicationListener = applicationListener;
this.factories = factories;
}

public void run() throws IOException, ClassNotFoundException {
for (ApplicationState.Factory factory : ApplicationState.Factory.loadFromServiceFactory()) {
for (ApplicationState.Factory factory : factories) {
loadApplicationFactory(factory);
}

Expand Down

0 comments on commit bf22c8e

Please sign in to comment.