More work on the demos

This commit is contained in:
Greg Wilkins 2022-07-15 09:18:52 +10:00
parent a86906b338
commit fc6a92f426
4 changed files with 23 additions and 14 deletions

View File

@ -82,17 +82,15 @@ public class HandlerDocs
{
response.setStatus(200);
response.getHeaders().add(HttpHeader.CONTENT_TYPE, "text/plain");
Blocker.Shared blocker = new Blocker.Shared();
try (Blocker.Callback cb = blocker.callback())
try (Blocker.Callback blocker = Blocker.callback())
{
response.write(true, BufferUtil.toBuffer("Hello "), callback);
cb.block();
}
try (Blocker.Callback cb = blocker.callback())
{
response.write(true, BufferUtil.toBuffer("World\n"), callback);
cb.block();
response.write(false, BufferUtil.toBuffer("Hello "), blocker);
blocker.block();
}
Content.Sink.write(response, true, BufferUtil.toBuffer("World\n"));
callback.succeeded();
}
}

View File

@ -161,7 +161,8 @@ public abstract class ScanningAppProvider extends ContainerLifeCycle implements
boolean coreProvider = _deploymentManager.getAppProviders().stream()
.map(AppProvider::getEnvironmentName).anyMatch(Environment.CORE.getName()::equals);
if (isWebapp)
// TODO review these heuristics... or even if we should have them at all
if (isWebapp || (Files.isDirectory(path) && _deploymentManager.getDefaultEnvironmentName() != null))
environmentName = _deploymentManager.getDefaultEnvironmentName();
else if (coreProvider)
environmentName = Environment.CORE.getName();

View File

@ -204,14 +204,23 @@ public class CachingContentFactory implements HttpContent.ContentFactory
{
_etag = precalculatedEtag;
_contentLengthValue = httpContent.getContentLengthValue(); // TODO getContentLengthValue() could return -1
ByteBuffer byteBuffer;
ByteBuffer byteBuffer = null;
if (_useFileMappedBuffer)
{
// mmap the content into memory
byteBuffer = BufferUtil.toMappedBuffer(httpContent.getResource().getPath(), 0, _contentLengthValue);
// map the content into memory
// TODO this is assuming the resource can be mapped! Inefficient to throw to test this
try
{
byteBuffer = BufferUtil.toMappedBuffer(httpContent.getResource().getPath(), 0, _contentLengthValue);
}
catch (Throwable t)
{
LOG.trace("ignored", t);
}
}
else
if (byteBuffer == null)
{
// TODO use pool & check length limit
// load the content into memory

View File

@ -167,6 +167,7 @@ public class WebSocketUpgradeFilter implements Filter, Dumpable
callback.block();
return;
}
callback.succeeded(); // TODO this is wasteful making a blocker on every request, even if it is not used. At leasts should be shared... but better to detect if we might need to upgrade first?
}
// If we reach this point, it means we had an incoming request to upgrade