1package dev.advo.fs.dispatch;
3import java.io.IOException;
4import java.nio.ByteBuffer;
6import org.jboss.netty.buffer.ChannelBuffer;
7import org.jboss.netty.buffer.ChannelBuffers;
8import org.jboss.netty.channel.Channel;
10import dev.advo.fs.fs.FileDescriptor;
11import dev.advo.fs.fs.IndexedFileSystem;
12import dev.advo.fs.net.ondemand.OnDemandRequest;
13import dev.advo.fs.net.ondemand.OnDemandResponse;
28 private final Object
lock =
new Object();
54 System.err.println(
"Serving file: " + desc.
toString());
56 ByteBuffer buf =
fs.getFile(desc);
57 int bufLen = buf.remaining();
60 byte[] tmp =
new byte[bufLen];
61 buf.get(tmp, 0, tmp.length);
62 ChannelBuffer chunkData = ChannelBuffers.wrappedBuffer(tmp, 0, bufLen);
65 channel.write(response);
78 public final void run() {
89 }
catch (InterruptedException e) {
97 }
catch (IOException e) {
A specialised request which contains a channel as well as the request object itself.
Channel getChannel()
Gets the channel.
T getRequest()
Gets the request.
void service(IndexedFileSystem fs, Channel channel, OnDemandRequest request)
OnDemandRequestWorker(IndexedFileSystem fs)
Creates the 'on-demand' request worker.
final void stop()
Stops this worker.
final IndexedFileSystem provider
The resource provider.
boolean running
A flag indicating if the worker should be running.
final Object lock
An object used for locking checks to see if the worker is running.
ChannelRequest< OnDemandRequest > nextRequest()
A class which dispatches requests to worker threads.
static ChannelRequest< OnDemandRequest > nextOnDemandRequest()
Gets the next 'on-demand' request from the queue, blocking if none are available.
A class which points to a file in the cache.
A file system based on top of the operating system's file system.