Google calendar

Tuesday 28 June 2016

Communication WebSocket and concurrency

The goal is to achieve multiple notes to be downloaded from the peers. Hence the concurrency, the downloading should not block the main running thread.This is common to IpfsNotebookrepo or Bittorentrepo. So how should the design be ?

Here is the current IpfsNotebookrepo class.
The get(hash : Multihash) and get(url : MagnetURL) are blocking calls. It waits till it downloads from peer. Hence they have to be run in a thread. Hence various approaches are
  1. IpfsNotebookRepo implements Runnable and submit it to scheduler. But I will have to create new IpfsNotebookRepo instances everytime.
  2. Create a class IpfsDownloadTask implements Runnable/Callable . Should this class be nested , inner or a separate class. If it is a separate class it should contain IpfsNotebookRepo instance as a member to call .get method.
 I have created a separate example project just focusing on the main part. 


here is the code..
 
Currently I have used callbacks from google-gauva. After the download is complete  send method is called with appropriate operation to notify the user.

So here are my questions 
  1. IpfsTask class call method currently calls getNote which just returns uppercase, actually it will be returning the note in string from peer. Where should this class be ? inner, separate ? If separate , it should contain IpfsNotebookRepo instance ?
  2. After the note is downloaded I need to call the importNote from Notebook Server class which actually adds the note and broadcasts. How to achieve this ?
  3. Ipfs servlet listens on separate url path for websocket. Should it be part of Notebook server path ? 
I thinks design will be common to Bittorrent as well. So I would be grateful if you would give your help and advice on the design of communication.