private void receivedHandlerMessage(Session session, Message message) {
final DFSHandlerMessage type = (DFSHandlerMessage) message.specification;
CompletionToken token = null;
AbstractFileHandlerDriver driver = null;
Object result;
switch (type)
{
case READ:
final DFSPayloads.ReadFile readPayload = (DFSPayloads.ReadFile) message.payload;
token = readPayload.getToken();
driver = drivers.get(readPayload.getFileHandler());
session.continueDispatch();
result = driver.read(readPayload.getNumBytes());
sendResult(session, token, FileHandlerOperantions.READ, result);
break;
case WRITE:
final DFSPayloads.WriteFile writePayload = (DFSPayloads.WriteFile) message.payload;
token = writePayload.getToken();
driver = drivers.get(writePayload.getFileHandler());
session.continueDispatch();
byte[] data = writePayload.getData().toByteArray();
result = driver.write(data);
sendResult(session, token, FileHandlerOperantions.WRITE, result);
break;
case FLUSH:
final DFSPayloads.FlushFile flushPayload = (DFSPayloads.FlushFile) message.payload;
token = flushPayload.getToken();
driver = drivers.get(flushPayload.getFileHandler());
result = driver.flush();
sendResult(session, token, FileHandlerOperantions.FLUSH, result);
break;
case SEEK:
final DFSPayloads.SeekFile seekPayload = (DFSPayloads.SeekFile) message.payload;
token = seekPayload.getToken();
driver = drivers.get(seekPayload.getFileHandler());
result = driver.seek(seekPayload.getPosition());
sendResult(session, token, FileHandlerOperantions.SEEK, result);
break;
case CLOSE:
final DFSPayloads.CloseFile closePayload = (DFSPayloads.CloseFile) message.payload;
token = closePayload.getToken();
String handle = closePayload.getFileHandler();
driver = drivers.get(handle);
drivers.remove(handle);
result = driver.close();
driver.destroy();
driver=null;
sendResult(session, token, FileHandlerOperantions.CLOSE, result);
break;
default: