Allow exit after frame for text and oneLine mode
This commit is contained in:
committed by
Laurent Clouet
parent
6510bbdbc7
commit
e703b9ea1b
@@ -233,6 +233,7 @@ public class Client {
|
|||||||
Date wakeup_time = new Date(new Date().getTime() + time_sleep);
|
Date wakeup_time = new Date(new Date().getTime() + time_sleep);
|
||||||
this.gui.status(String.format("No job available. Sleeping for 15 minutes (will wake up at ~%tR)", wakeup_time));
|
this.gui.status(String.format("No job available. Sleeping for 15 minutes (will wake up at ~%tR)", wakeup_time));
|
||||||
this.gui.framesRemaining(0);
|
this.gui.framesRemaining(0);
|
||||||
|
this.suspended = true;
|
||||||
int time_slept = 0;
|
int time_slept = 0;
|
||||||
while (time_slept < time_sleep && this.running == true) {
|
while (time_slept < time_sleep && this.running == true) {
|
||||||
try {
|
try {
|
||||||
@@ -243,6 +244,7 @@ public class Client {
|
|||||||
}
|
}
|
||||||
time_slept += 5000;
|
time_slept += 5000;
|
||||||
}
|
}
|
||||||
|
this.suspended = false;
|
||||||
continue; // go back to ask job
|
continue; // go back to ask job
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -342,6 +344,8 @@ public class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.server = null;
|
this.server = null;
|
||||||
|
|
||||||
|
this.gui.stop();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,11 +22,16 @@ package com.sheepit.client.standalone;
|
|||||||
import com.sheepit.client.Client;
|
import com.sheepit.client.Client;
|
||||||
import com.sheepit.client.Gui;
|
import com.sheepit.client.Gui;
|
||||||
import com.sheepit.client.Log;
|
import com.sheepit.client.Log;
|
||||||
|
import sun.misc.Signal;
|
||||||
|
import sun.misc.SignalHandler;
|
||||||
|
|
||||||
public class GuiText implements Gui {
|
public class GuiText implements Gui {
|
||||||
public static final String type = "text";
|
public static final String type = "text";
|
||||||
|
|
||||||
private int framesRendered;
|
private int framesRendered;
|
||||||
|
|
||||||
|
private int sigIntCount = 0;
|
||||||
|
|
||||||
private Log log;
|
private Log log;
|
||||||
|
|
||||||
private Client client;
|
private Client client;
|
||||||
@@ -39,6 +44,30 @@ public class GuiText implements Gui {
|
|||||||
@Override
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
if (client != null) {
|
if (client != null) {
|
||||||
|
|
||||||
|
Signal.handle(new Signal("INT"), new SignalHandler() {
|
||||||
|
@Override
|
||||||
|
public void handle(Signal signal) {
|
||||||
|
sigIntCount++;
|
||||||
|
|
||||||
|
if (sigIntCount == 4) {
|
||||||
|
// This is only for ugly issues that might occur
|
||||||
|
System.out.println("WARNING: Hitting Ctrl-C again will force close the application.");
|
||||||
|
}
|
||||||
|
else if (sigIntCount == 5) {
|
||||||
|
Signal.raise(new Signal("INT"));
|
||||||
|
Runtime.getRuntime().halt(0);
|
||||||
|
}
|
||||||
|
else if (client.isRunning() && client.isSuspended() == false) {
|
||||||
|
client.askForStop();
|
||||||
|
System.out.println("Will exit after current frame... Press Ctrl+C again to exit now.");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
client.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
client.run();
|
client.run();
|
||||||
client.stop();
|
client.stop();
|
||||||
}
|
}
|
||||||
@@ -46,6 +75,7 @@ public class GuiText implements Gui {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
|
Runtime.getRuntime().halt(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -2,14 +2,20 @@ package com.sheepit.client.standalone;
|
|||||||
|
|
||||||
import com.sheepit.client.Client;
|
import com.sheepit.client.Client;
|
||||||
import com.sheepit.client.Gui;
|
import com.sheepit.client.Gui;
|
||||||
|
import sun.misc.Signal;
|
||||||
|
import sun.misc.SignalHandler;
|
||||||
|
|
||||||
public class GuiTextOneLine implements Gui {
|
public class GuiTextOneLine implements Gui {
|
||||||
public static final String type = "oneLine";
|
public static final String type = "oneLine";
|
||||||
|
|
||||||
private int rendered;
|
private int rendered;
|
||||||
private int remaining;
|
private int remaining;
|
||||||
|
private int sigIntCount = 0;
|
||||||
|
|
||||||
private String status;
|
private String status;
|
||||||
private String line;
|
private String line;
|
||||||
|
|
||||||
|
private boolean exiting = false;
|
||||||
|
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
@@ -23,6 +29,26 @@ public class GuiTextOneLine implements Gui {
|
|||||||
@Override
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
if (client != null) {
|
if (client != null) {
|
||||||
|
|
||||||
|
Signal.handle(new Signal("INT"), new SignalHandler() {
|
||||||
|
@Override
|
||||||
|
public void handle(Signal signal) {
|
||||||
|
sigIntCount++;
|
||||||
|
|
||||||
|
if (sigIntCount == 5) {
|
||||||
|
Signal.raise(new Signal("INT"));
|
||||||
|
Runtime.getRuntime().halt(0);
|
||||||
|
}
|
||||||
|
else if (client.isRunning() && client.isSuspended() == false) {
|
||||||
|
client.askForStop();
|
||||||
|
exiting = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
client.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
client.run();
|
client.run();
|
||||||
client.stop();
|
client.stop();
|
||||||
}
|
}
|
||||||
@@ -30,6 +56,7 @@ public class GuiTextOneLine implements Gui {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
|
Runtime.getRuntime().halt(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -70,7 +97,7 @@ public class GuiTextOneLine implements Gui {
|
|||||||
int charToRemove = line.length();
|
int charToRemove = line.length();
|
||||||
|
|
||||||
System.out.print("\r");
|
System.out.print("\r");
|
||||||
line = String.format("Frames rendered: %d remaining: %d | %s", rendered, remaining, status);
|
line = String.format("Frames rendered: %d remaining: %d | %s", rendered, remaining, status) + (exiting ? " (Exiting after this frame)" : "");
|
||||||
System.out.print(line);
|
System.out.print(line);
|
||||||
for (int i = line.length(); i <= charToRemove; i++) {
|
for (int i = line.length(); i <= charToRemove; i++) {
|
||||||
System.out.print(" ");
|
System.out.print(" ");
|
||||||
|
|||||||
Reference in New Issue
Block a user