blob: 608ce417155eca6bdf7940a478b939472dd08709 [file] [log] [blame] [view]
ejonad4531da2014-12-15 10:24:42 -08001grpc-java
2=========
3
Eric Andersonfb28ad22015-01-29 15:00:58 -08004How to Build
5------------
6
Kun Zhangfd0aed22015-04-30 17:29:17 -07007### Build Netty
Jakob Buchgraberc56cec72015-03-11 13:44:32 -07008grpc-java requires Netty 4.1, which is still in flux. The version we need can be
Eric Andersonb10aaf82015-02-19 13:14:00 -08009found in the lib/netty submodule, which requires Maven 3.2 or higher to build:
Eric Andersonfb28ad22015-01-29 15:00:58 -080010```
11$ git submodule update --init
12$ cd lib/netty
13$ mvn install -pl codec-http2 -am -DskipTests=true
14```
15
Kun Zhangfd0aed22015-04-30 17:29:17 -070016### Build Protobuf
17The codegen plugin requires protobuf 3.0.0-alpha-2.
18
19For Linux, Mac and MinGW:
Eric Andersonfb28ad22015-01-29 15:00:58 -080020```
21$ git clone https://github.com/google/protobuf.git
22$ cd protobuf
Eric Andersona6f5fff2015-02-26 07:53:17 -080023$ git checkout v3.0.0-alpha-2
Eric Andersonfb28ad22015-01-29 15:00:58 -080024$ ./autogen.sh
25$ ./configure
26$ make
27$ make check
28$ sudo make install
Eric Andersonfb28ad22015-01-29 15:00:58 -080029```
30
31If you are comfortable with C++ compilation and autotools, you can specify a
Kun Zhangfd0aed22015-04-30 17:29:17 -070032``--prefix`` for Protobuf and use ``-I`` in ``CXXFLAGS``, ``-L`` in
33``LDFLAGS``, ``LD_LIBRARY_PATH``, and ``PATH`` to reference it. The
34environment variables will be used when building grpc-java.
Eric Andersonfb28ad22015-01-29 15:00:58 -080035
Kun Zhangfd0aed22015-04-30 17:29:17 -070036Protobuf installs to ``/usr/local`` by default.
37
38For Visual C++, please refer to the [Protobuf README](https://github.com/google/protobuf/blob/master/vsprojects/readme.txt)
39for how to compile Protobuf.
40
41#### Linux and MinGW
42If ``/usr/local/lib`` is not in your library search path, you can add it by running:
Louis Ryan65d64cd2015-02-18 14:51:42 -080043```
44$ sudo sh -c 'echo /usr/local/lib >> /etc/ld.so.conf'
45$ sudo ldconfig
46```
47
Kun Zhangfd0aed22015-04-30 17:29:17 -070048#### Mac
49Some versions of Mac OS X (e.g., 10.10) doesn't have ``/usr/local`` in the
50default search paths for header files and libraries. You will need to set
51environment variables:
52```
53$ export CXXFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib"
54```
55
56### Build GRPC
57On Linux, Mac or MinGW:
Eric Andersonfb28ad22015-01-29 15:00:58 -080058```
59$ ./gradlew install
60```
61
Kun Zhang221c5342015-04-29 18:16:15 -070062### Notes for Visual C++
63
Eric Anderson456216b2015-03-02 16:58:27 -080064When building on Windows and VC++, you need to specify project properties for
65Gradle to find protobuf:
66```
Kun Zhang221c5342015-04-29 18:16:15 -070067.\gradlew install ^
68 -Pvc.protobuf.include=C:\path\to\protobuf-3.0.0-alpha-2\src ^
69 -Pvc.protobuf.libs=C:\path\to\protobuf-3.0.0-alpha-2\vsprojects\Release
Eric Anderson456216b2015-03-02 16:58:27 -080070```
71
72Since specifying those properties every build is bothersome, you can instead
Kun Zhangfd0aed22015-04-30 17:29:17 -070073create ``%HOMEDRIVE%%HOMEPATH%\.gradle\gradle.properties`` with contents like:
Eric Anderson456216b2015-03-02 16:58:27 -080074```
Kun Zhang221c5342015-04-29 18:16:15 -070075vc.protobuf.include=C:\\path\\to\\protobuf-3.0.0-alpha-2\\src
76vc.protobuf.libs=C:\\path\\to\\protobuf-3.0.0-alpha-2\\vsprojects\\Release
Eric Anderson456216b2015-03-02 16:58:27 -080077```
78
Kun Zhang221c5342015-04-29 18:16:15 -070079The build script will build the codegen for the same architecture as the Java
80runtime installed on your system. If you are using 64-bit JVM, the codegen will
81be compiled for 64-bit, that means you must have compiled Protobuf in 64-bit.
82
83### Notes for MinGW on Windows
84If you have both MinGW and VC++ installed on Windows, VC++ will be used by
85default. To override this default and use MinGW, add ``-Dvc.disable`` to your
86Gradle command line.
87
Eric Andersonfb28ad22015-01-29 15:00:58 -080088Navigating Around the Source
89----------------------------
90
ejonad4531da2014-12-15 10:24:42 -080091Heres a quick readers guide to the code to help folks get started. At a high level there are three distinct layers
Kun Zhanga8ef36a2015-04-22 14:46:07 -070092to the library: stub, channel & transport.
ejonad4531da2014-12-15 10:24:42 -080093
Eric Andersonfb28ad22015-01-29 15:00:58 -080094### Stub
ejonad4531da2014-12-15 10:24:42 -080095
96The 'stub' layer is what is exposed to most developers and provides type-safe bindings to whatever
97datamodel/IDL/interface you are adapting. An example is provided of a binding to code generated by the protocol-buffers compiler but others should be trivial to add and are welcome.
98
99#### Key Interfaces
100
nmittlerf8314582015-01-27 10:25:39 -0800101[Stream Observer](https://github.com/google/grpc-java/blob/master/stub/src/main/java/io/grpc/stub/StreamObserver.java)
ejonad4531da2014-12-15 10:24:42 -0800102
103
Eric Andersonfb28ad22015-01-29 15:00:58 -0800104### Channel
ejonad4531da2014-12-15 10:24:42 -0800105
106The 'channel' layer is an abstraction over transport handling that is suitable for interception/decoration and exposes more behavior to the application than the stub layer. It is intended to be easy for application frameworks to use this layer to address cross-cutting concerns such as logging, monitoring, auth etc. Flow-control is also exposed at this layer to allow more sophisticated applications to interact with it directly.
107
108#### Common
109
nmittlerf8314582015-01-27 10:25:39 -0800110* [Metadata - headers & trailers](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Metadata.java)
111* [Status - error code namespace & handling](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Status.java)
ejonad4531da2014-12-15 10:24:42 -0800112
113#### Client
nmittlerf8314582015-01-27 10:25:39 -0800114* [Channel - client side binding](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Channel.java)
115* [Call](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Call.java)
116* [Client Interceptor](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ClientInterceptor.java)
ejonad4531da2014-12-15 10:24:42 -0800117
118#### Server
nmittlerf8314582015-01-27 10:25:39 -0800119* [Server call handler - analog to Channel on server](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ServerCallHandler.java)
120* [Server Call](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ServerCall.java)
ejonad4531da2014-12-15 10:24:42 -0800121
122
Eric Andersonfb28ad22015-01-29 15:00:58 -0800123### Transport
ejonad4531da2014-12-15 10:24:42 -0800124
125The 'transport' layer does the heavy lifting of putting & taking bytes off the wire. The interfaces to it are abstract just enough to allow plugging in of different implementations. Transports are modeled as 'Stream' factories. The variation in interface between a server stream and a client stream exists to codify their differing semantics for cancellation and error reporting.
126
127#### Common
128
nmittlerf8314582015-01-27 10:25:39 -0800129* [Stream](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/Stream.java)
130* [Stream Listener](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/StreamListener.java)
ejonad4531da2014-12-15 10:24:42 -0800131
132#### Client
133
nmittlerf8314582015-01-27 10:25:39 -0800134* [Client Stream](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/ClientStream.java)
135* [Client Stream Listener](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/ClientStreamListener.java)
ejonad4531da2014-12-15 10:24:42 -0800136
137#### Server
138
nmittlerf8314582015-01-27 10:25:39 -0800139* [Server Stream](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/ServerStream.java)
140* [Server Stream Listener](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/ServerStreamListener.java)
ejonad4531da2014-12-15 10:24:42 -0800141
142
Eric Andersonfb28ad22015-01-29 15:00:58 -0800143### Examples
ejonad4531da2014-12-15 10:24:42 -0800144
nmittlerf8314582015-01-27 10:25:39 -0800145Tests showing how these layers are composed to execute calls using protobuf messages can be found here https://github.com/google/grpc-java/tree/master/integration-testing/src/main/java/io/grpc/testing/integration