Guest User

Untitled

a guest
Sep 23rd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. class MindlessClient{
  2. ...
  3. if (request.invalid())
  4. {
  5. String requestLoggedUUID = FileLogger.persistFile(request.getOutputStream());
  6. String configurationFileUUID = FileLogger.persistFile(Configuration.toString());
  7. LOG.error("Request invalid. UUIDs request: "+requestLoggedUUID +", configuration: "+configurationFileUUID );
  8. // no guarantees, that files are successfully saved. we don't bother, anyway
  9. }
  10. ...
  11. }
  12.  
  13.  
  14. class FileLogger{
  15. Thread processorLog = new Thread(new Runnable(){
  16. @override
  17. public void run()
  18. {
  19. while(true)
  20. {
  21. try{
  22. Pair<Object,String> p = queue.take();
  23. File f = new File("/path/to/shared/nfs/"+p.getSecond());
  24. IOUtils.write(f,p.getFirst()); // blocking, cleans up
  25. }
  26. catch(InterruptedException ie) {/* disregard that*/}
  27. catch(IOException ioe) {LOGGER.error(e,e);}
  28. }
  29. }
  30. });
  31.  
  32. static{
  33. processorLog.start();
  34. }
  35. BlockingQueue<Pair<Object,String>> filesToPersist=new LinkedBlockingQueue<Pair<Object,String>>();
  36.  
  37. /* dont block, return always instantly*/
  38. public static String persistFile(String/* or InputStream */ content){
  39. String filename="FILE"+UUID.randomUUID(); // Should generate something like FILE{0aa1ff-08fa-1112ac-77341a} which is distinguishable, unique reference to file in log.
  40. filesToPersist.add(Pair.of(content,filename));
  41. return filename;
  42. };
  43. public static FileWriteStatus getFileStatus(String uuid)
  44. {
  45. //check queues, check file existence on fs, return status: WAITING, WRITTEN, MISSING
  46. }
  47.  
  48. }
Add Comment
Please, Sign In to add comment