| ejona | d4531da | 2014-12-15 10:24:42 -0800 | [diff] [blame] | 1 | grpc-java |
| 2 | ========= |
| 3 | |
| Eric Anderson | fb28ad2 | 2015-01-29 15:00:58 -0800 | [diff] [blame] | 4 | How to Build |
| 5 | ------------ |
| 6 | |
| Kun Zhang | fd0aed2 | 2015-04-30 17:29:17 -0700 | [diff] [blame^] | 7 | ### Build Netty |
| Jakob Buchgraber | c56cec7 | 2015-03-11 13:44:32 -0700 | [diff] [blame] | 8 | grpc-java requires Netty 4.1, which is still in flux. The version we need can be |
| Eric Anderson | b10aaf8 | 2015-02-19 13:14:00 -0800 | [diff] [blame] | 9 | found in the lib/netty submodule, which requires Maven 3.2 or higher to build: |
| Eric Anderson | fb28ad2 | 2015-01-29 15:00:58 -0800 | [diff] [blame] | 10 | ``` |
| 11 | $ git submodule update --init |
| 12 | $ cd lib/netty |
| 13 | $ mvn install -pl codec-http2 -am -DskipTests=true |
| 14 | ``` |
| 15 | |
| Kun Zhang | fd0aed2 | 2015-04-30 17:29:17 -0700 | [diff] [blame^] | 16 | ### Build Protobuf |
| 17 | The codegen plugin requires protobuf 3.0.0-alpha-2. |
| 18 | |
| 19 | For Linux, Mac and MinGW: |
| Eric Anderson | fb28ad2 | 2015-01-29 15:00:58 -0800 | [diff] [blame] | 20 | ``` |
| 21 | $ git clone https://github.com/google/protobuf.git |
| 22 | $ cd protobuf |
| Eric Anderson | a6f5fff | 2015-02-26 07:53:17 -0800 | [diff] [blame] | 23 | $ git checkout v3.0.0-alpha-2 |
| Eric Anderson | fb28ad2 | 2015-01-29 15:00:58 -0800 | [diff] [blame] | 24 | $ ./autogen.sh |
| 25 | $ ./configure |
| 26 | $ make |
| 27 | $ make check |
| 28 | $ sudo make install |
| Eric Anderson | fb28ad2 | 2015-01-29 15:00:58 -0800 | [diff] [blame] | 29 | ``` |
| 30 | |
| 31 | If you are comfortable with C++ compilation and autotools, you can specify a |
| Kun Zhang | fd0aed2 | 2015-04-30 17:29:17 -0700 | [diff] [blame^] | 32 | ``--prefix`` for Protobuf and use ``-I`` in ``CXXFLAGS``, ``-L`` in |
| 33 | ``LDFLAGS``, ``LD_LIBRARY_PATH``, and ``PATH`` to reference it. The |
| 34 | environment variables will be used when building grpc-java. |
| Eric Anderson | fb28ad2 | 2015-01-29 15:00:58 -0800 | [diff] [blame] | 35 | |
| Kun Zhang | fd0aed2 | 2015-04-30 17:29:17 -0700 | [diff] [blame^] | 36 | Protobuf installs to ``/usr/local`` by default. |
| 37 | |
| 38 | For Visual C++, please refer to the [Protobuf README](https://github.com/google/protobuf/blob/master/vsprojects/readme.txt) |
| 39 | for how to compile Protobuf. |
| 40 | |
| 41 | #### Linux and MinGW |
| 42 | If ``/usr/local/lib`` is not in your library search path, you can add it by running: |
| Louis Ryan | 65d64cd | 2015-02-18 14:51:42 -0800 | [diff] [blame] | 43 | ``` |
| 44 | $ sudo sh -c 'echo /usr/local/lib >> /etc/ld.so.conf' |
| 45 | $ sudo ldconfig |
| 46 | ``` |
| 47 | |
| Kun Zhang | fd0aed2 | 2015-04-30 17:29:17 -0700 | [diff] [blame^] | 48 | #### Mac |
| 49 | Some versions of Mac OS X (e.g., 10.10) doesn't have ``/usr/local`` in the |
| 50 | default search paths for header files and libraries. You will need to set |
| 51 | environment variables: |
| 52 | ``` |
| 53 | $ export CXXFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib" |
| 54 | ``` |
| 55 | |
| 56 | ### Build GRPC |
| 57 | On Linux, Mac or MinGW: |
| Eric Anderson | fb28ad2 | 2015-01-29 15:00:58 -0800 | [diff] [blame] | 58 | ``` |
| 59 | $ ./gradlew install |
| 60 | ``` |
| 61 | |
| Eric Anderson | 456216b | 2015-03-02 16:58:27 -0800 | [diff] [blame] | 62 | When building on Windows and VC++, you need to specify project properties for |
| 63 | Gradle to find protobuf: |
| 64 | ``` |
| 65 | .\gradlew install -Pprotobuf.include=C:\path\to\protobuf-3.0.0-alpha-2\src ^ |
| 66 | -Pprotobuf.libs=C:\path\to\protobuf-3.0.0-alpha-2\vsprojects\Release |
| 67 | ``` |
| 68 | |
| 69 | Since specifying those properties every build is bothersome, you can instead |
| Kun Zhang | fd0aed2 | 2015-04-30 17:29:17 -0700 | [diff] [blame^] | 70 | create ``%HOMEDRIVE%%HOMEPATH%\.gradle\gradle.properties`` with contents like: |
| Eric Anderson | 456216b | 2015-03-02 16:58:27 -0800 | [diff] [blame] | 71 | ``` |
| 72 | protobuf.include=C:\\path\\to\\protobuf-3.0.0-alpha-2\\src |
| 73 | protobuf.libs=C:\\path\\to\\protobuf-3.0.0-alpha-2\\vsprojects\\Release |
| 74 | ``` |
| 75 | |
| Eric Anderson | fb28ad2 | 2015-01-29 15:00:58 -0800 | [diff] [blame] | 76 | Navigating Around the Source |
| 77 | ---------------------------- |
| 78 | |
| ejona | d4531da | 2014-12-15 10:24:42 -0800 | [diff] [blame] | 79 | Heres a quick readers guide to the code to help folks get started. At a high level there are three distinct layers |
| Kun Zhang | a8ef36a | 2015-04-22 14:46:07 -0700 | [diff] [blame] | 80 | to the library: stub, channel & transport. |
| ejona | d4531da | 2014-12-15 10:24:42 -0800 | [diff] [blame] | 81 | |
| Eric Anderson | fb28ad2 | 2015-01-29 15:00:58 -0800 | [diff] [blame] | 82 | ### Stub |
| ejona | d4531da | 2014-12-15 10:24:42 -0800 | [diff] [blame] | 83 | |
| 84 | The 'stub' layer is what is exposed to most developers and provides type-safe bindings to whatever |
| 85 | datamodel/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. |
| 86 | |
| 87 | #### Key Interfaces |
| 88 | |
| nmittler | f831458 | 2015-01-27 10:25:39 -0800 | [diff] [blame] | 89 | [Stream Observer](https://github.com/google/grpc-java/blob/master/stub/src/main/java/io/grpc/stub/StreamObserver.java) |
| ejona | d4531da | 2014-12-15 10:24:42 -0800 | [diff] [blame] | 90 | |
| 91 | |
| Eric Anderson | fb28ad2 | 2015-01-29 15:00:58 -0800 | [diff] [blame] | 92 | ### Channel |
| ejona | d4531da | 2014-12-15 10:24:42 -0800 | [diff] [blame] | 93 | |
| 94 | The '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. |
| 95 | |
| 96 | #### Common |
| 97 | |
| nmittler | f831458 | 2015-01-27 10:25:39 -0800 | [diff] [blame] | 98 | * [Metadata - headers & trailers](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Metadata.java) |
| 99 | * [Status - error code namespace & handling](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Status.java) |
| ejona | d4531da | 2014-12-15 10:24:42 -0800 | [diff] [blame] | 100 | |
| 101 | #### Client |
| nmittler | f831458 | 2015-01-27 10:25:39 -0800 | [diff] [blame] | 102 | * [Channel - client side binding](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Channel.java) |
| 103 | * [Call](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Call.java) |
| 104 | * [Client Interceptor](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ClientInterceptor.java) |
| ejona | d4531da | 2014-12-15 10:24:42 -0800 | [diff] [blame] | 105 | |
| 106 | #### Server |
| nmittler | f831458 | 2015-01-27 10:25:39 -0800 | [diff] [blame] | 107 | * [Server call handler - analog to Channel on server](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ServerCallHandler.java) |
| 108 | * [Server Call](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ServerCall.java) |
| ejona | d4531da | 2014-12-15 10:24:42 -0800 | [diff] [blame] | 109 | |
| 110 | |
| Eric Anderson | fb28ad2 | 2015-01-29 15:00:58 -0800 | [diff] [blame] | 111 | ### Transport |
| ejona | d4531da | 2014-12-15 10:24:42 -0800 | [diff] [blame] | 112 | |
| 113 | The '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. |
| 114 | |
| 115 | #### Common |
| 116 | |
| nmittler | f831458 | 2015-01-27 10:25:39 -0800 | [diff] [blame] | 117 | * [Stream](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/Stream.java) |
| 118 | * [Stream Listener](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/StreamListener.java) |
| ejona | d4531da | 2014-12-15 10:24:42 -0800 | [diff] [blame] | 119 | |
| 120 | #### Client |
| 121 | |
| nmittler | f831458 | 2015-01-27 10:25:39 -0800 | [diff] [blame] | 122 | * [Client Stream](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/ClientStream.java) |
| 123 | * [Client Stream Listener](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/ClientStreamListener.java) |
| ejona | d4531da | 2014-12-15 10:24:42 -0800 | [diff] [blame] | 124 | |
| 125 | #### Server |
| 126 | |
| nmittler | f831458 | 2015-01-27 10:25:39 -0800 | [diff] [blame] | 127 | * [Server Stream](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/ServerStream.java) |
| 128 | * [Server Stream Listener](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/ServerStreamListener.java) |
| ejona | d4531da | 2014-12-15 10:24:42 -0800 | [diff] [blame] | 129 | |
| 130 | |
| Eric Anderson | fb28ad2 | 2015-01-29 15:00:58 -0800 | [diff] [blame] | 131 | ### Examples |
| ejona | d4531da | 2014-12-15 10:24:42 -0800 | [diff] [blame] | 132 | |
| nmittler | f831458 | 2015-01-27 10:25:39 -0800 | [diff] [blame] | 133 | Tests 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 |