1 /* |
1 /* |
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
22 * or visit www.oracle.com if you need additional information or have any |
22 * or visit www.oracle.com if you need additional information or have any |
23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 package com.sun.tools.sjavac.server; |
25 package com.sun.tools.sjavac.server; |
26 |
26 |
27 import java.io.File; |
|
28 import java.io.IOException; |
27 import java.io.IOException; |
29 import java.io.ObjectInputStream; |
28 import java.io.ObjectInputStream; |
30 import java.io.ObjectOutputStream; |
29 import java.io.ObjectOutputStream; |
31 import java.io.PrintWriter; |
30 import java.io.PrintWriter; |
32 import java.io.StringWriter; |
31 import java.io.StringWriter; |
33 import java.net.Socket; |
32 import java.net.Socket; |
34 import java.net.URI; |
|
35 import java.util.List; |
|
36 import java.util.Set; |
|
37 |
33 |
38 import com.sun.tools.sjavac.Log; |
34 import com.sun.tools.sjavac.Log; |
39 |
35 |
40 /** |
36 /** |
41 * A RequestHandler handles requests performed over a socket. Specifically it |
37 * A RequestHandler handles requests performed over a socket. Specifically it |
69 ObjectInputStream oin = new ObjectInputStream(socket.getInputStream())) { |
65 ObjectInputStream oin = new ObjectInputStream(socket.getInputStream())) { |
70 String id = (String) oin.readObject(); |
66 String id = (String) oin.readObject(); |
71 String cmd = (String) oin.readObject(); |
67 String cmd = (String) oin.readObject(); |
72 Log.info("Handling request, id: " + id + " cmd: " + cmd); |
68 Log.info("Handling request, id: " + id + " cmd: " + cmd); |
73 switch (cmd) { |
69 switch (cmd) { |
74 case SjavacServer.CMD_SYS_INFO: handleSysInfoRequest(oin, oout); break; |
70 case SjavacServer.CMD_COMPILE: handleCompileRequest(oin, oout); break; |
75 case SjavacServer.CMD_COMPILE: handleCompileRequest(oin, oout); break; |
|
76 default: Log.error("Unknown command: " + cmd); |
71 default: Log.error("Unknown command: " + cmd); |
77 } |
72 } |
78 } catch (Exception ex) { |
73 } catch (Exception ex) { |
79 // Not much to be done at this point. The client side request |
74 // Not much to be done at this point. The client side request |
80 // code will most likely throw an IOException and the |
75 // code will most likely throw an IOException and the |
83 ex.printStackTrace(new PrintWriter(sw)); |
78 ex.printStackTrace(new PrintWriter(sw)); |
84 Log.error(sw.toString()); |
79 Log.error(sw.toString()); |
85 } |
80 } |
86 } |
81 } |
87 |
82 |
88 private void handleSysInfoRequest(ObjectInputStream oin, |
|
89 ObjectOutputStream oout) throws IOException { |
|
90 oout.writeObject(sjavac.getSysInfo()); |
|
91 oout.flush(); |
|
92 } |
|
93 |
|
94 @SuppressWarnings("unchecked") |
|
95 private void handleCompileRequest(ObjectInputStream oin, |
83 private void handleCompileRequest(ObjectInputStream oin, |
96 ObjectOutputStream oout) throws IOException { |
84 ObjectOutputStream oout) throws IOException { |
97 try { |
85 try { |
98 // Read request arguments |
86 // Read request arguments |
99 String protocolId = (String) oin.readObject(); |
|
100 String invocationId = (String) oin.readObject(); |
|
101 String[] args = (String[]) oin.readObject(); |
87 String[] args = (String[]) oin.readObject(); |
102 List<File> explicitSources = (List<File>) oin.readObject(); |
|
103 Set<URI> sourcesToCompile = (Set<URI>) oin.readObject(); |
|
104 Set<URI> visibleSources = (Set<URI>) oin.readObject(); |
|
105 |
88 |
106 // Perform compilation |
89 // Perform compilation |
107 CompilationResult cr = sjavac.compile(protocolId, |
90 CompilationResult cr = sjavac.compile(args); |
108 invocationId, |
91 |
109 args, |
|
110 explicitSources, |
|
111 sourcesToCompile, |
|
112 visibleSources); |
|
113 // Write request response |
92 // Write request response |
114 oout.writeObject(cr); |
93 oout.writeObject(cr); |
115 oout.flush(); |
94 oout.flush(); |
116 } catch (ClassNotFoundException cnfe) { |
95 } catch (ClassNotFoundException cnfe) { |
117 throw new IOException(cnfe); |
96 throw new IOException(cnfe); |