// client sideDataProvider dp = new MemoryMapDataProvider();Location file = new FileLocation("someFolder/someFile");byte[] bytes = file.toByteArray();dp.setValue("file1", bytes);// node sidebyte[] bytes = (byte[]) getDataProvider().getValue("file1");Location memLoc = new MemoryLocation(bytes);// save to the node local file systemLocation fileLoc = new FileLocation("someFolder/someFile");memLoc.copyTo(fileLoc);
System.out.println("running JPPF version " + VersionUtils.getVersion().getVersionNumber());
System.out.println("own classloader = " + getClass().getClassLoader());System.out.println("context classloader = " + Thread.currentThread().getContextClassLoader());
public class MyTask extends JPPFTask { // maps the names of files in the directory to their content private Map<String, byte[]> fileMap = new HashMap<>(); private String directoryName; // used to generate a unique directory name on the node side private static AtomicInteger sequence = new AtomicInteger(0); public MyTask(File directory) { this.directoryName = directory.getName(); File[] files = directory.listFiles(); if (files != null) { for (File file: files) { if (file.isFile()) { byte[] content = new FileLocation(file).toByteArray(); fileMap.put(file.getName(), content); } } } } @Override public void run() { File directory = copyFiles(); ... task code ... } private File copyFiles() { // first create a unique directory, for instance in '/tmp' File dir = new File("/tmp/" + this.directoryName + "_" + sequence.incrementAndGet()); // create all necessary parent directories if (!dir.mkDirs()) throw new IllegalStateException("could not create directory '" + dir + "'"); // copy all the files in that directory for (Map.Entry<String, byte[]> entry: fileMap.entrySet()) { // wrap the byte[] into a MemoryLocation object Location memLocation = new MemoryLocation(entry.getValue()); // generate the path of the file to create File file = new File(dir, entry.getKey()); Location fileLocation = new FileLocation(file); // copy the content to the actual file memLocation.copyTo(fileLocation); } return dir; }}
Is there a way to trick jppf's cache to it can use the files I bring from the client instead of trying to get it itself?
import java.nio.file.Paths;import java.util.List;import org.jppf.client.JPPFClient;import org.jppf.client.JPPFJob;import org.jppf.server.protocol.JPPFTask;public class JppfSample { public static void main(String[] args) throws Exception { JPPFClient client = new JPPFClient(); JPPFJob job = new JPPFJob(); job.addTask(new JPPFTask() { private String resource1, resource2; public void run() { try { String file = Paths.get(Thread.currentThread().getContextClassLoader().getResource("resource2/resources/etc").toURI()).toFile().getAbsolutePath(); System.out.println(resource1 = file); file = Paths.get(Thread.currentThread().getContextClassLoader().getResource("resource2/resources").toURI()).toFile().getAbsolutePath(); System.out.println(resource2 = file); } catch (Throwable e) { e.printStackTrace(); } } @Override public String toString() { return resource1 + "\n" + resource2; } }); List<JPPFTask> submit = client.submit(job); JPPFTask task = submit.get(0); System.out.println(task); System.exit(0); }}
File file = Paths.get(Thread.currentThread().getContextClassLoader().getResource("resource2/resources/etc").toURI()).toFile();String resource = file.getAbsolutePath();System.out.println("resource1 = " + resource);resource = file.getParentFile().getAbsolutePath();System.out.println("resource2 = " + resource);