RuneHive-Game
Loading...
Searching...
No Matches
dev.advo.fs.dispatch.OnDemandRequestWorker Class Reference

A worker which services 'on-demand' requests. More...

Inheritance diagram for dev.advo.fs.dispatch.OnDemandRequestWorker:
Collaboration diagram for dev.advo.fs.dispatch.OnDemandRequestWorker:

Public Member Functions

 OnDemandRequestWorker (IndexedFileSystem fs)
 Creates the 'on-demand' request worker.
final void run ()
final void stop ()
 Stops this worker.

Protected Member Functions

ChannelRequest< OnDemandRequestnextRequest () throws InterruptedException
void service (IndexedFileSystem fs, Channel channel, OnDemandRequest request) throws IOException

Private Attributes

final Object lock = new Object()
 An object used for locking checks to see if the worker is running.
final IndexedFileSystem provider
 The resource provider.
boolean running = true
 A flag indicating if the worker should be running.

Detailed Description

A worker which services 'on-demand' requests.

Author
Graham

Definition at line 19 of file OnDemandRequestWorker.java.

Constructor & Destructor Documentation

◆ OnDemandRequestWorker()

dev.advo.fs.dispatch.OnDemandRequestWorker.OnDemandRequestWorker ( IndexedFileSystem fs)

Creates the 'on-demand' request worker.

Parameters
fsThe file system.

Definition at line 38 of file OnDemandRequestWorker.java.

38 {
39 this.provider = fs;
40 }

Member Function Documentation

◆ nextRequest()

ChannelRequest< OnDemandRequest > dev.advo.fs.dispatch.OnDemandRequestWorker.nextRequest ( ) throws InterruptedException
protected

Definition at line 42 of file OnDemandRequestWorker.java.

42 {
43 return RequestDispatcher.nextOnDemandRequest();
44 }

References dev.advo.fs.dispatch.RequestDispatcher.nextOnDemandRequest().

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

final void dev.advo.fs.dispatch.OnDemandRequestWorker.run ( )

Definition at line 78 of file OnDemandRequestWorker.java.

78 {
79 while (true) {
80 synchronized (lock) {
81 if (!running) {
82 break;
83 }
84 }
85
86 ChannelRequest<OnDemandRequest> request;
87 try {
88 request = nextRequest();
89 } catch (InterruptedException e) {
90 continue;
91 }
92
93 Channel channel = request.getChannel();
94
95 try {
96 service(provider, channel, request.getRequest());
97 } catch (IOException e) {
98 // System.err.println("Error serving file: " + request.getRequest().getFileDescriptor().toString());
99 // e.printStackTrace();
100 // channel.close();
101 }
102 }
103 }

References dev.advo.fs.dispatch.ChannelRequest< T >.getChannel(), dev.advo.fs.dispatch.ChannelRequest< T >.getRequest(), lock, nextRequest(), provider, running, and service().

Here is the call graph for this function:

◆ service()

void dev.advo.fs.dispatch.OnDemandRequestWorker.service ( IndexedFileSystem fs,
Channel channel,
OnDemandRequest request ) throws IOException
protected

Definition at line 52 of file OnDemandRequestWorker.java.

52 {
53 FileDescriptor desc = request.getFileDescriptor();
54 System.err.println("Serving file: " + desc.toString());
55
56 ByteBuffer buf = fs.getFile(desc);
57 int bufLen = buf.remaining();
58 int length = bufLen;
59
60 byte[] tmp = new byte[bufLen];
61 buf.get(tmp, 0, tmp.length);
62 ChannelBuffer chunkData = ChannelBuffers.wrappedBuffer(tmp, 0, bufLen);
63
64 OnDemandResponse response = new OnDemandResponse(desc, length, chunkData);
65 channel.write(response);
66 }

References dev.advo.fs.fs.FileDescriptor.toString().

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stop()

final void dev.advo.fs.dispatch.OnDemandRequestWorker.stop ( )

Stops this worker.

The worker's thread may need to be interrupted.

Definition at line 71 of file OnDemandRequestWorker.java.

71 {
72 synchronized (lock) {
73 running = false;
74 }
75 }

References lock, and running.

Member Data Documentation

◆ lock

final Object dev.advo.fs.dispatch.OnDemandRequestWorker.lock = new Object()
private

An object used for locking checks to see if the worker is running.

Definition at line 28 of file OnDemandRequestWorker.java.

Referenced by run(), and stop().

◆ provider

final IndexedFileSystem dev.advo.fs.dispatch.OnDemandRequestWorker.provider
private

The resource provider.

Definition at line 24 of file OnDemandRequestWorker.java.

Referenced by run().

◆ running

boolean dev.advo.fs.dispatch.OnDemandRequestWorker.running = true
private

A flag indicating if the worker should be running.

Definition at line 32 of file OnDemandRequestWorker.java.

Referenced by run(), and stop().


The documentation for this class was generated from the following file: