public static FileReadModuleStage<?, ?, ?, ?> newInstance(GraphManager graphManager, Pipe<HTTPRequestSchema> input, Pipe<ServerResponseSchema> output, HTTPSpecification<?, ?, ?, ?> httpSpec, String resourceRootFolder, String resourceDefaultPath) { return new FileReadModuleStage(graphManager, new Pipe[]{input}, new Pipe[]{output}, httpSpec, resourceRootFolder, resourceDefaultPath); }
private void collectAllKnownFiles(int rootSize, TrieParser pathCache, File[] children) { int i = children.length; StringBuilder builder = new StringBuilder(); // System.out.println("collect from "+root+" "+i); while (--i>=0) { File child = children[i]; if ((!child.isHidden()) && child.canRead()) { if (child.isDirectory()) { collectAllKnownFiles(rootSize, pathCache, child.listFiles()); } else { setupUnseenFile(pathCache, child.toString(), rootSize, data.fileSystem, builder); } } } }
private int countAllKnownFiles(File[] children) { int total = 0; int i = children.length; while (--i>=0) { File child = children[i]; if ((!child.isHidden()) && child.canRead()) { if (child.isDirectory()) { total += (countAllKnownFiles(child.listFiles())+1); } else { total++; } } } return total; }
if (writeBodiesWhileRoom(activeChannelHigh, activeChannelLow, activeSequenceId, activeFileChannel, activePathId, input, output)) { didWork++; disconnectDueToError(this, activeReadMessageSize, ioex, input, output); assert(recordIncomingState(!Pipe.hasContentToRead(input))); assert(recordOutgoingState(!Pipe.hasRoomForWrite(output))); beginReadingNextRequest(input, output); } else { if (-1 != msgIdx) { requestShutdown(); //NOTE: since we have multiple inputs now we must do a countdown before shutdown. break; checkForHotReplace();
debugFileProgress(); useInFlightData(output, headBlobPosInPipe, blobMask, len, prevBlobPos, blob, foundFile, countOfBytesToSkip); activeMessageStart = publishBodyPart(channelHigh, channelLow, sequence, output, len, data.getFcId()[pathId]); activeMessageStart = publishBodyPart(channelHigh, channelLow, sequence, output, (int)len, data.getFcId()[pathId]); long dataPos = positionOfFileDataBegin(output); PipeHashTable.replaceItem(outputHash, data.getFcId()[pathId], dataPos); long dataPos = positionOfFileDataBegin(output);
assert(Pipe.getWorkingBlobHeadPosition(output) == positionOfFileDataBegin(output)); publishBodiesMessage(this, verb, sequence, pathId, input, output); } catch (IOException ioex) { disconnectDueToError(this, activeReadMessageSize, ioex, input, output); publishErrorHeader(httpRevision, requestContext, sequence, e, input, output);
@Override public Pipe<ServerResponseSchema>[] registerModule(int a, GraphManager graphManager, RouterStageConfig routerConfig, Pipe<HTTPRequestSchema>[] inputPipes) { //the file server is stateless therefore we can build 1 instance for every input pipe int instances = inputPipes.length; Pipe<ServerResponseSchema>[] staticFileOutputs = new Pipe[instances]; int i = instances; while (--i>=0) { staticFileOutputs[i] = new Pipe<ServerResponseSchema>(fileServerOutgoingDataConfig); FileReadModuleStage.newInstance(graphManager, inputPipes[i], staticFileOutputs[i], (HTTPSpecification<HTTPContentTypeDefaults, HTTPRevisionDefaults, HTTPVerbDefaults, HTTPHeaderDefaults>) ((HTTPRouterStageConfig)routerConfig).httpSpec, new File(pathRoot)); } routerConfig.registerCompositeRoute().path("/${path}"); //no headers requested return staticFileOutputs; }
int pathId = selectActiveFileChannel(pathCacheReader, data.getPathCache(), bytesLength-2, bytesBackingArray, bytesPosition+2, bytesMask); publishErrorHeader(activeRequestContext, activeSequenceId, 404, input, output); beginSendingFile(httpRevision, activeRequestContext, pathId, verb, activeSequenceId, input, output); } else { publishErrorHeader(activeRequestContext, 0, activeSequenceId, null, output);
int counts = countAllKnownFiles(children)+1;//IDs start at 1 so we need extra room maxFileCount = 1<<(int)Math.ceil(Math.log(counts)/Math.log(2)); //convert to next power of 2 collectAllKnownFiles(rootSize, pc, children);
if (null!=(activeFileChannel = channelHolder.getValid(data.getFcId()[pathId]))) { } else { findAgainFileChannel(pathId);
public RouteFilter addFileServer(String path) { //adds server to all routes final int parallelIndex = (-1 == parallelInstanceUnderActiveConstruction) ? 0 : parallelInstanceUnderActiveConstruction; //due to internal implementation we must keep the same number of outputs as inputs. Pipe<HTTPRequestSchema>[] inputs = new Pipe[1]; Pipe<ServerResponseSchema>[] outputs = new Pipe[1]; populateHTTPInOut(inputs, outputs, 0, parallelIndex); FileReadModuleStage.newInstance(gm, inputs, outputs, builder.httpSpec, buildFilePath(path)); return new StageRouteFilter(inputs[0], builder, parallelIndex); }
if (null != pathRoot) { FileReadModuleStage.newInstance(graphManager, inputPipes[i], staticFileOutputs[i], (HTTPSpecification<HTTPContentTypeDefaults, HTTPRevisionDefaults, HTTPVerbDefaults, HTTPHeaderDefaults>) ((HTTPRouterStageConfig)routerConfig).httpSpec, pathRoot); } else {
public static FileReadModuleStage<?, ?, ?, ?> newInstance(GraphManager graphManager, Pipe<HTTPRequestSchema>[] inputs, Pipe<ServerResponseSchema>[] output, HTTPSpecification<?, ?, ?, ?> httpSpec, File rootPath) { return new FileReadModuleStage(graphManager, inputs, output, httpSpec, rootPath); }
public static FileReadModuleStage<?, ?, ?, ?> newInstance(GraphManager graphManager, Pipe<HTTPRequestSchema> input, Pipe<ServerResponseSchema> output, HTTPSpecification<?, ?, ?, ?> httpSpec, File rootPath) { return new FileReadModuleStage(graphManager, new Pipe[]{input}, new Pipe[]{output}, httpSpec, rootPath); }
public static FileReadModuleStage<?, ?, ?, ?> newInstance(GraphManager graphManager, Pipe<HTTPRequestSchema>[] inputs, Pipe<ServerResponseSchema>[] output, HTTPSpecification<?, ?, ?, ?> httpSpec, String resourceRootFolder, String resourceDefaultPath) { return new FileReadModuleStage(graphManager, inputs, output, httpSpec, resourceRootFolder, resourceDefaultPath); }