should fix #2
This commit is contained in:
parent
102f5c63a8
commit
b8e779927c
|
@ -5,6 +5,11 @@ 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.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import Comunication.Data.ContentType;
|
||||||
|
import Job.Job;
|
||||||
|
|
||||||
public class Client implements Runnable{
|
public class Client implements Runnable{
|
||||||
private Socket soc;
|
private Socket soc;
|
||||||
|
@ -13,6 +18,8 @@ public class Client implements Runnable{
|
||||||
|
|
||||||
private PacketHandler handler;
|
private PacketHandler handler;
|
||||||
private boolean hold_connection;
|
private boolean hold_connection;
|
||||||
|
|
||||||
|
private List<Job> takenjobs = new LinkedList<Job>();
|
||||||
|
|
||||||
public Client(Socket soc, PacketHandler hand) {//server side constructor
|
public Client(Socket soc, PacketHandler hand) {//server side constructor
|
||||||
hold_connection = true;
|
hold_connection = true;
|
||||||
|
@ -43,6 +50,9 @@ public class Client implements Runnable{
|
||||||
try {
|
try {
|
||||||
out.writeObject(data);
|
out.writeObject(data);
|
||||||
out.flush();
|
out.flush();
|
||||||
|
if(data.type == ContentType.Job) {
|
||||||
|
takenjobs.add((Job) data.content);
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -56,6 +66,9 @@ public class Client implements Runnable{
|
||||||
out.close();
|
out.close();
|
||||||
soc.close();
|
soc.close();
|
||||||
System.out.println("Disconnected!");
|
System.out.println("Disconnected!");
|
||||||
|
//re-enque all take jobs
|
||||||
|
Server.getServer().getProgram().jobmanager.reenque(takenjobs);
|
||||||
|
takenjobs.clear();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -75,6 +88,15 @@ public class Client implements Runnable{
|
||||||
}
|
}
|
||||||
disconnect();
|
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() {
|
public boolean hasConnection() {
|
||||||
return soc.isConnected();
|
return soc.isConnected();
|
||||||
|
|
|
@ -119,9 +119,11 @@ public class Server implements PacketHandler {
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Out of Tasks");
|
System.out.println("Out of Tasks");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if(data.type == ContentType.Result) {
|
} else if(data.type == ContentType.Result) {
|
||||||
prog.HandleResult((Result) data.content);
|
Result r = (Result) data.content;
|
||||||
|
c.removetakenjob(r.getJobId());
|
||||||
|
prog.HandleResult(r);
|
||||||
}else
|
}else
|
||||||
System.out.println("unhandled Data!");
|
System.out.println("unhandled Data!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import Job.JobManager;
|
||||||
import Job.Result;
|
import Job.Result;
|
||||||
import Job.Result.PartialResult;
|
import Job.Result.PartialResult;
|
||||||
|
|
||||||
public abstract class Program implements Runnable{
|
public abstract class Program implements Runnable {
|
||||||
|
|
||||||
public JobManager jobmanager = new JobManager();
|
public JobManager jobmanager = new JobManager();
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,12 @@ public class JobManager implements Iterator<Job>{
|
||||||
|
|
||||||
private boolean isCompiling = false;
|
private boolean isCompiling = false;
|
||||||
|
|
||||||
|
public void reenque(List<Job> jobs) {
|
||||||
|
todo.addAll(0, jobs);
|
||||||
|
send.removeAll(jobs);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
public void enque(Job newjob) {
|
public void enque(Job newjob) {
|
||||||
jobcount++;
|
jobcount++;
|
||||||
newjob.setId(jobcount);
|
newjob.setId(jobcount);
|
||||||
|
@ -30,6 +36,10 @@ public class JobManager implements Iterator<Job>{
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new Compiling Thread
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
private Thread getnewThread() {
|
private Thread getnewThread() {
|
||||||
return new Thread(new Runnable() {
|
return new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -94,6 +104,9 @@ public class JobManager implements Iterator<Job>{
|
||||||
}, "Compiler");
|
}, "Compiler");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* is a new Compiled job in the list
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
return todo.size() != 0;
|
return todo.size() != 0;
|
||||||
|
@ -108,11 +121,6 @@ public class JobManager implements Iterator<Job>{
|
||||||
return send.get(send.size()-1);
|
return send.get(send.size()-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove() {//unused
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
||||||
|
@ -137,6 +145,10 @@ public class JobManager implements Iterator<Job>{
|
||||||
return jobcount;
|
return jobcount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How many Jobs should stored compiled?
|
||||||
|
* @return 7 Jobs for every Connection, and at least 10.
|
||||||
|
*/
|
||||||
public int jobs_compiledtarget() {
|
public int jobs_compiledtarget() {
|
||||||
int w = 7 * Server.getServer().getConnectionCount();
|
int w = 7 * Server.getServer().getConnectionCount();
|
||||||
return (w < 10) ? 10 : w;
|
return (w < 10) ? 10 : w;
|
||||||
|
|
Loading…
Reference in New Issue