Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(474)

Side by Side Diff: README

Issue 5504046: remotize kit initial code review
Patch Set: Created 12 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Makefile ('k') | TODO » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 INTRODUCTION
2 ____________
3
4 Remotize provides easy remotization, as it's name implies.
5
6 Remotize aims to aid developers wanting to "remotize" Go code.
7
8 Using the Google's Go core rpc package directly, developers that want to call so me function, method or interface remotely have to create or redesign a rpc-compa tible interface following certain strict rules (http://golang.org/pkg/rpc/). Wit h remotize it is NOT needed to write the interface or a wrapper to an existing o ne following rpc's rules, because the remotize package will do that for you.
9
10 Remotize will build a remotizedMyinterface.go file containing the wrapping and u nwrapping of the rpc calls so that you can directly call remotely:
11
12 r:=c.add(1,2.5)·
13
14 instead of "the ugly":
15
16 c.add(pointerToArgs,pointerToResults)
17
18 You can call existing interfaces remotely without touching them or writing the r pc wrappers yourself.
19
20 Not all can be remotized, of course, channels are not remotizable, for instance. But for the time being there is no filter or argument type checking to avoid no nsense remotizations.
21
22
23
24 HOW DOES IT WORK?
25 _________________
26
27 Let's say you have some type called "URLStore" that have the following methods:
28
29 Get(key string) string
30 Set(key, url string) bool
31
32 And let's say you want to use it remotely to distribute the store load between v arious servers.
33
34 What you would do is to get a remote reference for the "URLStorer" interface ins tead of calling the local urlstore:
35
36 urlstore:=NewRemoteURLStorer(rpcClient,new(URLStorer)) // instead of old urlstor e:=NewURLStore(...)
37
38 Of course you also need to setup the rpcClient (of type rpc.Client) connected to the right rpc.Server you will be using.
39
40 And on the server side you'll have to prepare the serving URLStore object this w ay:
41
42 urlstoreService:=NewURLStoreService(rpcServer,NewURLStore(...))
43
44 Where rpcServer is a rpc.Server type properly setup to serve rpcs and NewURLStor e() is your old URLStore init or "constructor" function.
45
46 And thats it!
47
48 - "Really?"
49 - "Is it THAT magic?"
50 Well not exactly, no, you also need to do a small change into your package make file:
51
52 include $(GOROOT)/src/Make.inc
53
54 TARG=...
55 GOFILES=...go
56
57 #include $(GOROOT)/src/Make.pkg
58 include $(GOROOT)/src/Make.rpkg
59
60 Changing the last included make file will make sure that BEFORE your code is eve r compiled, the goremote command will be called on your go source code files and it will detect that you want to use the URLSore type remotely. Then it will cre ate a custom go program to remotize URLStore and that program will be run and ge nerate a go file called remotizedURLStorer.go that will be compiled with the res t of your package go sources. This go source file will provide you with:
61
62 - The URLStorer interface that have the URLStore Get and Set methods defined wit hin. The interface will be called after the type plus a "er" or "r" depending wh ether the name end with consonant or not.
63
64 - The NewRemoteURLStorer() function to get remote references to URLStorer object s. This will NOT return a URLStore, but a type implementing the URLStorer interf ace.
65
66 - The NewURLStorerService() function to create a URLStorer service for any type implementing the URLStorer Get/Set interface, as for instance URLStore does.
67
68 - The type returned by NewRemoteURLStorer() implementing the URLStorer as rpc ca lls with the arguments and returnen the rpc results.
69
70 - The type returned by NewURLStorerService() implementing the URLStorer interfac e as a rpc service that gets rpc equivalent calls to the URLStorer interface, ex ecutes them as calls to the URLStorer implementation that is given, and returns the results back via rpc again.
71
72
73 AGAIN, HOW ARE TYPES MARKED AS TO BE REMOTIZED?
74 _______________________________________________
75
76 Well you can't only mark types, but you can choose to mark a type or its interfa ce if you al ready defined it by hand.
77
78 The goremote tool will scan you code to find calls like such as NewXXXService() or NewRemoteXXX() or remotize.NewService(XXX...) or remotize.NewRemote(XXX...). If found it will deduce it has to produce the remotizedXXX() file for the type o r interface XXX.
79
80 If XXX it's a type, it will produce all the code needed, included the 'XXXer' in terface. If XXX is an interface it will NOT duplicate the interface declaration.
81
82 - "But... what if I want to make a type or interface remotized but I am not usin g those calls?"
83 - "Maybe I want it to be remotized to be used by other packages importing mine"
84
85 Well, there are two ways of doing this.
86
87 1) Put a comment on top of the interface declaration you want to remotize ending with the text "(remotize)". This comments will make the goremote tool mark the object for remotization.
88
89 2) Use the remotize.PleaseRemotize(YYY) function passing it the YYY interface or type to be remotized. This function really does nothing, but the goremote will interpret it as a request to remotize YYY.
90
91 Remember that you can:
92
93 - Remotize either interfaces or types.
94 - The types or interfaces can be defined by you within your package or defined b y some other package before yours.
95
96 But you shouldn't remotize types with methods that have arguments or returns tha t are not to be sent by rpc or do not make sens to be rpc'ed like channels or fu nctions. Remotize will not stop you from doing that, but it doesn't make sense.
97
98
99 TESTING & COMPILING
100 ___________________
101
102 "gomake" will run the tests, compile and install everything
103 "gomake clean" will clean everything
104
OLDNEW
« no previous file with comments | « Makefile ('k') | TODO » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b