blob: 65cdc9eb26480f97840a6b91a4a00074ed8a5a05 [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
7grpc-java requires Netty 5, which is still in flux. The version we need can be
Eric Andersonb10aaf82015-02-19 13:14:00 -08008found in the lib/netty submodule, which requires Maven 3.2 or higher to build:
Eric Andersonfb28ad22015-01-29 15:00:58 -08009```
10$ git submodule update --init
11$ cd lib/netty
12$ mvn install -pl codec-http2 -am -DskipTests=true
13```
14
15The codegen plugin requires a recent protobuf build from master (what will
16become proto3):
17```
18$ git clone https://github.com/google/protobuf.git
19$ cd protobuf
20$ ./autogen.sh
21$ ./configure
22$ make
23$ make check
24$ sudo make install
25$ cd java
26$ mvn install
rockingc60f0172015-02-25 12:34:28 -080027$ cd ../javanano
28$ mvn install
Eric Andersonfb28ad22015-01-29 15:00:58 -080029```
30
31If you are comfortable with C++ compilation and autotools, you can specify a
32--prefix for protobuf and use -I in CXXFLAGS, -L in LDFLAGS, LD\_LIBRARY\_PATH,
33and PATH to reference it. The environment variables will be used when building
34grpc-java.
35
Louis Ryan65d64cd2015-02-18 14:51:42 -080036Protobuf installs to /usr/local by default.
37If /usr/local/lib is not in your library search path, you can add it by running:
38```
39$ sudo sh -c 'echo /usr/local/lib >> /etc/ld.so.conf'
40$ sudo ldconfig
41```
42
Eric Andersonfb28ad22015-01-29 15:00:58 -080043Now to build grpc-java itself:
44```
45$ ./gradlew install
46```
47
48Navigating Around the Source
49----------------------------
50
ejonad4531da2014-12-15 10:24:42 -080051Heres a quick readers guide to the code to help folks get started. At a high level there are three distinct layers
52to the library: stub, channel & transport.
53
Eric Andersonfb28ad22015-01-29 15:00:58 -080054### Stub
ejonad4531da2014-12-15 10:24:42 -080055
56The 'stub' layer is what is exposed to most developers and provides type-safe bindings to whatever
57datamodel/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.
58
59#### Key Interfaces
60
nmittlerf8314582015-01-27 10:25:39 -080061[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 -080062
63
Eric Andersonfb28ad22015-01-29 15:00:58 -080064### Channel
ejonad4531da2014-12-15 10:24:42 -080065
66The '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.
67
68#### Common
69
nmittlerf8314582015-01-27 10:25:39 -080070* [Metadata - headers & trailers](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Metadata.java)
71* [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 -080072
73#### Client
nmittlerf8314582015-01-27 10:25:39 -080074* [Channel - client side binding](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Channel.java)
75* [Call](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Call.java)
76* [Client Interceptor](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ClientInterceptor.java)
ejonad4531da2014-12-15 10:24:42 -080077
78#### Server
nmittlerf8314582015-01-27 10:25:39 -080079* [Server call handler - analog to Channel on server](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ServerCallHandler.java)
80* [Server Call](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ServerCall.java)
ejonad4531da2014-12-15 10:24:42 -080081
82
Eric Andersonfb28ad22015-01-29 15:00:58 -080083### Transport
ejonad4531da2014-12-15 10:24:42 -080084
85The '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.
86
87#### Common
88
nmittlerf8314582015-01-27 10:25:39 -080089* [Stream](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/Stream.java)
90* [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 -080091
92#### Client
93
nmittlerf8314582015-01-27 10:25:39 -080094* [Client Stream](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/ClientStream.java)
95* [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 -080096
97#### Server
98
nmittlerf8314582015-01-27 10:25:39 -080099* [Server Stream](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/ServerStream.java)
100* [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 -0800101
102
Eric Andersonfb28ad22015-01-29 15:00:58 -0800103### Examples
ejonad4531da2014-12-15 10:24:42 -0800104
nmittlerf8314582015-01-27 10:25:39 -0800105Tests 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