Skip to content
This repository was archived by the owner on Oct 29, 2019. It is now read-only.

Commit b71b18c

Browse files
Fix Shutdown through SigTerm
1 parent 03867d1 commit b71b18c

6 files changed

Lines changed: 908 additions & 37 deletions

File tree

pom.xml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,27 @@
285285
</dependency>
286286

287287
<!-- Testing dependencies -->
288+
<dependency>
289+
<groupId>com.github.jnr</groupId>
290+
<artifactId>jnr-posix</artifactId>
291+
<optional>true</optional>
292+
<!-- For Testing purpose but could be used in production too -->
293+
<version>3.0.50</version>
294+
<scope>test</scope>
295+
</dependency>
296+
<dependency>
297+
<groupId>org.apache.ant</groupId>
298+
<artifactId>ant</artifactId>
299+
<version>1.10.6</version>
300+
<scope>test</scope>
301+
<!-- For Testing purpose but could be used in production too -->
302+
<exclusions>
303+
<exclusion>
304+
<groupId>com.sun</groupId>
305+
<artifactId>tools</artifactId>
306+
</exclusion>
307+
</exclusions>
308+
</dependency>
288309
<dependency>
289310
<groupId>junit</groupId>
290311
<artifactId>junit</artifactId>
@@ -416,6 +437,17 @@
416437
<rulesUri>file:///${session.executionRootDirectory}/maven-version-rules.xml</rulesUri>
417438
</configuration>
418439
</plugin>
440+
<plugin>
441+
<groupId>org.apache.maven.plugins</groupId>
442+
<artifactId>maven-jar-plugin</artifactId>
443+
<executions>
444+
<execution>
445+
<goals>
446+
<goal>test-jar</goal>
447+
</goals>
448+
</execution>
449+
</executions>
450+
</plugin>
419451
</plugins>
420452
</build>
421453
<reporting>

src/main/java/org/waarp/common/utility/WaarpShutdownHook.java

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
/**
2-
This file is part of Waarp Project.
3-
4-
Copyright 2009, Frederic Bregier, and individual contributors by the @author
5-
tags. See the COPYRIGHT.txt in the distribution for a full listing of
6-
individual contributors.
7-
8-
All Waarp Project is free software: you can redistribute it and/or
9-
modify it under the terms of the GNU General Public License as published
10-
by the Free Software Foundation, either version 3 of the License, or
11-
(at your option) any later version.
12-
13-
Waarp is distributed in the hope that it will be useful,
14-
but WITHOUT ANY WARRANTY; without even the implied warranty of
15-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16-
GNU General Public License for more details.
17-
18-
You should have received a copy of the GNU General Public License
19-
along with Waarp . If not, see <http://www.gnu.org/licenses/>.
2+
* This file is part of Waarp Project.
3+
* <p>
4+
* Copyright 2009, Frederic Bregier, and individual contributors by the @author
5+
* tags. See the COPYRIGHT.txt in the distribution for a full listing of
6+
* individual contributors.
7+
* <p>
8+
* All Waarp Project is free software: you can redistribute it and/or
9+
* modify it under the terms of the GNU General Public License as published
10+
* by the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
* <p>
13+
* Waarp is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
* <p>
18+
* You should have received a copy of the GNU General Public License
19+
* along with Waarp . If not, see <http://www.gnu.org/licenses/>.
2020
*/
2121
package org.waarp.common.utility;
2222

23+
import org.waarp.common.future.WaarpFuture;
24+
import org.waarp.common.logging.WaarpLogger;
25+
import org.waarp.common.logging.WaarpLoggerFactory;
26+
2327
import java.io.File;
2428
import java.io.IOException;
2529
import java.lang.management.ManagementFactory;
@@ -28,10 +32,6 @@
2832
import java.util.Timer;
2933
import java.util.TimerTask;
3034

31-
import org.waarp.common.future.WaarpFuture;
32-
import org.waarp.common.logging.WaarpLogger;
33-
import org.waarp.common.logging.WaarpLoggerFactory;
34-
3535
/**
3636
* @author "Frederic Bregier"
3737
*
@@ -78,15 +78,15 @@ public abstract class WaarpShutdownHook extends Thread {
7878
public WaarpShutdownHook(ShutdownConfiguration configuration) {
7979
if (initialized) {
8080
shutdownHook.shutdownConfiguration = configuration;
81-
this.setName("WaarpShutdownHook");
82-
this.setDaemon(true);
81+
setName("WaarpShutdownHook");
82+
setDaemon(true);
8383
shutdownHook = this;
84-
this.shutdownConfiguration = configuration;
84+
shutdownConfiguration = configuration;
8585
return;
8686
}
87-
this.shutdownConfiguration = configuration;
88-
this.setName("WaarpShutdownHook");
89-
this.setDaemon(true);
87+
shutdownConfiguration = configuration;
88+
setName("WaarpShutdownHook");
89+
setDaemon(true);
9090
shutdownHook = this;
9191
initialized = true;
9292
}
@@ -136,9 +136,10 @@ public static void terminate(boolean immediateSet) {
136136
if (shutdownHook != null) {
137137
removeShutdownHook();
138138
terminate();
139+
shutdownHook = null;
139140
} else {
140141
logger.error("No ShutdownHook setup");
141-
DetectionUtils.SystemExit(1);
142+
//FBGEXIT DetectionUtils.SystemExit(1);
142143
}
143144
}
144145

@@ -185,7 +186,7 @@ private static void terminate() {
185186
Thread.sleep(1000);
186187
} catch (InterruptedException e) {
187188
}
188-
DetectionUtils.SystemExit(0);
189+
//FBGEXIT DetectionUtils.SystemExit(0);
189190
} else {
190191
shutdownHook.launchFinalExit();
191192
immediate = true;
@@ -203,6 +204,10 @@ private static void terminate() {
203204
System.err.println("Exit System");
204205
//Runtime.getRuntime().halt(0);
205206
}
207+
shutdown = false;
208+
shutdownStarted = false;
209+
isShutdownOver = false;
210+
initialized = false;
206211
}
207212

208213
/**
@@ -218,12 +223,12 @@ private static void terminate() {
218223
*/
219224
static private void printStackTrace(Thread thread,
220225
StackTraceElement[] stacks) {
221-
System.err.print(thread.toString() + " : ");
226+
System.err.print(thread + " : ");
222227
for (int i = 0; i < stacks.length - 1; i++) {
223-
System.err.print(stacks[i].toString() + " ");
228+
System.err.print(stacks[i] + " ");
224229
}
225230
if (stacks.length >= 1) {
226-
System.err.println(stacks[stacks.length - 1].toString());
231+
System.err.println(stacks[stacks.length - 1]);
227232
} else {
228233
System.err.println();
229234
}
@@ -305,6 +310,8 @@ public void launchFinalExit() {
305310
}
306311
Timer timer = new Timer("R66FinalExit", true);
307312
ShutdownTimerTask timerTask = new ShutdownTimerTask();
313+
logger.warn("Launch Timer R66 Final Exit in {}",
314+
shutdownConfiguration.timeout * 4);
308315
timer.schedule(timerTask, shutdownConfiguration.timeout * 4);
309316
}
310317

@@ -381,11 +388,11 @@ public void run() {
381388
}
382389
// Already stopped
383390
System.err.println("Halt System now - services already stopped -");
384-
DetectionUtils.SystemExit(0);
391+
//FBGEXIT DetectionUtils.SystemExit(0);
385392
return;
386393
}
387394
try {
388-
terminate();
395+
terminate(false);
389396
} catch (Throwable t) {
390397
if (shutdownHook != null && shutdownHook.serviceStopped()) {
391398
try {
@@ -395,7 +402,7 @@ public void run() {
395402
}
396403
}
397404
System.err.println("Halt System now");
398-
DetectionUtils.SystemExit(0);
405+
//FBGEXIT DetectionUtils.SystemExit(0);
399406
}
400407

401408
/**
@@ -443,7 +450,7 @@ public void run() {
443450
printStackTrace(thread, map.get(thread));
444451
}
445452
}
446-
DetectionUtils.SystemExit(0);
453+
//FBGEXIT DetectionUtils.SystemExit(0);
447454
}
448455
}
449456
}

0 commit comments

Comments
 (0)