Created
April 3, 2012 23:55
-
-
Save altmind/2296459 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MindlessClient{ | |
| ... | |
| if (request.invalid()) | |
| { | |
| String requestLoggedUUID = FileLogger.persistFile(request.getOutputStream()); | |
| String configurationFileUUID = FileLogger.persistFile(Configuration.toString()); | |
| LOG.error("Request invalid. UUIDs request: "+requestLoggedUUID +", configuration: "+configurationFileUUID ); | |
| // no guarantees, that files are successfully saved. we don't bother, anyway | |
| } | |
| ... | |
| } | |
| class FileLogger{ | |
| Thread processorLog = new Thread(new Runnable(){ | |
| @override | |
| public void run() | |
| { | |
| while(true) | |
| { | |
| try{ | |
| Pair<Object,String> p = queue.take(); | |
| File f = new File("/path/to/shared/nfs/"+p.getSecond()); | |
| IOUtils.write(f,p.getFirst()); // blocking, cleans up | |
| } | |
| catch(InterruptedException ie) {/* disregard that*/} | |
| catch(IOException ioe) {LOGGER.error(e,e);} | |
| } | |
| } | |
| }); | |
| static{ | |
| processorLog.start(); | |
| } | |
| BlockingQueue<Pair<Object,String>> filesToPersist=new LinkedBlockingQueue<Pair<Object,String>>(); | |
| /* dont block, return always instantly*/ | |
| public static String persistFile(String/* or InputStream */ content){ | |
| String filename="FILE"+UUID.randomUUID(); // Should generate something like FILE{0aa1ff-08fa-1112ac-77341a} which is distinguishable, unique reference to file in log. | |
| filesToPersist.add(Pair.of(content,filename)); | |
| return filename; | |
| }; | |
| public static FileWriteStatus getFileStatus(String uuid) | |
| { | |
| //check queues, check file existence on fs, return status: WAITING, WRITTEN, MISSING | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment