How many lines of code to do something like this?
def host = new Ghost(“barman.byte-code.com“)
def result = host.ls()
println result
think about it carefully… do you think it’s possible in less then 10?
Let’s pull out a groovy solution!
The server:
1:import groovy.net.xmlrpc.*
2:import java.net.ServerSocket
3:
4:def server = new XMLRPCServer()
5:def socket = new ServerSocket(8080)
6:
7:server.executeShell = { commandArray ->
8: def p = commandArray.execute()
9: p.waitFor()
10: p.text
11:}
12:
13:server.startServer(socket)
And the client:
1:import groovy.net.xmlrpc.*
2:
3:class Ghost{
4:
5: def hostProxy
6:
7: Ghost(host){
8: hostProxy = new XMLRPCServerProxy(“http://${host}:8080“)
9: }
10:
11: def callCommand(methodName,params){
12: def commandArray = []
13: commandArray << methodName
14: params.each{ commandArray << it }
15: hostProxy.executeShell(commandArray)
16: }
17:
18: def methodMissing(String name , args){
19: callCommand name,args
20: }
21:
22:}
I’m just amazed… this is what I call next generation devlopemt: based on solid foundation of good java libs and move foward on top them.
I don’t think this a full “production-ready” implementation but..it works!
and they’re less the 10 line of code if you remove the “bloat”… half an hour work, a fullblown coffe break application!
Repeat… less then 10 line of code!
Happy groovin’ , keep DRY and write less code that do more;)
No comments yet.
Comments RSS TrackBack Identifier URI
Leave a comment










No Comments