Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.Objects;
import java.util.ServiceLoader;
import java.util.ServiceLoader.Provider;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
Expand Down Expand Up @@ -372,6 +373,12 @@ public void start() throws Exception
if (!readonly)
{
manager.start();

workers.stream()
.map(w -> w.attachRouter(routerConfig))
.reduce(CompletableFuture::allOf)
.ifPresent(CompletableFuture::join);

Ready.markReady(config.directory());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ final class EngineRouterContext implements RouterContext
}

@Override
public BindingHandler attach(
RouterConfig config)
public BindingHandler streamFactory()
{
return streamFactory;
}

@Override
public void attach(
RouterConfig config)
{
}

@Override
public void detach(
long routerId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ public EngineWorker(
EngineRouteable routeable = new EngineRouteable(config, this::newStream,
this::attachComposite, this::detachComposite, this::supplyStore);
this.router = router.supply(routeable);
this.streamFactory = this.router.streamFactory();

this.bindings = bindings;
this.exporters = exporters;
Expand Down Expand Up @@ -993,8 +994,6 @@ public void onStart()

private void doInit()
{
this.streamFactory = router.attach(routerConfig);

Map<String, BindingContext> bindingsByType = bindings.stream()
.collect(toMap(Binding::name, b -> b.supply(this), (a, b) -> a, LinkedHashMap::new));

Expand Down Expand Up @@ -1194,6 +1193,28 @@ public CompletableFuture<Void> detach(
return detachTask.future();
}

public CompletableFuture<Void> attachRouter(
RouterConfig config)
{
assert thread != Thread.currentThread();

CompletableFuture<Void> future = new CompletableFuture<>();
dispatch(() ->
{
try
{
router.attach(config);
future.complete(null);
}
catch (Throwable ex)
{
future.completeExceptionally(ex);
}
});

return future;
}

public AgentRunner runner()
{
return runner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,27 @@
public interface RouterContext
{
/**
* Attaches a router configuration to this thread's context, returning the composed
* {@link BindingHandler} that will be installed as the engine's stream factory.
* Returns this thread's composed {@link BindingHandler}, installed as the engine's
* stream factory.
* <p>
* Available immediately once this context is constructed, independent of {@link #attach},
* so the engine can wire it into bindings before any registry-dependent setup has run.
* </p>
*
* @return the composed stream factory
*/
BindingHandler streamFactory();

/**
* Attaches a router configuration to this thread's context.
* <p>
* Called once this thread's namespace registry reflects the engine's bootstrap
* configuration, so implementations may safely attach synthesized namespaces here.
* </p>
*
* @param config the router configuration to activate
* @return a {@link BindingHandler} that the engine installs as its stream factory
*/
BindingHandler attach(
void attach(
RouterConfig config);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,17 @@ public TestRouterContext(
}

@Override
public BindingHandler attach(
RouterConfig config)
public BindingHandler streamFactory()
{
return streamFactory;
}

@Override
public void attach(
RouterConfig config)
{
}

@Override
public void detach(
long routerId)
Expand Down
Loading