stuff
This commit is contained in:
parent
a65f6ea713
commit
79b608d156
|
@ -1,5 +1,7 @@
|
||||||
package Core;
|
package Core;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import Comunication.Client;
|
import Comunication.Client;
|
||||||
import Job.Worker;
|
import Job.Worker;
|
||||||
|
|
||||||
|
@ -7,8 +9,8 @@ public class Starter {
|
||||||
|
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
System.out.println("Starting BesenBoincClient...");
|
System.out.println("Starting BesenBoincClient...");
|
||||||
System.out.println("user.dir: " + System.getProperty("user.dir"));
|
|
||||||
|
|
||||||
|
//parsing Arguments
|
||||||
String host = BB.host;
|
String host = BB.host;
|
||||||
int port = BB.port;
|
int port = BB.port;
|
||||||
if(args.length >= 1) {
|
if(args.length >= 1) {
|
||||||
|
@ -20,8 +22,10 @@ public class Starter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//try to connect
|
||||||
boolean run = true;
|
boolean run = true;
|
||||||
int lost_counter = 0;//ho often loast?
|
int lost_counter = 0;//how often lost. - higher value - longer wait time until reconnect is tried.
|
||||||
long lasttest = -1;
|
long lasttest = -1;
|
||||||
while(run) {
|
while(run) {
|
||||||
boolean tryagain = false;
|
boolean tryagain = false;
|
||||||
|
@ -39,17 +43,25 @@ public class Starter {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.yield();
|
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
} catch(Exception e) {}
|
} catch(InterruptedException e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Connecting to " + host + " on port: " + port);
|
//try to connect
|
||||||
|
System.out.print("Connecting to " + host + " on port: " + port + " ");
|
||||||
lasttest = System.currentTimeMillis();
|
lasttest = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
Client c = new Client(host, port, new Worker());
|
Worker worker = new Worker();
|
||||||
|
Client c;
|
||||||
|
try {
|
||||||
|
c = new Client(host, port, worker);//throws IOException on failed connection
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Failed");
|
||||||
|
throw new Exception(e);//do not print stack trace
|
||||||
|
}
|
||||||
|
|
||||||
c.run();
|
worker.start();//start worker Thread, only if connection is established
|
||||||
|
c.run();//manage connection
|
||||||
|
|
||||||
if(lost_counter > 0) {
|
if(lost_counter > 0) {
|
||||||
int minus = (int) ((System.currentTimeMillis()-lasttest)/10000);//für alle 10 sekunden verbinung ein lost count weniger
|
int minus = (int) ((System.currentTimeMillis()-lasttest)/10000);//für alle 10 sekunden verbinung ein lost count weniger
|
||||||
|
@ -58,11 +70,14 @@ public class Starter {
|
||||||
else
|
else
|
||||||
lost_counter -= minus;
|
lost_counter -= minus;
|
||||||
}
|
}
|
||||||
|
System.out.println("Connection Lost!");
|
||||||
|
worker.stop();
|
||||||
|
} catch(IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
//failed
|
//failed
|
||||||
lost_counter++;
|
lost_counter++;
|
||||||
}
|
}
|
||||||
System.out.println("Connection LOST!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,7 +5,6 @@ import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.UnknownHostException;
|
|
||||||
|
|
||||||
public class Client implements Runnable{
|
public class Client implements Runnable{
|
||||||
private Socket soc;
|
private Socket soc;
|
||||||
|
@ -22,7 +21,7 @@ public class Client implements Runnable{
|
||||||
getStreams();
|
getStreams();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Client(String addr, int port, PacketHandler hand) throws UnknownHostException, IOException {//client side constructor
|
public Client(String addr, int port, PacketHandler hand) throws IOException {//client side constructor
|
||||||
hold_connection = true;
|
hold_connection = true;
|
||||||
handler = hand;
|
handler = hand;
|
||||||
soc = new Socket(InetAddress.getByName(addr), port);//connect
|
soc = new Socket(InetAddress.getByName(addr), port);//connect
|
||||||
|
|
|
@ -57,7 +57,13 @@ public class Server implements PacketHandler {
|
||||||
accept_new_connections = true;
|
accept_new_connections = true;
|
||||||
System.out.println("Server is Listening on port " + port);
|
System.out.println("Server is Listening on port " + port);
|
||||||
|
|
||||||
programthread = new Thread(prog, "Programm Thread");
|
programthread = new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
prog.run();
|
||||||
|
System.out.println("Program enqued " + prog.jobmanager.jobs_total() + " Jobs.");
|
||||||
|
}
|
||||||
|
}, "Programm Thread");
|
||||||
programthread.start();
|
programthread.start();
|
||||||
System.out.println("Programm execution started");
|
System.out.println("Programm execution started");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
|
@ -6,7 +6,7 @@ import Job.Result.PartialResult;
|
||||||
|
|
||||||
public abstract class Program implements Runnable{
|
public abstract class Program implements Runnable{
|
||||||
|
|
||||||
public JobManager jobmanager = new JobManager(this);
|
public JobManager jobmanager = new JobManager();
|
||||||
|
|
||||||
public void HandleResult(Result r) {
|
public void HandleResult(Result r) {
|
||||||
jobmanager.setdone(r.getJobId());
|
jobmanager.setdone(r.getJobId());
|
||||||
|
@ -21,6 +21,4 @@ public abstract class Program implements Runnable{
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void HandlePartialResult(PartialResult pres);
|
public abstract void HandlePartialResult(PartialResult pres);
|
||||||
|
|
||||||
public abstract void requestnewjobs(int amount);
|
|
||||||
}
|
}
|
|
@ -10,7 +10,6 @@ import java.util.List;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
import Comunication.Server;
|
import Comunication.Server;
|
||||||
import Core.Program;
|
|
||||||
import Utils.StringUtils;
|
import Utils.StringUtils;
|
||||||
|
|
||||||
public class JobManager implements Iterator<Job>{
|
public class JobManager implements Iterator<Job>{
|
||||||
|
@ -21,19 +20,13 @@ public class JobManager implements Iterator<Job>{
|
||||||
private List<Job> done = new ArrayList<Job>();//done jobs
|
private List<Job> done = new ArrayList<Job>();//done jobs
|
||||||
|
|
||||||
private int jobcount = 0;
|
private int jobcount = 0;
|
||||||
|
|
||||||
private Program prog;
|
|
||||||
|
|
||||||
public JobManager(Program prog) {
|
|
||||||
this.prog = prog;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isCompiling = false;
|
private boolean isCompiling = false;
|
||||||
|
|
||||||
public void enque(Job newjob) {
|
public void enque(Job newjob) {
|
||||||
|
jobcount++;
|
||||||
newjob.setId(jobcount);
|
newjob.setId(jobcount);
|
||||||
enqued.add(newjob);
|
enqued.add(newjob);
|
||||||
jobcount++;
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,9 +116,6 @@ public class JobManager implements Iterator<Job>{
|
||||||
public void update() {//called from Server on new Client Connection
|
public void update() {//called from Server on new Client Connection
|
||||||
if(enqued.size() > 0 & !isCompiling & todo.size() < jobs_compiledtarget()) {//7 für jede connection vorrätig
|
if(enqued.size() > 0 & !isCompiling & todo.size() < jobs_compiledtarget()) {//7 für jede connection vorrätig
|
||||||
startCompile();
|
startCompile();
|
||||||
} else if(enqued.size() < jobs_compiledtarget()) {
|
|
||||||
System.out.println("All jobs done.");
|
|
||||||
prog.requestnewjobs(jobs_compiledtarget() * 15);//mal nen par generieren
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,8 @@ public class Worker implements PacketHandler, Runnable{
|
||||||
private Client client;
|
private Client client;
|
||||||
private long lastasked = System.currentTimeMillis();
|
private long lastasked = System.currentTimeMillis();
|
||||||
private boolean run = true;
|
private boolean run = true;
|
||||||
|
|
||||||
public Worker() {
|
public void start() {
|
||||||
Thread workerthread = new Thread(this, "Worker");
|
Thread workerthread = new Thread(this, "Worker");
|
||||||
workerthread.start();
|
workerthread.start();
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ public class Worker implements PacketHandler, Runnable{
|
||||||
if(jobs.size()>0) {
|
if(jobs.size()>0) {
|
||||||
System.out.print("Executing Job: " + jobs.get(0).getId());
|
System.out.print("Executing Job: " + jobs.get(0).getId());
|
||||||
Result r = justrun(jobs.get(0));
|
Result r = justrun(jobs.get(0));
|
||||||
System.out.println("Done.");
|
System.out.println(" Done.");
|
||||||
if(r != null) {
|
if(r != null) {
|
||||||
client.send(new Data(r));
|
client.send(new Data(r));
|
||||||
jobs.remove(0);
|
jobs.remove(0);
|
||||||
|
|
|
@ -7,14 +7,11 @@ public class Test extends Program {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
for(int c = 5; c < 1000; c++) {
|
for(int c = 5; c < 1000; c++) {
|
||||||
String code = "import Job.Job;\nimport Job.Result;\nimport Job.Result.PartialResult;\nimport Job.Jobsrc;\npublic class A" + c + " extends Jobsrc {\n@Override\npublic Result run() {\ndouble i ="+c+";\nfor(int n = 2; n < " + c + ";n++){\n i *= n;\n}\n Result r = new Result();\nr.OutputConsole(\"!"+c+"= \"+i);\n return r;\n }}";
|
String code = "import Job.Job;\nimport Job.Result;\nimport Job.Result.PartialResult;\nimport Job.Jobsrc;\npublic class A" + c + " extends Jobsrc {\n@Override\npublic Result run() {\ndouble i ="+c+";\nfor(int n = 2; n < " + c + ";n++){\n i *= n;\n}\n Result r = new Result(" + (jobmanager.jobs_total() +1) +");\nr.OutputConsole(\"!"+c+"= \"+i);\n return r;\n }}";
|
||||||
jobmanager.enque(new Job(code));
|
jobmanager.enque(new Job(code));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void HandlePartialResult(PartialResult pres) {}//unused
|
public void HandlePartialResult(PartialResult pres) {}//unused
|
||||||
|
|
||||||
@Override
|
|
||||||
public void requestnewjobs(int amount) {}
|
|
||||||
}
|
}
|
|
@ -96,8 +96,4 @@ public class PrimeFinder extends Program {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void requestnewjobs(int amount) {}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue