use of com.ociweb.pronghorn.network.http.HTTP1xRouterStageConfig in project GreenLightning by oci-pronghorn.
the class MsgRuntime method buildLastHalfOfGraphForServer.
private void buildLastHalfOfGraphForServer(MsgApp app, ServerPipesConfig serverConfig, ServerCoordinator serverCoord, final int routerCount, Pipe[] acks, Pipe[] handshakeIncomingGroup, Pipe[] planIncomingGroup) {
if (app instanceof MsgAppParallel) {
int p = builder.parallelTracks();
for (int i = 0; i < p; i++) {
constructingParallelInstance(i);
// this creates all the modules for this parallel instance
((MsgAppParallel) app).declareParallelBehavior(this);
}
} else {
if (builder.parallelTracks() > 1) {
throw new UnsupportedOperationException("Remove call to parallelism(" + builder.parallelTracks() + ") OR make the application implement GreenAppParallel or something extending it.");
}
}
// ////////////////
// ////////////////
HTTP1xRouterStageConfig routerConfig = builder.routerConfig();
ArrayList<Pipe> forPipeCleaner = new ArrayList<Pipe>();
Pipe<HTTPRequestSchema>[][] fromRouterToModules = new Pipe[routerCount][];
int t = routerCount;
int totalRequestPipes = 0;
while (--t >= 0) {
// [router/parallel] then [parser/routes]
int path = routerConfig.totalPathsCount();
// /////////////
if (path == 0) {
path = 1;
}
// ///////////
fromRouterToModules[t] = new Pipe[path];
while (--path >= 0) {
ArrayList<Pipe<HTTPRequestSchema>> requestPipes = builder.buildFromRequestArray(t, path);
// with a single pipe just pass it one, otherwise use the replicator to fan out from a new single pipe.
int size = requestPipes.size();
totalRequestPipes += size;
if (1 == size) {
fromRouterToModules[t][path] = requestPipes.get(0);
} else {
// we only create a pipe when we are about to use the replicator
fromRouterToModules[t][path] = builder.newHTTPRequestPipe(builder.pcm.getConfig(HTTPRequestSchema.class));
if (0 == size) {
logger.info("warning there are routes without any consumers");
// we have no consumer so tie it to pipe cleaner
forPipeCleaner.add(fromRouterToModules[t][path]);
} else {
ReplicatorStage.newInstance(gm, fromRouterToModules[t][path], requestPipes.toArray(new Pipe[requestPipes.size()]));
}
}
}
if (0 == totalRequestPipes) {
logger.warn("ERROR: includeRoutes or includeAllRoutes must be called on REST listener.");
}
}
if (!forPipeCleaner.isEmpty()) {
PipeCleanerStage.newInstance(gm, forPipeCleaner.toArray(new Pipe[forPipeCleaner.size()]));
}
// NOTE: building arrays of pipes grouped by parallel/routers heading out to order supervisor
Pipe<ServerResponseSchema>[][] fromModulesToOrderSuper = new Pipe[routerCount][];
Pipe<ServerResponseSchema>[] errorResponsePipes = new Pipe[routerCount];
PipeConfig<ServerResponseSchema> errConfig = ServerResponseSchema.instance.newPipeConfig(4, 512);
final boolean catchAll = builder.routerConfig().totalPathsCount() == 0;
int j = routerCount;
while (--j >= 0) {
Pipe<ServerResponseSchema>[] temp = fromModulesToOrderSuper[j] = builder.buildToOrderArray(j);
// this block is required to make sure the ordering stage has room
int c = temp.length;
while (--c >= 0) {
// ensure that the ordering stage can consume messages of this size
serverConfig.ensureServerCanWrite(temp[c].config().maxVarLenSize());
}
}
serverConfig.ensureServerCanWrite(errConfig.maxVarLenSize());
int r = routerCount;
while (--r >= 0) {
errorResponsePipes[r] = new Pipe<ServerResponseSchema>(errConfig);
fromModulesToOrderSuper[r] = PronghornStage.join(errorResponsePipes[r], fromModulesToOrderSuper[r]);
}
NetGraphBuilder.buildRouters(gm, planIncomingGroup, acks, fromRouterToModules, errorResponsePipes, routerConfig, serverCoord, catchAll);
// NOTE: this array populated here must be equal or larger than the fromModules..
Pipe<NetPayloadSchema>[] fromOrderedContent = NetGraphBuilder.buildRemainderOFServerStages(gm, serverCoord, serverConfig, handshakeIncomingGroup);
// NOTE: the fromOrderedContent must hold var len data which is greater than fromModulesToOrderSuper
NetGraphBuilder.buildOrderingSupers(gm, serverCoord, routerCount, fromModulesToOrderSuper, fromOrderedContent);
}
Aggregations