File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\cli\CliProtocol.java.html

1 package hudson.cli;
2
3 import hudson.Extension;
4 import hudson.model.Computer;
5 import hudson.remoting.Channel;
6 import hudson.remoting.Channel.Mode;
7 import jenkins.AgentProtocol;
8 import jenkins.model.Jenkins;
9
10 import java.io.BufferedInputStream;
11 import java.io.BufferedOutputStream;
12 import java.io.IOException;
13 import java.io.PrintWriter;
14 import java.net.Socket;
15
16 /**
17 * {@link AgentProtocol} that accepts connection from CLI clients.
18 *
19 * @author Kohsuke Kawaguchi
20 * @since 1.467
21 */
22 @Extension
23 public class CliProtocol extends AgentProtocol {
24 @Override
25 public String getName() {
26 return "CLI-connect";
27 }
28
29 @Override
30 public void handle(Socket socket) throws IOException, InterruptedException {
31 new Handler(socket).run();
32 }
33
34 protected static class Handler {
35 protected final Socket socket;
36
37 public Handler(Socket socket) {
38 this.socket = socket;
39 }
40
41 public void run() throws IOException, InterruptedException {
42 PrintWriter out = new PrintWriter(socket.getOutputStream(),true);
43 out.println("Welcome");
44 runCli(new Connection(socket));
45 }
46
47 protected void runCli(Connection c) throws IOException, InterruptedException {
48 Channel channel = new Channel("CLI channel from " + socket.getInetAddress(),
49 Computer.threadPoolForRemoting, Mode.BINARY,
50 new BufferedInputStream(c.in), new BufferedOutputStream(c.out), null, true, Jenkins.getInstance().pluginManager.uberClassLoader);
51 channel.setProperty(CliEntryPoint.class.getName(),new CliManagerImpl(channel));
52 channel.join();
53 }
54 }
55 }
56