master
mrbesen 5 years ago
parent 102f5c63a8
commit b8e779927c
  1. 22
      Server/BesenBoincServer/src/Comunication/Client.java
  2. 6
      Server/BesenBoincServer/src/Comunication/Server.java
  3. 2
      Server/BesenBoincServer/src/Core/Program.java
  4. 22
      Server/BesenBoincServer/src/Job/JobManager.java

@ -5,6 +5,11 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.util.LinkedList;
import java.util.List;
import Comunication.Data.ContentType;
import Job.Job;
public class Client implements Runnable{
private Socket soc;
@ -13,6 +18,8 @@ public class Client implements Runnable{
private PacketHandler handler;
private boolean hold_connection;
private List<Job> takenjobs = new LinkedList<Job>();
public Client(Socket soc, PacketHandler hand) {//server side constructor
hold_connection = true;
@ -43,6 +50,9 @@ public class Client implements Runnable{
try {
out.writeObject(data);
out.flush();
if(data.type == ContentType.Job) {
takenjobs.add((Job) data.content);
}
} catch (IOException e) {
e.printStackTrace();
}
@ -56,6 +66,9 @@ public class Client implements Runnable{
out.close();
soc.close();
System.out.println("Disconnected!");
//re-enque all take jobs
Server.getServer().getProgram().jobmanager.reenque(takenjobs);
takenjobs.clear();
} catch (IOException e) {
e.printStackTrace();
}
@ -75,6 +88,15 @@ public class Client implements Runnable{
}
disconnect();
}
void removetakenjob(int jobid) {
for(int i = 0; i < takenjobs.size(); i++) {
if(takenjobs.get(i).getId() == jobid) {
takenjobs.remove(i);
break;
}
}
}
public boolean hasConnection() {
return soc.isConnected();

@ -119,9 +119,11 @@ public class Server implements PacketHandler {
} else {
System.out.println("Out of Tasks");
}
}
}
} else if(data.type == ContentType.Result) {
prog.HandleResult((Result) data.content);
Result r = (Result) data.content;
c.removetakenjob(r.getJobId());
prog.HandleResult(r);
}else
System.out.println("unhandled Data!");
}

@ -4,7 +4,7 @@ import Job.JobManager;
import Job.Result;
import Job.Result.PartialResult;
public abstract class Program implements Runnable{
public abstract class Program implements Runnable {
public JobManager jobmanager = new JobManager();

@ -23,6 +23,12 @@ public class JobManager implements Iterator<Job>{
private boolean isCompiling = false;
public void reenque(List<Job> jobs) {
todo.addAll(0, jobs);
send.removeAll(jobs);
update();
}
public void enque(Job newjob) {
jobcount++;
newjob.setId(jobcount);
@ -30,6 +36,10 @@ public class JobManager implements Iterator<Job>{
update();
}
/**
* Creates a new Compiling Thread
* @return
*/
private Thread getnewThread() {
return new Thread(new Runnable() {
@Override
@ -94,6 +104,9 @@ public class JobManager implements Iterator<Job>{
}, "Compiler");
}
/**
* is a new Compiled job in the list
*/
@Override
public boolean hasNext() {
return todo.size() != 0;
@ -108,11 +121,6 @@ public class JobManager implements Iterator<Job>{
return send.get(send.size()-1);
}
@Override
public void remove() {//unused
}
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
startCompile();
@ -137,6 +145,10 @@ public class JobManager implements Iterator<Job>{
return jobcount;
}
/**
* How many Jobs should stored compiled?
* @return 7 Jobs for every Connection, and at least 10.
*/
public int jobs_compiledtarget() {
int w = 7 * Server.getServer().getConnectionCount();
return (w < 10) ? 10 : w;

Loading…
Cancel
Save