Skip to content
This repository was archived by the owner on Apr 19, 2023. It is now read-only.

Commit ee9fb68

Browse files
authored
Merge pull request #117 from sbalabanov/nailgun.0.9.3_1
Nailgun.0.9.3
2 parents 0007cab + be57ec4 commit ee9fb68

File tree

12 files changed

+655
-504
lines changed

12 files changed

+655
-504
lines changed

nailgun-examples/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<parent>
2121
<groupId>com.martiansoftware</groupId>
2222
<artifactId>nailgun-all</artifactId>
23-
<version>0.9.2-SNAPSHOT</version>
23+
<version>0.9.3-SNAPSHOT</version>
2424
</parent>
2525

2626
<dependencies>

nailgun-examples/src/main/java/com/martiansoftware/nailgun/examples/Heartbeat.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@
1717
*/
1818

1919
package com.martiansoftware.nailgun.examples;
20-
import com.martiansoftware.nailgun.NGClientListener;
2120
import com.martiansoftware.nailgun.NGContext;
22-
import com.martiansoftware.nailgun.NGHeartbeatListener;
2321

2422
import java.io.IOException;
25-
import java.io.PrintStream;
2623

2724
/**
28-
* Print one hash per second to standard out while the client is running.
25+
* Print one hash per second to standard out while the client is running.
2926
*
3027
* @author <a href="http://jimpurbrick.com">Jim Purbrick</a>
3128
*/
@@ -42,21 +39,14 @@ public static void nailMain(final NGContext context) throws IOException {
4239
try {
4340
// Register a new NGClientListener. As clientDisconnected is called from
4441
// another thread any nail state access must be properly synchronized.
45-
context.addClientListener(new NGClientListener() {
46-
public void clientDisconnected() throws InterruptedException {
47-
throw new InterruptedException("Client Disconnected"); // Will interrupt the thread below.
48-
}
49-
});
42+
Thread mainThread = Thread.currentThread();
43+
context.addClientListener(mainThread::interrupt);
5044

5145
// Register a new NGHeartbeatListener. This is normally only used for debugging disconnection problems.
52-
context.addHeartbeatListener(new NGHeartbeatListener() {
53-
public void heartbeatReceived(long intervalMillis) {
54-
context.out.print("H");
55-
}
56-
});
46+
context.addHeartbeatListener(() -> context.out.print("H"));
5747

5848
// Loop printing a hash to the client every second until client disconnects.
59-
while(! Thread.currentThread().isInterrupted()) {
49+
while(!Thread.currentThread().isInterrupted()) {
6050
Thread.sleep(5000);
6151
context.out.print("S");
6252
}

nailgun-server/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<parent>
2121
<groupId>com.martiansoftware</groupId>
2222
<artifactId>nailgun-all</artifactId>
23-
<version>0.9.2-SNAPSHOT</version>
23+
<version>0.9.3-SNAPSHOT</version>
2424
</parent>
2525

2626
<dependencies>

nailgun-server/src/main/java/com/martiansoftware/nailgun/NGClientListener.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ public interface NGClientListener {
44

55
/**
66
* Called by an internal nailgun thread when the server detects that the nailgun client has disconnected.
7-
* {@link NGClientListener}s can be registered using {@link NGContext.registerClientListener}. If
8-
* clientDisconnected throws an InterruptedException nailgun interrupts the main session thread.
7+
* {@link NGClientListener}s can be registered using {@link NGContext#addClientListener}.
98
*/
10-
public void clientDisconnected() throws InterruptedException;
9+
void clientDisconnected();
1110
}

nailgun-server/src/main/java/com/martiansoftware/nailgun/NGContext.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,13 @@ public void removeClientListener(NGClientListener listener) {
287287
getInputStream().removeClientListener(listener);
288288
}
289289

290+
/**
291+
* Do not notify about client exit
292+
*/
293+
public void removeAllClientListeners() {
294+
getInputStream().removeAllClientListeners();
295+
}
296+
290297
/**
291298
* @param listener the {@link com.martiansoftware.nailgun.NGHeartbeatListener} to be notified of client events.
292299
*/

nailgun-server/src/main/java/com/martiansoftware/nailgun/NGHeartbeatListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ public interface NGHeartbeatListener {
77
* This can normally be implemented as a no-op handler and is primarily useful for debugging.
88
* {@link NGClientListener}s can be registered using {@link NGContext.registerHeartbeatListener}.
99
*/
10-
public void heartbeatReceived(long intervalMillis);
10+
void heartbeatReceived();
1111
}

0 commit comments

Comments
 (0)