From 1f70d53c609766d470773b6e5bf99c9711a6d488 Mon Sep 17 00:00:00 2001 From: mrbesen Date: Sat, 20 May 2017 13:42:44 +0200 Subject: [PATCH] little enhancements --- Client/BesenBoincClient/.classpath | 4 ++-- Client/BesenBoincClient/.gitignore | 1 + Client/BesenBoincClient/.settings/.gitignore | 1 + Client/BesenBoincClient/src/Core/Starter.java | 5 ++--- .../src/Comunication/Client.java | 2 -- Server/BesenBoincServer/src/Job/Worker.java | 20 ++++++++++++++++--- 6 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 Client/BesenBoincClient/.settings/.gitignore diff --git a/Client/BesenBoincClient/.classpath b/Client/BesenBoincClient/.classpath index be4e648..0de05e1 100644 --- a/Client/BesenBoincClient/.classpath +++ b/Client/BesenBoincClient/.classpath @@ -1,7 +1,7 @@ - - + + diff --git a/Client/BesenBoincClient/.gitignore b/Client/BesenBoincClient/.gitignore index ae3c172..9ae4020 100644 --- a/Client/BesenBoincClient/.gitignore +++ b/Client/BesenBoincClient/.gitignore @@ -1 +1,2 @@ /bin/ +/export.jardesc diff --git a/Client/BesenBoincClient/.settings/.gitignore b/Client/BesenBoincClient/.settings/.gitignore new file mode 100644 index 0000000..3b1537c --- /dev/null +++ b/Client/BesenBoincClient/.settings/.gitignore @@ -0,0 +1 @@ +/org.eclipse.jdt.core.prefs diff --git a/Client/BesenBoincClient/src/Core/Starter.java b/Client/BesenBoincClient/src/Core/Starter.java index 11f62b8..de5d3e9 100755 --- a/Client/BesenBoincClient/src/Core/Starter.java +++ b/Client/BesenBoincClient/src/Core/Starter.java @@ -7,7 +7,8 @@ public class Starter { public static void main(String args[]) { System.out.println("Starting BesenBoincClient..."); - + System.out.println("user.dir: " + System.getProperty("user.dir")); + String host = BB.host; int port = BB.port; if(args.length >= 1) { @@ -48,8 +49,6 @@ public class Starter { try { Client c = new Client(host, port, new Worker()); - System.out.println("Connection Established."); - c.run(); if(lost_counter > 0) { diff --git a/Server/BesenBoincServer/src/Comunication/Client.java b/Server/BesenBoincServer/src/Comunication/Client.java index 440d89b..4826df8 100755 --- a/Server/BesenBoincServer/src/Comunication/Client.java +++ b/Server/BesenBoincServer/src/Comunication/Client.java @@ -1,12 +1,10 @@ package Comunication; -import java.io.EOFException; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.net.InetAddress; import java.net.Socket; -import java.net.SocketException; import java.net.UnknownHostException; public class Client implements Runnable{ diff --git a/Server/BesenBoincServer/src/Job/Worker.java b/Server/BesenBoincServer/src/Job/Worker.java index f81f3b3..5d1a0e9 100755 --- a/Server/BesenBoincServer/src/Job/Worker.java +++ b/Server/BesenBoincServer/src/Job/Worker.java @@ -3,6 +3,8 @@ package Job; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.net.URL; +import java.net.URLClassLoader; import java.util.ArrayList; import java.util.List; @@ -64,7 +66,9 @@ public class Worker implements PacketHandler, Runnable{ try { File classfile = new File(j.classname+".class");//remove class file if(classfile.exists()) - classfile.delete(); + classfile.delete(); + + System.out.println("File: " + classfile.getAbsolutePath()); /* System.out.println("Writing file size:" + j.code.length()); FileWriter fw = new FileWriter(classfile);//file writing @@ -75,8 +79,18 @@ public class Worker implements PacketHandler, Runnable{ fos.write(j.classfile); fos.close(); - r = ((Jobsrc) Class.forName(j.classname).newInstance()).run();//load & run + //r = ((Jobsrc) Class.forName(j.classname).newInstance()).run();//load & run + String path = classfile.getAbsolutePath(); + path = "file://" + path.substring(0, path.lastIndexOf(File.separator)+1);//remove file name + URL[] url = {new URL(path)}; + URLClassLoader cl = new URLClassLoader(url); + r = ((Jobsrc) cl.loadClass(j.classname).newInstance()).run(); + cl.close(); + //unload? + Runtime.getRuntime().gc();//hopefully delete loader + //should unload because the loader is in the gc + if(classfile.exists()) classfile.delete(); @@ -104,7 +118,7 @@ public class Worker implements PacketHandler, Runnable{ } private void requestnewjob() { - if((System.currentTimeMillis()-lastasked) > 1500 & run & client.hasConnection()) {//request wenn letster unerfolg reicher lange genug her ist (Server nicht nerven) + if((System.currentTimeMillis()-lastasked) > 15 & run & client.hasConnection()) {//request wenn letster unerfolg reicher lange genug her ist (Server nicht nerven) client.send(new Data("nextplease")); // System.out.println("asked for next job"); lastasked = System.currentTimeMillis();