/** * Loads the model from the location that it saves to */ @Override public <E> E load(Class<E> clazz) { return SerializationUtils.readObject(file); } }
private void addAndSave(E e) { File path = new File(dir, UUID.randomUUID().toString()); SerializationUtils.saveObject(e, path); paths.add(path.getAbsolutePath()); }
@Override public void write(DataOutputStream dos) { SerializationUtils.writeObject(masterResults,dos); } }
@Override public void save(String id,Job save) throws Exception { if(save == null) throw new IllegalArgumentException("Saving null network not allowed"); if(updateableIMap != null) { updateableIMap.put(id,save); } else { File saveFile = new File(baseDir,id); SerializationUtils.saveObject(save,saveFile); boolean loadedProperly = false; while(!loadedProperly) { try { SerializationUtils.readObject(saveFile); }catch(Exception e) { } loadedProperly = true; } paths.put(id,saveFile.getAbsolutePath()); } } }
@Override public void save(Serializable ser) { if(!rewrite) { String path = file.getAbsolutePath(); if(file.exists()) { file.renameTo(new File(file.getParentFile(),file.getName() + "-" + System.currentTimeMillis())); } file = new File(path); } log.info("Saving to " + file); SerializationUtils.saveObject(ser, file); }
@Override public E poll() { String path = paths.poll(); E ret = SerializationUtils.readObject(new File(path)); File item = new File(path); item.delete(); return ret; }
@PUT @Path("/save") public Response saveModel() { log.info("Saving model..."); try { Serializable u = stateTracker.getCurrent(); SerializationUtils.saveObject(u,new File("savedmodel.ser")); }catch(Exception e) { return Response.ok(Collections.singletonMap("status", e.getMessage())).build(); } return Response.ok(Collections.singletonMap("status", "saved")).build(); }
@Override public synchronized Job load(String id) throws Exception { String path = paths.remove(id); if(path == null) { log.warn("Tried loading work from id " + id + " but path was null"); return null; } File load = new File(path); Job u = SerializationUtils.readObject(load); load.deleteOnExit(); return u; }
@GET @Path("/model.ser") @Produces(MediaType.APPLICATION_OCTET_STREAM) public Response getFile() throws Exception { Serializable u = stateTracker.getCurrent(); File file = new File("savedmodel.ser"); SerializationUtils.saveObject(u, file); return Response.ok(file, MediaType.APPLICATION_OCTET_STREAM) .header("Content-Disposition", "attachment; filename=\"" + file.getName() + "\"" ) //optional .build(); }
/** * Loads the data applyTransformToDestination * * @param worker the worker to load for * @return the data for the given worker or null */ @Override public Job load(String worker) { File f = workerData.get(worker) != null ? new File(workerData.get(worker)) : null; if(f == null || !f.exists()) return null; Job d = SerializationUtils.readObject(f); workerData.remove(f); f.delete(); return d; }
/** * Saves the data for a given worker * * @param worker the worker to save data for * @param data the data to save */ @Override public void save(String worker, Job data){ if(distributedData != null) distributedData.put(worker,data); else { File f = new File(worker + "-work"); SerializationUtils.saveObject(data,f); workerData.put(worker,f.getAbsolutePath()); } } }
@Override public void entryAdded(EntryEvent<String, Job> event) { String worker = event.getKey(); File f = new File(worker + "-work"); SerializationUtils.saveObject(event.getValue(), f); workerData.put(worker,f.getAbsolutePath()); //only needed for the save event distributedData.remove(worker); }
@Override public void entryAdded(EntryEvent<String, Job> event) { String fileName = event.getKey(); if(event.getKey().equals(".")) fileName = UUID.randomUUID().toString(); File saveFile = new File(LocalFileUpdateSaver.this.baseDir,fileName); if(saveFile.isDirectory()) { saveFile = new File(LocalFileUpdateSaver.this.baseDir,UUID.randomUUID().toString()); } SerializationUtils.saveObject(event.getValue(),saveFile); paths.put(event.getKey(),saveFile.getAbsolutePath()); //no longer needed after persistence updateableIMap.remove(event.getKey()); }