提交 3adada00 编写于 作者: K kohsuke

[HUDSON-3889] JNLP clients now report the reason when the connection is rejected by the master.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@22037 71c3de6d-444a-0410-be80-ed276b4c234a
上级 a9b49214
......@@ -29,6 +29,7 @@ import hudson.slaves.SlaveComputer;
import hudson.remoting.Channel;
import hudson.remoting.SocketOutputStream;
import hudson.remoting.SocketInputStream;
import hudson.remoting.Engine;
import hudson.remoting.Channel.Listener;
import hudson.remoting.Channel.Mode;
import hudson.cli.CliManagerImpl;
......@@ -223,7 +224,7 @@ public final class TcpSlaveAgentListener extends Thread {
return;
}
out.println("Welcome");
out.println(Engine.GREETING_SUCCESS);
final OutputStream log = computer.openLogFile();
new PrintWriter(log).println("JNLP agent connected from "+ this.s.getInetAddress());
......
......@@ -27,6 +27,8 @@ import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ByteArrayOutputStream;
import java.net.HttpURLConnection;
import java.net.Socket;
import java.net.URL;
......@@ -36,7 +38,6 @@ import java.util.concurrent.ThreadFactory;
import java.util.List;
import java.util.Collections;
import java.util.logging.Logger;
import java.util.logging.Level;
import static java.util.logging.Level.SEVERE;
/**
......@@ -110,6 +111,7 @@ public class Engine extends Thread {
this.noReconnect = noReconnect;
}
@SuppressWarnings({"ThrowableInstanceNeverThrown"})
@Override
public void run() {
try {
......@@ -173,8 +175,16 @@ public class Engine extends Thread {
dos.writeUTF(secretKey);
dos.writeUTF(slaveName);
BufferedInputStream in = new BufferedInputStream(s.getInputStream());
String greeting = readLine(in); // why, oh why didn't I use DataOutputStream when writing to the network?
if (!greeting.equals(GREETING_SUCCESS)) {
listener.error(new Exception("The server rejected the connection: "+greeting));
Thread.sleep(10*1000);
continue;
}
final Channel channel = new Channel("channel", executor,
new BufferedInputStream(s.getInputStream()),
in,
new BufferedOutputStream(s.getOutputStream()));
PingThread t = new PingThread(channel) {
protected void onDead() {
......@@ -205,6 +215,19 @@ public class Engine extends Thread {
}
}
/**
* Read until '\n' and returns it as a string.
*/
private static String readLine(InputStream in) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while (true) {
int ch = in.read();
if (ch<0 || ch=='\n')
return baos.toString().trim(); // trim off possible '\r'
baos.write(ch);
}
}
/**
* Connects to TCP slave port, with a few retries.
*/
......@@ -267,4 +290,6 @@ public class Engine extends Thread {
private static final ThreadLocal<Engine> CURRENT = new ThreadLocal<Engine>();
private static final Logger LOGGER = Logger.getLogger(Engine.class.getName());
public static final String GREETING_SUCCESS = "Welcome";
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册