{"id":179235,"date":"2013-05-10T10:06:03","date_gmt":"2013-05-10T06:06:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=179235"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=179235","title":{"rendered":"<span class=\"post_title\">Apache Thrift RPC Server. \u0414\u0440\u0443\u0436\u0438\u043c C++ \u0438 Java<\/span>"},"content":{"rendered":"<div class=\"content html_format\"> \t\t\t\u041f\u0440\u0438\u0432\u0435\u0442, \u043a\u043e\u043b\u043b\u0435\u0433\u0438. <br \/>  \u0425\u043e\u0447\u0443 \u0432 \u044d\u0442\u043e\u043c \u0442\u043e\u043f\u0438\u043a\u0435 \u0432\u044b\u043b\u043e\u0436\u0438\u0442\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e, \u043a\u0430\u043a \u0431\u044b\u0441\u0442\u0440\u043e \u043f\u0440\u0438\u043a\u0440\u0443\u0442\u0438\u0442\u044c Thrift, \u043a \u0441\u0432\u043e\u0438\u043c \u043f\u043e\u0434\u0435\u043b\u043a\u0430\u043c. <br \/>  <b>Thrift<\/b> \u2014 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f \u0434\u043b\u044f \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0435\u0436\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043d\u043e\u0433\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u0411\u044b\u043b\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u0430 \u0433\u0434\u0435 \u0442\u043e \u0432 \u043d\u0435\u0434\u0440\u0430\u0445 Facebook. \u041f\u043e\u0441\u0443\u0442\u0438 \u044d\u0442\u043e \u043a\u0440\u043e\u0441\u0441-\u044f\u0437\u044b\u043a\u043e\u0432\u043e\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f RPC \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432, \u043d\u0430 \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u043c \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0435. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u00ab\u043f\u043e\u0434\u0440\u0443\u0436\u0438\u0442\u044c\u00bb \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445 C#, C++, Delphi, Erlang, Go, Java, PHP, Python, Ruby, \u0438\u0442\u0434. \u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e IDL \u2014 \u044f\u0437\u044b\u043a\u0430. \u0422\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f, \u043f\u043e \u0441\u0432\u043e\u0435\u0439 \u0441\u0443\u0442\u0438, \u043f\u043e\u0445\u043e\u0436\u0430 \u043d\u0430 COM, \u043d\u043e \u0431\u0435\u0437 \u0432\u0441\u0435\u0439 \u044d\u0442\u043e\u0439 \u043e\u0431\u0432\u044f\u0437\u043a\u0438 \u0441 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0435\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442. \u0422\u0430\u043a \u0436\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u0431\u044b\u0432\u0430\u0442\u044c, \u0447\u0442\u043e COM \u044d\u0442\u043e \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f Windows, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a Thrift \u2014 \u043a\u0440\u043e\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u0430.<\/p>\n<p>  \u0412\u043e\u0431\u0449\u0435\u043c \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0447\u0430\u0441\u0442\u044c \u043d\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0439-\u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0438 \u0438\u0437 Java \u0432 \u0421++, \u0432 \u043d\u0430\u0434\u0435\u0436\u0434\u0435 \u0447\u0442\u043e \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0421++ \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u0435\u0439, \u0438 \u0437\u0430 \u043e\u0434\u043d\u043e \u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c Thrift RPC, \u0432 \u043d\u0430\u0434\u0435\u0436\u0434\u0435 \u0447\u0442\u043e \u044d\u0442\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0447\u0435\u043c REST.<br \/>  \u041a\u0430\u043a \u0438 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043e, \u0431\u0435\u0437 \u0431\u0443\u0431\u043d\u043e\u0432 \u0438 \u0433\u0440\u0430\u0431\u043b\u0435\u0439 \u043d\u0435 \u043e\u0431\u043e\u0448\u043b\u043e\u0441\u044c!<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0418 \u0442\u0430\u043a, \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u0434\u043e \u0432\u0441\u0451 \u044d\u0442\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c:<br \/>  1. \u0421\u0442\u0430\u0432\u0438\u043c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0434\u043b\u044f Boost, \u0438\u0431\u043e \u0432\u0441\u0451 \u0437\u0430\u0432\u044f\u0437\u0430\u043d\u043e \u043d\u0430 \u043d\u0451\u043c  <\/p>\n<pre><code class=\"bash\">$ sudo apt-get install libboost-dev libboost-test-dev libboost-program-options-dev libevent-dev automake libtool flex bison pkg-config g++ libssl-dev <\/code><\/pre>\n<p>  2. \u043a\u0430\u0447\u0430\u0435\u043c thrift tarball <a href=\"http:\/\/apache.softded.ru\/thrift\/0.9.0\/thrift-0.9.0.tar.gz\">apache.softded.ru\/thrift\/0.9.0\/thrift-0.9.0.tar.gz<\/a><br \/>  \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u044b\u0432\u0430\u0435\u043c, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c configure, \u0438 \u0437\u0430\u0442\u0435\u043c \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c.<\/p>\n<pre><code class=\"bash\">$ .\/configure $ make $ sudo make install <\/code><\/pre>\n<p>  \u0412\u0440\u043e\u0434\u0435 \u0431\u044b \u0432\u0441\u0451\u2026 \u041c\u043e\u0436\u043d\u043e \u0434\u0430\u0436\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0438\u0437 \u0443\u0447\u0435\u0431\u043d\u0438\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0434\u0435\u0442 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 thrift tarball<\/p>\n<pre><code class=\"bash\">$ thrift --gen cpp tutorial.thrift <\/code><\/pre>\n<p>  \u043a\u043e\u043c\u0430\u043d\u0434\u0430 thrift \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0421++ \u043e\u0431\u0432\u0435\u0440\u0442\u043a\u0438, \u0438 \u0431\u0435\u0440\u0435\u0436\u043d\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442 \u0438\u0445 \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e gen-cpp. \u0422\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u043b\u044f Java, PHP \u0438\u0442\u0434\u2026<br \/>  \u041f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u043d\u0430\u0433\u0435\u043d\u0435\u0440\u0435\u043d\u043d\u044b\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438<\/p>\n<pre><code class=\"bash\">$ g++ -Wall -I\/usr\/local\/include\/thrift *.cpp -L\/usr\/local\/lib -lthrift -o something <\/code><\/pre>\n<p>  \u0423\u043f\u0441, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435: <b>error: \u2018uint32_t\u2019 does not name a type<\/b><br \/>  \u041e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0435\u0441\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0442\u0430\u0440\u0430\u043a\u0430\u043d \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u0445 thrift \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0439 \u0441 uint32_t. \u041b\u0435\u0447\u0438\u0442\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c &quot;#include &lt;stdint.h&gt;&quot; \u0432 \u00abThrift.h\u00bb, \u0438\u043b\u0438 (\u0447\u0442\u043e \u043b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e) \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043e\u043f\u0446\u0438\u044f\u043c\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430<b> -DHAVE_NETINET_IN_H -DHAVE_INTTYPES_H<\/b><\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"bash\">$ g++ -DHAVE_INTTYPES_H -DHAVE_NETINET_IN_H -Wall -I\/usr\/local\/include\/thrift *.cpp -L\/usr\/local\/lib -lthrift -o something <\/code><\/pre>\n<p>  \u0412\u043e\u0442 \u0438 \u0432\u0441\u0451, \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u043c\u044b\u0439 \u0444\u0430\u0439\u043b, \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c something.<br \/>  \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c, \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c:<b> error while loading shared libraries: libthrift.so.0: cannot open shared object file: No such file or directory<\/b> <br \/>  \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u043d\u043e \u044f \u0440\u0435\u0448\u0438\u043b \u0435\u0451 \u0432 \u043b\u043e\u0431, \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c thrift \u0444\u0430\u0439\u043b\u043e\u0432 \u0438\u0437 \/usr\/local\/lib \u0432 \/lib<\/p>\n<p>  \u0412\u0441\u0451, \u043f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0441\u044f. \u0417\u043d\u0430\u0447\u0438\u0442, \u0432\u0441\u0435 \u043d\u0430 \u043c\u0435\u0441\u0442\u0430\u0445, \u0438 \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0439 RPC \u0441\u0435\u0440\u0432\u0435\u0440.<br \/>  \u0415\u0433\u043e \u0437\u0430\u0434\u0430\u0447\u0430, \u0431\u044b\u0442\u044c key-value \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435\u043c. \u0425\u0440\u0430\u043d\u0438\u0442\u044c \u0434\u043b\u0438\u043d\u043d\u044b\u0435 (\u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0442 \u0442\u044b\u0441\u044f\u0447) \u0431\u0438\u0442\u043e\u0432\u044b\u0435 \u043c\u0430\u0441\u043a\u0438. \u0421\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0438\u0445 (AND), \u0438 \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438\u0441\u044c \u0435\u0434\u0435\u043d\u0438\u0446\u044b. \u0414\u0430, \u043f\u043e\u0447\u0442\u0438 \u0442\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0443\u043c\u0435\u0435\u0442 Redis, \u043d\u043e \u043e\u043d \u043c\u043d\u0435 \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442.<\/p>\n<p>  \u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043b\u0435\u0436\u0438\u0442 \u0437\u0434\u0435\u0441\u044c: <a href=\"https:\/\/github.com\/2anikulin\/fast-hands.git\">github.com\/2anikulin\/fast-hands.git<\/a><\/p>\n<p>  \u041e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432, \u0432 <b>thrift definition file<\/b>:  <\/p>\n<pre><code class=\"cs\">namespace cpp fasthands namespace java fasthands namespace php fasthands namespace perl fasthands   exception InvalidOperation {   1: i32 what,   2: string why }   service FastHandsService {    i32 put(1:i32 key, 2:binary value),     binary get(1:i32 key),     list &lt;i32&gt; bitAnd(1:list&lt;i32&gt; keys) throws (1:InvalidOperation ouch) } <\/code><\/pre>\n<p>  \u0418 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u043e\u0431\u0432\u0435\u0440\u0442\u043a\u0438.<br \/>  \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 C++<br \/>  \u042d\u0442\u043e\u0442 \u043a\u043e\u0434, \u0441\u043e\u0437\u0434\u0430\u0435\u0442, \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 RPC \u0441\u0435\u0440\u0432\u0435\u0440<\/p>\n<pre><code class=\"cpp\">#define PORT 9090 #define THREAD_POOL_SIZE 15     int main() {     printf(&quot;FastHands Server started\\n&quot;);     shared_ptr&lt;TProtocolFactory&gt; protocolFactory(new TBinaryProtocolFactory());   shared_ptr&lt;FastHandsHandler&gt; handler(new FastHandsHandler());   shared_ptr&lt;TProcessor&gt; processor(new FastHandsServiceProcessor(handler));     shared_ptr&lt;ThreadManager&gt; threadManager = ThreadManager::newSimpleThreadManager(THREAD_POOL_SIZE);   shared_ptr&lt;PosixThreadFactory&gt; threadFactory = shared_ptr&lt;PosixThreadFactory&gt;(new PosixThreadFactory());   threadManager-&gt;threadFactory(threadFactory);   threadManager-&gt;start();     TNonblockingServer server(processor, protocolFactory, PORT, threadManager);   server.serve();   printf(&quot;done.\\n&quot;);     return 0; } <\/code><\/pre>\n<p>  \u0412 \u043a\u043b\u0430\u0441\u0441\u0435 FastHandsHandler \u2014 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432\u0435\u0441\u044c \u043d\u0430\u0448, \u043f\u0440\u0438\u043a\u043b\u0430\u0434\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b<br \/>  \u042d\u0442\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u044b\u0439 \u0444\u0430\u0439\u043b  <\/p>\n<pre><code class=\"cpp\">class FastHandsHandler : virtual public FastHandsServiceIf {    public:   FastHandsHandler();   int32_t put(const int32_t key, const std::string& value);   void get(std::string& _return, const int32_t key);   void bitAnd(std::vector&lt;int32_t&gt; & _return, const std::vector&lt;int32_t&gt; & keys);    private:   void appendBitPositions(std::vector&lt;int32_t&gt; & positions, unsigned char bits, int offset);    private:   std::map&lt;int32_t, std::string&gt; m_store;   }; <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u043e\u0431\u0440\u0430\u0442\u044c, \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443:<b> c++ undefined reference to apache::thrift::server::TNonblockingServer<\/b><br \/>  \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0438 \u043e\u0442 \u0443\u0447\u0435\u0431\u043d\u0438\u043a\u0430, \u043c\u043e\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u2014 \u0430\u0441\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439, \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043a\u043b\u0430\u0441\u0441 TNonblockingServer. \u0427\u0442\u043e\u0431\u044b \u043a\u043e\u0434 \u0441\u043e\u0431\u0438\u0440\u0430\u043b\u0441\u044f, \u043d\u0430\u0434\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<b> -lthriftnb -levent<\/b><\/p>\n<p>  \u0442.\u0435 \u0441\u0431\u043e\u0440\u043a\u0430 \u0441\u0435\u0439\u0447\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"dos\">g++ -DHAVE_INTTYPES_H -DHAVE_NETINET_IN_H -Wall -I\/usr\/local\/include\/thrift *.cpp -L\/usr\/local\/lib -lthrift -lthriftnb -levent -o something <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0435 \u0445\u043e\u0440\u043e\u0448\u043e. \u041a\u043e\u0434 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d, \u0441\u043b\u0438\u043d\u043a\u043e\u0432\u0430\u043d, \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0444\u0430\u0439\u043b \u043f\u043e \u0438\u043c\u0435\u043d\u0438 something<br \/>  \u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u043e\u0431\u0432\u0435\u0440\u0442\u043a\u0438 \u0434\u043b\u044f java, \u0438 \u043f\u0438\u0448\u0435\u043c \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430<\/p>\n<pre><code class=\"java\">import fasthands.FastHandsService; import fasthands.InvalidOperation; import org.apache.thrift.TException; import org.apache.thrift.transport.TFramedTransport; import org.apache.thrift.transport.TTransport; import org.apache.thrift.transport.TSocket; import org.apache.thrift.transport.TTransportException; import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TProtocol;   import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List;   public class JavaClient {       public static void main(String [] args) {         TTransport transport = new TFramedTransport(new TSocket(&quot;localhost&quot;, 9090));         TProtocol protocol = new TBinaryProtocol(transport);         final FastHandsService.Client client = new FastHandsService.Client(protocol);           final List&lt;Integer&gt; filters = new ArrayList&lt;Integer&gt;();           try {             transport.open();               int count = 12500;             byte bt[] = new byte[count];             for (int i =0; i &lt; count; i++) {                 bt[i] = (byte)0xFF;             }               for (int i = 0; i &lt; 50; i++) {                 client.put(i, ByteBuffer.wrap(bt)) ;                 filters.add(i);             }               List&lt;Integer&gt; list = client.bitAnd(filters);             System.out.println(list.size());             } catch (TTransportException e) {             e.printStackTrace();         } catch (TException e) {             e.printStackTrace();           }           transport.close();     } } <\/code><\/pre>\n<p>  \u0427\u0442\u043e \u0432 \u0438\u0442\u043e\u0433\u0435.<br \/>  \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f, \u0438 \u043d\u0435 \u043f\u043b\u043e\u0445\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0440\u0438\u043a\u0440\u0443\u0442\u0438\u0442\u044c \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u043d\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u043a \u0433\u043e\u043b\u043e\u043c\u0443 \u043a\u043e\u0434\u0443 \u043d\u0430 \u0421++. \u041d\u043e \u043d\u0435 \u0441\u043a\u0430\u0436\u0443, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0447\u0435\u043c REST, \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0438 \u043f\u043e http. \u0427\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u0434\u0430, \u0432\u044b\u043d\u0435\u0441\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u0437 Java \u0432 \u0421++, \u0442\u043e \u0447\u0443\u0434\u0430 \u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e, \u043e\u043d \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0432 1.2 \u2014 1.4 \u0440\u0430\u0437\u0430, \u0438\u0431\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f + \u0440\u0430\u0441\u0445\u043e\u0434\u044b \u043d\u0430 \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u043d\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c. \t\t\t \t\t\t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/179235\/\"> http:\/\/habrahabr.ru\/post\/179235\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\"> \t\t\t\u041f\u0440\u0438\u0432\u0435\u0442, \u043a\u043e\u043b\u043b\u0435\u0433\u0438. <br \/>  \u0425\u043e\u0447\u0443 \u0432 \u044d\u0442\u043e\u043c \u0442\u043e\u043f\u0438\u043a\u0435 \u0432\u044b\u043b\u043e\u0436\u0438\u0442\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e, \u043a\u0430\u043a \u0431\u044b\u0441\u0442\u0440\u043e \u043f\u0440\u0438\u043a\u0440\u0443\u0442\u0438\u0442\u044c Thrift, \u043a \u0441\u0432\u043e\u0438\u043c \u043f\u043e\u0434\u0435\u043b\u043a\u0430\u043c. <br \/>  <b>Thrift<\/b> \u2014 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f \u0434\u043b\u044f \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0435\u0436\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043d\u043e\u0433\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u0411\u044b\u043b\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u0430 \u0433\u0434\u0435 \u0442\u043e \u0432 \u043d\u0435\u0434\u0440\u0430\u0445 Facebook. \u041f\u043e\u0441\u0443\u0442\u0438 \u044d\u0442\u043e \u043a\u0440\u043e\u0441\u0441-\u044f\u0437\u044b\u043a\u043e\u0432\u043e\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f RPC \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432, \u043d\u0430 \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u043c \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0435. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u00ab\u043f\u043e\u0434\u0440\u0443\u0436\u0438\u0442\u044c\u00bb \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445 C#, C++, Delphi, Erlang, Go, Java, PHP, Python, Ruby, \u0438\u0442\u0434. \u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e IDL \u2014 \u044f\u0437\u044b\u043a\u0430. \u0422\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f, \u043f\u043e \u0441\u0432\u043e\u0435\u0439 \u0441\u0443\u0442\u0438, \u043f\u043e\u0445\u043e\u0436\u0430 \u043d\u0430 COM, \u043d\u043e \u0431\u0435\u0437 \u0432\u0441\u0435\u0439 \u044d\u0442\u043e\u0439 \u043e\u0431\u0432\u044f\u0437\u043a\u0438 \u0441 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0435\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442. \u0422\u0430\u043a \u0436\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u0431\u044b\u0432\u0430\u0442\u044c, \u0447\u0442\u043e COM \u044d\u0442\u043e \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f Windows, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a Thrift \u2014 \u043a\u0440\u043e\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u0430.<\/p>\n<p>  \u0412\u043e\u0431\u0449\u0435\u043c \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0447\u0430\u0441\u0442\u044c \u043d\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0439-\u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0438 \u0438\u0437 Java \u0432 \u0421++, \u0432 \u043d\u0430\u0434\u0435\u0436\u0434\u0435 \u0447\u0442\u043e \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0421++ \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u0435\u0439, \u0438 \u0437\u0430 \u043e\u0434\u043d\u043e \u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c Thrift RPC, \u0432 \u043d\u0430\u0434\u0435\u0436\u0434\u0435 \u0447\u0442\u043e \u044d\u0442\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0447\u0435\u043c REST.<br \/>  \u041a\u0430\u043a \u0438 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043e, \u0431\u0435\u0437 \u0431\u0443\u0431\u043d\u043e\u0432 \u0438 \u0433\u0440\u0430\u0431\u043b\u0435\u0439 \u043d\u0435 \u043e\u0431\u043e\u0448\u043b\u043e\u0441\u044c!  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-179235","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/179235","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=179235"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/179235\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=179235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=179235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=179235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}