GroovyServ - Technical Part

2,477 views

Published on

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,477
On SlideShare
0
From Embeds
0
Number of Embeds
182
Actions
Shares
0
Downloads
13
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

GroovyServ - Technical Part

  1. 1. Side-B: Technical Part
  2. 2. a.k.a nobeans Twitter: @nobeans : http://d.hatena.ne.jp/nobeans/ : NTT
  3. 3. groovyserver
  4. 4. based on: Ver 0.4-SNAPSHOT(7/24)
  5. 5. based on: Ver 0.4-SNAPSHOT(7/24)
  6. 6. $ groovyserver
  7. 7. GroovyServer main()
  8. 8. ServerSocket Listen 1961
  9. 9. $ groovyclient -e “println(‘Hello, GroovyServ!’)” groovyclient 1961(default) groovyserver
  10. 10. RequestWorker start()
  11. 11. ClientConnection#openSession() InvocationRequest
  12. 12. groovyclient Groovy
  13. 13. Groovy
  14. 14. based on: Ver 0.4-SNAPSHOT(7/24)
  15. 15. $ groovyserver
  16. 16. GroovyServer main()
  17. 17. System.in/out/err ※
  18. 18. ~/.groovy/groovyserv/cookie
  19. 19. ServerSocket Listen 1961
  20. 20. $ groovyclient -e “println(‘Hello, GroovyServ!’)” ./groovy/groovyserv/cookie Cookie groovyclient Cookie: 425ba835cb32688b1 1961(default) groovyserver
  21. 21. Socket Loopback Address RequestWorker
  22. 22. RequestWorker ClientConnection CientConnection ThreadGroup Singleton
  23. 23. RequestWorker start()
  24. 24. ClientConnection#openSession() InvocationRequest Cookie
  25. 25. groovyclient System.in
  26. 26. groovyclient Groovy
  27. 27. groovyclient (CWD) JVM 1. “user.dir” 2. JNA JVM CWD 3. CWD
  28. 28. GroovyMain GroovyMain2 Groovy
  29. 29. - (CWD) CTRL+C
  30. 30. - (CWD) CTRL+C
  31. 31. - System.out(err) System.in HTTP
  32. 32. System.out(err) ≪script≫ println “Hello, GroovyServ!” Socket System.out OutputStream#write() ClientConnection (StreamResponse OutputStream) OutputStream ClientConnectionRepository groovyclient ThreadGroup ClientConnection if Channel ==”out” if Channel ==”err” → → Hello, GroovyServ!
  33. 33. groovyclient StreamRequestHandler Socket.inputStream.read() pipedOutputStream.write() ClientConnection PipedOutputStream ClientConnection Repository ThreadGroup ClientConnection PipedInputStream ClientConnection System.in PipedInputStream (StreamRequestInputStream) System.in ≪script≫ System.in.eachLine { ... }
  34. 34. Piped [ ] Size:-1 [ A] StreamRequestInputStream Socket#getInputStream() System.in [ B] StreamRequestInputStream PipedInputStream()
  35. 35. Request InvocationRequest Groovy StreamRequest Response StreamResponse
  36. 36. InvocationRequest 'Cwd:' <cwd> LF 'Arg:' <argn> LF 'Arg:' <arg1> LF 'Arg:' <arg2> LF 'Cp:' <classpath> LF 'Cookie:' <cookie> LF LF where: <cwd> is current working directory. <arg1><arg2>.. are commandline arguments(optional). <classpath>.. is the value of environment variable CLASSPATH(optional). <cookie> is authentication value which certify client is the user who invoked the server. LF is line feed (0x0a, 'n').
  37. 37. StreamRequest 'Size:' <size> LF LF <data from STDIN> where: <size> is the size of data to send to server. <size>==-1 means client exited. <data from STDIN> is byte sequence from standard input.
  38. 38. StreamResponse 'Status:' <status> LF 'Channel:' <id> LF 'Size:' <size> LF LF <data for STDERR/STDOUT> where: <status> is exit status of invoked groovy script. <id> is 'out' or 'err', where 'out' means standard output of the program. 'err' means standard error of the program. <size> is the size of chunk. <data from STDERR/STDOUT> is byte sequence from standard output/error.
  39. 39. - (CWD) CTRL+C
  40. 40. Cookie / Loopback only 2 Only from Loopback address InetAddress#isLoopbackAddress() Cookie Loopback address NG HTTP Cookie ~/.groovy/groovyserv/ cookie Cookie Authentication failed
  41. 41. - (CWD) CTRL+C
  42. 42. CLASSPATH CLASSPATH InvocationRequest Cp GroovyMain2 “groovy.classpath” GroovyMain2 groovy.classpath groovyserver -r -cp InvocationRequest Arg GroovyMain2
  43. 43. - (CWD) CTRL+C
  44. 44. CWD(Current Working Directory) Java GroovyServ CWD CWD $ cd /tmp $ groovyserver -r $ cd /home/kobo $ cat > hoge.txt HOGE!! ^C $ groovyclient -e ‘println(new File(“hoge.txt”).text)’ Caught: java.io.FileNotFoundException: hoge.txt (No such file or directory) ...SNIP...
  45. 45. “user.dir” File#getAbsolutePath() “"user.dir", which is initialized during jvm startup, should be used as an informative/readonly system property” posted 2008-08-18 http://bugs.sun.com/bugdatabase/view_bug.do;:YfiG?bug_id=4117557 JNA JVM CWD “user.dir” FileInputStream CWD Groovy
  46. 46. JNA cwd POM <dependency> <groupId>net.java.dev.jna</groupId> <artifactId>jna</artifactId> <version>3.2.2</version> </dependency> ↓ OK import com.sun.jna.Library import com.sun.jna.Native import com.sun.jna.Platform interface CLibrary extends Library { String libname = (Platform.isWindows() ? "msvcrt" : "c") CLibrary INSTANCE = Native.loadLibrary(libname, CLibrary.class) int chdir(String dir) int _chdir(String dir) }
  47. 47. - (CWD) CTRL+C
  48. 48. groovyserver Windows groovyserver.bat PID Linux/MacOSX PID kill Windows Address already in use BAT PID
  49. 49. - (CWD) CTRL+C
  50. 50. CTRL+C groovyclient CTRL+C “Size: -1” StreamRequestHandler
  51. 51. - (CWD) CTRL+C
  52. 52. java.util.concurrent 2 StreamRequestHandler Groovy GroovyInvokeHandler
  53. 53. NW Groovy CTRL+C
  54. 54. System.exit() JVM
  55. 55. Maven + GMaven Maven + GMaven GMaven Gradle Gradle 0.4-SNAPSHOT groovy groovyc JDK API private IncompatibleClassChange Error
  56. 56. IntegrationTest GroovyServ groovyclient maven-failsafe-plugin “mvn integration- test” http://maven.apache.org/plugins/maven-failsafe-plugin/ index.html mvn
  57. 57. How to Build Maven2 $ cd groovyserv-<Version> $ mvn clean verify : target/groovyserv-<Version>-<OS>-<arch>-bin.zip Integration-Test target/groovyserv-<Version>-<OS>-<arch>.dir/groovyserv-<Version>-<OS>-<arch> : EncodeIT UTF-8 $ export _JAVA_OPTIONS=-Dfile.encoding=UTF-8 $ mvn -Dmaven.test.skip=true clean package Windows Cygwin gcc
  58. 58. Remote GroovyServ OFF Only Loopback adress Cookie
  59. 59. 3 groovyserver Loopback Address Cookie grovyclient “localhost”=> A groovyserver B groovyclient
  60. 60. GroovyServ GitHub clone/fork Welcome GroovyServ http://kobo.github.com/groovyserv GitHub http://github.com/kobo/groovyserv

×