diff --git .classpath._hbase .classpath._hbase deleted file mode 100644 index 15fd1c5..0000000 --- .classpath._hbase +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git .gitignore .gitignore index e54804f..a0449e0 100644 --- .gitignore +++ .gitignore @@ -1,6 +1,6 @@ build build-eclipse -.classpath +.classpath* .externalToolBuilders .project .settings diff --git build-common.xml build-common.xml index 601ab23..24fac36 100644 --- build-common.xml +++ build-common.xml @@ -25,6 +25,8 @@ + + @@ -34,6 +36,8 @@ + + @@ -101,7 +105,7 @@ - + @@ -159,18 +163,18 @@ log="${ivyresolvelog}"/> - - - - - + + + + - + @@ -461,4 +465,15 @@ + + + + + + + + + + + diff --git build.xml build.xml index dc20725..41a4dbc 100644 --- build.xml +++ build.xml @@ -25,6 +25,8 @@ + + @@ -91,6 +93,28 @@ + + + + + + + + + + + + + + + + + + + + + + @@ -121,7 +145,7 @@ - @@ -165,16 +189,24 @@ + + + + + + + + - @@ -212,7 +244,7 @@ - + @@ -280,16 +312,16 @@ - + - + - + - + @@ -298,16 +330,16 @@ - + - + - + - + @@ -320,7 +352,7 @@ - + @@ -449,18 +481,21 @@ - + - + + - + + + diff --git eclipse-templates/.classpath eclipse-templates/.classpath index d06d6bd..23e33cc 100644 --- eclipse-templates/.classpath +++ eclipse-templates/.classpath @@ -16,10 +16,10 @@ - - - - + + + + @@ -33,25 +33,28 @@ - - + + + + - + - + - + + - + diff --git eclipse-templates/.classpath._hbase eclipse-templates/.classpath._hbase index b81c24a..f0e5a33 100644 --- eclipse-templates/.classpath._hbase +++ eclipse-templates/.classpath._hbase @@ -6,29 +6,29 @@ - + - - - - - - + + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + @@ -42,7 +42,8 @@ - + + @@ -53,7 +54,7 @@ - + - + diff --git ivy/libraries.properties ivy/libraries.properties index fdd54c8..ef24aff 100644 --- ivy/libraries.properties +++ ivy/libraries.properties @@ -35,11 +35,16 @@ commons-lang.version=2.4 commons-logging.version=1.0.4 commons-logging-api.version=1.0.4 commons-pool.version=1.5.4 +hbase.version=0.20.3 +hbase-test.version=0.20.3 jdo-api.version=3.0.0 jdom.version=1.1 jline.version=0.9.94 junit.version=3.8.1 ivy.version=2.1.0 log4j.version=1.2.15 +slf4j-api.version=1.6.1 +slf4j-log4j12.version=1.6.1 +thrift.version=0.5.0 +thrift-fb303.version=0.5.0 zookeeper.version=3.2.2 - diff --git lib/README lib/README index 72d90b7..1c2f0b1 100644 --- lib/README +++ lib/README @@ -1,8 +1,8 @@ Folowing is the list of external jars contained in this directory and the sources from where they were obtained: --------------------------------------------------------------------------------------------------------------- -* libfb303.jar - http://developers.facebook.com/thrift/ -* libthrift.jar - http://developers.facebook.com/thrift/ +* thrift-0.5.0.jar - http://thrift.apache.org/ +* thrift-fb303-0.5.0.jar - http://thrift.apache.org/ * jpox-core-1.2.2.jar - http://www.jpox.org/docs/download.html * derby.jar - http://db.apache.org/derby/derby_downloads.html * asm-3.1.jar - http://forge.objectweb.org/projects/asm/ diff --git lib/libfb303.LICENSE lib/libfb303.LICENSE deleted file mode 100644 index 6b5c3b1..0000000 --- lib/libfb303.LICENSE +++ /dev/null @@ -1,19 +0,0 @@ -Thrift Software License - -Copyright © 2006- Facebook, Inc. - -Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the -software and accompanying documentation covered by this license (the "Software") to use, reproduce, -display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, -and to permit third-parties to whom the Software is furnished to do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including the above license grant, -this restriction and the following disclaimer, must be included in all copies of the Software, in whole -or in part, and all derivative works of the Software, unless such copies or derivative works are solely -in the form of machine-executable object code generated by a source language processor. - -The software is provided "as is", without warranty of any kind, express or implied, including but not -limited to the warranties of merchantability, fitness for a particular purpose, title and non-infringement. -In no event shall the copyright holders or anyone distributing the software be liable for any damages or -other liability, whether in contract, tort, or otherwise, arising from, out of or in connection with the -software or the use or other dealings in the software. diff --git lib/libfb303.jar lib/libfb303.jar deleted file mode 100644 index 516b597..0000000 Binary files lib/libfb303.jar and /dev/null differ diff --git lib/libthrift.LICENSE lib/libthrift.LICENSE deleted file mode 100644 index 6b5c3b1..0000000 --- lib/libthrift.LICENSE +++ /dev/null @@ -1,19 +0,0 @@ -Thrift Software License - -Copyright © 2006- Facebook, Inc. - -Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the -software and accompanying documentation covered by this license (the "Software") to use, reproduce, -display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, -and to permit third-parties to whom the Software is furnished to do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including the above license grant, -this restriction and the following disclaimer, must be included in all copies of the Software, in whole -or in part, and all derivative works of the Software, unless such copies or derivative works are solely -in the form of machine-executable object code generated by a source language processor. - -The software is provided "as is", without warranty of any kind, express or implied, including but not -limited to the warranties of merchantability, fitness for a particular purpose, title and non-infringement. -In no event shall the copyright holders or anyone distributing the software be liable for any damages or -other liability, whether in contract, tort, or otherwise, arising from, out of or in connection with the -software or the use or other dealings in the software. diff --git lib/libthrift.jar lib/libthrift.jar deleted file mode 100644 index 7e7f90e..0000000 Binary files lib/libthrift.jar and /dev/null differ diff --git lib/thrift-0.5.0.jar lib/thrift-0.5.0.jar new file mode 100644 index 0000000..f38617b Binary files /dev/null and lib/thrift-0.5.0.jar differ diff --git lib/thrift-fb303-0.5.0.jar lib/thrift-fb303-0.5.0.jar new file mode 100644 index 0000000..bad90ce Binary files /dev/null and lib/thrift-fb303-0.5.0.jar differ diff --git lib/thrift-fb303.LICENSE lib/thrift-fb303.LICENSE new file mode 100644 index 0000000..4eacb64 --- /dev/null +++ lib/thrift-fb303.LICENSE @@ -0,0 +1,16 @@ +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. diff --git lib/thrift.LICENSE lib/thrift.LICENSE new file mode 100644 index 0000000..9d189ef --- /dev/null +++ lib/thrift.LICENSE @@ -0,0 +1,324 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +-------------------------------------------------- +SOFTWARE DISTRIBUTED WITH THRIFT: + +The Apache Thrift software includes a number of subcomponents with +separate copyright notices and license terms. Your use of the source +code for the these subcomponents is subject to the terms and +conditions of the following licenses. + +-------------------------------------------------- +Portions of the following files are licensed under the MIT License: + + lib/erl/src/Makefile.am + +Please see doc/otp-base-license.txt for the full terms of this license. + + +-------------------------------------------------- +The following files contain some portions of code contributed under +the Thrift Software License (see doc/old-thrift-license.txt), and relicensed +under the Apache 2.0 License: + + compiler/cpp/Makefile.am + compiler/cpp/src/generate/t_cocoa_generator.cc + compiler/cpp/src/generate/t_cpp_generator.cc + compiler/cpp/src/generate/t_csharp_generator.cc + compiler/cpp/src/generate/t_erl_generator.cc + compiler/cpp/src/generate/t_hs_generator.cc + compiler/cpp/src/generate/t_java_generator.cc + compiler/cpp/src/generate/t_ocaml_generator.cc + compiler/cpp/src/generate/t_perl_generator.cc + compiler/cpp/src/generate/t_php_generator.cc + compiler/cpp/src/generate/t_py_generator.cc + compiler/cpp/src/generate/t_rb_generator.cc + compiler/cpp/src/generate/t_st_generator.cc + compiler/cpp/src/generate/t_xsd_generator.cc + compiler/cpp/src/main.cc + compiler/cpp/src/parse/t_field.h + compiler/cpp/src/parse/t_program.h + compiler/cpp/src/platform.h + compiler/cpp/src/thriftl.ll + compiler/cpp/src/thrifty.yy + lib/csharp/src/Protocol/TBinaryProtocol.cs + lib/csharp/src/Protocol/TField.cs + lib/csharp/src/Protocol/TList.cs + lib/csharp/src/Protocol/TMap.cs + lib/csharp/src/Protocol/TMessage.cs + lib/csharp/src/Protocol/TMessageType.cs + lib/csharp/src/Protocol/TProtocol.cs + lib/csharp/src/Protocol/TProtocolException.cs + lib/csharp/src/Protocol/TProtocolFactory.cs + lib/csharp/src/Protocol/TProtocolUtil.cs + lib/csharp/src/Protocol/TSet.cs + lib/csharp/src/Protocol/TStruct.cs + lib/csharp/src/Protocol/TType.cs + lib/csharp/src/Server/TServer.cs + lib/csharp/src/Server/TSimpleServer.cs + lib/csharp/src/Server/TThreadPoolServer.cs + lib/csharp/src/TApplicationException.cs + lib/csharp/src/Thrift.csproj + lib/csharp/src/Thrift.sln + lib/csharp/src/TProcessor.cs + lib/csharp/src/Transport/TServerSocket.cs + lib/csharp/src/Transport/TServerTransport.cs + lib/csharp/src/Transport/TSocket.cs + lib/csharp/src/Transport/TStreamTransport.cs + lib/csharp/src/Transport/TTransport.cs + lib/csharp/src/Transport/TTransportException.cs + lib/csharp/src/Transport/TTransportFactory.cs + lib/csharp/ThriftMSBuildTask/Properties/AssemblyInfo.cs + lib/csharp/ThriftMSBuildTask/ThriftBuild.cs + lib/csharp/ThriftMSBuildTask/ThriftMSBuildTask.csproj + lib/rb/lib/thrift.rb + lib/st/README + lib/st/thrift.st + test/OptionalRequiredTest.cpp + test/OptionalRequiredTest.thrift + test/ThriftTest.thrift + +-------------------------------------------------- +For the aclocal/ax_boost_base.m4 and contrib/fb303/aclocal/ax_boost_base.m4 components: + +# Copyright (c) 2007 Thomas Porschberg +# +# Copying and distribution of this file, with or without +# modification, are permitted in any medium without royalty provided +# the copyright notice and this notice are preserved. + +-------------------------------------------------- +For the compiler/cpp/src/md5.[ch] components: + +/* + Copyright (C) 1999, 2000, 2002 Aladdin Enterprises. All rights reserved. + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + L. Peter Deutsch + ghost@aladdin.com + + */ + +--------------------------------------------------- +For the lib/rb/setup.rb: Copyright (c) 2000-2005 Minero Aoki, +lib/ocaml/OCamlMakefile and lib/ocaml/README-OCamlMakefile components: + Copyright (C) 1999 - 2007 Markus Mottl + +Licensed under the terms of the GNU Lesser General Public License 2.1 +(see doc/lgpl-2.1.txt for the full terms of this license) diff --git metastore/build.xml metastore/build.xml index 93cc291..7f01f91 100755 --- metastore/build.xml +++ metastore/build.xml @@ -22,36 +22,37 @@ - - Executing thrift (which needs to be in your path) to build java metastore APIs.... + + You must set the 'thrift.home' property! + Executing ${thrift.home}/bin/thrift on ${ant.project.name}/if/hive_metastore.thrift - + - + Building Grammar ${src.dir}/java/org/apache/hadoop/hive/metastore/parser/Filter.g .... - + - + @@ -47,5 +63,7 @@ + + diff --git metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java index e7c939c..932f4f4 100644 --- metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java +++ metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java @@ -416,7 +416,7 @@ public class HiveMetaStore extends ThriftHiveMetastore { } @Override - public int getStatus() { + public fb_status getStatus() { return fb_status.ALIVE; } diff --git metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java index 2ae8e99..3002851 100644 --- metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java +++ metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java @@ -450,7 +450,12 @@ public class ObjectStore implements RawStore, Configurable { .getComment())); } } - return new Type(mtype.getName(), mtype.getType1(), mtype.getType2(), fields); + Type ret = new Type(); + ret.setName(mtype.getName()); + ret.setType1(mtype.getType1()); + ret.setType2(mtype.getType2()); + ret.setFields(fields); + return ret; } public boolean createType(Type type) { diff --git odbc/Makefile odbc/Makefile index 816ffd4..2c55903 100644 --- odbc/Makefile +++ odbc/Makefile @@ -56,12 +56,13 @@ LINK = ln -sf BUILD_DIR = $(HIVE_ROOT)/build ODBC_BUILD_DIR = $(BUILD_DIR)/odbc OBJ_SERVICE_BUILD_DIR = $(BUILD_DIR)/service/objs -OBJ_FB303_BUILD_DIR = $(BUILD_DIR)/service/fb303/objs +OBJ_QL_BUILD_DIR = $(BUILD_DIR)/ql/objs OBJ_METASTORE_BUILD_DIR = $(BUILD_DIR)/metastore/objs OBJ_ODBC_BUILD_DIR = $(ODBC_BUILD_DIR)/objs LIB_ODBC_BUILD_DIR = $(ODBC_BUILD_DIR)/lib TEST_ODBC_BUILD_DIR = $(ODBC_BUILD_DIR)/test -THRIFT_INCLUDE_PATH = $(HIVE_ROOT)/service/include/thrift +THRIFT_INCLUDE_PATH=$(THRIFT_HOME)/include/thrift +FB303_INCLUDE_PATH=$(THRIFT_INCLUDE_PATH)/fb303 INSTALL_PATH = /usr/local INSTALL_LIB_PATH = $(INSTALL_PATH)/lib INSTALL_INCLUDE_PATH = $(INSTALL_PATH)/include @@ -79,30 +80,31 @@ AR_NAME = lib$(LIB_NAME).a AR_TARGET = $(LIB_ODBC_BUILD_DIR)/$(AR_NAME) AR_INSTALL_TARGET = $(INSTALL_LIB_PATH)/$(AR_NAME) -SERVICE_SRC_DIR = $(HIVE_ROOT)/service/src/gen-cpp +SERVICE_SRC_DIR = $(HIVE_ROOT)/service/src/gen/thrift/gen-cpp SERVICE_SOURCES = ThriftHive.cpp \ hive_service_constants.cpp \ hive_service_types.cpp SERVICE_OBJS = $(addprefix $(OBJ_SERVICE_BUILD_DIR)/,$(patsubst %,%.o,$(basename $(SERVICE_SOURCES)))) -FB303_SRC_DIR = $(THRIFT_INCLUDE_PATH)/fb303 -FB303_SOURCES = FacebookService.cpp \ - fb303_constants.cpp \ - fb303_types.cpp -FB303_OBJS = $(addprefix $(OBJ_FB303_BUILD_DIR)/,$(patsubst %,%.o,$(basename $(FB303_SOURCES)))) +QL_SRC_DIR = $(HIVE_ROOT)/ql/src/gen/thrift/gen-cpp +QL_SOURCES = queryplan_types.cpp queryplan_constants.cpp +QL_OBJS = $(addprefix $(OBJ_QL_BUILD_DIR)/,$(patsubst %,%.o,$(basename $(QL_SOURCES)))) -METASTORE_SRC_DIR = $(HIVE_ROOT)/metastore/src/gen-cpp + +METASTORE_SRC_DIR = $(HIVE_ROOT)/metastore/src/gen/thrift/gen-cpp METASTORE_SOURCES = ThriftHiveMetastore.cpp \ hive_metastore_constants.cpp \ hive_metastore_types.cpp METASTORE_OBJS = $(addprefix $(OBJ_METASTORE_BUILD_DIR)/,$(patsubst %,%.o,$(basename $(METASTORE_SOURCES)))) ODBC_SRC_DIR = $(BASE_DIR)/src/cpp + ODBC_SOURCES = hiveclient.cpp \ HiveResultSet.cpp \ HiveColumnDesc.cpp \ HiveRowSet.cpp \ hiveclienthelper.cpp + ODBC_OBJS = $(addprefix $(OBJ_ODBC_BUILD_DIR)/,$(patsubst %,%.o,$(basename $(ODBC_SOURCES)))) ODBC_TEST_SRC_DIR = $(BASE_DIR)/src/test @@ -111,9 +113,10 @@ TEST_FLAGS = -DTEST_DATA_DIR=$(ODBC_TEST_DATA_DIR) HIVE_CLIENT_TEST = $(TEST_ODBC_BUILD_DIR)/HiveClientTestC INCLUDE_PATHS = -I$(THRIFT_INCLUDE_PATH) \ + -I$(FB303_INCLUDE_PATH) \ -I$(BOOST_INCLUDE_PATH) \ - -I$(FB303_SRC_DIR) \ -I$(SERVICE_SRC_DIR) \ + -I$(QL_SRC_DIR) \ -I$(METASTORE_SRC_DIR) \ -I$(ODBC_SRC_DIR) @@ -127,20 +130,25 @@ LIB_THRIFT_DIR = $(THRIFT_HOME)/lib LIB_THRIFT_ADD = -L$(LIB_THRIFT_DIR) -lthrift LIB_THRIFT_AR = $(LIB_THRIFT_DIR)/libthrift.a +LIB_FB303_DIR = $(THRIFT_HOME)/lib +LIB_FB303_ADD = -L$(LIB_FB303_DIR) -lfb303 +LIB_FB303_AR = $(LIB_FB303_DIR)/libfb303.a + all:: $(AR_TARGET) $(SO_TARGET) $(HIVE_CLIENT_TEST) -$(AR_TARGET): $(FB303_OBJS) $(METASTORE_OBJS) $(SERVICE_OBJS) $(ODBC_OBJS) +$(AR_TARGET): $(METASTORE_OBJS) $(SERVICE_OBJS) $(QL_OBJS) $(ODBC_OBJS) if test -z '$(THRIFT_HOME)'; then echo 'THRIFT_HOME directory?'; exit 1; else exit 0; fi mkdir -p $(LIB_ODBC_BUILD_DIR) $(AR) $(ARXFLAGS) $(LIB_THRIFT_AR) #Extract thrift archive + $(AR) $(ARXFLAGS) $(LIB_FB303_AR) #Extract fb303 archive $(AR) $(ARFLAGS) $@ $+ *.o #Include all object files into new archive rm *.o #Remove extracted archive object files -$(SO_TARGET): $(FB303_OBJS) $(METASTORE_OBJS) $(SERVICE_OBJS) $(ODBC_OBJS) +$(SO_TARGET): $(METASTORE_OBJS) $(SERVICE_OBJS) $(QL_OBJS) $(ODBC_OBJS) if test -z '$(THRIFT_HOME)'; then echo 'THRIFT_HOME directory?'; exit 1; else exit 0; fi mkdir -p $(LIB_ODBC_BUILD_DIR) - $(LD) $(ARCH_FLAGS) $(LDFLAGS) $+ $(LIB_THRIFT_ADD) -o $@ \ + $(LD) $(ARCH_FLAGS) $(LDFLAGS) $+ $(LIB_THRIFT_ADD) $(LIB_FB303_ADD) -o $@ \ && $(LINK) $(SO_NAME) $(SO_LINK_TARGET) @@ -148,8 +156,8 @@ $(OBJ_SERVICE_BUILD_DIR)/%.o: $(SERVICE_SRC_DIR)/%.cpp mkdir -p $(OBJ_SERVICE_BUILD_DIR) $(CXX) $(CXXFLAGS) $(ARCH_FLAGS) $(INCLUDE_PATHS) -c $< -o $@ -$(OBJ_FB303_BUILD_DIR)/%.o: $(FB303_SRC_DIR)/%.cpp - mkdir -p $(OBJ_FB303_BUILD_DIR) +$(OBJ_QL_BUILD_DIR)/%.o: $(QL_SRC_DIR)/%.cpp + mkdir -p $(OBJ_QL_BUILD_DIR) $(CXX) $(CXXFLAGS) $(ARCH_FLAGS) $(INCLUDE_PATHS) -c $< -o $@ $(OBJ_METASTORE_BUILD_DIR)/%.o: $(METASTORE_SRC_DIR)/%.cpp @@ -162,7 +170,7 @@ $(OBJ_ODBC_BUILD_DIR)/%.o: $(ODBC_SRC_DIR)/%.cpp $(HIVE_CLIENT_TEST): $(SO_TARGET) $(ODBC_TEST_SRC_DIR)/hiveclienttest.c mkdir -p $(TEST_ODBC_BUILD_DIR) - $(CC) $(CFLAGS) $(ARCH_FLAGS) $(TEST_FLAGS) $(INCLUDE_PATHS) $(ODBC_TEST_SRC_DIR)/hiveclienttest.c -L$(LIB_ODBC_BUILD_DIR) -L$(LIB_THRIFT_DIR) -l$(LIB_NAME) -lthrift -o $@ + $(CC) $(CFLAGS) $(ARCH_FLAGS) $(TEST_FLAGS) $(INCLUDE_PATHS) $(ODBC_TEST_SRC_DIR)/hiveclienttest.c -L$(LIB_ODBC_BUILD_DIR) -L$(LIB_THRIFT_DIR) -l$(LIB_NAME) -lthrift $(LIB_FB303_ADD) -o $@ install: $(AR_TARGET) $(SO_TARGET) @@ -179,7 +187,7 @@ uninstall: rm -f $(HEADER_TARGETS) clean: - rm -rf $(ODBC_BUILD_DIR) $(OBJ_SERVICE_BUILD_DIR) $(OBJ_FB303_BUILD_DIR) $(OBJ_METASTORE_BUILD_DIR) + rm -rf $(ODBC_BUILD_DIR) $(OBJ_SERVICE_BUILD_DIR) $(OBJ_QL_BUILD_DIR) $(OBJ_METASTORE_BUILD_DIR) test: $(AR_TARGET) $(SO_TARGET) $(HIVE_CLIENT_TEST) - LD_LIBRARY_PATH=$(LIB_ODBC_BUILD_DIR):$(LIB_THRIFT_DIR):$(LD_LIBRARY_PATH) $(HIVE_CLIENT_TEST) + LD_LIBRARY_PATH=$(LIB_ODBC_BUILD_DIR):$(LIB_THRIFT_DIR):$(LIB_FB303_DIR):$(LD_LIBRARY_PATH) $(HIVE_CLIENT_TEST) diff --git odbc/build.xml odbc/build.xml index 64cf988..db9f4af 100644 --- odbc/build.xml +++ odbc/build.xml @@ -46,18 +46,6 @@ - - - - - - - - - - - - diff --git odbc/src/cpp/HiveRowSet.cpp odbc/src/cpp/HiveRowSet.cpp index b4dc2c0..3de6124 100644 --- odbc/src/cpp/HiveRowSet.cpp +++ odbc/src/cpp/HiveRowSet.cpp @@ -17,6 +17,7 @@ */ #include +#include #include "HiveRowSet.h" #include "hiveclienthelper.h" diff --git odbc/src/cpp/hiveclienthelper.cpp odbc/src/cpp/hiveclienthelper.cpp index e2d48f3..b0f3aae 100644 --- odbc/src/cpp/hiveclienthelper.cpp +++ odbc/src/cpp/hiveclienthelper.cpp @@ -18,6 +18,7 @@ #include #include +#include #include "hiveclienthelper.h" #include "thriftserverconstants.h" diff --git ql/build.xml ql/build.xml index bcb2d05..3eea73c 100644 --- ql/build.xml +++ ql/build.xml @@ -28,7 +28,6 @@ - @@ -55,10 +54,11 @@ - - Executing thrift (which needs to be in your path) on if/queryplan.thrift + + You must set the 'thrift.home' property! + Executing ${thrift.home}/bin/thrift on ${ant.project.name}/if/queryplan.thrift - + @@ -132,27 +132,27 @@ - + Building Grammar ${src.dir}/org/apache/hadoop/hive/ql/parse/Hive.g .... - + - + - + diff --git ql/if/queryplan.thrift ql/if/queryplan.thrift index 9e080d4..b1346f6 100644 --- ql/if/queryplan.thrift +++ ql/if/queryplan.thrift @@ -1,5 +1,5 @@ namespace java org.apache.hadoop.hive.ql.plan.api -namespace cpp Hive +namespace cpp Apache.Hadoop.Hive enum AdjacencyType { CONJUNCTIVE, DISJUNCTIVE } struct Adjacency { @@ -16,7 +16,27 @@ struct Graph { } #Represents a operator along with its counters -enum OperatorType { JOIN, MAPJOIN, EXTRACT, FILTER, FORWARD, GROUPBY, LIMIT, SCRIPT, SELECT, TABLESCAN, FILESINK, REDUCESINK, UNION, UDTF, LATERALVIEWJOIN, LATERALVIEWFORWARD, HASHTABLESINK, HASHTABLEDUMMY } +enum OperatorType { + JOIN, + MAPJOIN, + EXTRACT, + FILTER, + FORWARD, + GROUPBY, + LIMIT, + SCRIPT, + SELECT, + TABLESCAN, + FILESINK, + REDUCESINK, + UNION, + UDTF, + LATERALVIEWJOIN, + LATERALVIEWFORWARD, + HASHTABLESINK, + HASHTABLEDUMMY, +} + struct Operator { 1: string operatorId, 2: OperatorType operatorType, @@ -41,7 +61,18 @@ struct Task { } # Represents a Stage - unfortunately, it is represented as Task in ql/exec -enum StageType { CONDITIONAL, COPY, DDL, MAPRED, EXPLAIN, FETCH, FUNC, MAPREDLOCAL, MOVE, STATS } +enum StageType { + CONDITIONAL, + COPY, + DDL, + MAPRED, + EXPLAIN, + FETCH, + FUNC, + MAPREDLOCAL, + MOVE, + STATS, +} struct Stage { 1: string stageId, diff --git ql/ivy.xml ql/ivy.xml index e72a450..26041b5 100644 --- ql/ivy.xml +++ ql/ivy.xml @@ -3,6 +3,8 @@ - + + + diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/AbstractMapJoinOperator.java ql/src/java/org/apache/hadoop/hive/ql/exec/AbstractMapJoinOperator.java index 5ccb909..52d14ae 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/AbstractMapJoinOperator.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/AbstractMapJoinOperator.java @@ -132,7 +132,7 @@ public abstract class AbstractMapJoinOperator extends Co } @Override - public int getType() { + public OperatorType getType() { return OperatorType.MAPJOIN; } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/CollectOperator.java ql/src/java/org/apache/hadoop/hive/ql/exec/CollectOperator.java index 7daea2d..aa45b7d 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/CollectOperator.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/CollectOperator.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hive.ql.metadata.HiveException; +import org.apache.hadoop.hive.ql.plan.api.OperatorType; import org.apache.hadoop.hive.ql.plan.CollectDesc; import org.apache.hadoop.hive.serde2.objectinspector.InspectableObject; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; @@ -78,7 +79,7 @@ public class CollectOperator extends Operator implements } @Override - public int getType() { - return -1; + public OperatorType getType() { + return null; } } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/ConditionalTask.java ql/src/java/org/apache/hadoop/hive/ql/exec/ConditionalTask.java index bf7b7a5..90589ed 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/ConditionalTask.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/ConditionalTask.java @@ -172,7 +172,7 @@ public class ConditionalTask extends Task implements Serializab } @Override - public int getType() { + public StageType getType() { return StageType.CONDITIONAL; } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/CopyTask.java ql/src/java/org/apache/hadoop/hive/ql/exec/CopyTask.java index 46b8bf4..30ea670 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/CopyTask.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/CopyTask.java @@ -90,7 +90,7 @@ public class CopyTask extends Task implements Serializable { } @Override - public int getType() { + public StageType getType() { return StageType.COPY; } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java index 6c2ab27..0783f5b 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java @@ -2689,7 +2689,7 @@ public class DDLTask extends Task implements Serializable { } @Override - public int getType() { + public StageType getType() { return StageType.DDL; } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/ExecDriver.java ql/src/java/org/apache/hadoop/hive/ql/exec/ExecDriver.java index 49e708c..622cee8 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/ExecDriver.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/ExecDriver.java @@ -1269,7 +1269,7 @@ public class ExecDriver extends Task implements Serializable { } @Override - public int getType() { + public StageType getType() { return StageType.MAPRED; } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/ExplainTask.java ql/src/java/org/apache/hadoop/hive/ql/exec/ExplainTask.java index a572bcb..9e0d48e 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/ExplainTask.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/ExplainTask.java @@ -407,7 +407,7 @@ public class ExplainTask extends Task implements Serializable { } @Override - public int getType() { + public StageType getType() { return StageType.EXPLAIN; } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/ExtractOperator.java ql/src/java/org/apache/hadoop/hive/ql/exec/ExtractOperator.java index 7bf8886..5257463 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/ExtractOperator.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/ExtractOperator.java @@ -46,7 +46,7 @@ public class ExtractOperator extends Operator implements } @Override - public int getType() { + public OperatorType getType() { return OperatorType.EXTRACT; } } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/FetchTask.java ql/src/java/org/apache/hadoop/hive/ql/exec/FetchTask.java index de2c42d..5987a3c 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/FetchTask.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/FetchTask.java @@ -151,7 +151,7 @@ public class FetchTask extends Task implements Serializable { } @Override - public int getType() { + public StageType getType() { return StageType.FETCH; } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/FileSinkOperator.java ql/src/java/org/apache/hadoop/hive/ql/exec/FileSinkOperator.java index d510f95..ba1a9b1 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/FileSinkOperator.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/FileSinkOperator.java @@ -759,7 +759,7 @@ public class FileSinkOperator extends TerminalOperator implements } @Override - public int getType() { + public OperatorType getType() { return OperatorType.FILESINK; } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/FilterOperator.java ql/src/java/org/apache/hadoop/hive/ql/exec/FilterOperator.java index 554bf25..44e0e31 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/FilterOperator.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/FilterOperator.java @@ -108,7 +108,7 @@ public class FilterOperator extends Operator implements } @Override - public int getType() { + public OperatorType getType() { return OperatorType.FILTER; } } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/ForwardOperator.java ql/src/java/org/apache/hadoop/hive/ql/exec/ForwardOperator.java index 2a35c96..4c15f69 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/ForwardOperator.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/ForwardOperator.java @@ -37,7 +37,7 @@ public class ForwardOperator extends Operator implements } @Override - public int getType() { + public OperatorType getType() { return OperatorType.FORWARD; } } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionTask.java ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionTask.java index 1e6941e..225c5c7 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionTask.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionTask.java @@ -120,7 +120,7 @@ public class FunctionTask extends Task { } @Override - public int getType() { + public StageType getType() { return StageType.FUNC; } @@ -133,4 +133,4 @@ public class FunctionTask extends Task { protected void localizeMRTmpFilesImpl(Context ctx) { throw new RuntimeException ("Unexpected call"); } -} \ No newline at end of file +} diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/GroupByOperator.java ql/src/java/org/apache/hadoop/hive/ql/exec/GroupByOperator.java index 8423178..e5de8d1 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/GroupByOperator.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/GroupByOperator.java @@ -1039,7 +1039,7 @@ public class GroupByOperator extends Operator implements } @Override - public int getType() { + public OperatorType getType() { return OperatorType.GROUPBY; } } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/HashTableDummyOperator.java ql/src/java/org/apache/hadoop/hive/ql/exec/HashTableDummyOperator.java index 87fc61c..57ae5fc 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/HashTableDummyOperator.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/HashTableDummyOperator.java @@ -58,7 +58,7 @@ public class HashTableDummyOperator extends Operator impleme } @Override - public int getType() { + public OperatorType getType() { return OperatorType.HASHTABLEDUMMY; } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/HashTableSinkOperator.java ql/src/java/org/apache/hadoop/hive/ql/exec/HashTableSinkOperator.java index 4cf055f..43749d4 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/HashTableSinkOperator.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/HashTableSinkOperator.java @@ -442,10 +442,7 @@ public class HashTableSinkOperator extends TerminalOperator i } @Override - public int getType() { + public OperatorType getType() { return OperatorType.HASHTABLESINK; } - - - } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/JoinOperator.java ql/src/java/org/apache/hadoop/hive/ql/exec/JoinOperator.java index e16df36..b9714cc 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/JoinOperator.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/JoinOperator.java @@ -133,7 +133,7 @@ public class JoinOperator extends CommonJoinOperator implements } @Override - public int getType() { + public OperatorType getType() { return OperatorType.JOIN; } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/LateralViewForwardOperator.java ql/src/java/org/apache/hadoop/hive/ql/exec/LateralViewForwardOperator.java index c070aca..5bfb805 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/LateralViewForwardOperator.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/LateralViewForwardOperator.java @@ -43,7 +43,7 @@ public class LateralViewForwardOperator extends Operator } @Override - public int getType() { + public OperatorType getType() { return OperatorType.LATERALVIEWFORWARD; } } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/LateralViewJoinOperator.java ql/src/java/org/apache/hadoop/hive/ql/exec/LateralViewJoinOperator.java index 5eb9098..f5c42ef 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/LateralViewJoinOperator.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/LateralViewJoinOperator.java @@ -143,7 +143,7 @@ public class LateralViewJoinOperator extends Operator { } @Override - public int getType() { + public OperatorType getType() { return OperatorType.LATERALVIEWJOIN; } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/LimitOperator.java ql/src/java/org/apache/hadoop/hive/ql/exec/LimitOperator.java index da5dbb9..b1958a5 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/LimitOperator.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/LimitOperator.java @@ -57,7 +57,7 @@ public class LimitOperator extends Operator implements Serializable { } @Override - public int getType() { + public OperatorType getType() { return OperatorType.LIMIT; } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/MapJoinOperator.java ql/src/java/org/apache/hadoop/hive/ql/exec/MapJoinOperator.java index c9f99ac..dd7c723 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/MapJoinOperator.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/MapJoinOperator.java @@ -297,7 +297,7 @@ public class MapJoinOperator extends AbstractMapJoinOperator implem } @Override - public int getType() { + public OperatorType getType() { return OperatorType.MAPJOIN; } } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/MapOperator.java ql/src/java/org/apache/hadoop/hive/ql/exec/MapOperator.java index 887ad30..3b7d5c1 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/MapOperator.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/MapOperator.java @@ -34,6 +34,7 @@ import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.hive.ql.io.IOContext; import org.apache.hadoop.hive.ql.metadata.HiveException; import org.apache.hadoop.hive.ql.metadata.VirtualColumn; +import org.apache.hadoop.hive.ql.plan.api.OperatorType; import org.apache.hadoop.hive.ql.plan.MapredWork; import org.apache.hadoop.hive.ql.plan.PartitionDesc; import org.apache.hadoop.hive.ql.plan.TableScanDesc; @@ -519,8 +520,8 @@ public class MapOperator extends Operator implements Serializable { } @Override - public int getType() { - return -1; + public OperatorType getType() { + return null; } } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/MapRedTask.java ql/src/java/org/apache/hadoop/hive/ql/exec/MapRedTask.java index 09238a8..a53b6d5 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/MapRedTask.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/MapRedTask.java @@ -411,7 +411,4 @@ public class MapRedTask extends ExecDriver implements Serializable { return null; } - - - } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/MapredLocalTask.java ql/src/java/org/apache/hadoop/hive/ql/exec/MapredLocalTask.java index 2bb7ec5..ff5f010 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/MapredLocalTask.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/MapredLocalTask.java @@ -451,8 +451,8 @@ public class MapredLocalTask extends Task implements Serializab } @Override - public int getType() { - // assert false; + public StageType getType() { + //assert false; return StageType.MAPREDLOCAL; } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java index 7fbc586..d19b1db 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/MoveTask.java @@ -283,7 +283,7 @@ public class MoveTask extends Task implements Serializable { } @Override - public int getType() { + public StageType getType() { return StageType.MOVE; } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/Operator.java ql/src/java/org/apache/hadoop/hive/ql/exec/Operator.java index 6c6ea89..dc3ea1e 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/Operator.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/Operator.java @@ -32,6 +32,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hive.ql.lib.Node; import org.apache.hadoop.hive.ql.metadata.HiveException; import org.apache.hadoop.hive.ql.parse.SemanticException; +import org.apache.hadoop.hive.ql.plan.api.OperatorType; import org.apache.hadoop.hive.ql.plan.Explain; import org.apache.hadoop.hive.ql.plan.ExprNodeDesc; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; @@ -1204,7 +1205,7 @@ public abstract class Operator implements Serializable, * * @return OperatorType.* */ - abstract public int getType(); + abstract public OperatorType getType(); public void setGroupKeyObject(Object keyObject) { this.groupKeyObject = keyObject; diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/ReduceSinkOperator.java ql/src/java/org/apache/hadoop/hive/ql/exec/ReduceSinkOperator.java index 592f4f7..2685820 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/ReduceSinkOperator.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/ReduceSinkOperator.java @@ -314,7 +314,7 @@ public class ReduceSinkOperator extends TerminalOperator } @Override - public int getType() { + public OperatorType getType() { return OperatorType.REDUCESINK; } } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/SMBMapJoinOperator.java ql/src/java/org/apache/hadoop/hive/ql/exec/SMBMapJoinOperator.java index 001d1f0..9c52deb 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/SMBMapJoinOperator.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/SMBMapJoinOperator.java @@ -588,7 +588,7 @@ public class SMBMapJoinOperator extends AbstractMapJoinOperator imp } @Override - public int getType() { + public OperatorType getType() { return OperatorType.MAPJOIN; } } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/ScriptOperator.java ql/src/java/org/apache/hadoop/hive/ql/exec/ScriptOperator.java index 4f8b4bd..aec5fca 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/ScriptOperator.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/ScriptOperator.java @@ -662,7 +662,7 @@ public class ScriptOperator extends Operator implements } @Override - public int getType() { + public OperatorType getType() { return OperatorType.SCRIPT; } } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/SelectOperator.java ql/src/java/org/apache/hadoop/hive/ql/exec/SelectOperator.java index d644a33..3582e78 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/SelectOperator.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/SelectOperator.java @@ -93,7 +93,7 @@ public class SelectOperator extends Operator implements } @Override - public int getType() { + public OperatorType getType() { return OperatorType.SELECT; } } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/StatsTask.java ql/src/java/org/apache/hadoop/hive/ql/exec/StatsTask.java index 47adbed..b818dc5 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/StatsTask.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/StatsTask.java @@ -211,7 +211,7 @@ public class StatsTask extends Task implements Serializable { } @Override - public int getType() { + public StageType getType() { return StageType.STATS; } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/TableScanOperator.java ql/src/java/org/apache/hadoop/hive/ql/exec/TableScanOperator.java index 96e63b8..6ba7a9d 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/TableScanOperator.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/TableScanOperator.java @@ -181,7 +181,7 @@ public class TableScanOperator extends Operator implements } @Override - public int getType() { + public OperatorType getType() { return OperatorType.TABLESCAN; } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/Task.java ql/src/java/org/apache/hadoop/hive/ql/exec/Task.java index 034f0a6..d91047d 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/Task.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/Task.java @@ -34,6 +34,7 @@ import org.apache.hadoop.hive.ql.QueryPlan; import org.apache.hadoop.hive.ql.lib.Node; import org.apache.hadoop.hive.ql.metadata.Hive; import org.apache.hadoop.hive.ql.metadata.HiveException; +import org.apache.hadoop.hive.ql.plan.api.StageType; import org.apache.hadoop.hive.ql.session.SessionState; import org.apache.hadoop.hive.ql.session.SessionState.LogHelper; import org.apache.hadoop.util.StringUtils; @@ -352,14 +353,11 @@ public abstract class Task implements Serializable, Node } /** - * Should be overridden to return the type of the specific task among the types in TaskType. + * Should be overridden to return the type of the specific task among the types in StageType. * - * @return TaskTypeType.* or -1 if not overridden + * @return StageType.* or null if not overridden */ - public int getType() { - assert false; - return -1; - } + public abstract StageType getType(); /** * If this task uses any map-reduce intermediate data (either for reading or for writing), diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/UDTFOperator.java ql/src/java/org/apache/hadoop/hive/ql/exec/UDTFOperator.java index 682f38a..919656c 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/UDTFOperator.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/UDTFOperator.java @@ -118,7 +118,7 @@ public class UDTFOperator extends Operator implements Serializable { } @Override - public int getType() { + public OperatorType getType() { return OperatorType.UDTF; } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/UnionOperator.java ql/src/java/org/apache/hadoop/hive/ql/exec/UnionOperator.java index 2c42ed7..2462517 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/UnionOperator.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/UnionOperator.java @@ -141,7 +141,7 @@ public class UnionOperator extends Operator implements Serializable { } @Override - public int getType() { + public OperatorType getType() { return OperatorType.UNION; } } diff --git ql/src/java/org/apache/hadoop/hive/ql/index/compact/CompactIndexHandler.java ql/src/java/org/apache/hadoop/hive/ql/index/compact/CompactIndexHandler.java index 0d60507..1f01446 100644 --- ql/src/java/org/apache/hadoop/hive/ql/index/compact/CompactIndexHandler.java +++ ql/src/java/org/apache/hadoop/hive/ql/index/compact/CompactIndexHandler.java @@ -57,7 +57,7 @@ public class CompactIndexHandler extends AbstractIndexHandler { Table indexTable) throws HiveException { StorageDescriptor storageDesc = index.getSd(); if (this.usesIndexTable() && indexTable != null) { - StorageDescriptor indexTableSd = storageDesc.clone(); + StorageDescriptor indexTableSd = storageDesc.deepCopy(); List indexTblCols = indexTableSd.getCols(); FieldSchema bucketFileName = new FieldSchema("_bucketname", "string", ""); indexTblCols.add(bucketFileName); diff --git ql/src/java/org/apache/hadoop/hive/ql/index/compact/IndexMetadataChangeTask.java ql/src/java/org/apache/hadoop/hive/ql/index/compact/IndexMetadataChangeTask.java index 734bd72..eac168f 100644 --- ql/src/java/org/apache/hadoop/hive/ql/index/compact/IndexMetadataChangeTask.java +++ ql/src/java/org/apache/hadoop/hive/ql/index/compact/IndexMetadataChangeTask.java @@ -96,7 +96,7 @@ public class IndexMetadataChangeTask extends Task{ } @Override - public int getType() { + public StageType getType() { return StageType.DDL; } diff --git ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java index 5d33550..9780fea 100644 --- ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java +++ ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java @@ -514,7 +514,7 @@ public class Hive { } } - org.apache.hadoop.hive.metastore.api.StorageDescriptor storageDescriptor = baseTbl.getSd().clone(); + org.apache.hadoop.hive.metastore.api.StorageDescriptor storageDescriptor = baseTbl.getSd().deepCopy(); SerDeInfo serdeInfo = storageDescriptor.getSerdeInfo(); if(serde != null) { serdeInfo.setSerializationLib(serde); diff --git ql/src/java/org/apache/hadoop/hive/ql/metadata/Table.java ql/src/java/org/apache/hadoop/hive/ql/metadata/Table.java index 33991f3..5a63196 100644 --- ql/src/java/org/apache/hadoop/hive/ql/metadata/Table.java +++ ql/src/java/org/apache/hadoop/hive/ql/metadata/Table.java @@ -730,7 +730,7 @@ public class Table implements Serializable { } public Table copy() throws HiveException { - return new Table(tTable.clone()); + return new Table(tTable.deepCopy()); } public void setCreateTime(int createTime) { diff --git serde/build.xml serde/build.xml index b1a9d57..51ac8dd 100644 --- serde/build.xml +++ serde/build.xml @@ -30,7 +30,6 @@ to call at top-level: ant deploy-contrib compile-core-test - - + @@ -56,18 +55,19 @@ to call at top-level: ant deploy-contrib compile-core-test - - Executing thrift (which needs to be in your path) to build java serde Constants... + + You must set the 'thrift.home' property! + Executing ${thrift.home}/bin/thrift to build java serde Constants... - + - Executing thrift (which needs to be in your path) to build complex.thrift test classes... + Executing ${thrift.home}/bin/thrift to build complex.thrift test classes... - + - Executing thrift (which needs to be in your path) to build testthrift.thrift classes... + Executing ${thrift.home}/bin/thrift to build testthrift.thrift classes... - + diff --git serde/ivy.xml serde/ivy.xml index da69342..2b38da4 100644 --- serde/ivy.xml +++ serde/ivy.xml @@ -1,8 +1,26 @@ + - + + + diff --git serde/src/java/org/apache/hadoop/hive/serde2/thrift/TBinarySortableProtocol.java serde/src/java/org/apache/hadoop/hive/serde2/thrift/TBinarySortableProtocol.java index 961c24f..2a4d0b7 100644 --- serde/src/java/org/apache/hadoop/hive/serde2/thrift/TBinarySortableProtocol.java +++ serde/src/java/org/apache/hadoop/hive/serde2/thrift/TBinarySortableProtocol.java @@ -19,6 +19,7 @@ package org.apache.hadoop.hive.serde2.thrift; import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; import java.util.Arrays; import java.util.Properties; @@ -345,12 +346,39 @@ public class TBinarySortableProtocol extends TProtocol implements } @Override + public void writeBinary(ByteBuffer bin) throws TException { + if (bin == null) { + writeRawBytes(nullByte, 0, 1); + return; + } + + int length = bin.limit() - bin.position() - bin.arrayOffset(); + if (bin.hasArray()) { + writeBinary(bin.array(), bin.arrayOffset() + bin.position(), + length); + } else { + byte []copy = new byte[length]; + bin.get(copy); + writeBinary(copy); + } + } + public void writeBinary(byte[] bin) throws TException { if (bin == null) { writeRawBytes(nullByte, 0, 1); } else { - writeI32(bin.length); - writeRawBytes(bin, 0, bin.length); + writeBinary(bin, 0, bin.length); + } + } + + + public void writeBinary(byte[] bin, int offset, int length) + throws TException { + if (bin == null) { + writeRawBytes(nullByte, 0, 1); + } else { + writeI32(length); + writeRawBytes(bin, offset, length); } } @@ -612,14 +640,14 @@ public class TBinarySortableProtocol extends TProtocol implements } @Override - public byte[] readBinary() throws TException { + public ByteBuffer readBinary() throws TException { int size = readI32(); if (lastPrimitiveWasNull) { return null; } byte[] buf = new byte[size]; readRawAll(buf, 0, size); - return buf; + return ByteBuffer.wrap(buf); } boolean lastPrimitiveWasNull; diff --git serde/src/java/org/apache/hadoop/hive/serde2/thrift/TCTLSeparatedProtocol.java serde/src/java/org/apache/hadoop/hive/serde2/thrift/TCTLSeparatedProtocol.java index e781a06..0e26f23 100644 --- serde/src/java/org/apache/hadoop/hive/serde2/thrift/TCTLSeparatedProtocol.java +++ serde/src/java/org/apache/hadoop/hive/serde2/thrift/TCTLSeparatedProtocol.java @@ -20,6 +20,7 @@ package org.apache.hadoop.hive.serde2.thrift; import java.io.EOFException; import java.nio.charset.CharacterCodingException; +import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.NoSuchElementException; import java.util.Properties; @@ -239,6 +240,10 @@ public class TCTLSeparatedProtocol extends TProtocol implements } tokenizer = new StringTokenizer(row, separator, true); } catch (TTransportException e) { + if(e.getType() == TTransportException.END_OF_FILE){ + tokenizer = new StringTokenizer("", separator, true); + return false; + } e.printStackTrace(); tokenizer = null; return false; @@ -605,7 +610,7 @@ public class TCTLSeparatedProtocol extends TProtocol implements } @Override - public void writeBinary(byte[] bin) throws TException { + public void writeBinary(ByteBuffer bin) throws TException { throw new TException( "Ctl separated protocol cannot support writing Binary data!"); } @@ -838,7 +843,7 @@ public class TCTLSeparatedProtocol extends TProtocol implements } @Override - public byte[] readBinary() throws TException { + public ByteBuffer readBinary() throws TException { throw new TException("Not implemented for control separated data"); } } diff --git serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestObjectInspectorUtils.java serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestObjectInspectorUtils.java index 4bdcf88..a18f4a7 100644 --- serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestObjectInspectorUtils.java +++ serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestObjectInspectorUtils.java @@ -56,15 +56,15 @@ public class TestObjectInspectorUtils extends TestCase { // real object Complex cc = new Complex(); - cc.aint = 1; - cc.aString = "test"; + cc.setAint(1); + cc.setAString("test"); List c2 = Arrays.asList(new Integer[] {1, 2, 3}); - cc.lint = c2; + cc.setLint(c2); List c3 = Arrays.asList(new String[] {"one", "two"}); - cc.lString = c3; + cc.setLString(c3); List c4 = new ArrayList(); - cc.lintString = c4; - cc.mStringString = null; + cc.setLintString(c4); + cc.setMStringString(null); // standard object Object c = ObjectInspectorUtils.copyToStandardObject(cc, oi1); diff --git serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestThriftObjectInspectors.java serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestThriftObjectInspectors.java index 99b0e90..5f692fb 100644 --- serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestThriftObjectInspectors.java +++ serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestThriftObjectInspectors.java @@ -59,15 +59,15 @@ public class TestThriftObjectInspectors extends TestCase { // real object Complex c = new Complex(); - c.aint = 1; - c.aString = "test"; + c.setAint(1); + c.setAString("test"); List c2 = Arrays.asList(new Integer[] {1, 2, 3}); - c.lint = c2; + c.setLint(c2); List c3 = Arrays.asList(new String[] {"one", "two"}); - c.lString = c3; + c.setLString(c3); List c4 = new ArrayList(); - c.lintString = c4; - c.mStringString = null; + c.setLintString(c4); + c.setMStringString(null); assertEquals(1, soi.getStructFieldData(c, fields.get(0))); assertEquals("test", soi.getStructFieldData(c, fields.get(1))); diff --git service/build.xml service/build.xml index eee25a2..3c54625 100644 --- service/build.xml +++ service/build.xml @@ -26,7 +26,6 @@ - @@ -41,17 +40,18 @@ - - Executing thrift (which needs to be in your path) on if/hive_service.thrift + + You must set the 'thrift.home' property! + Executing ${thrift.home}/bin/thrift on ${ant.project.name}/if/hive_service.thrift - + -#else -#include -#endif - -#ifdef HAVE_STDINT_H -#include -#endif - -/** - * T_GLOBAL_DEBUGGING_LEVEL = 0: all debugging turned off, debug macros undefined - * T_GLOBAL_DEBUGGING_LEVEL = 1: all debugging turned on - */ -#define T_GLOBAL_DEBUGGING_LEVEL 0 - - -/** - * T_GLOBAL_LOGGING_LEVEL = 0: all logging turned off, logging macros undefined - * T_GLOBAL_LOGGING_LEVEL = 1: all logging turned on - */ -#define T_GLOBAL_LOGGING_LEVEL 1 - - -/** - * Standard wrapper around fprintf what will prefix the file name and line - * number to the line. Uses T_GLOBAL_DEBUGGING_LEVEL to control whether it is - * turned on or off. - * - * @param format_string - */ -#if T_GLOBAL_DEBUGGING_LEVEL > 0 - #define T_DEBUG(format_string,...) \ - if (T_GLOBAL_DEBUGGING_LEVEL > 0) { \ - fprintf(stderr,"[%s,%d] " #format_string " \n", __FILE__, __LINE__,##__VA_ARGS__); \ - } -#else - #define T_DEBUG(format_string,...) -#endif - - -/** - * analagous to T_DEBUG but also prints the time - * - * @param string format_string input: printf style format string - */ -#if T_GLOBAL_DEBUGGING_LEVEL > 0 - #define T_DEBUG_T(format_string,...) \ - { \ - if (T_GLOBAL_DEBUGGING_LEVEL > 0) { \ - time_t now; \ - char dbgtime[26] ; \ - time(&now); \ - ctime_r(&now, dbgtime); \ - dbgtime[24] = '\0'; \ - fprintf(stderr,"[%s,%d] [%s] " #format_string " \n", __FILE__, __LINE__,dbgtime,##__VA_ARGS__); \ - } \ - } -#else - #define T_DEBUG_T(format_string,...) -#endif - - -/** - * analagous to T_DEBUG but uses input level to determine whether or not the string - * should be logged. - * - * @param int level: specified debug level - * @param string format_string input: format string - */ -#define T_DEBUG_L(level, format_string,...) \ - if ((level) > 0) { \ - fprintf(stderr,"[%s,%d] " #format_string " \n", __FILE__, __LINE__,##__VA_ARGS__); \ - } - - -/** - * Explicit error logging. Prints time, file name and line number - * - * @param string format_string input: printf style format string - */ -#define T_ERROR(format_string,...) \ - { \ - time_t now; \ - char dbgtime[26] ; \ - time(&now); \ - ctime_r(&now, dbgtime); \ - dbgtime[24] = '\0'; \ - fprintf(stderr,"[%s,%d] [%s] ERROR: " #format_string " \n", __FILE__, __LINE__,dbgtime,##__VA_ARGS__); \ - } - - -/** - * Analagous to T_ERROR, additionally aborting the process. - * WARNING: macro calls abort(), ending program execution - * - * @param string format_string input: printf style format string - */ -#define T_ERROR_ABORT(format_string,...) \ - { \ - time_t now; \ - char dbgtime[26] ; \ - time(&now); \ - ctime_r(&now, dbgtime); \ - dbgtime[24] = '\0'; \ - fprintf(stderr,"[%s,%d] [%s] ERROR: Going to abort " #format_string " \n", __FILE__, __LINE__,dbgtime,##__VA_ARGS__); \ - exit(1); \ - } - - -/** - * Log input message - * - * @param string format_string input: printf style format string - */ -#if T_GLOBAL_LOGGING_LEVEL > 0 - #define T_LOG_OPER(format_string,...) \ - { \ - if (T_GLOBAL_LOGGING_LEVEL > 0) { \ - time_t now; \ - char dbgtime[26] ; \ - time(&now); \ - ctime_r(&now, dbgtime); \ - dbgtime[24] = '\0'; \ - fprintf(stderr,"[%s] " #format_string " \n", dbgtime,##__VA_ARGS__); \ - } \ - } -#else - #define T_LOG_OPER(format_string,...) -#endif - -#endif // #ifndef _THRIFT_TLOGGING_H_ diff --git service/include/thrift/TProcessor.h service/include/thrift/TProcessor.h deleted file mode 100644 index f2d5279..0000000 --- service/include/thrift/TProcessor.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_TPROCESSOR_H_ -#define _THRIFT_TPROCESSOR_H_ 1 - -#include -#include -#include - -namespace apache { namespace thrift { - -/** - * A processor is a generic object that acts upon two streams of data, one - * an input and the other an output. The definition of this object is loose, - * though the typical case is for some sort of server that either generates - * responses to an input stream or forwards data from one pipe onto another. - * - */ -class TProcessor { - public: - virtual ~TProcessor() {} - - virtual bool process(boost::shared_ptr in, - boost::shared_ptr out) = 0; - - bool process(boost::shared_ptr io) { - return process(io, io); - } - - protected: - TProcessor() {} -}; - -}} // apache::thrift - -#endif // #ifndef _THRIFT_PROCESSOR_H_ diff --git service/include/thrift/TReflectionLocal.h service/include/thrift/TReflectionLocal.h deleted file mode 100644 index e83e475..0000000 --- service/include/thrift/TReflectionLocal.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_TREFLECTIONLOCAL_H_ -#define _THRIFT_TREFLECTIONLOCAL_H_ 1 - -#include -#include -#include - -/** - * Local Reflection is a blanket term referring to the the structure - * and generation of this particular representation of Thrift types. - * (It is called local because it cannot be serialized by Thrift). - * - */ - -namespace apache { namespace thrift { namespace reflection { namespace local { - -using apache::thrift::protocol::TType; - -// We include this many bytes of the structure's fingerprint when serializing -// a top-level structure. Long enough to make collisions unlikely, short -// enough to not significantly affect the amount of memory used. -const int FP_PREFIX_LEN = 4; - -struct FieldMeta { - int16_t tag; - bool is_optional; -}; - -struct TypeSpec { - TType ttype; - uint8_t fp_prefix[FP_PREFIX_LEN]; - - // Use an anonymous union here so we can fit two TypeSpecs in one cache line. - union { - struct { - // Use parallel arrays here for denser packing (of the arrays). - FieldMeta* metas; - TypeSpec** specs; - } tstruct; - struct { - TypeSpec *subtype1; - TypeSpec *subtype2; - } tcontainer; - }; - - // Static initialization of unions isn't really possible, - // so take the plunge and use constructors. - // Hopefully they'll be evaluated at compile time. - - TypeSpec(TType ttype) : ttype(ttype) { - std::memset(fp_prefix, 0, FP_PREFIX_LEN); - } - - TypeSpec(TType ttype, - const uint8_t* fingerprint, - FieldMeta* metas, - TypeSpec** specs) : - ttype(ttype) - { - std::memcpy(fp_prefix, fingerprint, FP_PREFIX_LEN); - tstruct.metas = metas; - tstruct.specs = specs; - } - - TypeSpec(TType ttype, TypeSpec* subtype1, TypeSpec* subtype2) : - ttype(ttype) - { - std::memset(fp_prefix, 0, FP_PREFIX_LEN); - tcontainer.subtype1 = subtype1; - tcontainer.subtype2 = subtype2; - } - -}; - -}}}} // apache::thrift::reflection::local - -#endif // #ifndef _THRIFT_TREFLECTIONLOCAL_H_ diff --git service/include/thrift/Thrift.h service/include/thrift/Thrift.h deleted file mode 100644 index 27a6476..0000000 --- service/include/thrift/Thrift.h +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_THRIFT_H_ -#define _THRIFT_THRIFT_H_ 1 - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif -#include - -#include -#include -#ifdef HAVE_INTTYPES_H -#include -#endif -#include -#include -#include -#include -#include -#include - -#include "TLogging.h" - -namespace apache { namespace thrift { - -class TOutput { - public: - TOutput() : f_(&errorTimeWrapper) {} - - inline void setOutputFunction(void (*function)(const char *)){ - f_ = function; - } - - inline void operator()(const char *message){ - f_(message); - } - - // It is important to have a const char* overload here instead of - // just the string version, otherwise errno could be corrupted - // if there is some problem allocating memory when constructing - // the string. - void perror(const char *message, int errno_copy); - inline void perror(const std::string &message, int errno_copy) { - perror(message.c_str(), errno_copy); - } - - void printf(const char *message, ...); - - inline static void errorTimeWrapper(const char* msg) { - time_t now; - char dbgtime[26]; - time(&now); - ctime_r(&now, dbgtime); - dbgtime[24] = 0; - fprintf(stderr, "Thrift: %s %s\n", dbgtime, msg); - } - - /** Just like strerror_r but returns a C++ string object. */ - static std::string strerror_s(int errno_copy); - - private: - void (*f_)(const char *); -}; - -extern TOutput GlobalOutput; - -namespace protocol { - class TProtocol; -} - -class TException : public std::exception { - public: - TException() {} - - TException(const std::string& message) : - message_(message) {} - - virtual ~TException() throw() {} - - virtual const char* what() const throw() { - if (message_.empty()) { - return "Default TException."; - } else { - return message_.c_str(); - } - } - - protected: - std::string message_; - -}; - -class TApplicationException : public TException { - public: - - /** - * Error codes for the various types of exceptions. - */ - enum TApplicationExceptionType - { UNKNOWN = 0 - , UNKNOWN_METHOD = 1 - , INVALID_MESSAGE_TYPE = 2 - , WRONG_METHOD_NAME = 3 - , BAD_SEQUENCE_ID = 4 - , MISSING_RESULT = 5 - }; - - TApplicationException() : - TException(), - type_(UNKNOWN) {} - - TApplicationException(TApplicationExceptionType type) : - TException(), - type_(type) {} - - TApplicationException(const std::string& message) : - TException(message), - type_(UNKNOWN) {} - - TApplicationException(TApplicationExceptionType type, - const std::string& message) : - TException(message), - type_(type) {} - - virtual ~TApplicationException() throw() {} - - /** - * Returns an error code that provides information about the type of error - * that has occurred. - * - * @return Error code - */ - TApplicationExceptionType getType() { - return type_; - } - - virtual const char* what() const throw() { - if (message_.empty()) { - switch (type_) { - case UNKNOWN : return "TApplicationException: Unknown application exception"; - case UNKNOWN_METHOD : return "TApplicationException: Unknown method"; - case INVALID_MESSAGE_TYPE : return "TApplicationException: Invalid message type"; - case WRONG_METHOD_NAME : return "TApplicationException: Wrong method name"; - case BAD_SEQUENCE_ID : return "TApplicationException: Bad sequence identifier"; - case MISSING_RESULT : return "TApplicationException: Missing result"; - default : return "TApplicationException: (Invalid exception type)"; - }; - } else { - return message_.c_str(); - } - } - - uint32_t read(protocol::TProtocol* iprot); - uint32_t write(protocol::TProtocol* oprot) const; - - protected: - /** - * Error code - */ - TApplicationExceptionType type_; - -}; - - -// Forward declare this structure used by TDenseProtocol -namespace reflection { namespace local { -struct TypeSpec; -}} - - -}} // apache::thrift - -#endif // #ifndef _THRIFT_THRIFT_H_ diff --git service/include/thrift/concurrency/Exception.h service/include/thrift/concurrency/Exception.h deleted file mode 100644 index ec46629..0000000 --- service/include/thrift/concurrency/Exception.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_CONCURRENCY_EXCEPTION_H_ -#define _THRIFT_CONCURRENCY_EXCEPTION_H_ 1 - -#include -#include - -namespace apache { namespace thrift { namespace concurrency { - -class NoSuchTaskException : public apache::thrift::TException {}; - -class UncancellableTaskException : public apache::thrift::TException {}; - -class InvalidArgumentException : public apache::thrift::TException {}; - -class IllegalStateException : public apache::thrift::TException {}; - -class TimedOutException : public apache::thrift::TException { -public: - TimedOutException():TException("TimedOutException"){}; - TimedOutException(const std::string& message ) : - TException(message) {} -}; - -class TooManyPendingTasksException : public apache::thrift::TException { -public: - TooManyPendingTasksException():TException("TooManyPendingTasksException"){}; - TooManyPendingTasksException(const std::string& message ) : - TException(message) {} -}; - -class SystemResourceException : public apache::thrift::TException { -public: - SystemResourceException() {} - - SystemResourceException(const std::string& message) : - TException(message) {} -}; - -}}} // apache::thrift::concurrency - -#endif // #ifndef _THRIFT_CONCURRENCY_EXCEPTION_H_ diff --git service/include/thrift/concurrency/FunctionRunner.h service/include/thrift/concurrency/FunctionRunner.h deleted file mode 100644 index 2216927..0000000 --- service/include/thrift/concurrency/FunctionRunner.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_CONCURRENCY_FUNCTION_RUNNER_H -#define _THRIFT_CONCURRENCY_FUNCTION_RUNNER_H 1 - -#include -#include "thrift/lib/cpp/concurrency/Thread.h" - -namespace apache { namespace thrift { namespace concurrency { - -/** - * Convenient implementation of Runnable that will execute arbitrary callbacks. - * Interfaces are provided to accept both a generic 'void(void)' callback, and - * a 'void* (void*)' pthread_create-style callback. - * - * Example use: - * void* my_thread_main(void* arg); - * shared_ptr factory = ...; - * shared_ptr thread = - * factory->newThread(shared_ptr( - * new FunctionRunner(my_thread_main, some_argument))); - * thread->start(); - * - * - */ - -class FunctionRunner : public Runnable { - public: - // This is the type of callback 'pthread_create()' expects. - typedef void* (*PthreadFuncPtr)(void *arg); - // This a fully-generic void(void) callback for custom bindings. - typedef std::tr1::function VoidFunc; - - /** - * Given a 'pthread_create' style callback, this FunctionRunner will - * execute the given callback. Note that the 'void*' return value is ignored. - */ - FunctionRunner(PthreadFuncPtr func, void* arg) - : func_(std::tr1::bind(func, arg)) - { } - - /** - * Given a generic callback, this FunctionRunner will execute it. - */ - FunctionRunner(const VoidFunc& cob) - : func_(cob) - { } - - - void run() { - func_(); - } - - private: - VoidFunc func_; -}; - -}}} // apache::thrift::concurrency - -#endif // #ifndef _THRIFT_CONCURRENCY_FUNCTION_RUNNER_H diff --git service/include/thrift/concurrency/Monitor.h service/include/thrift/concurrency/Monitor.h deleted file mode 100644 index 234bf32..0000000 --- service/include/thrift/concurrency/Monitor.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_CONCURRENCY_MONITOR_H_ -#define _THRIFT_CONCURRENCY_MONITOR_H_ 1 - -#include "Exception.h" - -namespace apache { namespace thrift { namespace concurrency { - -/** - * A monitor is a combination mutex and condition-event. Waiting and - * notifying condition events requires that the caller own the mutex. Mutex - * lock and unlock operations can be performed independently of condition - * events. This is more or less analogous to java.lang.Object multi-thread - * operations - * - * Note that all methods are const. Monitors implement logical constness, not - * bit constness. This allows const methods to call monitor methods without - * needing to cast away constness or change to non-const signatures. - * - * @version $Id:$ - */ -class Monitor { - - public: - - Monitor(); - - virtual ~Monitor(); - - virtual void lock() const; - - virtual void unlock() const; - - virtual void wait(int64_t timeout=0LL) const; - - virtual void notify() const; - - virtual void notifyAll() const; - - private: - - class Impl; - - Impl* impl_; -}; - -class Synchronized { - public: - - Synchronized(const Monitor& value) : - monitor_(value) { - monitor_.lock(); - } - - ~Synchronized() { - monitor_.unlock(); - } - - private: - const Monitor& monitor_; -}; - - -}}} // apache::thrift::concurrency - -#endif // #ifndef _THRIFT_CONCURRENCY_MONITOR_H_ diff --git service/include/thrift/concurrency/Mutex.h service/include/thrift/concurrency/Mutex.h deleted file mode 100644 index 73c73e0..0000000 --- service/include/thrift/concurrency/Mutex.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_CONCURRENCY_MUTEX_H_ -#define _THRIFT_CONCURRENCY_MUTEX_H_ 1 - -#include - -namespace apache { namespace thrift { namespace concurrency { - -/** - * A simple mutex class - * - * @version $Id:$ - */ -class Mutex { - public: - typedef void (*Initializer)(void*); - - Mutex(Initializer init = DEFAULT_INITIALIZER); - virtual ~Mutex() {} - virtual void lock() const; - virtual bool trylock() const; - virtual void unlock() const; - - static void DEFAULT_INITIALIZER(void*); - static void ADAPTIVE_INITIALIZER(void*); - static void RECURSIVE_INITIALIZER(void*); - - private: - - class impl; - boost::shared_ptr impl_; -}; - -class ReadWriteMutex { -public: - ReadWriteMutex(); - virtual ~ReadWriteMutex() {} - - // these get the lock and block until it is done successfully - virtual void acquireRead() const; - virtual void acquireWrite() const; - - // these attempt to get the lock, returning false immediately if they fail - virtual bool attemptRead() const; - virtual bool attemptWrite() const; - - // this releases both read and write locks - virtual void release() const; - -private: - - class impl; - boost::shared_ptr impl_; -}; - -class Guard { - public: - Guard(const Mutex& value) : mutex_(value) { - mutex_.lock(); - } - ~Guard() { - mutex_.unlock(); - } - - private: - const Mutex& mutex_; -}; - -class RWGuard { - public: - RWGuard(const ReadWriteMutex& value, bool write = 0) : rw_mutex_(value) { - if (write) { - rw_mutex_.acquireWrite(); - } else { - rw_mutex_.acquireRead(); - } - } - ~RWGuard() { - rw_mutex_.release(); - } - private: - const ReadWriteMutex& rw_mutex_; -}; - - -// A little hack to prevent someone from trying to do "Guard(m);" -// Such a use is invalid because the temporary Guard object is -// destoryed at the end of the line, releasing the lock. -// Sorry for polluting the global namespace, but I think it's worth it. -#define Guard(m) incorrect_use_of_Guard(m) -#define RWGuard(m) incorrect_use_of_RWGuard(m) - - -}}} // apache::thrift::concurrency - -#endif // #ifndef _THRIFT_CONCURRENCY_MUTEX_H_ diff --git service/include/thrift/concurrency/PosixThreadFactory.h service/include/thrift/concurrency/PosixThreadFactory.h deleted file mode 100644 index d6d83a3..0000000 --- service/include/thrift/concurrency/PosixThreadFactory.h +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_CONCURRENCY_POSIXTHREADFACTORY_H_ -#define _THRIFT_CONCURRENCY_POSIXTHREADFACTORY_H_ 1 - -#include "Thread.h" - -#include - -namespace apache { namespace thrift { namespace concurrency { - -/** - * A thread factory to create posix threads - * - * @version $Id:$ - */ -class PosixThreadFactory : public ThreadFactory { - - public: - - /** - * POSIX Thread scheduler policies - */ - enum POLICY { - OTHER, - FIFO, - ROUND_ROBIN - }; - - /** - * POSIX Thread scheduler relative priorities, - * - * Absolute priority is determined by scheduler policy and OS. This - * enumeration specifies relative priorities such that one can specify a - * priority withing a giving scheduler policy without knowing the absolute - * value of the priority. - */ - enum PRIORITY { - LOWEST = 0, - LOWER = 1, - LOW = 2, - NORMAL = 3, - HIGH = 4, - HIGHER = 5, - HIGHEST = 6, - INCREMENT = 7, - DECREMENT = 8 - }; - - /** - * Posix thread (pthread) factory. All threads created by a factory are reference-counted - * via boost::shared_ptr and boost::weak_ptr. The factory guarantees that threads and - * the Runnable tasks they host will be properly cleaned up once the last strong reference - * to both is given up. - * - * Threads are created with the specified policy, priority, stack-size and detachable-mode - * detached means the thread is free-running and will release all system resources the - * when it completes. A detachable thread is not joinable. The join method - * of a detachable thread will return immediately with no error. - * - * By default threads are not joinable. - */ - - PosixThreadFactory(POLICY policy=ROUND_ROBIN, PRIORITY priority=NORMAL, int stackSize=1, bool detached=true); - - // From ThreadFactory; - boost::shared_ptr newThread(boost::shared_ptr runnable) const; - - // From ThreadFactory; - Thread::id_t getCurrentThreadId() const; - - /** - * Gets stack size for created threads - * - * @return int size in megabytes - */ - virtual int getStackSize() const; - - /** - * Sets stack size for created threads - * - * @param value size in megabytes - */ - virtual void setStackSize(int value); - - /** - * Gets priority relative to current policy - */ - virtual PRIORITY getPriority() const; - - /** - * Sets priority relative to current policy - */ - virtual void setPriority(PRIORITY priority); - - /** - * Sets detached mode of threads - */ - virtual void setDetached(bool detached); - - /** - * Gets current detached mode - */ - virtual bool isDetached() const; - - private: - class Impl; - boost::shared_ptr impl_; -}; - -}}} // apache::thrift::concurrency - -#endif // #ifndef _THRIFT_CONCURRENCY_POSIXTHREADFACTORY_H_ diff --git service/include/thrift/concurrency/Thread.h service/include/thrift/concurrency/Thread.h deleted file mode 100644 index d4282ad..0000000 --- service/include/thrift/concurrency/Thread.h +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_CONCURRENCY_THREAD_H_ -#define _THRIFT_CONCURRENCY_THREAD_H_ 1 - -#include -#include -#include - -namespace apache { namespace thrift { namespace concurrency { - -class Thread; - -/** - * Minimal runnable class. More or less analogous to java.lang.Runnable. - * - * @version $Id:$ - */ -class Runnable { - - public: - virtual ~Runnable() {}; - virtual void run() = 0; - - /** - * Gets the thread object that is hosting this runnable object - can return - * an empty boost::shared pointer if no references remain on thet thread object - */ - virtual boost::shared_ptr thread() { return thread_.lock(); } - - /** - * Sets the thread that is executing this object. This is only meant for - * use by concrete implementations of Thread. - */ - virtual void thread(boost::shared_ptr value) { thread_ = value; } - - private: - boost::weak_ptr thread_; -}; - -/** - * Minimal thread class. Returned by thread factory bound to a Runnable object - * and ready to start execution. More or less analogous to java.lang.Thread - * (minus all the thread group, priority, mode and other baggage, since that - * is difficult to abstract across platforms and is left for platform-specific - * ThreadFactory implemtations to deal with - * - * @see apache::thrift::concurrency::ThreadFactory) - */ -class Thread { - - public: - - typedef uint64_t id_t; - - virtual ~Thread() {}; - - /** - * Starts the thread. Does platform specific thread creation and - * configuration then invokes the run method of the Runnable object bound - * to this thread. - */ - virtual void start() = 0; - - /** - * Join this thread. Current thread blocks until this target thread - * completes. - */ - virtual void join() = 0; - - /** - * Gets the thread's platform-specific ID - */ - virtual id_t getId() = 0; - - /** - * Gets the runnable object this thread is hosting - */ - virtual boost::shared_ptr runnable() const { return _runnable; } - - protected: - virtual void runnable(boost::shared_ptr value) { _runnable = value; } - - private: - boost::shared_ptr _runnable; - -}; - -/** - * Factory to create platform-specific thread object and bind them to Runnable - * object for execution - */ -class ThreadFactory { - - public: - virtual ~ThreadFactory() {} - virtual boost::shared_ptr newThread(boost::shared_ptr runnable) const = 0; - - /** Gets the current thread id or unknown_thread_id if the current thread is not a thrift thread */ - - static const Thread::id_t unknown_thread_id; - - virtual Thread::id_t getCurrentThreadId() const = 0; -}; - -}}} // apache::thrift::concurrency - -#endif // #ifndef _THRIFT_CONCURRENCY_THREAD_H_ diff --git service/include/thrift/concurrency/ThreadManager.h service/include/thrift/concurrency/ThreadManager.h deleted file mode 100644 index 6e5a178..0000000 --- service/include/thrift/concurrency/ThreadManager.h +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_CONCURRENCY_THREADMANAGER_H_ -#define _THRIFT_CONCURRENCY_THREADMANAGER_H_ 1 - -#include -#include -#include "Thread.h" - -namespace apache { namespace thrift { namespace concurrency { - -/** - * Thread Pool Manager and related classes - * - * @version $Id:$ - */ -class ThreadManager; - -/** - * ThreadManager class - * - * This class manages a pool of threads. It uses a ThreadFactory to create - * threads. It never actually creates or destroys worker threads, rather - * It maintains statistics on number of idle threads, number of active threads, - * task backlog, and average wait and service times and informs the PoolPolicy - * object bound to instances of this manager of interesting transitions. It is - * then up the PoolPolicy object to decide if the thread pool size needs to be - * adjusted and call this object addWorker and removeWorker methods to make - * changes. - * - * This design allows different policy implementations to used this code to - * handle basic worker thread management and worker task execution and focus on - * policy issues. The simplest policy, StaticPolicy, does nothing other than - * create a fixed number of threads. - */ -class ThreadManager { - - protected: - ThreadManager() {} - - public: - virtual ~ThreadManager() {} - - /** - * Starts the thread manager. Verifies all attributes have been properly - * initialized, then allocates necessary resources to begin operation - */ - virtual void start() = 0; - - /** - * Stops the thread manager. Aborts all remaining unprocessed task, shuts - * down all created worker threads, and realeases all allocated resources. - * This method blocks for all worker threads to complete, thus it can - * potentially block forever if a worker thread is running a task that - * won't terminate. - */ - virtual void stop() = 0; - - /** - * Joins the thread manager. This is the same as stop, except that it will - * block until all the workers have finished their work. At that point - * the ThreadManager will transition into the STOPPED state. - */ - virtual void join() = 0; - - enum STATE { - UNINITIALIZED, - STARTING, - STARTED, - JOINING, - STOPPING, - STOPPED - }; - - virtual const STATE state() const = 0; - - virtual boost::shared_ptr threadFactory() const = 0; - - virtual void threadFactory(boost::shared_ptr value) = 0; - - virtual void addWorker(size_t value=1) = 0; - - virtual void removeWorker(size_t value=1) = 0; - - /** - * Gets the current number of idle worker threads - */ - virtual size_t idleWorkerCount() const = 0; - - /** - * Gets the current number of total worker threads - */ - virtual size_t workerCount() const = 0; - - /** - * Gets the current number of pending tasks - */ - virtual size_t pendingTaskCount() const = 0; - - /** - * Gets the current number of pending and executing tasks - */ - virtual size_t totalTaskCount() const = 0; - - /** - * Gets the maximum pending task count. 0 indicates no maximum - */ - virtual size_t pendingTaskCountMax() const = 0; - - /** - * Adds a task to be executed at some time in the future by a worker thread. - * - * This method will block if pendingTaskCountMax() in not zero and pendingTaskCount() - * is greater than or equalt to pendingTaskCountMax(). If this method is called in the - * context of a ThreadManager worker thread it will throw a - * TooManyPendingTasksException - * - * @param task The task to queue for execution - * - * @param timeout Time to wait in milliseconds to add a task when a pending-task-count - * is specified. Specific cases: - * timeout = 0 : Wait forever to queue task. - * timeout = -1 : Return immediately if pending task count exceeds specified max - * - * @throws TooManyPendingTasksException Pending task count exceeds max pending task count - */ - virtual void add(boost::shared_ptrtask, int64_t timeout=0LL) = 0; - - /** - * Removes a pending task - */ - virtual void remove(boost::shared_ptr task) = 0; - - static boost::shared_ptr newThreadManager(); - - /** - * Creates a simple thread manager the uses count number of worker threads and has - * a pendingTaskCountMax maximum pending tasks. The default, 0, specified no limit - * on pending tasks - */ - static boost::shared_ptr newSimpleThreadManager(size_t count=4, size_t pendingTaskCountMax=0); - - class Task; - - class Worker; - - class Impl; -}; - -}}} // apache::thrift::concurrency - -#endif // #ifndef _THRIFT_CONCURRENCY_THREADMANAGER_H_ diff --git service/include/thrift/concurrency/TimerManager.h service/include/thrift/concurrency/TimerManager.h deleted file mode 100644 index dfbf0ea..0000000 --- service/include/thrift/concurrency/TimerManager.h +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_CONCURRENCY_TIMERMANAGER_H_ -#define _THRIFT_CONCURRENCY_TIMERMANAGER_H_ 1 - -#include "Exception.h" -#include "Monitor.h" -#include "Thread.h" - -#include -#include -#include - -namespace apache { namespace thrift { namespace concurrency { - -/** - * Timer Manager - * - * This class dispatches timer tasks when they fall due. - * - * @version $Id:$ - */ -class TimerManager { - - public: - - TimerManager(); - - virtual ~TimerManager(); - - virtual boost::shared_ptr threadFactory() const; - - virtual void threadFactory(boost::shared_ptr value); - - /** - * Starts the timer manager service - * - * @throws IllegalArgumentException Missing thread factory attribute - */ - virtual void start(); - - /** - * Stops the timer manager service - */ - virtual void stop(); - - virtual size_t taskCount() const ; - - /** - * Adds a task to be executed at some time in the future by a worker thread. - * - * @param task The task to execute - * @param timeout Time in milliseconds to delay before executing task - */ - virtual void add(boost::shared_ptr task, int64_t timeout); - - /** - * Adds a task to be executed at some time in the future by a worker thread. - * - * @param task The task to execute - * @param timeout Absolute time in the future to execute task. - */ - virtual void add(boost::shared_ptr task, const struct timespec& timeout); - - /** - * Removes a pending task - * - * @throws NoSuchTaskException Specified task doesn't exist. It was either - * processed already or this call was made for a - * task that was never added to this timer - * - * @throws UncancellableTaskException Specified task is already being - * executed or has completed execution. - */ - virtual void remove(boost::shared_ptr task); - - enum STATE { - UNINITIALIZED, - STARTING, - STARTED, - STOPPING, - STOPPED - }; - - virtual const STATE state() const; - - private: - boost::shared_ptr threadFactory_; - class Task; - friend class Task; - std::multimap > taskMap_; - size_t taskCount_; - Monitor monitor_; - STATE state_; - class Dispatcher; - friend class Dispatcher; - boost::shared_ptr dispatcher_; - boost::shared_ptr dispatcherThread_; - typedef std::multimap >::iterator task_iterator; - typedef std::pair task_range; -}; - -}}} // apache::thrift::concurrency - -#endif // #ifndef _THRIFT_CONCURRENCY_TIMERMANAGER_H_ diff --git service/include/thrift/concurrency/Util.h service/include/thrift/concurrency/Util.h deleted file mode 100644 index 25fcc20..0000000 --- service/include/thrift/concurrency/Util.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_CONCURRENCY_UTIL_H_ -#define _THRIFT_CONCURRENCY_UTIL_H_ 1 - -#include -#include -#include -#include -#include - -namespace apache { namespace thrift { namespace concurrency { - -/** - * Utility methods - * - * This class contains basic utility methods for converting time formats, - * and other common platform-dependent concurrency operations. - * It should not be included in API headers for other concurrency library - * headers, since it will, by definition, pull in all sorts of horrid - * platform dependent crap. Rather it should be inluded directly in - * concurrency library implementation source. - * - * @version $Id:$ - */ -class Util { - - static const int64_t NS_PER_S = 1000000000LL; - static const int64_t US_PER_S = 1000000LL; - static const int64_t MS_PER_S = 1000LL; - - static const int64_t NS_PER_MS = NS_PER_S / MS_PER_S; - static const int64_t US_PER_MS = US_PER_S / MS_PER_S; - - public: - - /** - * Converts millisecond timestamp into a timespec struct - * - * @param struct timespec& result - * @param time or duration in milliseconds - */ - static void toTimespec(struct timespec& result, int64_t value) { - result.tv_sec = value / MS_PER_S; // ms to s - result.tv_nsec = (value % MS_PER_S) * NS_PER_MS; // ms to ns - } - - static void toTimeval(struct timeval& result, int64_t value) { - result.tv_sec = value / MS_PER_S; // ms to s - result.tv_usec = (value % MS_PER_S) * US_PER_MS; // ms to us - } - - /** - * Converts struct timespec to milliseconds - */ - static const void toMilliseconds(int64_t& result, const struct timespec& value) { - result = (value.tv_sec * MS_PER_S) + (value.tv_nsec / NS_PER_MS); - // round up -- int64_t cast is to avoid a compiler error for some GCCs - if (int64_t(value.tv_nsec) % NS_PER_MS >= (NS_PER_MS / 2)) { - ++result; - } - } - - /** - * Converts struct timeval to milliseconds - */ - static const void toMilliseconds(int64_t& result, const struct timeval& value) { - result = (value.tv_sec * MS_PER_S) + (value.tv_usec / US_PER_MS); - // round up -- int64_t cast is to avoid a compiler error for some GCCs - if (int64_t(value.tv_usec) % US_PER_MS >= (US_PER_MS / 2)) { - ++result; - } - } - - /** - * Get current time as milliseconds from epoch - */ - static const int64_t currentTime(); -}; - -}}} // apache::thrift::concurrency - -#endif // #ifndef _THRIFT_CONCURRENCY_UTIL_H_ diff --git service/include/thrift/config.h service/include/thrift/config.h deleted file mode 100644 index 70264f2..0000000 --- service/include/thrift/config.h +++ /dev/null @@ -1,354 +0,0 @@ -/* config.h. Generated from config.hin by configure. */ -/* config.hin. Generated from configure.ac by autoheader. */ - -/* Define if the AI_ADDRCONFIG symbol is unavailable */ -/* #undef AI_ADDRCONFIG */ - -/* Possible value for SIGNED_RIGHT_SHIFT_IS */ -#define ARITHMETIC_RIGHT_SHIFT 1 - -/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP - systems. This function is required for `alloca.c' support on those systems. - */ -/* #undef CRAY_STACKSEG_END */ - -/* Define to 1 if using `alloca.c'. */ -/* #undef C_ALLOCA */ - -/* Define to 1 if you have `alloca', as a function or macro. */ -#define HAVE_ALLOCA 1 - -/* Define to 1 if you have and it should be used (not on Ultrix). - */ -#define HAVE_ALLOCA_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_ARPA_INET_H 1 - -/* define if the Boost library is available */ -#define HAVE_BOOST /**/ - -/* Define to 1 if you have the `bzero' function. */ -#define HAVE_BZERO 1 - -/* Define to 1 if you have the `clock_gettime' function. */ -#define HAVE_CLOCK_GETTIME 1 - -/* Define to 1 if you have the declaration of `strerror_r', and to 0 if you - don't. */ -#define HAVE_DECL_STRERROR_R 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_DLFCN_H 1 - -/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */ -/* #undef HAVE_DOPRNT */ - -/* Define to 1 if you have the header file. */ -#define HAVE_ENDIAN_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_FCNTL_H 1 - -/* Define to 1 if you have the `ftruncate' function. */ -#define HAVE_FTRUNCATE 1 - -/* Define to 1 if you have the `gethostbyname' function. */ -#define HAVE_GETHOSTBYNAME 1 - -/* Define to 1 if you have the `gettimeofday' function. */ -#define HAVE_GETTIMEOFDAY 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_INTTYPES_H 1 - -/* define if libevent is available */ -#define HAVE_LIBEVENT /**/ - -/* Define to 1 if you have the header file. */ -#define HAVE_LIBINTL_H 1 - -/* Define to 1 if you have the `pthread' library (-lpthread). */ -#define HAVE_LIBPTHREAD 1 - -/* Define to 1 if you have the `rt' library (-lrt). */ -#define HAVE_LIBRT 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_LIMITS_H 1 - -/* Define to 1 if your system has a GNU libc compatible `malloc' function, and - to 0 otherwise. */ -#define HAVE_MALLOC 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_MALLOC_H 1 - -/* Define to 1 if you have the `memmove' function. */ -#define HAVE_MEMMOVE 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_MEMORY_H 1 - -/* Define to 1 if you have the `memset' function. */ -#define HAVE_MEMSET 1 - -/* Define to 1 if you have the `mkdir' function. */ -#define HAVE_MKDIR 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_NETDB_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_NETINET_IN_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_PTHREAD_H 1 - -/* Define to 1 if the system has the type `ptrdiff_t'. */ -#define HAVE_PTRDIFF_T 1 - -/* Define to 1 if your system has a GNU libc compatible `realloc' function, - and to 0 otherwise. */ -#define HAVE_REALLOC 1 - -/* Define to 1 if you have the `realpath' function. */ -#define HAVE_REALPATH 1 - -/* Define to 1 if you have the `sched_get_priority_max' function. */ -#define HAVE_SCHED_GET_PRIORITY_MAX 1 - -/* Define to 1 if you have the `sched_get_priority_min' function. */ -#define HAVE_SCHED_GET_PRIORITY_MIN 1 - -/* Define to 1 if you have the `select' function. */ -#define HAVE_SELECT 1 - -/* Define to 1 if you have the `socket' function. */ -#define HAVE_SOCKET 1 - -/* Define to 1 if you have the `sqrt' function. */ -#define HAVE_SQRT 1 - -/* Define to 1 if `stat' has the bug that it succeeds when given the - zero-length file name argument. */ -/* #undef HAVE_STAT_EMPTY_STRING_BUG */ - -/* Define to 1 if stdbool.h conforms to C99. */ -#define HAVE_STDBOOL_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDDEF_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDINT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDLIB_H 1 - -/* Define to 1 if you have the `strchr' function. */ -#define HAVE_STRCHR 1 - -/* Define to 1 if you have the `strdup' function. */ -#define HAVE_STRDUP 1 - -/* Define to 1 if you have the `strerror' function. */ -#define HAVE_STRERROR 1 - -/* Define to 1 if you have the `strerror_r' function. */ -#define HAVE_STRERROR_R 1 - -/* Define to 1 if you have the `strftime' function. */ -#define HAVE_STRFTIME 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRINGS_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRING_H 1 - -/* Define to 1 if you have the `strstr' function. */ -#define HAVE_STRSTR 1 - -/* Define to 1 if you have the `strtol' function. */ -#define HAVE_STRTOL 1 - -/* Define to 1 if you have the `strtoul' function. */ -#define HAVE_STRTOUL 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_SELECT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_SOCKET_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_STAT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TIME_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_UNISTD_H 1 - -/* Define to 1 if you have the `vprintf' function. */ -#define HAVE_VPRINTF 1 - -/* define if zlib is available */ -/* #undef HAVE_ZLIB */ - -/* Define to 1 if the system has the type `_Bool'. */ -/* #undef HAVE__BOOL */ - -/* Possible value for SIGNED_RIGHT_SHIFT_IS */ -#define LOGICAL_RIGHT_SHIFT 2 - -/* Define to 1 if `lstat' dereferences a symlink specified with a trailing - slash. */ -#define LSTAT_FOLLOWS_SLASHED_SYMLINK 1 - -/* Define to the sub-directory in which libtool stores uninstalled libraries. - */ -#define LT_OBJDIR ".libs/" - -/* Name of package */ -#define PACKAGE "thrift" - -/* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "" - -/* Define to the full name of this package. */ -#define PACKAGE_NAME "thrift" - -/* Define to the full name and version of this package. */ -#define PACKAGE_STRING "thrift instant" - -/* Define to the one symbol short name of this package. */ -#define PACKAGE_TARNAME "thrift" - -/* Define to the version of this package. */ -#define PACKAGE_VERSION "instant" - -/* Define to the type of arg 1 for `select'. */ -#define SELECT_TYPE_ARG1 int - -/* Define to the type of args 2, 3 and 4 for `select'. */ -#define SELECT_TYPE_ARG234 (fd_set *) - -/* Define to the type of arg 5 for `select'. */ -#define SELECT_TYPE_ARG5 (struct timeval *) - -/* Indicates the effect of the right shift operator on negative signed - integers */ -#define SIGNED_RIGHT_SHIFT_IS 1 - -/* If using the C implementation of alloca, define if you know the - direction of stack growth for your system; otherwise it will be - automatically deduced at runtime. - STACK_DIRECTION > 0 => grows toward higher addresses - STACK_DIRECTION < 0 => grows toward lower addresses - STACK_DIRECTION = 0 => direction of growth unknown */ -/* #undef STACK_DIRECTION */ - -/* Define to 1 if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* Define to 1 if strerror_r returns char *. */ -#define STRERROR_R_CHAR_P 1 - -/* Define to 1 if you can safely include both and . */ -#define TIME_WITH_SYS_TIME 1 - -/* Define to 1 if your declares `struct tm'. */ -/* #undef TM_IN_SYS_TIME */ - -/* Possible value for SIGNED_RIGHT_SHIFT_IS */ -#define UNKNOWN_RIGHT_SHIFT 3 - -/* Version number of package */ -#define VERSION "instant" - -/* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a - `char[]'. */ -#define YYTEXT_POINTER 1 - -/* Define for Solaris 2.5.1 so the uint32_t typedef from , - , or is not used. If the typedef were allowed, the - #define below would cause a syntax error. */ -/* #undef _UINT32_T */ - -/* Define for Solaris 2.5.1 so the uint64_t typedef from , - , or is not used. If the typedef were allowed, the - #define below would cause a syntax error. */ -/* #undef _UINT64_T */ - -/* Define for Solaris 2.5.1 so the uint8_t typedef from , - , or is not used. If the typedef were allowed, the - #define below would cause a syntax error. */ -/* #undef _UINT8_T */ - -/* Define to empty if `const' does not conform to ANSI C. */ -/* #undef const */ - -/* Define to `__inline__' or `__inline' if that's what the C compiler - calls it, or to nothing if 'inline' is not supported under any name. */ -#ifndef __cplusplus -/* #undef inline */ -#endif - -/* Define to the type of a signed integer type of width exactly 16 bits if - such a type exists and the standard includes do not define it. */ -/* #undef int16_t */ - -/* Define to the type of a signed integer type of width exactly 32 bits if - such a type exists and the standard includes do not define it. */ -/* #undef int32_t */ - -/* Define to the type of a signed integer type of width exactly 64 bits if - such a type exists and the standard includes do not define it. */ -/* #undef int64_t */ - -/* Define to the type of a signed integer type of width exactly 8 bits if such - a type exists and the standard includes do not define it. */ -/* #undef int8_t */ - -/* Define to rpl_malloc if the replacement function should be used. */ -/* #undef malloc */ - -/* Define to `int' if does not define. */ -/* #undef mode_t */ - -/* Define to `long int' if does not define. */ -/* #undef off_t */ - -/* Define to rpl_realloc if the replacement function should be used. */ -/* #undef realloc */ - -/* Define to `unsigned int' if does not define. */ -/* #undef size_t */ - -/* Define to `int' if does not define. */ -/* #undef ssize_t */ - -/* Define to the type of an unsigned integer type of width exactly 16 bits if - such a type exists and the standard includes do not define it. */ -/* #undef uint16_t */ - -/* Define to the type of an unsigned integer type of width exactly 32 bits if - such a type exists and the standard includes do not define it. */ -/* #undef uint32_t */ - -/* Define to the type of an unsigned integer type of width exactly 64 bits if - such a type exists and the standard includes do not define it. */ -/* #undef uint64_t */ - -/* Define to the type of an unsigned integer type of width exactly 8 bits if - such a type exists and the standard includes do not define it. */ -/* #undef uint8_t */ - -/* Define to empty if the keyword `volatile' does not work. Warning: valid - code using `volatile' can become incorrect without. Disable with care. */ -/* #undef volatile */ diff --git service/include/thrift/fb303/FacebookBase.h service/include/thrift/fb303/FacebookBase.h deleted file mode 100644 index fd169e6..0000000 --- service/include/thrift/fb303/FacebookBase.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _FACEBOOK_TB303_FACEBOOKBASE_H_ -#define _FACEBOOK_TB303_FACEBOOKBASE_H_ 1 - -#include "FacebookService.h" - -#include "server/TServer.h" -#include "concurrency/Mutex.h" - -#include -#include -#include - -namespace facebook { namespace fb303 { - -using apache::thrift::concurrency::Mutex; -using apache::thrift::concurrency::ReadWriteMutex; -using apache::thrift::server::TServer; - -struct ReadWriteInt : ReadWriteMutex {int64_t value;}; -struct ReadWriteCounterMap : ReadWriteMutex, - std::map {}; - -/** - * Base Facebook service implementation in C++. - * - */ -class FacebookBase : virtual public FacebookServiceIf { - protected: - FacebookBase(std::string name); - virtual ~FacebookBase() {} - - public: - void getName(std::string& _return); - virtual void getVersion(std::string& _return) { _return = ""; } - - virtual fb_status getStatus() = 0; - virtual void getStatusDetails(std::string& _return) { _return = ""; } - - void setOption(const std::string& key, const std::string& value); - void getOption(std::string& _return, const std::string& key); - void getOptions(std::map & _return); - - int64_t aliveSince(); - - virtual void reinitialize() {} - - virtual void shutdown() { - if (server_.get() != NULL) { - server_->stop(); - } - } - - int64_t incrementCounter(const std::string& key, int64_t amount = 1); - int64_t setCounter(const std::string& key, int64_t value); - - void getCounters(std::map& _return); - int64_t getCounter(const std::string& key); - - /** - * Set server handle for shutdown method - */ - void setServer(boost::shared_ptr server) { - server_ = server; - } - - void getCpuProfile(std::string& _return, int32_t durSecs) { _return = ""; } - - private: - - std::string name_; - int64_t aliveSince_; - - std::map options_; - Mutex optionsLock_; - - ReadWriteCounterMap counters_; - - boost::shared_ptr server_; - -}; - -}} // facebook::tb303 - -#endif // _FACEBOOK_TB303_FACEBOOKBASE_H_ diff --git service/include/thrift/fb303/FacebookService.cpp service/include/thrift/fb303/FacebookService.cpp deleted file mode 100644 index 4a34362..0000000 --- service/include/thrift/fb303/FacebookService.cpp +++ /dev/null @@ -1,2887 +0,0 @@ -/** - * Autogenerated by Thrift - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - */ -#include "FacebookService.h" - -namespace facebook { namespace fb303 { - -uint32_t FacebookService_getName_args::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_getName_args::write(apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - xfer += oprot->writeStructBegin("FacebookService_getName_args"); - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_getName_pargs::write(apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - xfer += oprot->writeStructBegin("FacebookService_getName_pargs"); - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_getName_result::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 0: - if (ftype == apache::thrift::protocol::T_STRING) { - xfer += iprot->readString(this->success); - this->__isset.success = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_getName_result::write(apache::thrift::protocol::TProtocol* oprot) const { - - uint32_t xfer = 0; - - xfer += oprot->writeStructBegin("FacebookService_getName_result"); - - if (this->__isset.success) { - xfer += oprot->writeFieldBegin("success", apache::thrift::protocol::T_STRING, 0); - xfer += oprot->writeString(this->success); - xfer += oprot->writeFieldEnd(); - } - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_getName_presult::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 0: - if (ftype == apache::thrift::protocol::T_STRING) { - xfer += iprot->readString((*(this->success))); - this->__isset.success = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_getVersion_args::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_getVersion_args::write(apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - xfer += oprot->writeStructBegin("FacebookService_getVersion_args"); - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_getVersion_pargs::write(apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - xfer += oprot->writeStructBegin("FacebookService_getVersion_pargs"); - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_getVersion_result::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 0: - if (ftype == apache::thrift::protocol::T_STRING) { - xfer += iprot->readString(this->success); - this->__isset.success = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_getVersion_result::write(apache::thrift::protocol::TProtocol* oprot) const { - - uint32_t xfer = 0; - - xfer += oprot->writeStructBegin("FacebookService_getVersion_result"); - - if (this->__isset.success) { - xfer += oprot->writeFieldBegin("success", apache::thrift::protocol::T_STRING, 0); - xfer += oprot->writeString(this->success); - xfer += oprot->writeFieldEnd(); - } - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_getVersion_presult::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 0: - if (ftype == apache::thrift::protocol::T_STRING) { - xfer += iprot->readString((*(this->success))); - this->__isset.success = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_getStatus_args::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_getStatus_args::write(apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - xfer += oprot->writeStructBegin("FacebookService_getStatus_args"); - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_getStatus_pargs::write(apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - xfer += oprot->writeStructBegin("FacebookService_getStatus_pargs"); - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_getStatus_result::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 0: - if (ftype == apache::thrift::protocol::T_I32) { - int32_t ecast0; - xfer += iprot->readI32(ecast0); - this->success = (fb_status)ecast0; - this->__isset.success = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_getStatus_result::write(apache::thrift::protocol::TProtocol* oprot) const { - - uint32_t xfer = 0; - - xfer += oprot->writeStructBegin("FacebookService_getStatus_result"); - - if (this->__isset.success) { - xfer += oprot->writeFieldBegin("success", apache::thrift::protocol::T_I32, 0); - xfer += oprot->writeI32((int32_t)this->success); - xfer += oprot->writeFieldEnd(); - } - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_getStatus_presult::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 0: - if (ftype == apache::thrift::protocol::T_I32) { - int32_t ecast1; - xfer += iprot->readI32(ecast1); - (*(this->success)) = (fb_status)ecast1; - this->__isset.success = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_getStatusDetails_args::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_getStatusDetails_args::write(apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - xfer += oprot->writeStructBegin("FacebookService_getStatusDetails_args"); - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_getStatusDetails_pargs::write(apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - xfer += oprot->writeStructBegin("FacebookService_getStatusDetails_pargs"); - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_getStatusDetails_result::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 0: - if (ftype == apache::thrift::protocol::T_STRING) { - xfer += iprot->readString(this->success); - this->__isset.success = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_getStatusDetails_result::write(apache::thrift::protocol::TProtocol* oprot) const { - - uint32_t xfer = 0; - - xfer += oprot->writeStructBegin("FacebookService_getStatusDetails_result"); - - if (this->__isset.success) { - xfer += oprot->writeFieldBegin("success", apache::thrift::protocol::T_STRING, 0); - xfer += oprot->writeString(this->success); - xfer += oprot->writeFieldEnd(); - } - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_getStatusDetails_presult::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 0: - if (ftype == apache::thrift::protocol::T_STRING) { - xfer += iprot->readString((*(this->success))); - this->__isset.success = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_getCounters_args::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_getCounters_args::write(apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - xfer += oprot->writeStructBegin("FacebookService_getCounters_args"); - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_getCounters_pargs::write(apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - xfer += oprot->writeStructBegin("FacebookService_getCounters_pargs"); - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_getCounters_result::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 0: - if (ftype == apache::thrift::protocol::T_MAP) { - { - this->success.clear(); - uint32_t _size2; - apache::thrift::protocol::TType _ktype3; - apache::thrift::protocol::TType _vtype4; - iprot->readMapBegin(_ktype3, _vtype4, _size2); - uint32_t _i6; - for (_i6 = 0; _i6 < _size2; ++_i6) - { - std::string _key7; - xfer += iprot->readString(_key7); - int64_t& _val8 = this->success[_key7]; - xfer += iprot->readI64(_val8); - } - iprot->readMapEnd(); - } - this->__isset.success = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_getCounters_result::write(apache::thrift::protocol::TProtocol* oprot) const { - - uint32_t xfer = 0; - - xfer += oprot->writeStructBegin("FacebookService_getCounters_result"); - - if (this->__isset.success) { - xfer += oprot->writeFieldBegin("success", apache::thrift::protocol::T_MAP, 0); - { - xfer += oprot->writeMapBegin(apache::thrift::protocol::T_STRING, apache::thrift::protocol::T_I64, this->success.size()); - std::map ::const_iterator _iter9; - for (_iter9 = this->success.begin(); _iter9 != this->success.end(); ++_iter9) - { - xfer += oprot->writeString(_iter9->first); - xfer += oprot->writeI64(_iter9->second); - } - xfer += oprot->writeMapEnd(); - } - xfer += oprot->writeFieldEnd(); - } - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_getCounters_presult::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 0: - if (ftype == apache::thrift::protocol::T_MAP) { - { - (*(this->success)).clear(); - uint32_t _size10; - apache::thrift::protocol::TType _ktype11; - apache::thrift::protocol::TType _vtype12; - iprot->readMapBegin(_ktype11, _vtype12, _size10); - uint32_t _i14; - for (_i14 = 0; _i14 < _size10; ++_i14) - { - std::string _key15; - xfer += iprot->readString(_key15); - int64_t& _val16 = (*(this->success))[_key15]; - xfer += iprot->readI64(_val16); - } - iprot->readMapEnd(); - } - this->__isset.success = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_getCounter_args::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 1: - if (ftype == apache::thrift::protocol::T_STRING) { - xfer += iprot->readString(this->key); - this->__isset.key = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_getCounter_args::write(apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - xfer += oprot->writeStructBegin("FacebookService_getCounter_args"); - xfer += oprot->writeFieldBegin("key", apache::thrift::protocol::T_STRING, 1); - xfer += oprot->writeString(this->key); - xfer += oprot->writeFieldEnd(); - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_getCounter_pargs::write(apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - xfer += oprot->writeStructBegin("FacebookService_getCounter_pargs"); - xfer += oprot->writeFieldBegin("key", apache::thrift::protocol::T_STRING, 1); - xfer += oprot->writeString((*(this->key))); - xfer += oprot->writeFieldEnd(); - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_getCounter_result::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 0: - if (ftype == apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->success); - this->__isset.success = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_getCounter_result::write(apache::thrift::protocol::TProtocol* oprot) const { - - uint32_t xfer = 0; - - xfer += oprot->writeStructBegin("FacebookService_getCounter_result"); - - if (this->__isset.success) { - xfer += oprot->writeFieldBegin("success", apache::thrift::protocol::T_I64, 0); - xfer += oprot->writeI64(this->success); - xfer += oprot->writeFieldEnd(); - } - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_getCounter_presult::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 0: - if (ftype == apache::thrift::protocol::T_I64) { - xfer += iprot->readI64((*(this->success))); - this->__isset.success = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_setOption_args::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 1: - if (ftype == apache::thrift::protocol::T_STRING) { - xfer += iprot->readString(this->key); - this->__isset.key = true; - } else { - xfer += iprot->skip(ftype); - } - break; - case 2: - if (ftype == apache::thrift::protocol::T_STRING) { - xfer += iprot->readString(this->value); - this->__isset.value = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_setOption_args::write(apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - xfer += oprot->writeStructBegin("FacebookService_setOption_args"); - xfer += oprot->writeFieldBegin("key", apache::thrift::protocol::T_STRING, 1); - xfer += oprot->writeString(this->key); - xfer += oprot->writeFieldEnd(); - xfer += oprot->writeFieldBegin("value", apache::thrift::protocol::T_STRING, 2); - xfer += oprot->writeString(this->value); - xfer += oprot->writeFieldEnd(); - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_setOption_pargs::write(apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - xfer += oprot->writeStructBegin("FacebookService_setOption_pargs"); - xfer += oprot->writeFieldBegin("key", apache::thrift::protocol::T_STRING, 1); - xfer += oprot->writeString((*(this->key))); - xfer += oprot->writeFieldEnd(); - xfer += oprot->writeFieldBegin("value", apache::thrift::protocol::T_STRING, 2); - xfer += oprot->writeString((*(this->value))); - xfer += oprot->writeFieldEnd(); - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_setOption_result::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_setOption_result::write(apache::thrift::protocol::TProtocol* oprot) const { - - uint32_t xfer = 0; - - xfer += oprot->writeStructBegin("FacebookService_setOption_result"); - - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_setOption_presult::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_getOption_args::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 1: - if (ftype == apache::thrift::protocol::T_STRING) { - xfer += iprot->readString(this->key); - this->__isset.key = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_getOption_args::write(apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - xfer += oprot->writeStructBegin("FacebookService_getOption_args"); - xfer += oprot->writeFieldBegin("key", apache::thrift::protocol::T_STRING, 1); - xfer += oprot->writeString(this->key); - xfer += oprot->writeFieldEnd(); - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_getOption_pargs::write(apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - xfer += oprot->writeStructBegin("FacebookService_getOption_pargs"); - xfer += oprot->writeFieldBegin("key", apache::thrift::protocol::T_STRING, 1); - xfer += oprot->writeString((*(this->key))); - xfer += oprot->writeFieldEnd(); - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_getOption_result::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 0: - if (ftype == apache::thrift::protocol::T_STRING) { - xfer += iprot->readString(this->success); - this->__isset.success = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_getOption_result::write(apache::thrift::protocol::TProtocol* oprot) const { - - uint32_t xfer = 0; - - xfer += oprot->writeStructBegin("FacebookService_getOption_result"); - - if (this->__isset.success) { - xfer += oprot->writeFieldBegin("success", apache::thrift::protocol::T_STRING, 0); - xfer += oprot->writeString(this->success); - xfer += oprot->writeFieldEnd(); - } - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_getOption_presult::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 0: - if (ftype == apache::thrift::protocol::T_STRING) { - xfer += iprot->readString((*(this->success))); - this->__isset.success = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_getOptions_args::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_getOptions_args::write(apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - xfer += oprot->writeStructBegin("FacebookService_getOptions_args"); - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_getOptions_pargs::write(apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - xfer += oprot->writeStructBegin("FacebookService_getOptions_pargs"); - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_getOptions_result::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 0: - if (ftype == apache::thrift::protocol::T_MAP) { - { - this->success.clear(); - uint32_t _size17; - apache::thrift::protocol::TType _ktype18; - apache::thrift::protocol::TType _vtype19; - iprot->readMapBegin(_ktype18, _vtype19, _size17); - uint32_t _i21; - for (_i21 = 0; _i21 < _size17; ++_i21) - { - std::string _key22; - xfer += iprot->readString(_key22); - std::string& _val23 = this->success[_key22]; - xfer += iprot->readString(_val23); - } - iprot->readMapEnd(); - } - this->__isset.success = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_getOptions_result::write(apache::thrift::protocol::TProtocol* oprot) const { - - uint32_t xfer = 0; - - xfer += oprot->writeStructBegin("FacebookService_getOptions_result"); - - if (this->__isset.success) { - xfer += oprot->writeFieldBegin("success", apache::thrift::protocol::T_MAP, 0); - { - xfer += oprot->writeMapBegin(apache::thrift::protocol::T_STRING, apache::thrift::protocol::T_STRING, this->success.size()); - std::map ::const_iterator _iter24; - for (_iter24 = this->success.begin(); _iter24 != this->success.end(); ++_iter24) - { - xfer += oprot->writeString(_iter24->first); - xfer += oprot->writeString(_iter24->second); - } - xfer += oprot->writeMapEnd(); - } - xfer += oprot->writeFieldEnd(); - } - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_getOptions_presult::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 0: - if (ftype == apache::thrift::protocol::T_MAP) { - { - (*(this->success)).clear(); - uint32_t _size25; - apache::thrift::protocol::TType _ktype26; - apache::thrift::protocol::TType _vtype27; - iprot->readMapBegin(_ktype26, _vtype27, _size25); - uint32_t _i29; - for (_i29 = 0; _i29 < _size25; ++_i29) - { - std::string _key30; - xfer += iprot->readString(_key30); - std::string& _val31 = (*(this->success))[_key30]; - xfer += iprot->readString(_val31); - } - iprot->readMapEnd(); - } - this->__isset.success = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_getCpuProfile_args::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 1: - if (ftype == apache::thrift::protocol::T_I32) { - xfer += iprot->readI32(this->profileDurationInSec); - this->__isset.profileDurationInSec = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_getCpuProfile_args::write(apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - xfer += oprot->writeStructBegin("FacebookService_getCpuProfile_args"); - xfer += oprot->writeFieldBegin("profileDurationInSec", apache::thrift::protocol::T_I32, 1); - xfer += oprot->writeI32(this->profileDurationInSec); - xfer += oprot->writeFieldEnd(); - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_getCpuProfile_pargs::write(apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - xfer += oprot->writeStructBegin("FacebookService_getCpuProfile_pargs"); - xfer += oprot->writeFieldBegin("profileDurationInSec", apache::thrift::protocol::T_I32, 1); - xfer += oprot->writeI32((*(this->profileDurationInSec))); - xfer += oprot->writeFieldEnd(); - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_getCpuProfile_result::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 0: - if (ftype == apache::thrift::protocol::T_STRING) { - xfer += iprot->readString(this->success); - this->__isset.success = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_getCpuProfile_result::write(apache::thrift::protocol::TProtocol* oprot) const { - - uint32_t xfer = 0; - - xfer += oprot->writeStructBegin("FacebookService_getCpuProfile_result"); - - if (this->__isset.success) { - xfer += oprot->writeFieldBegin("success", apache::thrift::protocol::T_STRING, 0); - xfer += oprot->writeString(this->success); - xfer += oprot->writeFieldEnd(); - } - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_getCpuProfile_presult::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 0: - if (ftype == apache::thrift::protocol::T_STRING) { - xfer += iprot->readString((*(this->success))); - this->__isset.success = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_aliveSince_args::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_aliveSince_args::write(apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - xfer += oprot->writeStructBegin("FacebookService_aliveSince_args"); - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_aliveSince_pargs::write(apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - xfer += oprot->writeStructBegin("FacebookService_aliveSince_pargs"); - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_aliveSince_result::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 0: - if (ftype == apache::thrift::protocol::T_I64) { - xfer += iprot->readI64(this->success); - this->__isset.success = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_aliveSince_result::write(apache::thrift::protocol::TProtocol* oprot) const { - - uint32_t xfer = 0; - - xfer += oprot->writeStructBegin("FacebookService_aliveSince_result"); - - if (this->__isset.success) { - xfer += oprot->writeFieldBegin("success", apache::thrift::protocol::T_I64, 0); - xfer += oprot->writeI64(this->success); - xfer += oprot->writeFieldEnd(); - } - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_aliveSince_presult::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - case 0: - if (ftype == apache::thrift::protocol::T_I64) { - xfer += iprot->readI64((*(this->success))); - this->__isset.success = true; - } else { - xfer += iprot->skip(ftype); - } - break; - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_reinitialize_args::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_reinitialize_args::write(apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - xfer += oprot->writeStructBegin("FacebookService_reinitialize_args"); - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_reinitialize_pargs::write(apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - xfer += oprot->writeStructBegin("FacebookService_reinitialize_pargs"); - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_shutdown_args::read(apache::thrift::protocol::TProtocol* iprot) { - - uint32_t xfer = 0; - std::string fname; - apache::thrift::protocol::TType ftype; - int16_t fid; - - xfer += iprot->readStructBegin(fname); - - using apache::thrift::protocol::TProtocolException; - - - while (true) - { - xfer += iprot->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - switch (fid) - { - default: - xfer += iprot->skip(ftype); - break; - } - xfer += iprot->readFieldEnd(); - } - - xfer += iprot->readStructEnd(); - - return xfer; -} - -uint32_t FacebookService_shutdown_args::write(apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - xfer += oprot->writeStructBegin("FacebookService_shutdown_args"); - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -uint32_t FacebookService_shutdown_pargs::write(apache::thrift::protocol::TProtocol* oprot) const { - uint32_t xfer = 0; - xfer += oprot->writeStructBegin("FacebookService_shutdown_pargs"); - xfer += oprot->writeFieldStop(); - xfer += oprot->writeStructEnd(); - return xfer; -} - -void FacebookServiceClient::getName(std::string& _return) -{ - send_getName(); - recv_getName(_return); -} - -void FacebookServiceClient::send_getName() -{ - int32_t cseqid = 0; - oprot_->writeMessageBegin("getName", apache::thrift::protocol::T_CALL, cseqid); - - FacebookService_getName_pargs args; - args.write(oprot_); - - oprot_->writeMessageEnd(); - oprot_->getTransport()->flush(); - oprot_->getTransport()->writeEnd(); -} - -void FacebookServiceClient::recv_getName(std::string& _return) -{ - - int32_t rseqid = 0; - std::string fname; - apache::thrift::protocol::TMessageType mtype; - - iprot_->readMessageBegin(fname, mtype, rseqid); - if (mtype == apache::thrift::protocol::T_EXCEPTION) { - apache::thrift::TApplicationException x; - x.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw x; - } - if (mtype != apache::thrift::protocol::T_REPLY) { - iprot_->skip(apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::INVALID_MESSAGE_TYPE); - } - if (fname.compare("getName") != 0) { - iprot_->skip(apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::WRONG_METHOD_NAME); - } - FacebookService_getName_presult result; - result.success = &_return; - result.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - - if (result.__isset.success) { - // _return pointer has now been filled - return; - } - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::MISSING_RESULT, "getName failed: unknown result"); -} - -void FacebookServiceClient::getVersion(std::string& _return) -{ - send_getVersion(); - recv_getVersion(_return); -} - -void FacebookServiceClient::send_getVersion() -{ - int32_t cseqid = 0; - oprot_->writeMessageBegin("getVersion", apache::thrift::protocol::T_CALL, cseqid); - - FacebookService_getVersion_pargs args; - args.write(oprot_); - - oprot_->writeMessageEnd(); - oprot_->getTransport()->flush(); - oprot_->getTransport()->writeEnd(); -} - -void FacebookServiceClient::recv_getVersion(std::string& _return) -{ - - int32_t rseqid = 0; - std::string fname; - apache::thrift::protocol::TMessageType mtype; - - iprot_->readMessageBegin(fname, mtype, rseqid); - if (mtype == apache::thrift::protocol::T_EXCEPTION) { - apache::thrift::TApplicationException x; - x.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw x; - } - if (mtype != apache::thrift::protocol::T_REPLY) { - iprot_->skip(apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::INVALID_MESSAGE_TYPE); - } - if (fname.compare("getVersion") != 0) { - iprot_->skip(apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::WRONG_METHOD_NAME); - } - FacebookService_getVersion_presult result; - result.success = &_return; - result.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - - if (result.__isset.success) { - // _return pointer has now been filled - return; - } - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::MISSING_RESULT, "getVersion failed: unknown result"); -} - -fb_status FacebookServiceClient::getStatus() -{ - send_getStatus(); - return recv_getStatus(); -} - -void FacebookServiceClient::send_getStatus() -{ - int32_t cseqid = 0; - oprot_->writeMessageBegin("getStatus", apache::thrift::protocol::T_CALL, cseqid); - - FacebookService_getStatus_pargs args; - args.write(oprot_); - - oprot_->writeMessageEnd(); - oprot_->getTransport()->flush(); - oprot_->getTransport()->writeEnd(); -} - -fb_status FacebookServiceClient::recv_getStatus() -{ - - int32_t rseqid = 0; - std::string fname; - apache::thrift::protocol::TMessageType mtype; - - iprot_->readMessageBegin(fname, mtype, rseqid); - if (mtype == apache::thrift::protocol::T_EXCEPTION) { - apache::thrift::TApplicationException x; - x.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw x; - } - if (mtype != apache::thrift::protocol::T_REPLY) { - iprot_->skip(apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::INVALID_MESSAGE_TYPE); - } - if (fname.compare("getStatus") != 0) { - iprot_->skip(apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::WRONG_METHOD_NAME); - } - fb_status _return; - FacebookService_getStatus_presult result; - result.success = &_return; - result.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - - if (result.__isset.success) { - return _return; - } - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::MISSING_RESULT, "getStatus failed: unknown result"); -} - -void FacebookServiceClient::getStatusDetails(std::string& _return) -{ - send_getStatusDetails(); - recv_getStatusDetails(_return); -} - -void FacebookServiceClient::send_getStatusDetails() -{ - int32_t cseqid = 0; - oprot_->writeMessageBegin("getStatusDetails", apache::thrift::protocol::T_CALL, cseqid); - - FacebookService_getStatusDetails_pargs args; - args.write(oprot_); - - oprot_->writeMessageEnd(); - oprot_->getTransport()->flush(); - oprot_->getTransport()->writeEnd(); -} - -void FacebookServiceClient::recv_getStatusDetails(std::string& _return) -{ - - int32_t rseqid = 0; - std::string fname; - apache::thrift::protocol::TMessageType mtype; - - iprot_->readMessageBegin(fname, mtype, rseqid); - if (mtype == apache::thrift::protocol::T_EXCEPTION) { - apache::thrift::TApplicationException x; - x.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw x; - } - if (mtype != apache::thrift::protocol::T_REPLY) { - iprot_->skip(apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::INVALID_MESSAGE_TYPE); - } - if (fname.compare("getStatusDetails") != 0) { - iprot_->skip(apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::WRONG_METHOD_NAME); - } - FacebookService_getStatusDetails_presult result; - result.success = &_return; - result.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - - if (result.__isset.success) { - // _return pointer has now been filled - return; - } - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::MISSING_RESULT, "getStatusDetails failed: unknown result"); -} - -void FacebookServiceClient::getCounters(std::map & _return) -{ - send_getCounters(); - recv_getCounters(_return); -} - -void FacebookServiceClient::send_getCounters() -{ - int32_t cseqid = 0; - oprot_->writeMessageBegin("getCounters", apache::thrift::protocol::T_CALL, cseqid); - - FacebookService_getCounters_pargs args; - args.write(oprot_); - - oprot_->writeMessageEnd(); - oprot_->getTransport()->flush(); - oprot_->getTransport()->writeEnd(); -} - -void FacebookServiceClient::recv_getCounters(std::map & _return) -{ - - int32_t rseqid = 0; - std::string fname; - apache::thrift::protocol::TMessageType mtype; - - iprot_->readMessageBegin(fname, mtype, rseqid); - if (mtype == apache::thrift::protocol::T_EXCEPTION) { - apache::thrift::TApplicationException x; - x.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw x; - } - if (mtype != apache::thrift::protocol::T_REPLY) { - iprot_->skip(apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::INVALID_MESSAGE_TYPE); - } - if (fname.compare("getCounters") != 0) { - iprot_->skip(apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::WRONG_METHOD_NAME); - } - FacebookService_getCounters_presult result; - result.success = &_return; - result.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - - if (result.__isset.success) { - // _return pointer has now been filled - return; - } - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::MISSING_RESULT, "getCounters failed: unknown result"); -} - -int64_t FacebookServiceClient::getCounter(const std::string& key) -{ - send_getCounter(key); - return recv_getCounter(); -} - -void FacebookServiceClient::send_getCounter(const std::string& key) -{ - int32_t cseqid = 0; - oprot_->writeMessageBegin("getCounter", apache::thrift::protocol::T_CALL, cseqid); - - FacebookService_getCounter_pargs args; - args.key = &key; - args.write(oprot_); - - oprot_->writeMessageEnd(); - oprot_->getTransport()->flush(); - oprot_->getTransport()->writeEnd(); -} - -int64_t FacebookServiceClient::recv_getCounter() -{ - - int32_t rseqid = 0; - std::string fname; - apache::thrift::protocol::TMessageType mtype; - - iprot_->readMessageBegin(fname, mtype, rseqid); - if (mtype == apache::thrift::protocol::T_EXCEPTION) { - apache::thrift::TApplicationException x; - x.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw x; - } - if (mtype != apache::thrift::protocol::T_REPLY) { - iprot_->skip(apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::INVALID_MESSAGE_TYPE); - } - if (fname.compare("getCounter") != 0) { - iprot_->skip(apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::WRONG_METHOD_NAME); - } - int64_t _return; - FacebookService_getCounter_presult result; - result.success = &_return; - result.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - - if (result.__isset.success) { - return _return; - } - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::MISSING_RESULT, "getCounter failed: unknown result"); -} - -void FacebookServiceClient::setOption(const std::string& key, const std::string& value) -{ - send_setOption(key, value); - recv_setOption(); -} - -void FacebookServiceClient::send_setOption(const std::string& key, const std::string& value) -{ - int32_t cseqid = 0; - oprot_->writeMessageBegin("setOption", apache::thrift::protocol::T_CALL, cseqid); - - FacebookService_setOption_pargs args; - args.key = &key; - args.value = &value; - args.write(oprot_); - - oprot_->writeMessageEnd(); - oprot_->getTransport()->flush(); - oprot_->getTransport()->writeEnd(); -} - -void FacebookServiceClient::recv_setOption() -{ - - int32_t rseqid = 0; - std::string fname; - apache::thrift::protocol::TMessageType mtype; - - iprot_->readMessageBegin(fname, mtype, rseqid); - if (mtype == apache::thrift::protocol::T_EXCEPTION) { - apache::thrift::TApplicationException x; - x.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw x; - } - if (mtype != apache::thrift::protocol::T_REPLY) { - iprot_->skip(apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::INVALID_MESSAGE_TYPE); - } - if (fname.compare("setOption") != 0) { - iprot_->skip(apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::WRONG_METHOD_NAME); - } - FacebookService_setOption_presult result; - result.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - - return; -} - -void FacebookServiceClient::getOption(std::string& _return, const std::string& key) -{ - send_getOption(key); - recv_getOption(_return); -} - -void FacebookServiceClient::send_getOption(const std::string& key) -{ - int32_t cseqid = 0; - oprot_->writeMessageBegin("getOption", apache::thrift::protocol::T_CALL, cseqid); - - FacebookService_getOption_pargs args; - args.key = &key; - args.write(oprot_); - - oprot_->writeMessageEnd(); - oprot_->getTransport()->flush(); - oprot_->getTransport()->writeEnd(); -} - -void FacebookServiceClient::recv_getOption(std::string& _return) -{ - - int32_t rseqid = 0; - std::string fname; - apache::thrift::protocol::TMessageType mtype; - - iprot_->readMessageBegin(fname, mtype, rseqid); - if (mtype == apache::thrift::protocol::T_EXCEPTION) { - apache::thrift::TApplicationException x; - x.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw x; - } - if (mtype != apache::thrift::protocol::T_REPLY) { - iprot_->skip(apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::INVALID_MESSAGE_TYPE); - } - if (fname.compare("getOption") != 0) { - iprot_->skip(apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::WRONG_METHOD_NAME); - } - FacebookService_getOption_presult result; - result.success = &_return; - result.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - - if (result.__isset.success) { - // _return pointer has now been filled - return; - } - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::MISSING_RESULT, "getOption failed: unknown result"); -} - -void FacebookServiceClient::getOptions(std::map & _return) -{ - send_getOptions(); - recv_getOptions(_return); -} - -void FacebookServiceClient::send_getOptions() -{ - int32_t cseqid = 0; - oprot_->writeMessageBegin("getOptions", apache::thrift::protocol::T_CALL, cseqid); - - FacebookService_getOptions_pargs args; - args.write(oprot_); - - oprot_->writeMessageEnd(); - oprot_->getTransport()->flush(); - oprot_->getTransport()->writeEnd(); -} - -void FacebookServiceClient::recv_getOptions(std::map & _return) -{ - - int32_t rseqid = 0; - std::string fname; - apache::thrift::protocol::TMessageType mtype; - - iprot_->readMessageBegin(fname, mtype, rseqid); - if (mtype == apache::thrift::protocol::T_EXCEPTION) { - apache::thrift::TApplicationException x; - x.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw x; - } - if (mtype != apache::thrift::protocol::T_REPLY) { - iprot_->skip(apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::INVALID_MESSAGE_TYPE); - } - if (fname.compare("getOptions") != 0) { - iprot_->skip(apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::WRONG_METHOD_NAME); - } - FacebookService_getOptions_presult result; - result.success = &_return; - result.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - - if (result.__isset.success) { - // _return pointer has now been filled - return; - } - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::MISSING_RESULT, "getOptions failed: unknown result"); -} - -void FacebookServiceClient::getCpuProfile(std::string& _return, const int32_t profileDurationInSec) -{ - send_getCpuProfile(profileDurationInSec); - recv_getCpuProfile(_return); -} - -void FacebookServiceClient::send_getCpuProfile(const int32_t profileDurationInSec) -{ - int32_t cseqid = 0; - oprot_->writeMessageBegin("getCpuProfile", apache::thrift::protocol::T_CALL, cseqid); - - FacebookService_getCpuProfile_pargs args; - args.profileDurationInSec = &profileDurationInSec; - args.write(oprot_); - - oprot_->writeMessageEnd(); - oprot_->getTransport()->flush(); - oprot_->getTransport()->writeEnd(); -} - -void FacebookServiceClient::recv_getCpuProfile(std::string& _return) -{ - - int32_t rseqid = 0; - std::string fname; - apache::thrift::protocol::TMessageType mtype; - - iprot_->readMessageBegin(fname, mtype, rseqid); - if (mtype == apache::thrift::protocol::T_EXCEPTION) { - apache::thrift::TApplicationException x; - x.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw x; - } - if (mtype != apache::thrift::protocol::T_REPLY) { - iprot_->skip(apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::INVALID_MESSAGE_TYPE); - } - if (fname.compare("getCpuProfile") != 0) { - iprot_->skip(apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::WRONG_METHOD_NAME); - } - FacebookService_getCpuProfile_presult result; - result.success = &_return; - result.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - - if (result.__isset.success) { - // _return pointer has now been filled - return; - } - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::MISSING_RESULT, "getCpuProfile failed: unknown result"); -} - -int64_t FacebookServiceClient::aliveSince() -{ - send_aliveSince(); - return recv_aliveSince(); -} - -void FacebookServiceClient::send_aliveSince() -{ - int32_t cseqid = 0; - oprot_->writeMessageBegin("aliveSince", apache::thrift::protocol::T_CALL, cseqid); - - FacebookService_aliveSince_pargs args; - args.write(oprot_); - - oprot_->writeMessageEnd(); - oprot_->getTransport()->flush(); - oprot_->getTransport()->writeEnd(); -} - -int64_t FacebookServiceClient::recv_aliveSince() -{ - - int32_t rseqid = 0; - std::string fname; - apache::thrift::protocol::TMessageType mtype; - - iprot_->readMessageBegin(fname, mtype, rseqid); - if (mtype == apache::thrift::protocol::T_EXCEPTION) { - apache::thrift::TApplicationException x; - x.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw x; - } - if (mtype != apache::thrift::protocol::T_REPLY) { - iprot_->skip(apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::INVALID_MESSAGE_TYPE); - } - if (fname.compare("aliveSince") != 0) { - iprot_->skip(apache::thrift::protocol::T_STRUCT); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::WRONG_METHOD_NAME); - } - int64_t _return; - FacebookService_aliveSince_presult result; - result.success = &_return; - result.read(iprot_); - iprot_->readMessageEnd(); - iprot_->getTransport()->readEnd(); - - if (result.__isset.success) { - return _return; - } - throw apache::thrift::TApplicationException(apache::thrift::TApplicationException::MISSING_RESULT, "aliveSince failed: unknown result"); -} - -void FacebookServiceClient::reinitialize() -{ - send_reinitialize(); -} - -void FacebookServiceClient::send_reinitialize() -{ - int32_t cseqid = 0; - oprot_->writeMessageBegin("reinitialize", apache::thrift::protocol::T_CALL, cseqid); - - FacebookService_reinitialize_pargs args; - args.write(oprot_); - - oprot_->writeMessageEnd(); - oprot_->getTransport()->flush(); - oprot_->getTransport()->writeEnd(); -} - -void FacebookServiceClient::shutdown() -{ - send_shutdown(); -} - -void FacebookServiceClient::send_shutdown() -{ - int32_t cseqid = 0; - oprot_->writeMessageBegin("shutdown", apache::thrift::protocol::T_CALL, cseqid); - - FacebookService_shutdown_pargs args; - args.write(oprot_); - - oprot_->writeMessageEnd(); - oprot_->getTransport()->flush(); - oprot_->getTransport()->writeEnd(); -} - -bool FacebookServiceProcessor::process(boost::shared_ptr piprot, boost::shared_ptr poprot) { - - apache::thrift::protocol::TProtocol* iprot = piprot.get(); - apache::thrift::protocol::TProtocol* oprot = poprot.get(); - std::string fname; - apache::thrift::protocol::TMessageType mtype; - int32_t seqid; - - iprot->readMessageBegin(fname, mtype, seqid); - - if (mtype != apache::thrift::protocol::T_CALL && mtype != apache::thrift::protocol::T_ONEWAY) { - iprot->skip(apache::thrift::protocol::T_STRUCT); - iprot->readMessageEnd(); - iprot->getTransport()->readEnd(); - apache::thrift::TApplicationException x(apache::thrift::TApplicationException::INVALID_MESSAGE_TYPE); - oprot->writeMessageBegin(fname, apache::thrift::protocol::T_EXCEPTION, seqid); - x.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->flush(); - oprot->getTransport()->writeEnd(); - return true; - } - - return process_fn(iprot, oprot, fname, seqid); -} - -bool FacebookServiceProcessor::process_fn(apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot, std::string& fname, int32_t seqid) { - std::map::iterator pfn; - pfn = processMap_.find(fname); - if (pfn == processMap_.end()) { - iprot->skip(apache::thrift::protocol::T_STRUCT); - iprot->readMessageEnd(); - iprot->getTransport()->readEnd(); - apache::thrift::TApplicationException x(apache::thrift::TApplicationException::UNKNOWN_METHOD, "Invalid method name: '"+fname+"'"); - oprot->writeMessageBegin(fname, apache::thrift::protocol::T_EXCEPTION, seqid); - x.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->flush(); - oprot->getTransport()->writeEnd(); - return true; - } - (this->*(pfn->second))(seqid, iprot, oprot); - return true; -} - -void FacebookServiceProcessor::process_getName(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot) -{ - FacebookService_getName_args args; - args.read(iprot); - iprot->readMessageEnd(); - iprot->getTransport()->readEnd(); - - FacebookService_getName_result result; - try { - iface_->getName(result.success); - result.__isset.success = true; - } catch (const std::exception& e) { - apache::thrift::TApplicationException x(e.what()); - oprot->writeMessageBegin("getName", apache::thrift::protocol::T_EXCEPTION, seqid); - x.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->flush(); - oprot->getTransport()->writeEnd(); - return; - } - - oprot->writeMessageBegin("getName", apache::thrift::protocol::T_REPLY, seqid); - result.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->flush(); - oprot->getTransport()->writeEnd(); -} - -void FacebookServiceProcessor::process_getVersion(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot) -{ - FacebookService_getVersion_args args; - args.read(iprot); - iprot->readMessageEnd(); - iprot->getTransport()->readEnd(); - - FacebookService_getVersion_result result; - try { - iface_->getVersion(result.success); - result.__isset.success = true; - } catch (const std::exception& e) { - apache::thrift::TApplicationException x(e.what()); - oprot->writeMessageBegin("getVersion", apache::thrift::protocol::T_EXCEPTION, seqid); - x.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->flush(); - oprot->getTransport()->writeEnd(); - return; - } - - oprot->writeMessageBegin("getVersion", apache::thrift::protocol::T_REPLY, seqid); - result.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->flush(); - oprot->getTransport()->writeEnd(); -} - -void FacebookServiceProcessor::process_getStatus(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot) -{ - FacebookService_getStatus_args args; - args.read(iprot); - iprot->readMessageEnd(); - iprot->getTransport()->readEnd(); - - FacebookService_getStatus_result result; - try { - result.success = iface_->getStatus(); - result.__isset.success = true; - } catch (const std::exception& e) { - apache::thrift::TApplicationException x(e.what()); - oprot->writeMessageBegin("getStatus", apache::thrift::protocol::T_EXCEPTION, seqid); - x.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->flush(); - oprot->getTransport()->writeEnd(); - return; - } - - oprot->writeMessageBegin("getStatus", apache::thrift::protocol::T_REPLY, seqid); - result.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->flush(); - oprot->getTransport()->writeEnd(); -} - -void FacebookServiceProcessor::process_getStatusDetails(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot) -{ - FacebookService_getStatusDetails_args args; - args.read(iprot); - iprot->readMessageEnd(); - iprot->getTransport()->readEnd(); - - FacebookService_getStatusDetails_result result; - try { - iface_->getStatusDetails(result.success); - result.__isset.success = true; - } catch (const std::exception& e) { - apache::thrift::TApplicationException x(e.what()); - oprot->writeMessageBegin("getStatusDetails", apache::thrift::protocol::T_EXCEPTION, seqid); - x.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->flush(); - oprot->getTransport()->writeEnd(); - return; - } - - oprot->writeMessageBegin("getStatusDetails", apache::thrift::protocol::T_REPLY, seqid); - result.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->flush(); - oprot->getTransport()->writeEnd(); -} - -void FacebookServiceProcessor::process_getCounters(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot) -{ - FacebookService_getCounters_args args; - args.read(iprot); - iprot->readMessageEnd(); - iprot->getTransport()->readEnd(); - - FacebookService_getCounters_result result; - try { - iface_->getCounters(result.success); - result.__isset.success = true; - } catch (const std::exception& e) { - apache::thrift::TApplicationException x(e.what()); - oprot->writeMessageBegin("getCounters", apache::thrift::protocol::T_EXCEPTION, seqid); - x.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->flush(); - oprot->getTransport()->writeEnd(); - return; - } - - oprot->writeMessageBegin("getCounters", apache::thrift::protocol::T_REPLY, seqid); - result.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->flush(); - oprot->getTransport()->writeEnd(); -} - -void FacebookServiceProcessor::process_getCounter(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot) -{ - FacebookService_getCounter_args args; - args.read(iprot); - iprot->readMessageEnd(); - iprot->getTransport()->readEnd(); - - FacebookService_getCounter_result result; - try { - result.success = iface_->getCounter(args.key); - result.__isset.success = true; - } catch (const std::exception& e) { - apache::thrift::TApplicationException x(e.what()); - oprot->writeMessageBegin("getCounter", apache::thrift::protocol::T_EXCEPTION, seqid); - x.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->flush(); - oprot->getTransport()->writeEnd(); - return; - } - - oprot->writeMessageBegin("getCounter", apache::thrift::protocol::T_REPLY, seqid); - result.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->flush(); - oprot->getTransport()->writeEnd(); -} - -void FacebookServiceProcessor::process_setOption(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot) -{ - FacebookService_setOption_args args; - args.read(iprot); - iprot->readMessageEnd(); - iprot->getTransport()->readEnd(); - - FacebookService_setOption_result result; - try { - iface_->setOption(args.key, args.value); - } catch (const std::exception& e) { - apache::thrift::TApplicationException x(e.what()); - oprot->writeMessageBegin("setOption", apache::thrift::protocol::T_EXCEPTION, seqid); - x.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->flush(); - oprot->getTransport()->writeEnd(); - return; - } - - oprot->writeMessageBegin("setOption", apache::thrift::protocol::T_REPLY, seqid); - result.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->flush(); - oprot->getTransport()->writeEnd(); -} - -void FacebookServiceProcessor::process_getOption(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot) -{ - FacebookService_getOption_args args; - args.read(iprot); - iprot->readMessageEnd(); - iprot->getTransport()->readEnd(); - - FacebookService_getOption_result result; - try { - iface_->getOption(result.success, args.key); - result.__isset.success = true; - } catch (const std::exception& e) { - apache::thrift::TApplicationException x(e.what()); - oprot->writeMessageBegin("getOption", apache::thrift::protocol::T_EXCEPTION, seqid); - x.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->flush(); - oprot->getTransport()->writeEnd(); - return; - } - - oprot->writeMessageBegin("getOption", apache::thrift::protocol::T_REPLY, seqid); - result.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->flush(); - oprot->getTransport()->writeEnd(); -} - -void FacebookServiceProcessor::process_getOptions(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot) -{ - FacebookService_getOptions_args args; - args.read(iprot); - iprot->readMessageEnd(); - iprot->getTransport()->readEnd(); - - FacebookService_getOptions_result result; - try { - iface_->getOptions(result.success); - result.__isset.success = true; - } catch (const std::exception& e) { - apache::thrift::TApplicationException x(e.what()); - oprot->writeMessageBegin("getOptions", apache::thrift::protocol::T_EXCEPTION, seqid); - x.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->flush(); - oprot->getTransport()->writeEnd(); - return; - } - - oprot->writeMessageBegin("getOptions", apache::thrift::protocol::T_REPLY, seqid); - result.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->flush(); - oprot->getTransport()->writeEnd(); -} - -void FacebookServiceProcessor::process_getCpuProfile(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot) -{ - FacebookService_getCpuProfile_args args; - args.read(iprot); - iprot->readMessageEnd(); - iprot->getTransport()->readEnd(); - - FacebookService_getCpuProfile_result result; - try { - iface_->getCpuProfile(result.success, args.profileDurationInSec); - result.__isset.success = true; - } catch (const std::exception& e) { - apache::thrift::TApplicationException x(e.what()); - oprot->writeMessageBegin("getCpuProfile", apache::thrift::protocol::T_EXCEPTION, seqid); - x.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->flush(); - oprot->getTransport()->writeEnd(); - return; - } - - oprot->writeMessageBegin("getCpuProfile", apache::thrift::protocol::T_REPLY, seqid); - result.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->flush(); - oprot->getTransport()->writeEnd(); -} - -void FacebookServiceProcessor::process_aliveSince(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot) -{ - FacebookService_aliveSince_args args; - args.read(iprot); - iprot->readMessageEnd(); - iprot->getTransport()->readEnd(); - - FacebookService_aliveSince_result result; - try { - result.success = iface_->aliveSince(); - result.__isset.success = true; - } catch (const std::exception& e) { - apache::thrift::TApplicationException x(e.what()); - oprot->writeMessageBegin("aliveSince", apache::thrift::protocol::T_EXCEPTION, seqid); - x.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->flush(); - oprot->getTransport()->writeEnd(); - return; - } - - oprot->writeMessageBegin("aliveSince", apache::thrift::protocol::T_REPLY, seqid); - result.write(oprot); - oprot->writeMessageEnd(); - oprot->getTransport()->flush(); - oprot->getTransport()->writeEnd(); -} - -void FacebookServiceProcessor::process_reinitialize(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot) -{ - FacebookService_reinitialize_args args; - args.read(iprot); - iprot->readMessageEnd(); - iprot->getTransport()->readEnd(); - - try { - iface_->reinitialize(); - } catch (const std::exception& e) { - } - return; -} - -void FacebookServiceProcessor::process_shutdown(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot) -{ - FacebookService_shutdown_args args; - args.read(iprot); - iprot->readMessageEnd(); - iprot->getTransport()->readEnd(); - - try { - iface_->shutdown(); - } catch (const std::exception& e) { - } - return; -} - -}} // namespace - diff --git service/include/thrift/fb303/FacebookService.h service/include/thrift/fb303/FacebookService.h deleted file mode 100644 index dcd843f..0000000 --- service/include/thrift/fb303/FacebookService.h +++ /dev/null @@ -1,1359 +0,0 @@ -/** - * Autogenerated by Thrift - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - */ -#ifndef FacebookService_H -#define FacebookService_H - -#include -#include "fb303_types.h" - -namespace facebook { namespace fb303 { - -class FacebookServiceIf { - public: - virtual ~FacebookServiceIf() {} - virtual void getName(std::string& _return) = 0; - virtual void getVersion(std::string& _return) = 0; - virtual fb_status getStatus() = 0; - virtual void getStatusDetails(std::string& _return) = 0; - virtual void getCounters(std::map & _return) = 0; - virtual int64_t getCounter(const std::string& key) = 0; - virtual void setOption(const std::string& key, const std::string& value) = 0; - virtual void getOption(std::string& _return, const std::string& key) = 0; - virtual void getOptions(std::map & _return) = 0; - virtual void getCpuProfile(std::string& _return, const int32_t profileDurationInSec) = 0; - virtual int64_t aliveSince() = 0; - virtual void reinitialize() = 0; - virtual void shutdown() = 0; -}; - -class FacebookServiceNull : virtual public FacebookServiceIf { - public: - virtual ~FacebookServiceNull() {} - void getName(std::string& /* _return */) { - return; - } - void getVersion(std::string& /* _return */) { - return; - } - fb_status getStatus() { - fb_status _return = (fb_status)0; - return _return; - } - void getStatusDetails(std::string& /* _return */) { - return; - } - void getCounters(std::map & /* _return */) { - return; - } - int64_t getCounter(const std::string& /* key */) { - int64_t _return = 0; - return _return; - } - void setOption(const std::string& /* key */, const std::string& /* value */) { - return; - } - void getOption(std::string& /* _return */, const std::string& /* key */) { - return; - } - void getOptions(std::map & /* _return */) { - return; - } - void getCpuProfile(std::string& /* _return */, const int32_t /* profileDurationInSec */) { - return; - } - int64_t aliveSince() { - int64_t _return = 0; - return _return; - } - void reinitialize() { - return; - } - void shutdown() { - return; - } -}; - -class FacebookService_getName_args { - public: - - FacebookService_getName_args() { - } - - virtual ~FacebookService_getName_args() throw() {} - - - bool operator == (const FacebookService_getName_args & /* rhs */) const - { - return true; - } - bool operator != (const FacebookService_getName_args &rhs) const { - return !(*this == rhs); - } - - bool operator < (const FacebookService_getName_args & ) const; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_getName_pargs { - public: - - - virtual ~FacebookService_getName_pargs() throw() {} - - - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_getName_result { - public: - - FacebookService_getName_result() : success("") { - } - - virtual ~FacebookService_getName_result() throw() {} - - std::string success; - - struct __isset { - __isset() : success(false) {} - bool success; - } __isset; - - bool operator == (const FacebookService_getName_result & rhs) const - { - if (!(success == rhs.success)) - return false; - return true; - } - bool operator != (const FacebookService_getName_result &rhs) const { - return !(*this == rhs); - } - - bool operator < (const FacebookService_getName_result & ) const; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_getName_presult { - public: - - - virtual ~FacebookService_getName_presult() throw() {} - - std::string* success; - - struct __isset { - __isset() : success(false) {} - bool success; - } __isset; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - -}; - -class FacebookService_getVersion_args { - public: - - FacebookService_getVersion_args() { - } - - virtual ~FacebookService_getVersion_args() throw() {} - - - bool operator == (const FacebookService_getVersion_args & /* rhs */) const - { - return true; - } - bool operator != (const FacebookService_getVersion_args &rhs) const { - return !(*this == rhs); - } - - bool operator < (const FacebookService_getVersion_args & ) const; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_getVersion_pargs { - public: - - - virtual ~FacebookService_getVersion_pargs() throw() {} - - - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_getVersion_result { - public: - - FacebookService_getVersion_result() : success("") { - } - - virtual ~FacebookService_getVersion_result() throw() {} - - std::string success; - - struct __isset { - __isset() : success(false) {} - bool success; - } __isset; - - bool operator == (const FacebookService_getVersion_result & rhs) const - { - if (!(success == rhs.success)) - return false; - return true; - } - bool operator != (const FacebookService_getVersion_result &rhs) const { - return !(*this == rhs); - } - - bool operator < (const FacebookService_getVersion_result & ) const; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_getVersion_presult { - public: - - - virtual ~FacebookService_getVersion_presult() throw() {} - - std::string* success; - - struct __isset { - __isset() : success(false) {} - bool success; - } __isset; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - -}; - -class FacebookService_getStatus_args { - public: - - FacebookService_getStatus_args() { - } - - virtual ~FacebookService_getStatus_args() throw() {} - - - bool operator == (const FacebookService_getStatus_args & /* rhs */) const - { - return true; - } - bool operator != (const FacebookService_getStatus_args &rhs) const { - return !(*this == rhs); - } - - bool operator < (const FacebookService_getStatus_args & ) const; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_getStatus_pargs { - public: - - - virtual ~FacebookService_getStatus_pargs() throw() {} - - - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_getStatus_result { - public: - - FacebookService_getStatus_result() { - } - - virtual ~FacebookService_getStatus_result() throw() {} - - fb_status success; - - struct __isset { - __isset() : success(false) {} - bool success; - } __isset; - - bool operator == (const FacebookService_getStatus_result & rhs) const - { - if (!(success == rhs.success)) - return false; - return true; - } - bool operator != (const FacebookService_getStatus_result &rhs) const { - return !(*this == rhs); - } - - bool operator < (const FacebookService_getStatus_result & ) const; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_getStatus_presult { - public: - - - virtual ~FacebookService_getStatus_presult() throw() {} - - fb_status* success; - - struct __isset { - __isset() : success(false) {} - bool success; - } __isset; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - -}; - -class FacebookService_getStatusDetails_args { - public: - - FacebookService_getStatusDetails_args() { - } - - virtual ~FacebookService_getStatusDetails_args() throw() {} - - - bool operator == (const FacebookService_getStatusDetails_args & /* rhs */) const - { - return true; - } - bool operator != (const FacebookService_getStatusDetails_args &rhs) const { - return !(*this == rhs); - } - - bool operator < (const FacebookService_getStatusDetails_args & ) const; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_getStatusDetails_pargs { - public: - - - virtual ~FacebookService_getStatusDetails_pargs() throw() {} - - - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_getStatusDetails_result { - public: - - FacebookService_getStatusDetails_result() : success("") { - } - - virtual ~FacebookService_getStatusDetails_result() throw() {} - - std::string success; - - struct __isset { - __isset() : success(false) {} - bool success; - } __isset; - - bool operator == (const FacebookService_getStatusDetails_result & rhs) const - { - if (!(success == rhs.success)) - return false; - return true; - } - bool operator != (const FacebookService_getStatusDetails_result &rhs) const { - return !(*this == rhs); - } - - bool operator < (const FacebookService_getStatusDetails_result & ) const; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_getStatusDetails_presult { - public: - - - virtual ~FacebookService_getStatusDetails_presult() throw() {} - - std::string* success; - - struct __isset { - __isset() : success(false) {} - bool success; - } __isset; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - -}; - -class FacebookService_getCounters_args { - public: - - FacebookService_getCounters_args() { - } - - virtual ~FacebookService_getCounters_args() throw() {} - - - bool operator == (const FacebookService_getCounters_args & /* rhs */) const - { - return true; - } - bool operator != (const FacebookService_getCounters_args &rhs) const { - return !(*this == rhs); - } - - bool operator < (const FacebookService_getCounters_args & ) const; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_getCounters_pargs { - public: - - - virtual ~FacebookService_getCounters_pargs() throw() {} - - - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_getCounters_result { - public: - - FacebookService_getCounters_result() { - } - - virtual ~FacebookService_getCounters_result() throw() {} - - std::map success; - - struct __isset { - __isset() : success(false) {} - bool success; - } __isset; - - bool operator == (const FacebookService_getCounters_result & rhs) const - { - if (!(success == rhs.success)) - return false; - return true; - } - bool operator != (const FacebookService_getCounters_result &rhs) const { - return !(*this == rhs); - } - - bool operator < (const FacebookService_getCounters_result & ) const; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_getCounters_presult { - public: - - - virtual ~FacebookService_getCounters_presult() throw() {} - - std::map * success; - - struct __isset { - __isset() : success(false) {} - bool success; - } __isset; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - -}; - -class FacebookService_getCounter_args { - public: - - FacebookService_getCounter_args() : key("") { - } - - virtual ~FacebookService_getCounter_args() throw() {} - - std::string key; - - struct __isset { - __isset() : key(false) {} - bool key; - } __isset; - - bool operator == (const FacebookService_getCounter_args & rhs) const - { - if (!(key == rhs.key)) - return false; - return true; - } - bool operator != (const FacebookService_getCounter_args &rhs) const { - return !(*this == rhs); - } - - bool operator < (const FacebookService_getCounter_args & ) const; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_getCounter_pargs { - public: - - - virtual ~FacebookService_getCounter_pargs() throw() {} - - const std::string* key; - - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_getCounter_result { - public: - - FacebookService_getCounter_result() : success(0) { - } - - virtual ~FacebookService_getCounter_result() throw() {} - - int64_t success; - - struct __isset { - __isset() : success(false) {} - bool success; - } __isset; - - bool operator == (const FacebookService_getCounter_result & rhs) const - { - if (!(success == rhs.success)) - return false; - return true; - } - bool operator != (const FacebookService_getCounter_result &rhs) const { - return !(*this == rhs); - } - - bool operator < (const FacebookService_getCounter_result & ) const; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_getCounter_presult { - public: - - - virtual ~FacebookService_getCounter_presult() throw() {} - - int64_t* success; - - struct __isset { - __isset() : success(false) {} - bool success; - } __isset; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - -}; - -class FacebookService_setOption_args { - public: - - FacebookService_setOption_args() : key(""), value("") { - } - - virtual ~FacebookService_setOption_args() throw() {} - - std::string key; - std::string value; - - struct __isset { - __isset() : key(false), value(false) {} - bool key; - bool value; - } __isset; - - bool operator == (const FacebookService_setOption_args & rhs) const - { - if (!(key == rhs.key)) - return false; - if (!(value == rhs.value)) - return false; - return true; - } - bool operator != (const FacebookService_setOption_args &rhs) const { - return !(*this == rhs); - } - - bool operator < (const FacebookService_setOption_args & ) const; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_setOption_pargs { - public: - - - virtual ~FacebookService_setOption_pargs() throw() {} - - const std::string* key; - const std::string* value; - - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_setOption_result { - public: - - FacebookService_setOption_result() { - } - - virtual ~FacebookService_setOption_result() throw() {} - - - bool operator == (const FacebookService_setOption_result & /* rhs */) const - { - return true; - } - bool operator != (const FacebookService_setOption_result &rhs) const { - return !(*this == rhs); - } - - bool operator < (const FacebookService_setOption_result & ) const; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_setOption_presult { - public: - - - virtual ~FacebookService_setOption_presult() throw() {} - - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - -}; - -class FacebookService_getOption_args { - public: - - FacebookService_getOption_args() : key("") { - } - - virtual ~FacebookService_getOption_args() throw() {} - - std::string key; - - struct __isset { - __isset() : key(false) {} - bool key; - } __isset; - - bool operator == (const FacebookService_getOption_args & rhs) const - { - if (!(key == rhs.key)) - return false; - return true; - } - bool operator != (const FacebookService_getOption_args &rhs) const { - return !(*this == rhs); - } - - bool operator < (const FacebookService_getOption_args & ) const; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_getOption_pargs { - public: - - - virtual ~FacebookService_getOption_pargs() throw() {} - - const std::string* key; - - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_getOption_result { - public: - - FacebookService_getOption_result() : success("") { - } - - virtual ~FacebookService_getOption_result() throw() {} - - std::string success; - - struct __isset { - __isset() : success(false) {} - bool success; - } __isset; - - bool operator == (const FacebookService_getOption_result & rhs) const - { - if (!(success == rhs.success)) - return false; - return true; - } - bool operator != (const FacebookService_getOption_result &rhs) const { - return !(*this == rhs); - } - - bool operator < (const FacebookService_getOption_result & ) const; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_getOption_presult { - public: - - - virtual ~FacebookService_getOption_presult() throw() {} - - std::string* success; - - struct __isset { - __isset() : success(false) {} - bool success; - } __isset; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - -}; - -class FacebookService_getOptions_args { - public: - - FacebookService_getOptions_args() { - } - - virtual ~FacebookService_getOptions_args() throw() {} - - - bool operator == (const FacebookService_getOptions_args & /* rhs */) const - { - return true; - } - bool operator != (const FacebookService_getOptions_args &rhs) const { - return !(*this == rhs); - } - - bool operator < (const FacebookService_getOptions_args & ) const; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_getOptions_pargs { - public: - - - virtual ~FacebookService_getOptions_pargs() throw() {} - - - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_getOptions_result { - public: - - FacebookService_getOptions_result() { - } - - virtual ~FacebookService_getOptions_result() throw() {} - - std::map success; - - struct __isset { - __isset() : success(false) {} - bool success; - } __isset; - - bool operator == (const FacebookService_getOptions_result & rhs) const - { - if (!(success == rhs.success)) - return false; - return true; - } - bool operator != (const FacebookService_getOptions_result &rhs) const { - return !(*this == rhs); - } - - bool operator < (const FacebookService_getOptions_result & ) const; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_getOptions_presult { - public: - - - virtual ~FacebookService_getOptions_presult() throw() {} - - std::map * success; - - struct __isset { - __isset() : success(false) {} - bool success; - } __isset; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - -}; - -class FacebookService_getCpuProfile_args { - public: - - FacebookService_getCpuProfile_args() : profileDurationInSec(0) { - } - - virtual ~FacebookService_getCpuProfile_args() throw() {} - - int32_t profileDurationInSec; - - struct __isset { - __isset() : profileDurationInSec(false) {} - bool profileDurationInSec; - } __isset; - - bool operator == (const FacebookService_getCpuProfile_args & rhs) const - { - if (!(profileDurationInSec == rhs.profileDurationInSec)) - return false; - return true; - } - bool operator != (const FacebookService_getCpuProfile_args &rhs) const { - return !(*this == rhs); - } - - bool operator < (const FacebookService_getCpuProfile_args & ) const; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_getCpuProfile_pargs { - public: - - - virtual ~FacebookService_getCpuProfile_pargs() throw() {} - - const int32_t* profileDurationInSec; - - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_getCpuProfile_result { - public: - - FacebookService_getCpuProfile_result() : success("") { - } - - virtual ~FacebookService_getCpuProfile_result() throw() {} - - std::string success; - - struct __isset { - __isset() : success(false) {} - bool success; - } __isset; - - bool operator == (const FacebookService_getCpuProfile_result & rhs) const - { - if (!(success == rhs.success)) - return false; - return true; - } - bool operator != (const FacebookService_getCpuProfile_result &rhs) const { - return !(*this == rhs); - } - - bool operator < (const FacebookService_getCpuProfile_result & ) const; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_getCpuProfile_presult { - public: - - - virtual ~FacebookService_getCpuProfile_presult() throw() {} - - std::string* success; - - struct __isset { - __isset() : success(false) {} - bool success; - } __isset; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - -}; - -class FacebookService_aliveSince_args { - public: - - FacebookService_aliveSince_args() { - } - - virtual ~FacebookService_aliveSince_args() throw() {} - - - bool operator == (const FacebookService_aliveSince_args & /* rhs */) const - { - return true; - } - bool operator != (const FacebookService_aliveSince_args &rhs) const { - return !(*this == rhs); - } - - bool operator < (const FacebookService_aliveSince_args & ) const; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_aliveSince_pargs { - public: - - - virtual ~FacebookService_aliveSince_pargs() throw() {} - - - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_aliveSince_result { - public: - - FacebookService_aliveSince_result() : success(0) { - } - - virtual ~FacebookService_aliveSince_result() throw() {} - - int64_t success; - - struct __isset { - __isset() : success(false) {} - bool success; - } __isset; - - bool operator == (const FacebookService_aliveSince_result & rhs) const - { - if (!(success == rhs.success)) - return false; - return true; - } - bool operator != (const FacebookService_aliveSince_result &rhs) const { - return !(*this == rhs); - } - - bool operator < (const FacebookService_aliveSince_result & ) const; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_aliveSince_presult { - public: - - - virtual ~FacebookService_aliveSince_presult() throw() {} - - int64_t* success; - - struct __isset { - __isset() : success(false) {} - bool success; - } __isset; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - -}; - -class FacebookService_reinitialize_args { - public: - - FacebookService_reinitialize_args() { - } - - virtual ~FacebookService_reinitialize_args() throw() {} - - - bool operator == (const FacebookService_reinitialize_args & /* rhs */) const - { - return true; - } - bool operator != (const FacebookService_reinitialize_args &rhs) const { - return !(*this == rhs); - } - - bool operator < (const FacebookService_reinitialize_args & ) const; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_reinitialize_pargs { - public: - - - virtual ~FacebookService_reinitialize_pargs() throw() {} - - - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_shutdown_args { - public: - - FacebookService_shutdown_args() { - } - - virtual ~FacebookService_shutdown_args() throw() {} - - - bool operator == (const FacebookService_shutdown_args & /* rhs */) const - { - return true; - } - bool operator != (const FacebookService_shutdown_args &rhs) const { - return !(*this == rhs); - } - - bool operator < (const FacebookService_shutdown_args & ) const; - - uint32_t read(apache::thrift::protocol::TProtocol* iprot); - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookService_shutdown_pargs { - public: - - - virtual ~FacebookService_shutdown_pargs() throw() {} - - - uint32_t write(apache::thrift::protocol::TProtocol* oprot) const; - -}; - -class FacebookServiceClient : virtual public FacebookServiceIf { - public: - FacebookServiceClient(boost::shared_ptr prot) : - piprot_(prot), - poprot_(prot) { - iprot_ = prot.get(); - oprot_ = prot.get(); - } - FacebookServiceClient(boost::shared_ptr iprot, boost::shared_ptr oprot) : - piprot_(iprot), - poprot_(oprot) { - iprot_ = iprot.get(); - oprot_ = oprot.get(); - } - boost::shared_ptr getInputProtocol() { - return piprot_; - } - boost::shared_ptr getOutputProtocol() { - return poprot_; - } - void getName(std::string& _return); - void send_getName(); - void recv_getName(std::string& _return); - void getVersion(std::string& _return); - void send_getVersion(); - void recv_getVersion(std::string& _return); - fb_status getStatus(); - void send_getStatus(); - fb_status recv_getStatus(); - void getStatusDetails(std::string& _return); - void send_getStatusDetails(); - void recv_getStatusDetails(std::string& _return); - void getCounters(std::map & _return); - void send_getCounters(); - void recv_getCounters(std::map & _return); - int64_t getCounter(const std::string& key); - void send_getCounter(const std::string& key); - int64_t recv_getCounter(); - void setOption(const std::string& key, const std::string& value); - void send_setOption(const std::string& key, const std::string& value); - void recv_setOption(); - void getOption(std::string& _return, const std::string& key); - void send_getOption(const std::string& key); - void recv_getOption(std::string& _return); - void getOptions(std::map & _return); - void send_getOptions(); - void recv_getOptions(std::map & _return); - void getCpuProfile(std::string& _return, const int32_t profileDurationInSec); - void send_getCpuProfile(const int32_t profileDurationInSec); - void recv_getCpuProfile(std::string& _return); - int64_t aliveSince(); - void send_aliveSince(); - int64_t recv_aliveSince(); - void reinitialize(); - void send_reinitialize(); - void shutdown(); - void send_shutdown(); - protected: - boost::shared_ptr piprot_; - boost::shared_ptr poprot_; - apache::thrift::protocol::TProtocol* iprot_; - apache::thrift::protocol::TProtocol* oprot_; -}; - -class FacebookServiceProcessor : virtual public apache::thrift::TProcessor { - protected: - boost::shared_ptr iface_; - virtual bool process_fn(apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot, std::string& fname, int32_t seqid); - private: - std::map processMap_; - void process_getName(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot); - void process_getVersion(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot); - void process_getStatus(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot); - void process_getStatusDetails(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot); - void process_getCounters(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot); - void process_getCounter(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot); - void process_setOption(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot); - void process_getOption(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot); - void process_getOptions(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot); - void process_getCpuProfile(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot); - void process_aliveSince(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot); - void process_reinitialize(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot); - void process_shutdown(int32_t seqid, apache::thrift::protocol::TProtocol* iprot, apache::thrift::protocol::TProtocol* oprot); - public: - FacebookServiceProcessor(boost::shared_ptr iface) : - iface_(iface) { - processMap_["getName"] = &FacebookServiceProcessor::process_getName; - processMap_["getVersion"] = &FacebookServiceProcessor::process_getVersion; - processMap_["getStatus"] = &FacebookServiceProcessor::process_getStatus; - processMap_["getStatusDetails"] = &FacebookServiceProcessor::process_getStatusDetails; - processMap_["getCounters"] = &FacebookServiceProcessor::process_getCounters; - processMap_["getCounter"] = &FacebookServiceProcessor::process_getCounter; - processMap_["setOption"] = &FacebookServiceProcessor::process_setOption; - processMap_["getOption"] = &FacebookServiceProcessor::process_getOption; - processMap_["getOptions"] = &FacebookServiceProcessor::process_getOptions; - processMap_["getCpuProfile"] = &FacebookServiceProcessor::process_getCpuProfile; - processMap_["aliveSince"] = &FacebookServiceProcessor::process_aliveSince; - processMap_["reinitialize"] = &FacebookServiceProcessor::process_reinitialize; - processMap_["shutdown"] = &FacebookServiceProcessor::process_shutdown; - } - - virtual bool process(boost::shared_ptr piprot, boost::shared_ptr poprot); - virtual ~FacebookServiceProcessor() {} -}; - -class FacebookServiceMultiface : virtual public FacebookServiceIf { - public: - FacebookServiceMultiface(std::vector >& ifaces) : ifaces_(ifaces) { - } - virtual ~FacebookServiceMultiface() {} - protected: - std::vector > ifaces_; - FacebookServiceMultiface() {} - void add(boost::shared_ptr iface) { - ifaces_.push_back(iface); - } - public: - void getName(std::string& _return) { - uint32_t sz = ifaces_.size(); - for (uint32_t i = 0; i < sz; ++i) { - if (i == sz - 1) { - ifaces_[i]->getName(_return); - return; - } else { - ifaces_[i]->getName(_return); - } - } - } - - void getVersion(std::string& _return) { - uint32_t sz = ifaces_.size(); - for (uint32_t i = 0; i < sz; ++i) { - if (i == sz - 1) { - ifaces_[i]->getVersion(_return); - return; - } else { - ifaces_[i]->getVersion(_return); - } - } - } - - fb_status getStatus() { - uint32_t sz = ifaces_.size(); - for (uint32_t i = 0; i < sz; ++i) { - if (i == sz - 1) { - return ifaces_[i]->getStatus(); - } else { - ifaces_[i]->getStatus(); - } - } - } - - void getStatusDetails(std::string& _return) { - uint32_t sz = ifaces_.size(); - for (uint32_t i = 0; i < sz; ++i) { - if (i == sz - 1) { - ifaces_[i]->getStatusDetails(_return); - return; - } else { - ifaces_[i]->getStatusDetails(_return); - } - } - } - - void getCounters(std::map & _return) { - uint32_t sz = ifaces_.size(); - for (uint32_t i = 0; i < sz; ++i) { - if (i == sz - 1) { - ifaces_[i]->getCounters(_return); - return; - } else { - ifaces_[i]->getCounters(_return); - } - } - } - - int64_t getCounter(const std::string& key) { - uint32_t sz = ifaces_.size(); - for (uint32_t i = 0; i < sz; ++i) { - if (i == sz - 1) { - return ifaces_[i]->getCounter(key); - } else { - ifaces_[i]->getCounter(key); - } - } - } - - void setOption(const std::string& key, const std::string& value) { - uint32_t sz = ifaces_.size(); - for (uint32_t i = 0; i < sz; ++i) { - ifaces_[i]->setOption(key, value); - } - } - - void getOption(std::string& _return, const std::string& key) { - uint32_t sz = ifaces_.size(); - for (uint32_t i = 0; i < sz; ++i) { - if (i == sz - 1) { - ifaces_[i]->getOption(_return, key); - return; - } else { - ifaces_[i]->getOption(_return, key); - } - } - } - - void getOptions(std::map & _return) { - uint32_t sz = ifaces_.size(); - for (uint32_t i = 0; i < sz; ++i) { - if (i == sz - 1) { - ifaces_[i]->getOptions(_return); - return; - } else { - ifaces_[i]->getOptions(_return); - } - } - } - - void getCpuProfile(std::string& _return, const int32_t profileDurationInSec) { - uint32_t sz = ifaces_.size(); - for (uint32_t i = 0; i < sz; ++i) { - if (i == sz - 1) { - ifaces_[i]->getCpuProfile(_return, profileDurationInSec); - return; - } else { - ifaces_[i]->getCpuProfile(_return, profileDurationInSec); - } - } - } - - int64_t aliveSince() { - uint32_t sz = ifaces_.size(); - for (uint32_t i = 0; i < sz; ++i) { - if (i == sz - 1) { - return ifaces_[i]->aliveSince(); - } else { - ifaces_[i]->aliveSince(); - } - } - } - - void reinitialize() { - uint32_t sz = ifaces_.size(); - for (uint32_t i = 0; i < sz; ++i) { - ifaces_[i]->reinitialize(); - } - } - - void shutdown() { - uint32_t sz = ifaces_.size(); - for (uint32_t i = 0; i < sz; ++i) { - ifaces_[i]->shutdown(); - } - } - -}; - -}} // namespace - -#endif diff --git service/include/thrift/fb303/ServiceTracker.h service/include/thrift/fb303/ServiceTracker.h deleted file mode 100644 index 9304386..0000000 --- service/include/thrift/fb303/ServiceTracker.h +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/** - * ServiceTracker is a utility class for logging and timing service - * calls to a fb303 Thrift server. Currently, ServiceTracker offers - * the following features: - * - * . Logging of service method start, end (and duration), and - * optional steps in between. - * - * . Automatic check of server status via fb303::getStatus() - * with a ServiceException thrown if server not alive - * (at method start). - * - * . A periodic logged checkpoint reporting lifetime time, lifetime - * service count, and per-method statistics since the last checkpoint - * time (at method finish). - * - * . Export of fb303 counters for lifetime and checkpoint statistics - * (at method finish). - * - * . For TThreadPoolServers, a logged warning when all server threads - * are busy (at method start). (Must call setThreadManager() after - * ServiceTracker instantiation for this feature to be enabled.) - * - * Individual features may be enabled or disabled by arguments to the - * constructor. The constructor also accepts a pointer to a logging - * method -- if no pointer is passed, the tracker will log to stdout. - * - * ServiceTracker defines private methods for service start, finish, - * and step, which are designed to be accessed by instantiating a - * friend ServiceMethod object, as in the following example: - * - * #include - * class MyServiceHandler : virtual public MyServiceIf, - * public facebook::fb303::FacebookBase - * { - * public: - * MyServiceHandler::MyServiceHandler() : mServiceTracker(this) {} - * void MyServiceHandler::myServiceMethod(int userId) { - * // note: Instantiating a ServiceMethod object starts a timer - * // and tells the ServiceTracker to log the start. Might throw - * // a ServiceException. - * ServiceMethod serviceMethod(&mServiceTracker, - * "myServiceMethod", - * userId); - * ... - * // note: Calling the step method tells the ServiceTracker to - * // log the step, with a time elapsed since start. - * serviceMethod.step("post parsing, begin processing"); - * ... - * // note: When the ServiceMethod object goes out of scope, the - * // ServiceTracker will log the total elapsed time of the method. - * } - * ... - * private: - * ServiceTracker mServiceTracker; - * } - * - * The step() method call is optional; the startService() and - * finishService() methods are handled by the object's constructor and - * destructor. - * - * The ServiceTracker is (intended to be) thread-safe. - * - * Future: - * - * . Come up with something better for logging than passing a - * function pointer to the constructor. - * - * . Add methods for tracking errors from service methods, e.g. - * ServiceTracker::reportService(). - */ - -#ifndef SERVICETRACKER_H -#define SERVICETRACKER_H - - -#include -#include -#include -#include -#include -#include - -#include "concurrency/Mutex.h" - - -namespace apache { namespace thrift { namespace concurrency { - class ThreadManager; -}}} - - -namespace facebook { namespace fb303 { - - -class FacebookBase; -class ServiceMethod; - - -class Stopwatch -{ -public: - enum Unit { UNIT_SECONDS, UNIT_MILLISECONDS, UNIT_MICROSECONDS }; - Stopwatch(); - uint64_t elapsedUnits(Unit unit, std::string *label = NULL) const; - void reset(); -private: - timeval startTime_; -}; - - -class ServiceTracker -{ - friend class ServiceMethod; - -public: - - static uint64_t CHECKPOINT_MINIMUM_INTERVAL_SECONDS; - static int LOG_LEVEL; - - ServiceTracker(facebook::fb303::FacebookBase *handler, - void (*logMethod)(int, const std::string &) - = &ServiceTracker::defaultLogMethod, - bool featureCheckpoint = true, - bool featureStatusCheck = true, - bool featureThreadCheck = true, - Stopwatch::Unit stopwatchUnit - = Stopwatch::UNIT_MILLISECONDS); - - void setThreadManager(boost::shared_ptr threadManager); - -private: - - facebook::fb303::FacebookBase *handler_; - void (*logMethod_)(int, const std::string &); - boost::shared_ptr threadManager_; - - bool featureCheckpoint_; - bool featureStatusCheck_; - bool featureThreadCheck_; - Stopwatch::Unit stopwatchUnit_; - - apache::thrift::concurrency::Mutex statisticsMutex_; - time_t checkpointTime_; - uint64_t checkpointServices_; - uint64_t checkpointDuration_; - std::map > checkpointServiceDuration_; - - void startService(const ServiceMethod &serviceMethod); - int64_t stepService(const ServiceMethod &serviceMethod, - const std::string &stepName); - void finishService(const ServiceMethod &serviceMethod); - void reportCheckpoint(); - static void defaultLogMethod(int level, const std::string &message); -}; - - -class ServiceMethod -{ - friend class ServiceTracker; -public: - ServiceMethod(ServiceTracker *tracker, - const std::string &name, - const std::string &signature, - bool featureLogOnly = false); - ServiceMethod(ServiceTracker *tracker, - const std::string &name, - uint64_t id, - bool featureLogOnly = false); - ~ServiceMethod(); - uint64_t step(const std::string &stepName); -private: - ServiceTracker *tracker_; - std::string name_; - std::string signature_; - bool featureLogOnly_; - Stopwatch timer_; -}; - - -class ServiceException : public std::exception -{ -public: - explicit ServiceException(const std::string &message, int code = 0) - : message_(message), code_(code) {} - ~ServiceException() throw() {} - virtual const char *what() const throw() { return message_.c_str(); } - int code() const throw() { return code_; } -private: - std::string message_; - int code_; -}; - - -}} // facebook::fb303 - -#endif diff --git service/include/thrift/fb303/fb303_constants.cpp service/include/thrift/fb303/fb303_constants.cpp deleted file mode 100644 index 66b8782..0000000 --- service/include/thrift/fb303/fb303_constants.cpp +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Autogenerated by Thrift - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - */ -#include "fb303_constants.h" - -namespace facebook { namespace fb303 { - -const fb303Constants g_fb303_constants; - -fb303Constants::fb303Constants() { -} - -}} // namespace - diff --git service/include/thrift/fb303/fb303_constants.h service/include/thrift/fb303/fb303_constants.h deleted file mode 100644 index 19405bc..0000000 --- service/include/thrift/fb303/fb303_constants.h +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Autogenerated by Thrift - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - */ -#ifndef fb303_CONSTANTS_H -#define fb303_CONSTANTS_H - -#include "fb303_types.h" - -namespace facebook { namespace fb303 { - -class fb303Constants { - public: - fb303Constants(); - -}; - -extern const fb303Constants g_fb303_constants; - -}} // namespace - -#endif diff --git service/include/thrift/fb303/fb303_types.cpp service/include/thrift/fb303/fb303_types.cpp deleted file mode 100644 index f290125..0000000 --- service/include/thrift/fb303/fb303_types.cpp +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Autogenerated by Thrift - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - */ -#include "fb303_types.h" - -namespace facebook { namespace fb303 { - -}} // namespace diff --git service/include/thrift/fb303/fb303_types.h service/include/thrift/fb303/fb303_types.h deleted file mode 100644 index 18936f9..0000000 --- service/include/thrift/fb303/fb303_types.h +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Autogenerated by Thrift - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - */ -#ifndef fb303_TYPES_H -#define fb303_TYPES_H - -#include -#include -#include - - - -namespace facebook { namespace fb303 { - -enum fb_status { - DEAD = 0, - STARTING = 1, - ALIVE = 2, - STOPPING = 3, - STOPPED = 4, - WARNING = 5 -}; - -}} // namespace - -#endif diff --git service/include/thrift/fb303/if/fb303.thrift service/include/thrift/fb303/if/fb303.thrift deleted file mode 100644 index 66c8315..0000000 --- service/include/thrift/fb303/if/fb303.thrift +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/** - * fb303.thrift - */ - -namespace java com.facebook.fb303 -namespace cpp facebook.fb303 -namespace perl Facebook.FB303 - -/** - * Common status reporting mechanism across all services - */ -enum fb_status { - DEAD = 0, - STARTING = 1, - ALIVE = 2, - STOPPING = 3, - STOPPED = 4, - WARNING = 5, -} - -/** - * Standard base service - */ -service FacebookService { - - /** - * Returns a descriptive name of the service - */ - string getName(), - - /** - * Returns the version of the service - */ - string getVersion(), - - /** - * Gets the status of this service - */ - fb_status getStatus(), - - /** - * User friendly description of status, such as why the service is in - * the dead or warning state, or what is being started or stopped. - */ - string getStatusDetails(), - - /** - * Gets the counters for this service - */ - map getCounters(), - - /** - * Gets the value of a single counter - */ - i64 getCounter(1: string key), - - /** - * Sets an option - */ - void setOption(1: string key, 2: string value), - - /** - * Gets an option - */ - string getOption(1: string key), - - /** - * Gets all options - */ - map getOptions(), - - /** - * Returns a CPU profile over the given time interval (client and server - * must agree on the profile format). - */ - string getCpuProfile(1: i32 profileDurationInSec), - - /** - * Returns the unix time that the server has been running since - */ - i64 aliveSince(), - - /** - * Tell the server to reload its configuration, reopen log files, etc - */ - oneway void reinitialize(), - - /** - * Suggest a shutdown to the server - */ - oneway void shutdown(), - -} diff --git service/include/thrift/if/reflection_limited.thrift service/include/thrift/if/reflection_limited.thrift deleted file mode 100644 index 993c46e..0000000 --- service/include/thrift/if/reflection_limited.thrift +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/local/bin/thrift -php -java -cpp -py - -// NOTICE!!! -// DO NOT FORGET to run regen.sh if you change this file -// (or if you change the compiler). - -// This interface is deprecated. -// There is no replacement yet, but I hate it so much that -// I'm deprecating it before it's done. -// @author I'm too ashamed to say. - -// dreiss naively thinks he knows how to do this better, -// so talk to him if you are interested in taking it on, -// or if you just want someone to make it better for you. - -namespace cpp facebook.thrift.reflection.limited -namespace java com.facebook.thrift.reflection.limited -namespace py thrift.reflection.limited - -enum TTypeTag { - T_VOID = 1, - T_BOOL = 2, - T_BYTE = 3, - T_I16 = 6, - T_I32 = 8, - T_I64 = 10, - T_DOUBLE = 4, - T_STRING = 11, - T_STRUCT = 12, - T_MAP = 13, - T_SET = 14, - T_LIST = 15, - // This doesn't exist in TBinaryProtocol, but it could be useful for reflection. - T_ENUM = 101, - T_NOT_REFLECTED = 102, -} - -struct SimpleType { - 1: TTypeTag ttype, - 2: string name, // For structs and emums. -} - -struct ContainerType { - 1: TTypeTag ttype, - 2: SimpleType subtype1, - 3: optional SimpleType subtype2, -} - -struct ThriftType { - 1: bool is_container, - 2: optional SimpleType simple_type, - 3: optional ContainerType container_type, -} - -struct Argument { - 1: i16 key, - 2: string name, - 3: ThriftType type, -} - -struct Method { - 1: string name, - 2: ThriftType return_type, - 3: list arguments, -} - -struct Service { - 1: string name, - 2: list methods, - 3: bool fully_reflected, -} diff --git service/include/thrift/processor/PeekProcessor.h service/include/thrift/processor/PeekProcessor.h deleted file mode 100644 index 0f7c016..0000000 --- service/include/thrift/processor/PeekProcessor.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef PEEKPROCESSOR_H -#define PEEKPROCESSOR_H - -#include -#include -#include -#include -#include -#include - -namespace apache { namespace thrift { namespace processor { - -/* - * Class for peeking at the raw data that is being processed by another processor - * and gives the derived class a chance to change behavior accordingly - * - */ -class PeekProcessor : public apache::thrift::TProcessor { - - public: - PeekProcessor(); - virtual ~PeekProcessor(); - - // Input here: actualProcessor - the underlying processor - // protocolFactory - the protocol factory used to wrap the memory buffer - // transportFactory - this TPipedTransportFactory is used to wrap the source transport - // via a call to getPipedTransport - void initialize(boost::shared_ptr actualProcessor, - boost::shared_ptr protocolFactory, - boost::shared_ptr transportFactory); - - boost::shared_ptr getPipedTransport(boost::shared_ptr in); - - void setTargetTransport(boost::shared_ptr targetTransport); - - virtual bool process(boost::shared_ptr in, - boost::shared_ptr out); - - // The following three functions can be overloaded by child classes to - // achieve desired peeking behavior - virtual void peekName(const std::string& fname); - virtual void peekBuffer(uint8_t* buffer, uint32_t size); - virtual void peek(boost::shared_ptr in, - apache::thrift::protocol::TType ftype, - int16_t fid); - virtual void peekEnd(); - - private: - boost::shared_ptr actualProcessor_; - boost::shared_ptr pipedProtocol_; - boost::shared_ptr transportFactory_; - boost::shared_ptr memoryBuffer_; - boost::shared_ptr targetTransport_; -}; - -}}} // apache::thrift::processor - -#endif diff --git service/include/thrift/processor/StatsProcessor.h service/include/thrift/processor/StatsProcessor.h deleted file mode 100644 index 820b3ad..0000000 --- service/include/thrift/processor/StatsProcessor.h +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef STATSPROCESSOR_H -#define STATSPROCESSOR_H - -#include -#include -#include -#include - -namespace apache { namespace thrift { namespace processor { - -/* - * Class for keeping track of function call statistics and printing them if desired - * - */ -class StatsProcessor : public apache::thrift::TProcessor { -public: - StatsProcessor(bool print, bool frequency) - : print_(print), - frequency_(frequency) - {} - virtual ~StatsProcessor() {}; - - virtual bool process(boost::shared_ptr piprot, boost::shared_ptr poprot) { - - piprot_ = piprot; - - std::string fname; - apache::thrift::protocol::TMessageType mtype; - int32_t seqid; - - piprot_->readMessageBegin(fname, mtype, seqid); - if (mtype != apache::thrift::protocol::T_CALL) { - if (print_) { - printf("Unknown message type\n"); - } - throw apache::thrift::TException("Unexpected message type"); - } - if (print_) { - printf("%s (", fname.c_str()); - } - if (frequency_) { - if (frequency_map_.find(fname) != frequency_map_.end()) { - frequency_map_[fname]++; - } else { - frequency_map_[fname] = 1; - } - } - - apache::thrift::protocol::TType ftype; - int16_t fid; - - while (true) { - piprot_->readFieldBegin(fname, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - - printAndPassToBuffer(ftype); - if (print_) { - printf(", "); - } - } - - if (print_) { - printf("\b\b)\n"); - } - return true; - } - - const std::map& get_frequency_map() { - return frequency_map_; - } - -protected: - void printAndPassToBuffer(apache::thrift::protocol::TType ftype) { - switch (ftype) { - case apache::thrift::protocol::T_BOOL: - { - bool boolv; - piprot_->readBool(boolv); - if (print_) { - printf("%d", boolv); - } - } - break; - case apache::thrift::protocol::T_BYTE: - { - int8_t bytev; - piprot_->readByte(bytev); - if (print_) { - printf("%d", bytev); - } - } - break; - case apache::thrift::protocol::T_I16: - { - int16_t i16; - piprot_->readI16(i16); - if (print_) { - printf("%d", i16); - } - } - break; - case apache::thrift::protocol::T_I32: - { - int32_t i32; - piprot_->readI32(i32); - if (print_) { - printf("%d", i32); - } - } - break; - case apache::thrift::protocol::T_I64: - { - int64_t i64; - piprot_->readI64(i64); - if (print_) { - printf("%ld", i64); - } - } - break; - case apache::thrift::protocol::T_DOUBLE: - { - double dub; - piprot_->readDouble(dub); - if (print_) { - printf("%f", dub); - } - } - break; - case apache::thrift::protocol::T_STRING: - { - std::string str; - piprot_->readString(str); - if (print_) { - printf("%s", str.c_str()); - } - } - break; - case apache::thrift::protocol::T_STRUCT: - { - std::string name; - int16_t fid; - apache::thrift::protocol::TType ftype; - piprot_->readStructBegin(name); - if (print_) { - printf("<"); - } - while (true) { - piprot_->readFieldBegin(name, ftype, fid); - if (ftype == apache::thrift::protocol::T_STOP) { - break; - } - printAndPassToBuffer(ftype); - if (print_) { - printf(","); - } - piprot_->readFieldEnd(); - } - piprot_->readStructEnd(); - if (print_) { - printf("\b>"); - } - } - break; - case apache::thrift::protocol::T_MAP: - { - apache::thrift::protocol::TType keyType; - apache::thrift::protocol::TType valType; - uint32_t i, size; - piprot_->readMapBegin(keyType, valType, size); - if (print_) { - printf("{"); - } - for (i = 0; i < size; i++) { - printAndPassToBuffer(keyType); - if (print_) { - printf("=>"); - } - printAndPassToBuffer(valType); - if (print_) { - printf(","); - } - } - piprot_->readMapEnd(); - if (print_) { - printf("\b}"); - } - } - break; - case apache::thrift::protocol::T_SET: - { - apache::thrift::protocol::TType elemType; - uint32_t i, size; - piprot_->readSetBegin(elemType, size); - if (print_) { - printf("{"); - } - for (i = 0; i < size; i++) { - printAndPassToBuffer(elemType); - if (print_) { - printf(","); - } - } - piprot_->readSetEnd(); - if (print_) { - printf("\b}"); - } - } - break; - case apache::thrift::protocol::T_LIST: - { - apache::thrift::protocol::TType elemType; - uint32_t i, size; - piprot_->readListBegin(elemType, size); - if (print_) { - printf("["); - } - for (i = 0; i < size; i++) { - printAndPassToBuffer(elemType); - if (print_) { - printf(","); - } - } - piprot_->readListEnd(); - if (print_) { - printf("\b]"); - } - } - break; - default: - break; - } - } - - boost::shared_ptr piprot_; - std::map frequency_map_; - - bool print_; - bool frequency_; -}; - -}}} // apache::thrift::processor - -#endif diff --git service/include/thrift/protocol/TBase64Utils.h service/include/thrift/protocol/TBase64Utils.h deleted file mode 100644 index 3def733..0000000 --- service/include/thrift/protocol/TBase64Utils.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_PROTOCOL_TBASE64UTILS_H_ -#define _THRIFT_PROTOCOL_TBASE64UTILS_H_ - -#include -#include - -namespace apache { namespace thrift { namespace protocol { - -// in must be at least len bytes -// len must be 1, 2, or 3 -// buf must be a buffer of at least 4 bytes and may not overlap in -// the data is not padded with '='; the caller can do this if desired -void base64_encode(const uint8_t *in, uint32_t len, uint8_t *buf); - -// buf must be a buffer of at least 4 bytes and contain base64 encoded values -// buf will be changed to contain output bytes -// len is number of bytes to consume from input (must be 2, 3, or 4) -// no '=' padding should be included in the input -void base64_decode(uint8_t *buf, uint32_t len); - -}}} // apache::thrift::protocol - -#endif // #define _THRIFT_PROTOCOL_TBASE64UTILS_H_ diff --git service/include/thrift/protocol/TBinaryProtocol.h service/include/thrift/protocol/TBinaryProtocol.h deleted file mode 100644 index 7fd3de6..0000000 --- service/include/thrift/protocol/TBinaryProtocol.h +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_PROTOCOL_TBINARYPROTOCOL_H_ -#define _THRIFT_PROTOCOL_TBINARYPROTOCOL_H_ 1 - -#include "TProtocol.h" - -#include - -namespace apache { namespace thrift { namespace protocol { - -/** - * The default binary protocol for thrift. Writes all data in a very basic - * binary format, essentially just spitting out the raw bytes. - * - */ -class TBinaryProtocol : public TProtocol { - protected: - static const int32_t VERSION_MASK = 0xffff0000; - static const int32_t VERSION_1 = 0x80010000; - // VERSION_2 (0x80020000) is taken by TDenseProtocol. - - public: - TBinaryProtocol(boost::shared_ptr trans) : - TProtocol(trans), - string_limit_(0), - container_limit_(0), - strict_read_(false), - strict_write_(true), - string_buf_(NULL), - string_buf_size_(0) {} - - TBinaryProtocol(boost::shared_ptr trans, - int32_t string_limit, - int32_t container_limit, - bool strict_read, - bool strict_write) : - TProtocol(trans), - string_limit_(string_limit), - container_limit_(container_limit), - strict_read_(strict_read), - strict_write_(strict_write), - string_buf_(NULL), - string_buf_size_(0) {} - - ~TBinaryProtocol() { - if (string_buf_ != NULL) { - std::free(string_buf_); - string_buf_size_ = 0; - } - } - - void setStringSizeLimit(int32_t string_limit) { - string_limit_ = string_limit; - } - - void setContainerSizeLimit(int32_t container_limit) { - container_limit_ = container_limit; - } - - void setStrict(bool strict_read, bool strict_write) { - strict_read_ = strict_read; - strict_write_ = strict_write; - } - - /** - * Writing functions. - */ - - virtual uint32_t writeMessageBegin(const std::string& name, - const TMessageType messageType, - const int32_t seqid); - - virtual uint32_t writeMessageEnd(); - - - uint32_t writeStructBegin(const char* name); - - uint32_t writeStructEnd(); - - uint32_t writeFieldBegin(const char* name, - const TType fieldType, - const int16_t fieldId); - - uint32_t writeFieldEnd(); - - uint32_t writeFieldStop(); - - uint32_t writeMapBegin(const TType keyType, - const TType valType, - const uint32_t size); - - uint32_t writeMapEnd(); - - uint32_t writeListBegin(const TType elemType, - const uint32_t size); - - uint32_t writeListEnd(); - - uint32_t writeSetBegin(const TType elemType, - const uint32_t size); - - uint32_t writeSetEnd(); - - uint32_t writeBool(const bool value); - - uint32_t writeByte(const int8_t byte); - - uint32_t writeI16(const int16_t i16); - - uint32_t writeI32(const int32_t i32); - - uint32_t writeI64(const int64_t i64); - - uint32_t writeDouble(const double dub); - - uint32_t writeString(const std::string& str); - - uint32_t writeBinary(const std::string& str); - - /** - * Reading functions - */ - - - uint32_t readMessageBegin(std::string& name, - TMessageType& messageType, - int32_t& seqid); - - uint32_t readMessageEnd(); - - uint32_t readStructBegin(std::string& name); - - uint32_t readStructEnd(); - - uint32_t readFieldBegin(std::string& name, - TType& fieldType, - int16_t& fieldId); - - uint32_t readFieldEnd(); - - uint32_t readMapBegin(TType& keyType, - TType& valType, - uint32_t& size); - - uint32_t readMapEnd(); - - uint32_t readListBegin(TType& elemType, - uint32_t& size); - - uint32_t readListEnd(); - - uint32_t readSetBegin(TType& elemType, - uint32_t& size); - - uint32_t readSetEnd(); - - uint32_t readBool(bool& value); - - uint32_t readByte(int8_t& byte); - - uint32_t readI16(int16_t& i16); - - uint32_t readI32(int32_t& i32); - - uint32_t readI64(int64_t& i64); - - uint32_t readDouble(double& dub); - - uint32_t readString(std::string& str); - - uint32_t readBinary(std::string& str); - - protected: - uint32_t readStringBody(std::string& str, int32_t sz); - - int32_t string_limit_; - int32_t container_limit_; - - // Enforce presence of version identifier - bool strict_read_; - bool strict_write_; - - // Buffer for reading strings, save for the lifetime of the protocol to - // avoid memory churn allocating memory on every string read - uint8_t* string_buf_; - int32_t string_buf_size_; - -}; - -/** - * Constructs binary protocol handlers - */ -class TBinaryProtocolFactory : public TProtocolFactory { - public: - TBinaryProtocolFactory() : - string_limit_(0), - container_limit_(0), - strict_read_(false), - strict_write_(true) {} - - TBinaryProtocolFactory(int32_t string_limit, int32_t container_limit, bool strict_read, bool strict_write) : - string_limit_(string_limit), - container_limit_(container_limit), - strict_read_(strict_read), - strict_write_(strict_write) {} - - virtual ~TBinaryProtocolFactory() {} - - void setStringSizeLimit(int32_t string_limit) { - string_limit_ = string_limit; - } - - void setContainerSizeLimit(int32_t container_limit) { - container_limit_ = container_limit; - } - - void setStrict(bool strict_read, bool strict_write) { - strict_read_ = strict_read; - strict_write_ = strict_write; - } - - boost::shared_ptr getProtocol(boost::shared_ptr trans) { - return boost::shared_ptr(new TBinaryProtocol(trans, string_limit_, container_limit_, strict_read_, strict_write_)); - } - - private: - int32_t string_limit_; - int32_t container_limit_; - bool strict_read_; - bool strict_write_; - -}; - -}}} // apache::thrift::protocol - -#endif // #ifndef _THRIFT_PROTOCOL_TBINARYPROTOCOL_H_ diff --git service/include/thrift/protocol/TCompactProtocol.h service/include/thrift/protocol/TCompactProtocol.h deleted file mode 100644 index b4e06f0..0000000 --- service/include/thrift/protocol/TCompactProtocol.h +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_PROTOCOL_TCOMPACTPROTOCOL_H_ -#define _THRIFT_PROTOCOL_TCOMPACTPROTOCOL_H_ 1 - -#include "TProtocol.h" - -#include -#include - -namespace apache { namespace thrift { namespace protocol { - -/** - * C++ Implementation of the Compact Protocol as described in THRIFT-110 - */ -class TCompactProtocol : public TProtocol { - - protected: - static const int8_t PROTOCOL_ID = 0x82; - static const int8_t VERSION_N = 1; - static const int8_t VERSION_MASK = 0x1f; // 0001 1111 - static const int8_t TYPE_MASK = 0xE0; // 1110 0000 - static const int32_t TYPE_SHIFT_AMOUNT = 5; - - /** - * (Writing) If we encounter a boolean field begin, save the TField here - * so it can have the value incorporated. - */ - struct { - const char* name; - TType fieldType; - int16_t fieldId; - } booleanField_; - - /** - * (Reading) If we read a field header, and it's a boolean field, save - * the boolean value here so that readBool can use it. - */ - struct { - bool hasBoolValue; - bool boolValue; - } boolValue_; - - /** - * Used to keep track of the last field for the current and previous structs, - * so we can do the delta stuff. - */ - - std::stack lastField_; - int16_t lastFieldId_; - - enum Types { - CT_STOP = 0x00, - CT_BOOLEAN_TRUE = 0x01, - CT_BOOLEAN_FALSE = 0x02, - CT_BYTE = 0x03, - CT_I16 = 0x04, - CT_I32 = 0x05, - CT_I64 = 0x06, - CT_DOUBLE = 0x07, - CT_BINARY = 0x08, - CT_LIST = 0x09, - CT_SET = 0x0A, - CT_MAP = 0x0B, - CT_STRUCT = 0x0C, - }; - - static const int8_t TTypeToCType[16]; - - public: - TCompactProtocol(boost::shared_ptr trans) : - TProtocol(trans), - lastFieldId_(0), - string_limit_(0), - string_buf_(NULL), - string_buf_size_(0), - container_limit_(0) { - booleanField_.name = NULL; - boolValue_.hasBoolValue = false; - } - - TCompactProtocol(boost::shared_ptr trans, - int32_t string_limit, - int32_t container_limit) : - TProtocol(trans), - lastFieldId_(0), - string_limit_(string_limit), - string_buf_(NULL), - string_buf_size_(0), - container_limit_(container_limit) { - booleanField_.name = NULL; - boolValue_.hasBoolValue = false; - } - - - - /** - * Writing functions - */ - - virtual uint32_t writeMessageBegin(const std::string& name, - const TMessageType messageType, - const int32_t seqid); - - uint32_t writeStructBegin(const char* name); - - uint32_t writeStructEnd(); - - uint32_t writeFieldBegin(const char* name, - const TType fieldType, - const int16_t fieldId); - - uint32_t writeFieldStop(); - - uint32_t writeListBegin(const TType elemType, - const uint32_t size); - - uint32_t writeSetBegin(const TType elemType, - const uint32_t size); - - virtual uint32_t writeMapBegin(const TType keyType, - const TType valType, - const uint32_t size); - - uint32_t writeBool(const bool value); - - uint32_t writeByte(const int8_t byte); - - uint32_t writeI16(const int16_t i16); - - uint32_t writeI32(const int32_t i32); - - uint32_t writeI64(const int64_t i64); - - uint32_t writeDouble(const double dub); - - uint32_t writeString(const std::string& str); - - uint32_t writeBinary(const std::string& str); - - /** - * These methods are called by structs, but don't actually have any wired - * output or purpose - */ - virtual uint32_t writeMessageEnd() { return 0; } - uint32_t writeMapEnd() { return 0; } - uint32_t writeListEnd() { return 0; } - uint32_t writeSetEnd() { return 0; } - uint32_t writeFieldEnd() { return 0; } - - protected: - int32_t writeFieldBeginInternal(const char* name, - const TType fieldType, - const int16_t fieldId, - int8_t typeOverride); - uint32_t writeCollectionBegin(int8_t elemType, int32_t size); - uint32_t writeVarint32(uint32_t n); - uint32_t writeVarint64(uint64_t n); - uint64_t i64ToZigzag(const int64_t l); - uint32_t i32ToZigzag(const int32_t n); - inline int8_t getCompactType(int8_t ttype); - - public: - uint32_t readMessageBegin(std::string& name, - TMessageType& messageType, - int32_t& seqid); - - uint32_t readStructBegin(std::string& name); - - uint32_t readStructEnd(); - - uint32_t readFieldBegin(std::string& name, - TType& fieldType, - int16_t& fieldId); - - uint32_t readMapBegin(TType& keyType, - TType& valType, - uint32_t& size); - - uint32_t readListBegin(TType& elemType, - uint32_t& size); - - uint32_t readSetBegin(TType& elemType, - uint32_t& size); - - uint32_t readBool(bool& value); - - uint32_t readByte(int8_t& byte); - - uint32_t readI16(int16_t& i16); - - uint32_t readI32(int32_t& i32); - - uint32_t readI64(int64_t& i64); - - uint32_t readDouble(double& dub); - - uint32_t readString(std::string& str); - - uint32_t readBinary(std::string& str); - - /* - *These methods are here for the struct to call, but don't have any wire - * encoding. - */ - uint32_t readMessageEnd() { return 0; } - uint32_t readFieldEnd() { return 0; } - uint32_t readMapEnd() { return 0; } - uint32_t readListEnd() { return 0; } - uint32_t readSetEnd() { return 0; } - - protected: - uint32_t readVarint32(int32_t& i32); - uint32_t readVarint64(int64_t& i64); - int32_t zigzagToI32(uint32_t n); - int64_t zigzagToI64(uint64_t n); - TType getTType(int8_t type); - - // Buffer for reading strings, save for the lifetime of the protocol to - // avoid memory churn allocating memory on every string read - int32_t string_limit_; - uint8_t* string_buf_; - int32_t string_buf_size_; - int32_t container_limit_; -}; - -/** - * Constructs compact protocol handlers - */ -class TCompactProtocolFactory : public TProtocolFactory { - public: - TCompactProtocolFactory() : - string_limit_(0), - container_limit_(0) {} - - TCompactProtocolFactory(int32_t string_limit, int32_t container_limit) : - string_limit_(string_limit), - container_limit_(container_limit) {} - - virtual ~TCompactProtocolFactory() {} - - void setStringSizeLimit(int32_t string_limit) { - string_limit_ = string_limit; - } - - void setContainerSizeLimit(int32_t container_limit) { - container_limit_ = container_limit; - } - - boost::shared_ptr getProtocol(boost::shared_ptr trans) { - return boost::shared_ptr(new TCompactProtocol(trans, string_limit_, container_limit_)); - } - - private: - int32_t string_limit_; - int32_t container_limit_; - -}; - -}}} // apache::thrift::protocol - -#endif diff --git service/include/thrift/protocol/TDebugProtocol.h service/include/thrift/protocol/TDebugProtocol.h deleted file mode 100644 index ab69e0c..0000000 --- service/include/thrift/protocol/TDebugProtocol.h +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_PROTOCOL_TDEBUGPROTOCOL_H_ -#define _THRIFT_PROTOCOL_TDEBUGPROTOCOL_H_ 1 - -#include "TProtocol.h" -#include "TOneWayProtocol.h" - -#include - -namespace apache { namespace thrift { namespace protocol { - -/* - -!!! EXPERIMENTAL CODE !!! - -This protocol is very much a work in progress. -It doesn't handle many cases properly. -It throws exceptions in many cases. -It probably segfaults in many cases. -Bug reports and feature requests are welcome. -Complaints are not. :R - -*/ - - -/** - * Protocol that prints the payload in a nice human-readable format. - * Reading from this protocol is not supported. - * - */ -class TDebugProtocol : public TWriteOnlyProtocol { - private: - enum write_state_t - { UNINIT - , STRUCT - , LIST - , SET - , MAP_KEY - , MAP_VALUE - }; - - public: - TDebugProtocol(boost::shared_ptr trans) - : TWriteOnlyProtocol(trans, "TDebugProtocol") - , string_limit_(DEFAULT_STRING_LIMIT) - , string_prefix_size_(DEFAULT_STRING_PREFIX_SIZE) - { - write_state_.push_back(UNINIT); - } - - static const int32_t DEFAULT_STRING_LIMIT = 256; - static const int32_t DEFAULT_STRING_PREFIX_SIZE = 16; - - void setStringSizeLimit(int32_t string_limit) { - string_limit_ = string_limit; - } - - void setStringPrefixSize(int32_t string_prefix_size) { - string_prefix_size_ = string_prefix_size; - } - - - virtual uint32_t writeMessageBegin(const std::string& name, - const TMessageType messageType, - const int32_t seqid); - - virtual uint32_t writeMessageEnd(); - - - uint32_t writeStructBegin(const char* name); - - uint32_t writeStructEnd(); - - uint32_t writeFieldBegin(const char* name, - const TType fieldType, - const int16_t fieldId); - - uint32_t writeFieldEnd(); - - uint32_t writeFieldStop(); - - uint32_t writeMapBegin(const TType keyType, - const TType valType, - const uint32_t size); - - uint32_t writeMapEnd(); - - uint32_t writeListBegin(const TType elemType, - const uint32_t size); - - uint32_t writeListEnd(); - - uint32_t writeSetBegin(const TType elemType, - const uint32_t size); - - uint32_t writeSetEnd(); - - uint32_t writeBool(const bool value); - - uint32_t writeByte(const int8_t byte); - - uint32_t writeI16(const int16_t i16); - - uint32_t writeI32(const int32_t i32); - - uint32_t writeI64(const int64_t i64); - - uint32_t writeDouble(const double dub); - - uint32_t writeString(const std::string& str); - - uint32_t writeBinary(const std::string& str); - - - private: - void indentUp(); - void indentDown(); - uint32_t writePlain(const std::string& str); - uint32_t writeIndented(const std::string& str); - uint32_t startItem(); - uint32_t endItem(); - uint32_t writeItem(const std::string& str); - - static std::string fieldTypeName(TType type); - - int32_t string_limit_; - int32_t string_prefix_size_; - - std::string indent_str_; - static const int indent_inc = 2; - - std::vector write_state_; - std::vector list_idx_; -}; - -/** - * Constructs debug protocol handlers - */ -class TDebugProtocolFactory : public TProtocolFactory { - public: - TDebugProtocolFactory() {} - virtual ~TDebugProtocolFactory() {} - - boost::shared_ptr getProtocol(boost::shared_ptr trans) { - return boost::shared_ptr(new TDebugProtocol(trans)); - } - -}; - -}}} // apache::thrift::protocol - - -// TODO(dreiss): Move (part of) ThriftDebugString into a .cpp file and remove this. -#include - -namespace apache { namespace thrift { - -template -std::string ThriftDebugString(const ThriftStruct& ts) { - using namespace apache::thrift::transport; - using namespace apache::thrift::protocol; - TMemoryBuffer* buffer = new TMemoryBuffer; - boost::shared_ptr trans(buffer); - TDebugProtocol protocol(trans); - - ts.write(&protocol); - - uint8_t* buf; - uint32_t size; - buffer->getBuffer(&buf, &size); - return std::string((char*)buf, (unsigned int)size); -} - -// TODO(dreiss): This is badly broken. Don't use it unless you are me. -#if 0 -template -std::string DebugString(const std::vector& vec) { - using namespace apache::thrift::transport; - using namespace apache::thrift::protocol; - TMemoryBuffer* buffer = new TMemoryBuffer; - boost::shared_ptr trans(buffer); - TDebugProtocol protocol(trans); - - // I am gross! - protocol.writeStructBegin("SomeRandomVector"); - - // TODO: Fix this with a trait. - protocol.writeListBegin((TType)99, vec.size()); - typename std::vector::const_iterator it; - for (it = vec.begin(); it != vec.end(); ++it) { - it->write(&protocol); - } - protocol.writeListEnd(); - - uint8_t* buf; - uint32_t size; - buffer->getBuffer(&buf, &size); - return std::string((char*)buf, (unsigned int)size); -} -#endif // 0 - -}} // apache::thrift - - -#endif // #ifndef _THRIFT_PROTOCOL_TDEBUGPROTOCOL_H_ - - diff --git service/include/thrift/protocol/TDenseProtocol.h service/include/thrift/protocol/TDenseProtocol.h deleted file mode 100644 index 7655a47..0000000 --- service/include/thrift/protocol/TDenseProtocol.h +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_PROTOCOL_TDENSEPROTOCOL_H_ -#define _THRIFT_PROTOCOL_TDENSEPROTOCOL_H_ 1 - -#include "TBinaryProtocol.h" - -namespace apache { namespace thrift { namespace protocol { - -/** - * !!!WARNING!!! - * This class is still highly experimental. Incompatible changes - * WILL be made to it without notice. DO NOT USE IT YET unless - * you are coordinating your testing with the author. - * - * The dense protocol is designed to use as little space as possible. - * - * There are two types of dense protocol instances. Standalone instances - * are not used for RPC and just encoded and decode structures of - * a predetermined type. Non-standalone instances are used for RPC. - * Currently, only standalone instances exist. - * - * To use a standalone dense protocol object, you must set the type_spec - * property (either in the constructor, or with setTypeSpec) to the local - * reflection TypeSpec of the structures you will write to (or read from) the - * protocol instance. - * - * BEST PRACTICES: - * - Never use optional for primitives or containers. - * - Only use optional for structures if they are very big and very rarely set. - * - All integers are variable-length, so you can use i64 without bloating. - * - NEVER EVER change the struct definitions IN ANY WAY without either - * changing your cache keys or talking to dreiss. - * - * TODO(dreiss): New class write with old meta. - * - * We override all of TBinaryProtocol's methods. - * We inherit so that we can can explicitly call TBPs's primitive-writing - * methods within our versions. - * - */ -class TDenseProtocol : public TBinaryProtocol { - protected: - static const int32_t VERSION_MASK = 0xffff0000; - // VERSION_1 (0x80010000) is taken by TBinaryProtocol. - static const int32_t VERSION_2 = 0x80020000; - - public: - typedef apache::thrift::reflection::local::TypeSpec TypeSpec; - static const int FP_PREFIX_LEN; - - /** - * @param tran The transport to use. - * @param type_spec The TypeSpec of the structures using this protocol. - */ - TDenseProtocol(boost::shared_ptr trans, - TypeSpec* type_spec = NULL) : - TBinaryProtocol(trans), - type_spec_(type_spec), - standalone_(true) - {} - - void setTypeSpec(TypeSpec* type_spec) { - type_spec_ = type_spec; - } - TypeSpec* getTypeSpec() { - return type_spec_; - } - - - /* - * Writing functions. - */ - - virtual uint32_t writeMessageBegin(const std::string& name, - const TMessageType messageType, - const int32_t seqid); - - virtual uint32_t writeMessageEnd(); - - - virtual uint32_t writeStructBegin(const char* name); - - virtual uint32_t writeStructEnd(); - - virtual uint32_t writeFieldBegin(const char* name, - const TType fieldType, - const int16_t fieldId); - - virtual uint32_t writeFieldEnd(); - - virtual uint32_t writeFieldStop(); - - virtual uint32_t writeMapBegin(const TType keyType, - const TType valType, - const uint32_t size); - - virtual uint32_t writeMapEnd(); - - virtual uint32_t writeListBegin(const TType elemType, - const uint32_t size); - - virtual uint32_t writeListEnd(); - - virtual uint32_t writeSetBegin(const TType elemType, - const uint32_t size); - - virtual uint32_t writeSetEnd(); - - virtual uint32_t writeBool(const bool value); - - virtual uint32_t writeByte(const int8_t byte); - - virtual uint32_t writeI16(const int16_t i16); - - virtual uint32_t writeI32(const int32_t i32); - - virtual uint32_t writeI64(const int64_t i64); - - virtual uint32_t writeDouble(const double dub); - - virtual uint32_t writeString(const std::string& str); - - virtual uint32_t writeBinary(const std::string& str); - - - /* - * Helper writing functions (don't do state transitions). - */ - inline uint32_t subWriteI32(const int32_t i32); - - inline uint32_t subWriteString(const std::string& str); - - uint32_t subWriteBool(const bool value) { - return TBinaryProtocol::writeBool(value); - } - - - /* - * Reading functions - */ - - uint32_t readMessageBegin(std::string& name, - TMessageType& messageType, - int32_t& seqid); - - uint32_t readMessageEnd(); - - uint32_t readStructBegin(std::string& name); - - uint32_t readStructEnd(); - - uint32_t readFieldBegin(std::string& name, - TType& fieldType, - int16_t& fieldId); - - uint32_t readFieldEnd(); - - uint32_t readMapBegin(TType& keyType, - TType& valType, - uint32_t& size); - - uint32_t readMapEnd(); - - uint32_t readListBegin(TType& elemType, - uint32_t& size); - - uint32_t readListEnd(); - - uint32_t readSetBegin(TType& elemType, - uint32_t& size); - - uint32_t readSetEnd(); - - uint32_t readBool(bool& value); - - uint32_t readByte(int8_t& byte); - - uint32_t readI16(int16_t& i16); - - uint32_t readI32(int32_t& i32); - - uint32_t readI64(int64_t& i64); - - uint32_t readDouble(double& dub); - - uint32_t readString(std::string& str); - - uint32_t readBinary(std::string& str); - - /* - * Helper reading functions (don't do state transitions). - */ - inline uint32_t subReadI32(int32_t& i32); - - inline uint32_t subReadString(std::string& str); - - uint32_t subReadBool(bool& value) { - return TBinaryProtocol::readBool(value); - } - - - private: - - // Implementation functions, documented in the .cpp. - inline void checkTType(const TType ttype); - inline void stateTransition(); - - // Read and write variable-length integers. - // Uses the same technique as the MIDI file format. - inline uint32_t vlqRead(uint64_t& vlq); - inline uint32_t vlqWrite(uint64_t vlq); - - // Called before throwing an exception to make the object reusable. - void resetState() { - ts_stack_.clear(); - idx_stack_.clear(); - mkv_stack_.clear(); - } - - // TypeSpec of the top-level structure to write, - // for standalone protocol objects. - TypeSpec* type_spec_; - - std::vector ts_stack_; // TypeSpec stack. - std::vector idx_stack_; // InDeX stack. - std::vector mkv_stack_; // Map Key/Vlue stack. - // True = key, False = value. - - // True iff this is a standalone instance (no RPC). - bool standalone_; -}; - -}}} // apache::thrift::protocol - -#endif // #ifndef _THRIFT_PROTOCOL_TDENSEPROTOCOL_H_ diff --git service/include/thrift/protocol/TJSONProtocol.h service/include/thrift/protocol/TJSONProtocol.h deleted file mode 100644 index 2df499a..0000000 --- service/include/thrift/protocol/TJSONProtocol.h +++ /dev/null @@ -1,340 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_PROTOCOL_TJSONPROTOCOL_H_ -#define _THRIFT_PROTOCOL_TJSONPROTOCOL_H_ 1 - -#include "TProtocol.h" - -#include - -namespace apache { namespace thrift { namespace protocol { - -// Forward declaration -class TJSONContext; - -/** - * JSON protocol for Thrift. - * - * Implements a protocol which uses JSON as the wire-format. - * - * Thrift types are represented as described below: - * - * 1. Every Thrift integer type is represented as a JSON number. - * - * 2. Thrift doubles are represented as JSON numbers. Some special values are - * represented as strings: - * a. "NaN" for not-a-number values - * b. "Infinity" for postive infinity - * c. "-Infinity" for negative infinity - * - * 3. Thrift string values are emitted as JSON strings, with appropriate - * escaping. - * - * 4. Thrift binary values are encoded into Base64 and emitted as JSON strings. - * The readBinary() method is written such that it will properly skip if - * called on a Thrift string (although it will decode garbage data). - * - * 5. Thrift structs are represented as JSON objects, with the field ID as the - * key, and the field value represented as a JSON object with a single - * key-value pair. The key is a short string identifier for that type, - * followed by the value. The valid type identifiers are: "tf" for bool, - * "i8" for byte, "i16" for 16-bit integer, "i32" for 32-bit integer, "i64" - * for 64-bit integer, "dbl" for double-precision loating point, "str" for - * string (including binary), "rec" for struct ("records"), "map" for map, - * "lst" for list, "set" for set. - * - * 6. Thrift lists and sets are represented as JSON arrays, with the first - * element of the JSON array being the string identifier for the Thrift - * element type and the second element of the JSON array being the count of - * the Thrift elements. The Thrift elements then follow. - * - * 7. Thrift maps are represented as JSON arrays, with the first two elements - * of the JSON array being the string identifiers for the Thrift key type - * and value type, followed by the count of the Thrift pairs, followed by a - * JSON object containing the key-value pairs. Note that JSON keys can only - * be strings, which means that the key type of the Thrift map should be - * restricted to numeric or string types -- in the case of numerics, they - * are serialized as strings. - * - * 8. Thrift messages are represented as JSON arrays, with the protocol - * version #, the message name, the message type, and the sequence ID as - * the first 4 elements. - * - * More discussion of the double handling is probably warranted. The aim of - * the current implementation is to match as closely as possible the behavior - * of Java's Double.toString(), which has no precision loss. Implementors in - * other languages should strive to achieve that where possible. I have not - * yet verified whether boost:lexical_cast, which is doing that work for me in - * C++, loses any precision, but I am leaving this as a future improvement. I - * may try to provide a C component for this, so that other languages could - * bind to the same underlying implementation for maximum consistency. - * - * Note further that JavaScript itself is not capable of representing - * floating point infinities -- presumably when we have a JavaScript Thrift - * client, this would mean that infinities get converted to not-a-number in - * transmission. I don't know of any work-around for this issue. - * - */ -class TJSONProtocol : public TProtocol { - public: - - TJSONProtocol(boost::shared_ptr ptrans); - - ~TJSONProtocol(); - - private: - - void pushContext(boost::shared_ptr c); - - void popContext(); - - uint32_t writeJSONEscapeChar(uint8_t ch); - - uint32_t writeJSONChar(uint8_t ch); - - uint32_t writeJSONString(const std::string &str); - - uint32_t writeJSONBase64(const std::string &str); - - template - uint32_t writeJSONInteger(NumberType num); - - uint32_t writeJSONDouble(double num); - - uint32_t writeJSONObjectStart() ; - - uint32_t writeJSONObjectEnd(); - - uint32_t writeJSONArrayStart(); - - uint32_t writeJSONArrayEnd(); - - uint32_t readJSONSyntaxChar(uint8_t ch); - - uint32_t readJSONEscapeChar(uint8_t *out); - - uint32_t readJSONString(std::string &str, bool skipContext = false); - - uint32_t readJSONBase64(std::string &str); - - uint32_t readJSONNumericChars(std::string &str); - - template - uint32_t readJSONInteger(NumberType &num); - - uint32_t readJSONDouble(double &num); - - uint32_t readJSONObjectStart(); - - uint32_t readJSONObjectEnd(); - - uint32_t readJSONArrayStart(); - - uint32_t readJSONArrayEnd(); - - public: - - /** - * Writing functions. - */ - - uint32_t writeMessageBegin(const std::string& name, - const TMessageType messageType, - const int32_t seqid); - - uint32_t writeMessageEnd(); - - uint32_t writeStructBegin(const char* name); - - uint32_t writeStructEnd(); - - uint32_t writeFieldBegin(const char* name, - const TType fieldType, - const int16_t fieldId); - - uint32_t writeFieldEnd(); - - uint32_t writeFieldStop(); - - uint32_t writeMapBegin(const TType keyType, - const TType valType, - const uint32_t size); - - uint32_t writeMapEnd(); - - uint32_t writeListBegin(const TType elemType, - const uint32_t size); - - uint32_t writeListEnd(); - - uint32_t writeSetBegin(const TType elemType, - const uint32_t size); - - uint32_t writeSetEnd(); - - uint32_t writeBool(const bool value); - - uint32_t writeByte(const int8_t byte); - - uint32_t writeI16(const int16_t i16); - - uint32_t writeI32(const int32_t i32); - - uint32_t writeI64(const int64_t i64); - - uint32_t writeDouble(const double dub); - - uint32_t writeString(const std::string& str); - - uint32_t writeBinary(const std::string& str); - - /** - * Reading functions - */ - - uint32_t readMessageBegin(std::string& name, - TMessageType& messageType, - int32_t& seqid); - - uint32_t readMessageEnd(); - - uint32_t readStructBegin(std::string& name); - - uint32_t readStructEnd(); - - uint32_t readFieldBegin(std::string& name, - TType& fieldType, - int16_t& fieldId); - - uint32_t readFieldEnd(); - - uint32_t readMapBegin(TType& keyType, - TType& valType, - uint32_t& size); - - uint32_t readMapEnd(); - - uint32_t readListBegin(TType& elemType, - uint32_t& size); - - uint32_t readListEnd(); - - uint32_t readSetBegin(TType& elemType, - uint32_t& size); - - uint32_t readSetEnd(); - - uint32_t readBool(bool& value); - - uint32_t readByte(int8_t& byte); - - uint32_t readI16(int16_t& i16); - - uint32_t readI32(int32_t& i32); - - uint32_t readI64(int64_t& i64); - - uint32_t readDouble(double& dub); - - uint32_t readString(std::string& str); - - uint32_t readBinary(std::string& str); - - class LookaheadReader { - - public: - - LookaheadReader(TTransport &trans) : - trans_(&trans), - hasData_(false) { - } - - uint8_t read() { - if (hasData_) { - hasData_ = false; - } - else { - trans_->readAll(&data_, 1); - } - return data_; - } - - uint8_t peek() { - if (!hasData_) { - trans_->readAll(&data_, 1); - } - hasData_ = true; - return data_; - } - - private: - TTransport *trans_; - bool hasData_; - uint8_t data_; - }; - - private: - - std::stack > contexts_; - boost::shared_ptr context_; - LookaheadReader reader_; -}; - -/** - * Constructs input and output protocol objects given transports. - */ -class TJSONProtocolFactory : public TProtocolFactory { - public: - TJSONProtocolFactory() {} - - virtual ~TJSONProtocolFactory() {} - - boost::shared_ptr getProtocol(boost::shared_ptr trans) { - return boost::shared_ptr(new TJSONProtocol(trans)); - } -}; - -}}} // apache::thrift::protocol - - -// TODO(dreiss): Move part of ThriftJSONString into a .cpp file and remove this. -#include - -namespace apache { namespace thrift { - -template - std::string ThriftJSONString(const ThriftStruct& ts) { - using namespace apache::thrift::transport; - using namespace apache::thrift::protocol; - TMemoryBuffer* buffer = new TMemoryBuffer; - boost::shared_ptr trans(buffer); - TJSONProtocol protocol(trans); - - ts.write(&protocol); - - uint8_t* buf; - uint32_t size; - buffer->getBuffer(&buf, &size); - return std::string((char*)buf, (unsigned int)size); -} - -}} // apache::thrift - -#endif // #define _THRIFT_PROTOCOL_TJSONPROTOCOL_H_ 1 diff --git service/include/thrift/protocol/TOneWayProtocol.h service/include/thrift/protocol/TOneWayProtocol.h deleted file mode 100644 index 6f08fe1..0000000 --- service/include/thrift/protocol/TOneWayProtocol.h +++ /dev/null @@ -1,304 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_PROTOCOL_TONEWAYPROTOCOL_H_ -#define _THRIFT_PROTOCOL_TONEWAYPROTOCOL_H_ 1 - -#include "TProtocol.h" - -namespace apache { namespace thrift { namespace protocol { - -/** - * Abstract class for implementing a protocol that can only be written, - * not read. - * - */ -class TWriteOnlyProtocol : public TProtocol { - public: - /** - * @param subclass_name The name of the concrete subclass. - */ - TWriteOnlyProtocol(boost::shared_ptr trans, - const std::string& subclass_name) - : TProtocol(trans) - , subclass_(subclass_name) - {} - - // All writing functions remain abstract. - - /** - * Reading functions all throw an exception. - */ - - uint32_t readMessageBegin(std::string& name, - TMessageType& messageType, - int32_t& seqid) { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support reading (yet)."); - } - - uint32_t readMessageEnd() { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support reading (yet)."); - } - - uint32_t readStructBegin(std::string& name) { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support reading (yet)."); - } - - uint32_t readStructEnd() { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support reading (yet)."); - } - - uint32_t readFieldBegin(std::string& name, - TType& fieldType, - int16_t& fieldId) { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support reading (yet)."); - } - - uint32_t readFieldEnd() { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support reading (yet)."); - } - - uint32_t readMapBegin(TType& keyType, - TType& valType, - uint32_t& size) { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support reading (yet)."); - } - - uint32_t readMapEnd() { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support reading (yet)."); - } - - uint32_t readListBegin(TType& elemType, - uint32_t& size) { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support reading (yet)."); - } - - uint32_t readListEnd() { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support reading (yet)."); - } - - uint32_t readSetBegin(TType& elemType, - uint32_t& size) { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support reading (yet)."); - } - - uint32_t readSetEnd() { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support reading (yet)."); - } - - uint32_t readBool(bool& value) { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support reading (yet)."); - } - - uint32_t readByte(int8_t& byte) { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support reading (yet)."); - } - - uint32_t readI16(int16_t& i16) { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support reading (yet)."); - } - - uint32_t readI32(int32_t& i32) { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support reading (yet)."); - } - - uint32_t readI64(int64_t& i64) { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support reading (yet)."); - } - - uint32_t readDouble(double& dub) { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support reading (yet)."); - } - - uint32_t readString(std::string& str) { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support reading (yet)."); - } - - uint32_t readBinary(std::string& str) { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support reading (yet)."); - } - - private: - std::string subclass_; -}; - - -/** - * Abstract class for implementing a protocol that can only be read, - * not written. - * - */ -class TReadOnlyProtocol : public TProtocol { - public: - /** - * @param subclass_name The name of the concrete subclass. - */ - TReadOnlyProtocol(boost::shared_ptr trans, - const std::string& subclass_name) - : TProtocol(trans) - , subclass_(subclass_name) - {} - - // All reading functions remain abstract. - - /** - * Writing functions all throw an exception. - */ - - uint32_t writeMessageBegin(const std::string& name, - const TMessageType messageType, - const int32_t seqid) { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support writing (yet)."); - } - - uint32_t writeMessageEnd() { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support writing (yet)."); - } - - - uint32_t writeStructBegin(const char* name) { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support writing (yet)."); - } - - uint32_t writeStructEnd() { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support writing (yet)."); - } - - uint32_t writeFieldBegin(const char* name, - const TType fieldType, - const int16_t fieldId) { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support writing (yet)."); - } - - uint32_t writeFieldEnd() { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support writing (yet)."); - } - - uint32_t writeFieldStop() { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support writing (yet)."); - } - - uint32_t writeMapBegin(const TType keyType, - const TType valType, - const uint32_t size) { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support writing (yet)."); - } - - uint32_t writeMapEnd() { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support writing (yet)."); - } - - uint32_t writeListBegin(const TType elemType, - const uint32_t size) { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support writing (yet)."); - } - - uint32_t writeListEnd() { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support writing (yet)."); - } - - uint32_t writeSetBegin(const TType elemType, - const uint32_t size) { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support writing (yet)."); - } - - uint32_t writeSetEnd() { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support writing (yet)."); - } - - uint32_t writeBool(const bool value) { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support writing (yet)."); - } - - uint32_t writeByte(const int8_t byte) { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support writing (yet)."); - } - - uint32_t writeI16(const int16_t i16) { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support writing (yet)."); - } - - uint32_t writeI32(const int32_t i32) { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support writing (yet)."); - } - - uint32_t writeI64(const int64_t i64) { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support writing (yet)."); - } - - uint32_t writeDouble(const double dub) { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support writing (yet)."); - } - - uint32_t writeString(const std::string& str) { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support writing (yet)."); - } - - uint32_t writeBinary(const std::string& str) { - throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, - subclass_ + " does not support writing (yet)."); - } - - private: - std::string subclass_; -}; - -}}} // apache::thrift::protocol - -#endif // #ifndef _THRIFT_PROTOCOL_TBINARYPROTOCOL_H_ diff --git service/include/thrift/protocol/TProtocol.h service/include/thrift/protocol/TProtocol.h deleted file mode 100644 index 4025827..0000000 --- service/include/thrift/protocol/TProtocol.h +++ /dev/null @@ -1,438 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_PROTOCOL_TPROTOCOL_H_ -#define _THRIFT_PROTOCOL_TPROTOCOL_H_ 1 - -#include -#include - -#include -#include - -#include -#include -#include -#include - - -// Use this to get around strict aliasing rules. -// For example, uint64_t i = bitwise_cast(returns_double()); -// The most obvious implementation is to just cast a pointer, -// but that doesn't work. -// For a pretty in-depth explanation of the problem, see -// http://www.cellperformance.com/mike_acton/2006/06/ (...) -// understanding_strict_aliasing.html -template -static inline To bitwise_cast(From from) { - BOOST_STATIC_ASSERT(sizeof(From) == sizeof(To)); - - // BAD!!! These are all broken with -O2. - //return *reinterpret_cast(&from); // BAD!!! - //return *static_cast(static_cast(&from)); // BAD!!! - //return *(To*)(void*)&from; // BAD!!! - - // Super clean and paritally blessed by section 3.9 of the standard. - //unsigned char c[sizeof(from)]; - //memcpy(c, &from, sizeof(from)); - //To to; - //memcpy(&to, c, sizeof(c)); - //return to; - - // Slightly more questionable. - // Same code emitted by GCC. - //To to; - //memcpy(&to, &from, sizeof(from)); - //return to; - - // Technically undefined, but almost universally supported, - // and the most efficient implementation. - union { - From f; - To t; - } u; - u.f = from; - return u.t; -} - - -namespace apache { namespace thrift { namespace protocol { - -using apache::thrift::transport::TTransport; - -#ifdef HAVE_ENDIAN_H -#include -#endif - -#ifndef __BYTE_ORDER -# if defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN) -# define __BYTE_ORDER BYTE_ORDER -# define __LITTLE_ENDIAN LITTLE_ENDIAN -# define __BIG_ENDIAN BIG_ENDIAN -# else -# error "Cannot determine endianness" -# endif -#endif - -#if __BYTE_ORDER == __BIG_ENDIAN -# define ntohll(n) (n) -# define htonll(n) (n) -# if defined(__GNUC__) && defined(__GLIBC__) -# include -# define htolell(n) bswap_64(n) -# define letohll(n) bswap_64(n) -# else /* GNUC & GLIBC */ -# define bswap_64(n) \ - ( (((n) & 0xff00000000000000ull) >> 56) \ - | (((n) & 0x00ff000000000000ull) >> 40) \ - | (((n) & 0x0000ff0000000000ull) >> 24) \ - | (((n) & 0x000000ff00000000ull) >> 8) \ - | (((n) & 0x00000000ff000000ull) << 8) \ - | (((n) & 0x0000000000ff0000ull) << 24) \ - | (((n) & 0x000000000000ff00ull) << 40) \ - | (((n) & 0x00000000000000ffull) << 56) ) -# define ntolell(n) bswap_64(n) -# define letonll(n) bswap_64(n) -# endif /* GNUC & GLIBC */ -#elif __BYTE_ORDER == __LITTLE_ENDIAN -# define htolell(n) (n) -# define letohll(n) (n) -# if defined(__GNUC__) && defined(__GLIBC__) -# include -# define ntohll(n) bswap_64(n) -# define htonll(n) bswap_64(n) -# else /* GNUC & GLIBC */ -# define ntohll(n) ( (((unsigned long long)ntohl(n)) << 32) + ntohl(n >> 32) ) -# define htonll(n) ( (((unsigned long long)htonl(n)) << 32) + htonl(n >> 32) ) -# endif /* GNUC & GLIBC */ -#else /* __BYTE_ORDER */ -# error "Can't define htonll or ntohll!" -#endif - -/** - * Enumerated definition of the types that the Thrift protocol supports. - * Take special note of the T_END type which is used specifically to mark - * the end of a sequence of fields. - */ -enum TType { - T_STOP = 0, - T_VOID = 1, - T_BOOL = 2, - T_BYTE = 3, - T_I08 = 3, - T_I16 = 6, - T_I32 = 8, - T_U64 = 9, - T_I64 = 10, - T_DOUBLE = 4, - T_STRING = 11, - T_UTF7 = 11, - T_STRUCT = 12, - T_MAP = 13, - T_SET = 14, - T_LIST = 15, - T_UTF8 = 16, - T_UTF16 = 17 -}; - -/** - * Enumerated definition of the message types that the Thrift protocol - * supports. - */ -enum TMessageType { - T_CALL = 1, - T_REPLY = 2, - T_EXCEPTION = 3, - T_ONEWAY = 4 -}; - -/** - * Abstract class for a thrift protocol driver. These are all the methods that - * a protocol must implement. Essentially, there must be some way of reading - * and writing all the base types, plus a mechanism for writing out structs - * with indexed fields. - * - * TProtocol objects should not be shared across multiple encoding contexts, - * as they may need to maintain internal state in some protocols (i.e. XML). - * Note that is is acceptable for the TProtocol module to do its own internal - * buffered reads/writes to the underlying TTransport where appropriate (i.e. - * when parsing an input XML stream, reading should be batched rather than - * looking ahead character by character for a close tag). - * - */ -class TProtocol { - public: - virtual ~TProtocol() {} - - /** - * Writing functions. - */ - - virtual uint32_t writeMessageBegin(const std::string& name, - const TMessageType messageType, - const int32_t seqid) = 0; - - virtual uint32_t writeMessageEnd() = 0; - - - virtual uint32_t writeStructBegin(const char* name) = 0; - - virtual uint32_t writeStructEnd() = 0; - - virtual uint32_t writeFieldBegin(const char* name, - const TType fieldType, - const int16_t fieldId) = 0; - - virtual uint32_t writeFieldEnd() = 0; - - virtual uint32_t writeFieldStop() = 0; - - virtual uint32_t writeMapBegin(const TType keyType, - const TType valType, - const uint32_t size) = 0; - - virtual uint32_t writeMapEnd() = 0; - - virtual uint32_t writeListBegin(const TType elemType, - const uint32_t size) = 0; - - virtual uint32_t writeListEnd() = 0; - - virtual uint32_t writeSetBegin(const TType elemType, - const uint32_t size) = 0; - - virtual uint32_t writeSetEnd() = 0; - - virtual uint32_t writeBool(const bool value) = 0; - - virtual uint32_t writeByte(const int8_t byte) = 0; - - virtual uint32_t writeI16(const int16_t i16) = 0; - - virtual uint32_t writeI32(const int32_t i32) = 0; - - virtual uint32_t writeI64(const int64_t i64) = 0; - - virtual uint32_t writeDouble(const double dub) = 0; - - virtual uint32_t writeString(const std::string& str) = 0; - - virtual uint32_t writeBinary(const std::string& str) = 0; - - /** - * Reading functions - */ - - virtual uint32_t readMessageBegin(std::string& name, - TMessageType& messageType, - int32_t& seqid) = 0; - - virtual uint32_t readMessageEnd() = 0; - - virtual uint32_t readStructBegin(std::string& name) = 0; - - virtual uint32_t readStructEnd() = 0; - - virtual uint32_t readFieldBegin(std::string& name, - TType& fieldType, - int16_t& fieldId) = 0; - - virtual uint32_t readFieldEnd() = 0; - - virtual uint32_t readMapBegin(TType& keyType, - TType& valType, - uint32_t& size) = 0; - - virtual uint32_t readMapEnd() = 0; - - virtual uint32_t readListBegin(TType& elemType, - uint32_t& size) = 0; - - virtual uint32_t readListEnd() = 0; - - virtual uint32_t readSetBegin(TType& elemType, - uint32_t& size) = 0; - - virtual uint32_t readSetEnd() = 0; - - virtual uint32_t readBool(bool& value) = 0; - - virtual uint32_t readByte(int8_t& byte) = 0; - - virtual uint32_t readI16(int16_t& i16) = 0; - - virtual uint32_t readI32(int32_t& i32) = 0; - - virtual uint32_t readI64(int64_t& i64) = 0; - - virtual uint32_t readDouble(double& dub) = 0; - - virtual uint32_t readString(std::string& str) = 0; - - virtual uint32_t readBinary(std::string& str) = 0; - - uint32_t readBool(std::vector::reference ref) { - bool value; - uint32_t rv = readBool(value); - ref = value; - return rv; - } - - /** - * Method to arbitrarily skip over data. - */ - uint32_t skip(TType type) { - switch (type) { - case T_BOOL: - { - bool boolv; - return readBool(boolv); - } - case T_BYTE: - { - int8_t bytev; - return readByte(bytev); - } - case T_I16: - { - int16_t i16; - return readI16(i16); - } - case T_I32: - { - int32_t i32; - return readI32(i32); - } - case T_I64: - { - int64_t i64; - return readI64(i64); - } - case T_DOUBLE: - { - double dub; - return readDouble(dub); - } - case T_STRING: - { - std::string str; - return readBinary(str); - } - case T_STRUCT: - { - uint32_t result = 0; - std::string name; - int16_t fid; - TType ftype; - result += readStructBegin(name); - while (true) { - result += readFieldBegin(name, ftype, fid); - if (ftype == T_STOP) { - break; - } - result += skip(ftype); - result += readFieldEnd(); - } - result += readStructEnd(); - return result; - } - case T_MAP: - { - uint32_t result = 0; - TType keyType; - TType valType; - uint32_t i, size; - result += readMapBegin(keyType, valType, size); - for (i = 0; i < size; i++) { - result += skip(keyType); - result += skip(valType); - } - result += readMapEnd(); - return result; - } - case T_SET: - { - uint32_t result = 0; - TType elemType; - uint32_t i, size; - result += readSetBegin(elemType, size); - for (i = 0; i < size; i++) { - result += skip(elemType); - } - result += readSetEnd(); - return result; - } - case T_LIST: - { - uint32_t result = 0; - TType elemType; - uint32_t i, size; - result += readListBegin(elemType, size); - for (i = 0; i < size; i++) { - result += skip(elemType); - } - result += readListEnd(); - return result; - } - default: - return 0; - } - } - - inline boost::shared_ptr getTransport() { - return ptrans_; - } - - // TODO: remove these two calls, they are for backwards - // compatibility - inline boost::shared_ptr getInputTransport() { - return ptrans_; - } - inline boost::shared_ptr getOutputTransport() { - return ptrans_; - } - - protected: - TProtocol(boost::shared_ptr ptrans): - ptrans_(ptrans) { - trans_ = ptrans.get(); - } - - boost::shared_ptr ptrans_; - TTransport* trans_; - - private: - TProtocol() {} -}; - -/** - * Constructs input and output protocol objects given transports. - */ -class TProtocolFactory { - public: - TProtocolFactory() {} - - virtual ~TProtocolFactory() {} - - virtual boost::shared_ptr getProtocol(boost::shared_ptr trans) = 0; -}; - -}}} // apache::thrift::protocol - -#endif // #define _THRIFT_PROTOCOL_TPROTOCOL_H_ 1 diff --git service/include/thrift/protocol/TProtocolException.h service/include/thrift/protocol/TProtocolException.h deleted file mode 100644 index 33011b3..0000000 --- service/include/thrift/protocol/TProtocolException.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_PROTOCOL_TPROTOCOLEXCEPTION_H_ -#define _THRIFT_PROTOCOL_TPROTOCOLEXCEPTION_H_ 1 - -#include - -namespace apache { namespace thrift { namespace protocol { - -/** - * Class to encapsulate all the possible types of protocol errors that may - * occur in various protocol systems. This provides a sort of generic - * wrapper around the shitty UNIX E_ error codes that lets a common code - * base of error handling to be used for various types of protocols, i.e. - * pipes etc. - * - */ -class TProtocolException : public apache::thrift::TException { - public: - - /** - * Error codes for the various types of exceptions. - */ - enum TProtocolExceptionType - { UNKNOWN = 0 - , INVALID_DATA = 1 - , NEGATIVE_SIZE = 2 - , SIZE_LIMIT = 3 - , BAD_VERSION = 4 - , NOT_IMPLEMENTED = 5 - }; - - TProtocolException() : - apache::thrift::TException(), - type_(UNKNOWN) {} - - TProtocolException(TProtocolExceptionType type) : - apache::thrift::TException(), - type_(type) {} - - TProtocolException(const std::string& message) : - apache::thrift::TException(message), - type_(UNKNOWN) {} - - TProtocolException(TProtocolExceptionType type, const std::string& message) : - apache::thrift::TException(message), - type_(type) {} - - virtual ~TProtocolException() throw() {} - - /** - * Returns an error code that provides information about the type of error - * that has occurred. - * - * @return Error code - */ - TProtocolExceptionType getType() { - return type_; - } - - virtual const char* what() const throw() { - if (message_.empty()) { - switch (type_) { - case UNKNOWN : return "TProtocolException: Unknown protocol exception"; - case INVALID_DATA : return "TProtocolException: Invalid data"; - case NEGATIVE_SIZE : return "TProtocolException: Negative size"; - case SIZE_LIMIT : return "TProtocolException: Exceeded size limit"; - case BAD_VERSION : return "TProtocolException: Invalid version"; - case NOT_IMPLEMENTED : return "TProtocolException: Not implemented"; - default : return "TProtocolException: (Invalid exception type)"; - } - } else { - return message_.c_str(); - } - } - - protected: - /** - * Error code - */ - TProtocolExceptionType type_; - -}; - -}}} // apache::thrift::protocol - -#endif // #ifndef _THRIFT_PROTOCOL_TPROTOCOLEXCEPTION_H_ diff --git service/include/thrift/protocol/TProtocolTap.h service/include/thrift/protocol/TProtocolTap.h deleted file mode 100644 index 5580216..0000000 --- service/include/thrift/protocol/TProtocolTap.h +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_PROTOCOL_TPROTOCOLTAP_H_ -#define _THRIFT_PROTOCOL_TPROTOCOLTAP_H_ 1 - -#include - -namespace apache { namespace thrift { namespace protocol { - -using apache::thrift::transport::TTransport; - -/** - * Puts a wiretap on a protocol object. Any reads to this class are passed - * through to an enclosed protocol object, but also mirrored as write to a - * second protocol object. - * - */ -class TProtocolTap : public TReadOnlyProtocol { - public: - TProtocolTap(boost::shared_ptr source, - boost::shared_ptr sink) - : TReadOnlyProtocol(source->getTransport(), "TProtocolTap") - , source_(source) - , sink_(sink) - {} - - virtual uint32_t readMessageBegin(std::string& name, - TMessageType& messageType, - int32_t& seqid) { - uint32_t rv = source_->readMessageBegin(name, messageType, seqid); - sink_->writeMessageBegin(name, messageType, seqid); - return rv; - } - - virtual uint32_t readMessageEnd() { - uint32_t rv = source_->readMessageEnd(); - sink_->writeMessageEnd(); - return rv; - } - - virtual uint32_t readStructBegin(std::string& name) { - uint32_t rv = source_->readStructBegin(name); - sink_->writeStructBegin(name.c_str()); - return rv; - } - - virtual uint32_t readStructEnd() { - uint32_t rv = source_->readStructEnd(); - sink_->writeStructEnd(); - return rv; - } - - virtual uint32_t readFieldBegin(std::string& name, - TType& fieldType, - int16_t& fieldId) { - uint32_t rv = source_->readFieldBegin(name, fieldType, fieldId); - if (fieldType == T_STOP) { - sink_->writeFieldStop(); - } else { - sink_->writeFieldBegin(name.c_str(), fieldType, fieldId); - } - return rv; - } - - - virtual uint32_t readFieldEnd() { - uint32_t rv = source_->readFieldEnd(); - sink_->writeFieldEnd(); - return rv; - } - - virtual uint32_t readMapBegin(TType& keyType, - TType& valType, - uint32_t& size) { - uint32_t rv = source_->readMapBegin(keyType, valType, size); - sink_->writeMapBegin(keyType, valType, size); - return rv; - } - - - virtual uint32_t readMapEnd() { - uint32_t rv = source_->readMapEnd(); - sink_->writeMapEnd(); - return rv; - } - - virtual uint32_t readListBegin(TType& elemType, - uint32_t& size) { - uint32_t rv = source_->readListBegin(elemType, size); - sink_->writeListBegin(elemType, size); - return rv; - } - - - virtual uint32_t readListEnd() { - uint32_t rv = source_->readListEnd(); - sink_->writeListEnd(); - return rv; - } - - virtual uint32_t readSetBegin(TType& elemType, - uint32_t& size) { - uint32_t rv = source_->readSetBegin(elemType, size); - sink_->writeSetBegin(elemType, size); - return rv; - } - - - virtual uint32_t readSetEnd() { - uint32_t rv = source_->readSetEnd(); - sink_->writeSetEnd(); - return rv; - } - - virtual uint32_t readBool(bool& value) { - uint32_t rv = source_->readBool(value); - sink_->writeBool(value); - return rv; - } - - virtual uint32_t readByte(int8_t& byte) { - uint32_t rv = source_->readByte(byte); - sink_->writeByte(byte); - return rv; - } - - virtual uint32_t readI16(int16_t& i16) { - uint32_t rv = source_->readI16(i16); - sink_->writeI16(i16); - return rv; - } - - virtual uint32_t readI32(int32_t& i32) { - uint32_t rv = source_->readI32(i32); - sink_->writeI32(i32); - return rv; - } - - virtual uint32_t readI64(int64_t& i64) { - uint32_t rv = source_->readI64(i64); - sink_->writeI64(i64); - return rv; - } - - virtual uint32_t readDouble(double& dub) { - uint32_t rv = source_->readDouble(dub); - sink_->writeDouble(dub); - return rv; - } - - virtual uint32_t readString(std::string& str) { - uint32_t rv = source_->readString(str); - sink_->writeString(str); - return rv; - } - - virtual uint32_t readBinary(std::string& str) { - uint32_t rv = source_->readBinary(str); - sink_->writeBinary(str); - return rv; - } - - private: - boost::shared_ptr source_; - boost::shared_ptr sink_; -}; - -}}} // apache::thrift::protocol - -#endif // #define _THRIFT_PROTOCOL_TPROTOCOLTAP_H_ 1 diff --git service/include/thrift/reflection_limited_types.h service/include/thrift/reflection_limited_types.h deleted file mode 100644 index 677cb4a..0000000 --- service/include/thrift/reflection_limited_types.h +++ /dev/null @@ -1,285 +0,0 @@ -/** - * Autogenerated by Thrift - * - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - */ -#ifndef reflection_limited_TYPES_H -#define reflection_limited_TYPES_H - -#include -#include -#include -#include - - - -namespace facebook { namespace thrift { namespace reflection { namespace limited { - -enum TTypeTag { - T_VOID = 1, - T_BOOL = 2, - T_BYTE = 3, - T_I16 = 6, - T_I32 = 8, - T_I64 = 10, - T_DOUBLE = 4, - T_STRING = 11, - T_STRUCT = 12, - T_MAP = 13, - T_SET = 14, - T_LIST = 15, - T_ENUM = 101, - T_NOT_REFLECTED = 102 -}; - -class SimpleType { - public: - - static char* ascii_fingerprint; // = "19B5240589E680301A7E32DF3971EFBE"; - static char binary_fingerprint[16]; // = {0x19,0xB5,0x24,0x05,0x89,0xE6,0x80,0x30,0x1A,0x7E,0x32,0xDF,0x39,0x71,0xEF,0xBE}; - - SimpleType() : name("") { - } - - virtual ~SimpleType() throw() {} - - TTypeTag ttype; - std::string name; - - struct __isset { - __isset() : ttype(false), name(false) {} - bool ttype; - bool name; - } __isset; - - bool operator == (const SimpleType & rhs) const - { - if (!(ttype == rhs.ttype)) - return false; - if (!(name == rhs.name)) - return false; - return true; - } - bool operator != (const SimpleType &rhs) const { - return !(*this == rhs); - } - - uint32_t read(facebook::thrift::protocol::TProtocol* iprot); - uint32_t write(facebook::thrift::protocol::TProtocol* oprot) const; - -}; - -class ContainerType { - public: - - static char* ascii_fingerprint; // = "654FA6EFFF8242F4C2A604B970686634"; - static char binary_fingerprint[16]; // = {0x65,0x4F,0xA6,0xEF,0xFF,0x82,0x42,0xF4,0xC2,0xA6,0x04,0xB9,0x70,0x68,0x66,0x34}; - - ContainerType() { - } - - virtual ~ContainerType() throw() {} - - TTypeTag ttype; - SimpleType subtype1; - SimpleType subtype2; - - struct __isset { - __isset() : ttype(false), subtype1(false), subtype2(false) {} - bool ttype; - bool subtype1; - bool subtype2; - } __isset; - - bool operator == (const ContainerType & rhs) const - { - if (!(ttype == rhs.ttype)) - return false; - if (!(subtype1 == rhs.subtype1)) - return false; - if (__isset.subtype2 != rhs.__isset.subtype2) - return false; - else if (__isset.subtype2 && !(subtype2 == rhs.subtype2)) - return false; - return true; - } - bool operator != (const ContainerType &rhs) const { - return !(*this == rhs); - } - - uint32_t read(facebook::thrift::protocol::TProtocol* iprot); - uint32_t write(facebook::thrift::protocol::TProtocol* oprot) const; - -}; - -class ThriftType { - public: - - static char* ascii_fingerprint; // = "76BC1CC759001D7D85FEE75C4F183062"; - static char binary_fingerprint[16]; // = {0x76,0xBC,0x1C,0xC7,0x59,0x00,0x1D,0x7D,0x85,0xFE,0xE7,0x5C,0x4F,0x18,0x30,0x62}; - - ThriftType() : is_container(0) { - } - - virtual ~ThriftType() throw() {} - - bool is_container; - SimpleType simple_type; - ContainerType container_type; - - struct __isset { - __isset() : is_container(false), simple_type(false), container_type(false) {} - bool is_container; - bool simple_type; - bool container_type; - } __isset; - - bool operator == (const ThriftType & rhs) const - { - if (!(is_container == rhs.is_container)) - return false; - if (__isset.simple_type != rhs.__isset.simple_type) - return false; - else if (__isset.simple_type && !(simple_type == rhs.simple_type)) - return false; - if (__isset.container_type != rhs.__isset.container_type) - return false; - else if (__isset.container_type && !(container_type == rhs.container_type)) - return false; - return true; - } - bool operator != (const ThriftType &rhs) const { - return !(*this == rhs); - } - - uint32_t read(facebook::thrift::protocol::TProtocol* iprot); - uint32_t write(facebook::thrift::protocol::TProtocol* oprot) const; - -}; - -class Argument { - public: - - static char* ascii_fingerprint; // = "8C45506BE0EFBB22FB19FA40DDCECB3F"; - static char binary_fingerprint[16]; // = {0x8C,0x45,0x50,0x6B,0xE0,0xEF,0xBB,0x22,0xFB,0x19,0xFA,0x40,0xDD,0xCE,0xCB,0x3F}; - - Argument() : key(0), name("") { - } - - virtual ~Argument() throw() {} - - int16_t key; - std::string name; - ThriftType type; - - struct __isset { - __isset() : key(false), name(false), type(false) {} - bool key; - bool name; - bool type; - } __isset; - - bool operator == (const Argument & rhs) const - { - if (!(key == rhs.key)) - return false; - if (!(name == rhs.name)) - return false; - if (!(type == rhs.type)) - return false; - return true; - } - bool operator != (const Argument &rhs) const { - return !(*this == rhs); - } - - uint32_t read(facebook::thrift::protocol::TProtocol* iprot); - uint32_t write(facebook::thrift::protocol::TProtocol* oprot) const; - -}; - -class Method { - public: - - static char* ascii_fingerprint; // = "E6573428C492D24C84A19432D39A17B0"; - static char binary_fingerprint[16]; // = {0xE6,0x57,0x34,0x28,0xC4,0x92,0xD2,0x4C,0x84,0xA1,0x94,0x32,0xD3,0x9A,0x17,0xB0}; - - Method() : name("") { - } - - virtual ~Method() throw() {} - - std::string name; - ThriftType return_type; - std::vector arguments; - - struct __isset { - __isset() : name(false), return_type(false), arguments(false) {} - bool name; - bool return_type; - bool arguments; - } __isset; - - bool operator == (const Method & rhs) const - { - if (!(name == rhs.name)) - return false; - if (!(return_type == rhs.return_type)) - return false; - if (!(arguments == rhs.arguments)) - return false; - return true; - } - bool operator != (const Method &rhs) const { - return !(*this == rhs); - } - - uint32_t read(facebook::thrift::protocol::TProtocol* iprot); - uint32_t write(facebook::thrift::protocol::TProtocol* oprot) const; - -}; - -class Service { - public: - - static char* ascii_fingerprint; // = "4673B0777B701D9B02A7A74CEC7908A7"; - static char binary_fingerprint[16]; // = {0x46,0x73,0xB0,0x77,0x7B,0x70,0x1D,0x9B,0x02,0xA7,0xA7,0x4C,0xEC,0x79,0x08,0xA7}; - - Service() : name(""), fully_reflected(0) { - } - - virtual ~Service() throw() {} - - std::string name; - std::vector methods; - bool fully_reflected; - - struct __isset { - __isset() : name(false), methods(false), fully_reflected(false) {} - bool name; - bool methods; - bool fully_reflected; - } __isset; - - bool operator == (const Service & rhs) const - { - if (!(name == rhs.name)) - return false; - if (!(methods == rhs.methods)) - return false; - if (!(fully_reflected == rhs.fully_reflected)) - return false; - return true; - } - bool operator != (const Service &rhs) const { - return !(*this == rhs); - } - - uint32_t read(facebook::thrift::protocol::TProtocol* iprot); - uint32_t write(facebook::thrift::protocol::TProtocol* oprot) const; - -}; - -}}}} // namespace - -#endif diff --git service/include/thrift/server/TNonblockingServer.h service/include/thrift/server/TNonblockingServer.h deleted file mode 100644 index 8506507..0000000 --- service/include/thrift/server/TNonblockingServer.h +++ /dev/null @@ -1,435 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_SERVER_TNONBLOCKINGSERVER_H_ -#define _THRIFT_SERVER_TNONBLOCKINGSERVER_H_ 1 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace apache { namespace thrift { namespace server { - -using apache::thrift::transport::TMemoryBuffer; -using apache::thrift::protocol::TProtocol; -using apache::thrift::concurrency::Runnable; -using apache::thrift::concurrency::ThreadManager; - -// Forward declaration of class -class TConnection; - -/** - * This is a non-blocking server in C++ for high performance that operates a - * single IO thread. It assumes that all incoming requests are framed with a - * 4 byte length indicator and writes out responses using the same framing. - * - * It does not use the TServerTransport framework, but rather has socket - * operations hardcoded for use with select. - * - */ -class TNonblockingServer : public TServer { - private: - - // Listen backlog - static const int LISTEN_BACKLOG = 1024; - - // Default limit on size of idle connection pool - static const size_t CONNECTION_STACK_LIMIT = 1024; - - // Maximum size of buffer allocated to idle connection - static const uint32_t IDLE_BUFFER_MEM_LIMIT = 8192; - - // Server socket file descriptor - int serverSocket_; - - // Port server runs on - int port_; - - // For processing via thread pool, may be NULL - boost::shared_ptr threadManager_; - - // Is thread pool processing? - bool threadPoolProcessing_; - - // The event base for libevent - event_base* eventBase_; - - // Event struct, for use with eventBase_ - struct event serverEvent_; - - // Number of TConnection object we've created - size_t numTConnections_; - - // Limit for how many TConnection objects to cache - size_t connectionStackLimit_; - - /** - * Max read buffer size for an idle connection. When we place an idle - * TConnection into connectionStack_, we insure that its read buffer is - * reduced to this size to insure that idle connections don't hog memory. - */ - uint32_t idleBufferMemLimit_; - - /** - * This is a stack of all the objects that have been created but that - * are NOT currently in use. When we close a connection, we place it on this - * stack so that the object can be reused later, rather than freeing the - * memory and reallocating a new object later. - */ - std::stack connectionStack_; - - void handleEvent(int fd, short which); - - public: - TNonblockingServer(boost::shared_ptr processor, - int port) : - TServer(processor), - serverSocket_(-1), - port_(port), - threadPoolProcessing_(false), - eventBase_(NULL), - numTConnections_(0), - connectionStackLimit_(CONNECTION_STACK_LIMIT), - idleBufferMemLimit_(IDLE_BUFFER_MEM_LIMIT) {} - - TNonblockingServer(boost::shared_ptr processor, - boost::shared_ptr protocolFactory, - int port, - boost::shared_ptr threadManager = boost::shared_ptr()) : - TServer(processor), - serverSocket_(-1), - port_(port), - threadManager_(threadManager), - eventBase_(NULL), - numTConnections_(0), - connectionStackLimit_(CONNECTION_STACK_LIMIT), - idleBufferMemLimit_(IDLE_BUFFER_MEM_LIMIT) { - setInputTransportFactory(boost::shared_ptr(new TTransportFactory())); - setOutputTransportFactory(boost::shared_ptr(new TTransportFactory())); - setInputProtocolFactory(protocolFactory); - setOutputProtocolFactory(protocolFactory); - setThreadManager(threadManager); - } - - TNonblockingServer(boost::shared_ptr processor, - boost::shared_ptr inputTransportFactory, - boost::shared_ptr outputTransportFactory, - boost::shared_ptr inputProtocolFactory, - boost::shared_ptr outputProtocolFactory, - int port, - boost::shared_ptr threadManager = boost::shared_ptr()) : - TServer(processor), - serverSocket_(0), - port_(port), - threadManager_(threadManager), - eventBase_(NULL), - numTConnections_(0), - connectionStackLimit_(CONNECTION_STACK_LIMIT), - idleBufferMemLimit_(IDLE_BUFFER_MEM_LIMIT) { - setInputTransportFactory(inputTransportFactory); - setOutputTransportFactory(outputTransportFactory); - setInputProtocolFactory(inputProtocolFactory); - setOutputProtocolFactory(outputProtocolFactory); - setThreadManager(threadManager); - } - - ~TNonblockingServer() {} - - void setThreadManager(boost::shared_ptr threadManager) { - threadManager_ = threadManager; - threadPoolProcessing_ = (threadManager != NULL); - } - - boost::shared_ptr getThreadManager() { - return threadManager_; - } - - /** - * Get the maximum number of unused TConnection we will hold in reserve. - * - * @return the current limit on TConnection pool size. - */ - size_t getConnectionStackLimit() const { - return connectionStackLimit_; - } - - /** - * Set the maximum number of unused TConnection we will hold in reserve. - * - * @param sz the new limit for TConnection pool size. - */ - void setConnectionStackLimit(size_t sz) { - connectionStackLimit_ = sz; - } - - bool isThreadPoolProcessing() const { - return threadPoolProcessing_; - } - - void addTask(boost::shared_ptr task) { - threadManager_->add(task); - } - - event_base* getEventBase() const { - return eventBase_; - } - - void incrementNumConnections() { - ++numTConnections_; - } - - void decrementNumConnections() { - --numTConnections_; - } - - size_t getNumConnections() { - return numTConnections_; - } - - size_t getNumIdleConnections() { - return connectionStack_.size(); - } - - /** - * Get the maximum limit of memory allocated to idle TConnection objects. - * - * @return # bytes beyond which we will shrink buffers when idle. - */ - size_t getIdleBufferMemLimit() const { - return idleBufferMemLimit_; - } - - /** - * Set the maximum limit of memory allocated to idle TConnection objects. - * If a TConnection object goes idle with more than this much memory - * allocated to its buffer, we shrink it to this value. - * - * @param limit of bytes beyond which we will shrink buffers when idle. - */ - void setIdleBufferMemLimit(size_t limit) { - idleBufferMemLimit_ = limit; - } - - TConnection* createConnection(int socket, short flags); - - void returnConnection(TConnection* connection); - - static void eventHandler(int fd, short which, void* v) { - ((TNonblockingServer*)v)->handleEvent(fd, which); - } - - void listenSocket(); - - void listenSocket(int fd); - - void registerEvents(event_base* base); - - void serve(); -}; - -/** - * Two states for sockets, recv and send mode - */ -enum TSocketState { - SOCKET_RECV, - SOCKET_SEND -}; - -/** - * Four states for the nonblocking servr: - * 1) initialize - * 2) read 4 byte frame size - * 3) read frame of data - * 4) send back data (if any) - */ -enum TAppState { - APP_INIT, - APP_READ_FRAME_SIZE, - APP_READ_REQUEST, - APP_WAIT_TASK, - APP_SEND_RESULT -}; - -/** - * Represents a connection that is handled via libevent. This connection - * essentially encapsulates a socket that has some associated libevent state. - */ -class TConnection { - private: - - class Task; - - // Server handle - TNonblockingServer* server_; - - // Socket handle - int socket_; - - // Libevent object - struct event event_; - - // Libevent flags - short eventFlags_; - - // Socket mode - TSocketState socketState_; - - // Application state - TAppState appState_; - - // How much data needed to read - uint32_t readWant_; - - // Where in the read buffer are we - uint32_t readBufferPos_; - - // Read buffer - uint8_t* readBuffer_; - - // Read buffer size - uint32_t readBufferSize_; - - // Write buffer - uint8_t* writeBuffer_; - - // Write buffer size - uint32_t writeBufferSize_; - - // How far through writing are we? - uint32_t writeBufferPos_; - - // How many times have we read since our last buffer reset? - uint32_t numReadsSinceReset_; - - // How many times have we written since our last buffer reset? - uint32_t numWritesSinceReset_; - - // Task handle - int taskHandle_; - - // Task event - struct event taskEvent_; - - // Transport to read from - boost::shared_ptr inputTransport_; - - // Transport that processor writes to - boost::shared_ptr outputTransport_; - - // extra transport generated by transport factory (e.g. BufferedRouterTransport) - boost::shared_ptr factoryInputTransport_; - boost::shared_ptr factoryOutputTransport_; - - // Protocol decoder - boost::shared_ptr inputProtocol_; - - // Protocol encoder - boost::shared_ptr outputProtocol_; - - // Go into read mode - void setRead() { - setFlags(EV_READ | EV_PERSIST); - } - - // Go into write mode - void setWrite() { - setFlags(EV_WRITE | EV_PERSIST); - } - - // Set socket idle - void setIdle() { - setFlags(0); - } - - // Set event flags - void setFlags(short eventFlags); - - // Libevent handlers - void workSocket(); - - // Close this client and reset - void close(); - - public: - - // Constructor - TConnection(int socket, short eventFlags, TNonblockingServer *s) { - readBuffer_ = (uint8_t*)std::malloc(1024); - if (readBuffer_ == NULL) { - throw new apache::thrift::TException("Out of memory."); - } - readBufferSize_ = 1024; - - numReadsSinceReset_ = 0; - numWritesSinceReset_ = 0; - - // Allocate input and output tranpsorts - // these only need to be allocated once per TConnection (they don't need to be - // reallocated on init() call) - inputTransport_ = boost::shared_ptr(new TMemoryBuffer(readBuffer_, readBufferSize_)); - outputTransport_ = boost::shared_ptr(new TMemoryBuffer()); - - init(socket, eventFlags, s); - server_->incrementNumConnections(); - } - - ~TConnection() { - server_->decrementNumConnections(); - } - - /** - * Check read buffer against a given limit and shrink it if exceeded. - * - * @param limit we limit buffer size to. - */ - void checkIdleBufferMemLimit(uint32_t limit); - - // Initialize - void init(int socket, short eventFlags, TNonblockingServer *s); - - // Transition into a new state - void transition(); - - // Handler wrapper - static void eventHandler(int fd, short /* which */, void* v) { - assert(fd == ((TConnection*)v)->socket_); - ((TConnection*)v)->workSocket(); - } - - // Handler wrapper for task block - static void taskHandler(int fd, short /* which */, void* v) { - assert(fd == ((TConnection*)v)->taskHandle_); - if (-1 == ::close(((TConnection*)v)->taskHandle_)) { - GlobalOutput.perror("TConnection::taskHandler close handle failed, resource leak ", errno); - } - ((TConnection*)v)->transition(); - } - -}; - -}}} // apache::thrift::server - -#endif // #ifndef _THRIFT_SERVER_TSIMPLESERVER_H_ diff --git service/include/thrift/server/TServer.h service/include/thrift/server/TServer.h deleted file mode 100644 index 5c4c588..0000000 --- service/include/thrift/server/TServer.h +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_SERVER_TSERVER_H_ -#define _THRIFT_SERVER_TSERVER_H_ 1 - -#include -#include -#include -#include - -#include - -namespace apache { namespace thrift { namespace server { - -using apache::thrift::TProcessor; -using apache::thrift::protocol::TBinaryProtocolFactory; -using apache::thrift::protocol::TProtocol; -using apache::thrift::protocol::TProtocolFactory; -using apache::thrift::transport::TServerTransport; -using apache::thrift::transport::TTransport; -using apache::thrift::transport::TTransportFactory; - -/** - * Virtual interface class that can handle events from the server core. To - * use this you should subclass it and implement the methods that you care - * about. Your subclass can also store local data that you may care about, - * such as additional "arguments" to these methods (stored in the object - * instance's state). - */ -class TServerEventHandler { - public: - - virtual ~TServerEventHandler() {} - - /** - * Called before the server begins. - */ - virtual void preServe() {} - - /** - * Called when a new client has connected and is about to being processing. - */ - virtual void clientBegin(boost::shared_ptr /* input */, - boost::shared_ptr /* output */) {} - - /** - * Called when a client has finished making requests. - */ - virtual void clientEnd(boost::shared_ptr /* input */, - boost::shared_ptr /* output */) {} - - protected: - - /** - * Prevent direct instantiation. - */ - TServerEventHandler() {} - -}; - -/** - * Thrift server. - * - */ -class TServer : public concurrency::Runnable { - public: - - virtual ~TServer() {} - - virtual void serve() = 0; - - virtual void stop() {} - - // Allows running the server as a Runnable thread - virtual void run() { - serve(); - } - - boost::shared_ptr getProcessor() { - return processor_; - } - - boost::shared_ptr getServerTransport() { - return serverTransport_; - } - - boost::shared_ptr getInputTransportFactory() { - return inputTransportFactory_; - } - - boost::shared_ptr getOutputTransportFactory() { - return outputTransportFactory_; - } - - boost::shared_ptr getInputProtocolFactory() { - return inputProtocolFactory_; - } - - boost::shared_ptr getOutputProtocolFactory() { - return outputProtocolFactory_; - } - - boost::shared_ptr getEventHandler() { - return eventHandler_; - } - -protected: - TServer(boost::shared_ptr processor): - processor_(processor) { - setInputTransportFactory(boost::shared_ptr(new TTransportFactory())); - setOutputTransportFactory(boost::shared_ptr(new TTransportFactory())); - setInputProtocolFactory(boost::shared_ptr(new TBinaryProtocolFactory())); - setOutputProtocolFactory(boost::shared_ptr(new TBinaryProtocolFactory())); - } - - TServer(boost::shared_ptr processor, - boost::shared_ptr serverTransport): - processor_(processor), - serverTransport_(serverTransport) { - setInputTransportFactory(boost::shared_ptr(new TTransportFactory())); - setOutputTransportFactory(boost::shared_ptr(new TTransportFactory())); - setInputProtocolFactory(boost::shared_ptr(new TBinaryProtocolFactory())); - setOutputProtocolFactory(boost::shared_ptr(new TBinaryProtocolFactory())); - } - - TServer(boost::shared_ptr processor, - boost::shared_ptr serverTransport, - boost::shared_ptr transportFactory, - boost::shared_ptr protocolFactory): - processor_(processor), - serverTransport_(serverTransport), - inputTransportFactory_(transportFactory), - outputTransportFactory_(transportFactory), - inputProtocolFactory_(protocolFactory), - outputProtocolFactory_(protocolFactory) {} - - TServer(boost::shared_ptr processor, - boost::shared_ptr serverTransport, - boost::shared_ptr inputTransportFactory, - boost::shared_ptr outputTransportFactory, - boost::shared_ptr inputProtocolFactory, - boost::shared_ptr outputProtocolFactory): - processor_(processor), - serverTransport_(serverTransport), - inputTransportFactory_(inputTransportFactory), - outputTransportFactory_(outputTransportFactory), - inputProtocolFactory_(inputProtocolFactory), - outputProtocolFactory_(outputProtocolFactory) {} - - - // Class variables - boost::shared_ptr processor_; - boost::shared_ptr serverTransport_; - - boost::shared_ptr inputTransportFactory_; - boost::shared_ptr outputTransportFactory_; - - boost::shared_ptr inputProtocolFactory_; - boost::shared_ptr outputProtocolFactory_; - - boost::shared_ptr eventHandler_; - -public: - void setInputTransportFactory(boost::shared_ptr inputTransportFactory) { - inputTransportFactory_ = inputTransportFactory; - } - - void setOutputTransportFactory(boost::shared_ptr outputTransportFactory) { - outputTransportFactory_ = outputTransportFactory; - } - - void setInputProtocolFactory(boost::shared_ptr inputProtocolFactory) { - inputProtocolFactory_ = inputProtocolFactory; - } - - void setOutputProtocolFactory(boost::shared_ptr outputProtocolFactory) { - outputProtocolFactory_ = outputProtocolFactory; - } - - void setServerEventHandler(boost::shared_ptr eventHandler) { - eventHandler_ = eventHandler; - } - -}; - -/** - * Helper function to increase the max file descriptors limit - * for the current process and all of its children. - * By default, tries to increase it to as much as 2^24. - */ - int increase_max_fds(int max_fds=(1<<24)); - - -}}} // apache::thrift::server - -#endif // #ifndef _THRIFT_SERVER_TSERVER_H_ diff --git service/include/thrift/server/TSimpleServer.h service/include/thrift/server/TSimpleServer.h deleted file mode 100644 index c4fc91c..0000000 --- service/include/thrift/server/TSimpleServer.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_SERVER_TSIMPLESERVER_H_ -#define _THRIFT_SERVER_TSIMPLESERVER_H_ 1 - -#include "server/TServer.h" -#include "transport/TServerTransport.h" - -namespace apache { namespace thrift { namespace server { - -/** - * This is the most basic simple server. It is single-threaded and runs a - * continuous loop of accepting a single connection, processing requests on - * that connection until it closes, and then repeating. It is a good example - * of how to extend the TServer interface. - * - */ -class TSimpleServer : public TServer { - public: - TSimpleServer(boost::shared_ptr processor, - boost::shared_ptr serverTransport, - boost::shared_ptr transportFactory, - boost::shared_ptr protocolFactory) : - TServer(processor, serverTransport, transportFactory, protocolFactory), - stop_(false) {} - - TSimpleServer(boost::shared_ptr processor, - boost::shared_ptr serverTransport, - boost::shared_ptr inputTransportFactory, - boost::shared_ptr outputTransportFactory, - boost::shared_ptr inputProtocolFactory, - boost::shared_ptr outputProtocolFactory): - TServer(processor, serverTransport, - inputTransportFactory, outputTransportFactory, - inputProtocolFactory, outputProtocolFactory), - stop_(false) {} - - ~TSimpleServer() {} - - void serve(); - - void stop() { - stop_ = true; - } - - protected: - bool stop_; - -}; - -}}} // apache::thrift::server - -#endif // #ifndef _THRIFT_SERVER_TSIMPLESERVER_H_ diff --git service/include/thrift/server/TThreadPoolServer.h service/include/thrift/server/TThreadPoolServer.h deleted file mode 100644 index 7b7e906..0000000 --- service/include/thrift/server/TThreadPoolServer.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_SERVER_TTHREADPOOLSERVER_H_ -#define _THRIFT_SERVER_TTHREADPOOLSERVER_H_ 1 - -#include -#include -#include - -#include - -namespace apache { namespace thrift { namespace server { - -using apache::thrift::concurrency::ThreadManager; -using apache::thrift::protocol::TProtocolFactory; -using apache::thrift::transport::TServerTransport; -using apache::thrift::transport::TTransportFactory; - -class TThreadPoolServer : public TServer { - public: - class Task; - - TThreadPoolServer(boost::shared_ptr processor, - boost::shared_ptr serverTransport, - boost::shared_ptr transportFactory, - boost::shared_ptr protocolFactory, - boost::shared_ptr threadManager); - - TThreadPoolServer(boost::shared_ptr processor, - boost::shared_ptr serverTransport, - boost::shared_ptr inputTransportFactory, - boost::shared_ptr outputTransportFactory, - boost::shared_ptr inputProtocolFactory, - boost::shared_ptr outputProtocolFactory, - boost::shared_ptr threadManager); - - virtual ~TThreadPoolServer(); - - virtual void serve(); - - virtual int64_t getTimeout() const; - - virtual void setTimeout(int64_t value); - - virtual void stop() { - stop_ = true; - serverTransport_->interrupt(); - } - - protected: - - boost::shared_ptr threadManager_; - - volatile bool stop_; - - volatile int64_t timeout_; - -}; - -}}} // apache::thrift::server - -#endif // #ifndef _THRIFT_SERVER_TTHREADPOOLSERVER_H_ diff --git service/include/thrift/server/TThreadedServer.h service/include/thrift/server/TThreadedServer.h deleted file mode 100644 index 4d0811a..0000000 --- service/include/thrift/server/TThreadedServer.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_SERVER_TTHREADEDSERVER_H_ -#define _THRIFT_SERVER_TTHREADEDSERVER_H_ 1 - -#include -#include -#include -#include - -#include - -namespace apache { namespace thrift { namespace server { - -using apache::thrift::TProcessor; -using apache::thrift::transport::TServerTransport; -using apache::thrift::transport::TTransportFactory; -using apache::thrift::concurrency::Monitor; -using apache::thrift::concurrency::ThreadFactory; - -class TThreadedServer : public TServer { - - public: - class Task; - - TThreadedServer(boost::shared_ptr processor, - boost::shared_ptr serverTransport, - boost::shared_ptr transportFactory, - boost::shared_ptr protocolFactory); - - TThreadedServer(boost::shared_ptr processor, - boost::shared_ptr serverTransport, - boost::shared_ptr transportFactory, - boost::shared_ptr protocolFactory, - boost::shared_ptr threadFactory); - - virtual ~TThreadedServer(); - - virtual void serve(); - - void stop() { - stop_ = true; - serverTransport_->interrupt(); - } - - protected: - boost::shared_ptr threadFactory_; - volatile bool stop_; - - Monitor tasksMonitor_; - std::set tasks_; - -}; - -}}} // apache::thrift::server - -#endif // #ifndef _THRIFT_SERVER_TTHREADEDSERVER_H_ diff --git service/include/thrift/transport/TBufferTransports.h service/include/thrift/transport/TBufferTransports.h deleted file mode 100644 index 1908205..0000000 --- service/include/thrift/transport/TBufferTransports.h +++ /dev/null @@ -1,667 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_TRANSPORT_TBUFFERTRANSPORTS_H_ -#define _THRIFT_TRANSPORT_TBUFFERTRANSPORTS_H_ 1 - -#include -#include "boost/scoped_array.hpp" - -#include - -#ifdef __GNUC__ -#define TDB_LIKELY(val) (__builtin_expect((val), 1)) -#define TDB_UNLIKELY(val) (__builtin_expect((val), 0)) -#else -#define TDB_LIKELY(val) (val) -#define TDB_UNLIKELY(val) (val) -#endif - -namespace apache { namespace thrift { namespace transport { - - -/** - * Base class for all transports that use read/write buffers for performance. - * - * TBufferBase is designed to implement the fast-path "memcpy" style - * operations that work in the common case. It does so with small and - * (eventually) nonvirtual, inlinable methods. TBufferBase is an abstract - * class. Subclasses are expected to define the "slow path" operations - * that have to be done when the buffers are full or empty. - * - */ -class TBufferBase : public TTransport { - - public: - - /** - * Fast-path read. - * - * When we have enough data buffered to fulfill the read, we can satisfy it - * with a single memcpy, then adjust our internal pointers. If the buffer - * is empty, we call out to our slow path, implemented by a subclass. - * This method is meant to eventually be nonvirtual and inlinable. - */ - uint32_t read(uint8_t* buf, uint32_t len) { - uint8_t* new_rBase = rBase_ + len; - if (TDB_LIKELY(new_rBase <= rBound_)) { - std::memcpy(buf, rBase_, len); - rBase_ = new_rBase; - return len; - } - return readSlow(buf, len); - } - - /** - * Fast-path write. - * - * When we have enough empty space in our buffer to accomodate the write, we - * can satisfy it with a single memcpy, then adjust our internal pointers. - * If the buffer is full, we call out to our slow path, implemented by a - * subclass. This method is meant to eventually be nonvirtual and - * inlinable. - */ - void write(const uint8_t* buf, uint32_t len) { - uint8_t* new_wBase = wBase_ + len; - if (TDB_LIKELY(new_wBase <= wBound_)) { - std::memcpy(wBase_, buf, len); - wBase_ = new_wBase; - return; - } - writeSlow(buf, len); - } - - /** - * Fast-path borrow. A lot like the fast-path read. - */ - const uint8_t* borrow(uint8_t* buf, uint32_t* len) { - if (TDB_LIKELY(static_cast(*len) <= rBound_ - rBase_)) { - // With strict aliasing, writing to len shouldn't force us to - // refetch rBase_ from memory. TODO(dreiss): Verify this. - *len = rBound_ - rBase_; - return rBase_; - } - return borrowSlow(buf, len); - } - - /** - * Consume doesn't require a slow path. - */ - void consume(uint32_t len) { - if (TDB_LIKELY(static_cast(len) <= rBound_ - rBase_)) { - rBase_ += len; - } else { - throw TTransportException(TTransportException::BAD_ARGS, - "consume did not follow a borrow."); - } - } - - - protected: - - /// Slow path read. - virtual uint32_t readSlow(uint8_t* buf, uint32_t len) = 0; - - /// Slow path write. - virtual void writeSlow(const uint8_t* buf, uint32_t len) = 0; - - /** - * Slow path borrow. - * - * POSTCONDITION: return == NULL || rBound_ - rBase_ >= *len - */ - virtual const uint8_t* borrowSlow(uint8_t* buf, uint32_t* len) = 0; - - /** - * Trivial constructor. - * - * Initialize pointers safely. Constructing is not a very - * performance-sensitive operation, so it is okay to just leave it to - * the concrete class to set up pointers correctly. - */ - TBufferBase() - : rBase_(NULL) - , rBound_(NULL) - , wBase_(NULL) - , wBound_(NULL) - {} - - /// Convenience mutator for setting the read buffer. - void setReadBuffer(uint8_t* buf, uint32_t len) { - rBase_ = buf; - rBound_ = buf+len; - } - - /// Convenience mutator for setting the write buffer. - void setWriteBuffer(uint8_t* buf, uint32_t len) { - wBase_ = buf; - wBound_ = buf+len; - } - - virtual ~TBufferBase() {} - - /// Reads begin here. - uint8_t* rBase_; - /// Reads may extend to just before here. - uint8_t* rBound_; - - /// Writes begin here. - uint8_t* wBase_; - /// Writes may extend to just before here. - uint8_t* wBound_; -}; - - -/** - * Base class for all transport which wraps transport to new one. - */ -class TUnderlyingTransport : public TBufferBase { - public: - static const int DEFAULT_BUFFER_SIZE = 512; - - virtual bool peek() { - return (rBase_ < rBound_) || transport_->peek(); - } - - void open() { - transport_->open(); - } - - bool isOpen() { - return transport_->isOpen(); - } - - void close() { - flush(); - transport_->close(); - } - - boost::shared_ptr getUnderlyingTransport() { - return transport_; - } - - protected: - boost::shared_ptr transport_; - - uint32_t rBufSize_; - uint32_t wBufSize_; - boost::scoped_array rBuf_; - boost::scoped_array wBuf_; - - TUnderlyingTransport(boost::shared_ptr transport, uint32_t sz) - : transport_(transport) - , rBufSize_(sz) - , wBufSize_(sz) - , rBuf_(new uint8_t[rBufSize_]) - , wBuf_(new uint8_t[wBufSize_]) {} - - TUnderlyingTransport(boost::shared_ptr transport) - : transport_(transport) - , rBufSize_(DEFAULT_BUFFER_SIZE) - , wBufSize_(DEFAULT_BUFFER_SIZE) - , rBuf_(new uint8_t[rBufSize_]) - , wBuf_(new uint8_t[wBufSize_]) {} - - TUnderlyingTransport(boost::shared_ptr transport, uint32_t rsz, uint32_t wsz) - : transport_(transport) - , rBufSize_(rsz) - , wBufSize_(wsz) - , rBuf_(new uint8_t[rBufSize_]) - , wBuf_(new uint8_t[wBufSize_]) {} -}; - -/** - * Buffered transport. For reads it will read more data than is requested - * and will serve future data out of a local buffer. For writes, data is - * stored to an in memory buffer before being written out. - * - */ -class TBufferedTransport : public TUnderlyingTransport { - public: - - /// Use default buffer sizes. - TBufferedTransport(boost::shared_ptr transport) - : TUnderlyingTransport(transport) - { - initPointers(); - } - - /// Use specified buffer sizes. - TBufferedTransport(boost::shared_ptr transport, uint32_t sz) - : TUnderlyingTransport(transport, sz) - { - initPointers(); - } - - /// Use specified read and write buffer sizes. - TBufferedTransport(boost::shared_ptr transport, uint32_t rsz, uint32_t wsz) - : TUnderlyingTransport(transport, rsz, wsz) - { - initPointers(); - } - - virtual bool peek() { - /* shigin: see THRIFT-96 discussion */ - if (rBase_ == rBound_) { - setReadBuffer(rBuf_.get(), transport_->read(rBuf_.get(), rBufSize_)); - } - return (rBound_ > rBase_); - } - virtual uint32_t readSlow(uint8_t* buf, uint32_t len); - - virtual void writeSlow(const uint8_t* buf, uint32_t len); - - void flush(); - - - /** - * The following behavior is currently implemented by TBufferedTransport, - * but that may change in a future version: - * 1/ If len is at most rBufSize_, borrow will never return NULL. - * Depending on the underlying transport, it could throw an exception - * or hang forever. - * 2/ Some borrow requests may copy bytes internally. However, - * if len is at most rBufSize_/2, none of the copied bytes - * will ever have to be copied again. For optimial performance, - * stay under this limit. - */ - virtual const uint8_t* borrowSlow(uint8_t* buf, uint32_t* len); - - protected: - void initPointers() { - setReadBuffer(rBuf_.get(), 0); - setWriteBuffer(wBuf_.get(), wBufSize_); - // Write size never changes. - } -}; - - -/** - * Wraps a transport into a buffered one. - * - */ -class TBufferedTransportFactory : public TTransportFactory { - public: - TBufferedTransportFactory() {} - - virtual ~TBufferedTransportFactory() {} - - /** - * Wraps the transport into a buffered one. - */ - virtual boost::shared_ptr getTransport(boost::shared_ptr trans) { - return boost::shared_ptr(new TBufferedTransport(trans)); - } - -}; - - -/** - * Framed transport. All writes go into an in-memory buffer until flush is - * called, at which point the transport writes the length of the entire - * binary chunk followed by the data payload. This allows the receiver on the - * other end to always do fixed-length reads. - * - */ -class TFramedTransport : public TUnderlyingTransport { - public: - - /// Use default buffer sizes. - TFramedTransport(boost::shared_ptr transport) - : TUnderlyingTransport(transport) - { - initPointers(); - } - - TFramedTransport(boost::shared_ptr transport, uint32_t sz) - : TUnderlyingTransport(transport, sz) - { - initPointers(); - } - - virtual uint32_t readSlow(uint8_t* buf, uint32_t len); - - virtual void writeSlow(const uint8_t* buf, uint32_t len); - - virtual void flush(); - - const uint8_t* borrowSlow(uint8_t* buf, uint32_t* len); - - protected: - /** - * Reads a frame of input from the underlying stream. - */ - void readFrame(); - - void initPointers() { - setReadBuffer(NULL, 0); - setWriteBuffer(wBuf_.get(), wBufSize_); - - // Pad the buffer so we can insert the size later. - int32_t pad = 0; - this->write((uint8_t*)&pad, sizeof(pad)); - } -}; - -/** - * Wraps a transport into a framed one. - * - */ -class TFramedTransportFactory : public TTransportFactory { - public: - TFramedTransportFactory() {} - - virtual ~TFramedTransportFactory() {} - - /** - * Wraps the transport into a framed one. - */ - virtual boost::shared_ptr getTransport(boost::shared_ptr trans) { - return boost::shared_ptr(new TFramedTransport(trans)); - } - -}; - - -/** - * A memory buffer is a tranpsort that simply reads from and writes to an - * in memory buffer. Anytime you call write on it, the data is simply placed - * into a buffer, and anytime you call read, data is read from that buffer. - * - * The buffers are allocated using C constructs malloc,realloc, and the size - * doubles as necessary. We've considered using scoped - * - */ -class TMemoryBuffer : public TBufferBase { - private: - - // Common initialization done by all constructors. - void initCommon(uint8_t* buf, uint32_t size, bool owner, uint32_t wPos) { - if (buf == NULL && size != 0) { - assert(owner); - buf = (uint8_t*)std::malloc(size); - if (buf == NULL) { - throw TTransportException("Out of memory"); - } - } - - buffer_ = buf; - bufferSize_ = size; - - rBase_ = buffer_; - rBound_ = buffer_ + wPos; - // TODO(dreiss): Investigate NULL-ing this if !owner. - wBase_ = buffer_ + wPos; - wBound_ = buffer_ + bufferSize_; - - owner_ = owner; - - // rBound_ is really an artifact. In principle, it should always be - // equal to wBase_. We update it in a few places (computeRead, etc.). - } - - public: - static const uint32_t defaultSize = 1024; - - /** - * This enum specifies how a TMemoryBuffer should treat - * memory passed to it via constructors or resetBuffer. - * - * OBSERVE: - * TMemoryBuffer will simply store a pointer to the memory. - * It is the callers responsibility to ensure that the pointer - * remains valid for the lifetime of the TMemoryBuffer, - * and that it is properly cleaned up. - * Note that no data can be written to observed buffers. - * - * COPY: - * TMemoryBuffer will make an internal copy of the buffer. - * The caller has no responsibilities. - * - * TAKE_OWNERSHIP: - * TMemoryBuffer will become the "owner" of the buffer, - * and will be responsible for freeing it. - * The membory must have been allocated with malloc. - */ - enum MemoryPolicy - { OBSERVE = 1 - , COPY = 2 - , TAKE_OWNERSHIP = 3 - }; - - /** - * Construct a TMemoryBuffer with a default-sized buffer, - * owned by the TMemoryBuffer object. - */ - TMemoryBuffer() { - initCommon(NULL, defaultSize, true, 0); - } - - /** - * Construct a TMemoryBuffer with a buffer of a specified size, - * owned by the TMemoryBuffer object. - * - * @param sz The initial size of the buffer. - */ - TMemoryBuffer(uint32_t sz) { - initCommon(NULL, sz, true, 0); - } - - /** - * Construct a TMemoryBuffer with buf as its initial contents. - * - * @param buf The initial contents of the buffer. - * Note that, while buf is a non-const pointer, - * TMemoryBuffer will not write to it if policy == OBSERVE, - * so it is safe to const_cast(whatever). - * @param sz The size of @c buf. - * @param policy See @link MemoryPolicy @endlink . - */ - TMemoryBuffer(uint8_t* buf, uint32_t sz, MemoryPolicy policy = OBSERVE) { - if (buf == NULL && sz != 0) { - throw TTransportException(TTransportException::BAD_ARGS, - "TMemoryBuffer given null buffer with non-zero size."); - } - - switch (policy) { - case OBSERVE: - case TAKE_OWNERSHIP: - initCommon(buf, sz, policy == TAKE_OWNERSHIP, sz); - break; - case COPY: - initCommon(NULL, sz, true, 0); - this->write(buf, sz); - break; - default: - throw TTransportException(TTransportException::BAD_ARGS, - "Invalid MemoryPolicy for TMemoryBuffer"); - } - } - - ~TMemoryBuffer() { - if (owner_) { - std::free(buffer_); - } - } - - bool isOpen() { - return true; - } - - bool peek() { - return (rBase_ < wBase_); - } - - void open() {} - - void close() {} - - // TODO(dreiss): Make bufPtr const. - void getBuffer(uint8_t** bufPtr, uint32_t* sz) { - *bufPtr = rBase_; - *sz = wBase_ - rBase_; - } - - std::string getBufferAsString() { - if (buffer_ == NULL) { - return ""; - } - uint8_t* buf; - uint32_t sz; - getBuffer(&buf, &sz); - return std::string((char*)buf, (std::string::size_type)sz); - } - - void appendBufferToString(std::string& str) { - if (buffer_ == NULL) { - return; - } - uint8_t* buf; - uint32_t sz; - getBuffer(&buf, &sz); - str.append((char*)buf, sz); - } - - void resetBuffer(bool reset_capacity = false) { - if (reset_capacity) - { - assert(owner_); - - void* new_buffer = std::realloc(buffer_, defaultSize); - - if (new_buffer == NULL) { - throw TTransportException("Out of memory."); - } - - buffer_ = (uint8_t*) new_buffer; - bufferSize_ = defaultSize; - - wBound_ = buffer_ + bufferSize_; - } - - rBase_ = buffer_; - rBound_ = buffer_; - wBase_ = buffer_; - // It isn't safe to write into a buffer we don't own. - if (!owner_) { - wBound_ = wBase_; - bufferSize_ = 0; - } - } - - /// See constructor documentation. - void resetBuffer(uint8_t* buf, uint32_t sz, MemoryPolicy policy = OBSERVE) { - // Use a variant of the copy-and-swap trick for assignment operators. - // This is sub-optimal in terms of performance for two reasons: - // 1/ The constructing and swapping of the (small) values - // in the temporary object takes some time, and is not necessary. - // 2/ If policy == COPY, we allocate the new buffer before - // freeing the old one, precluding the possibility of - // reusing that memory. - // I doubt that either of these problems could be optimized away, - // but the second is probably no a common case, and the first is minor. - // I don't expect resetBuffer to be a common operation, so I'm willing to - // bite the performance bullet to make the method this simple. - - // Construct the new buffer. - TMemoryBuffer new_buffer(buf, sz, policy); - // Move it into ourself. - this->swap(new_buffer); - // Our old self gets destroyed. - } - - std::string readAsString(uint32_t len) { - std::string str; - (void)readAppendToString(str, len); - return str; - } - - uint32_t readAppendToString(std::string& str, uint32_t len); - - void readEnd() { - if (rBase_ == wBase_) { - resetBuffer(); - } - } - - uint32_t available_read() const { - // Remember, wBase_ is the real rBound_. - return wBase_ - rBase_; - } - - uint32_t available_write() const { - return wBound_ - wBase_; - } - - // Returns a pointer to where the client can write data to append to - // the TMemoryBuffer, and ensures the buffer is big enough to accomodate a - // write of the provided length. The returned pointer is very convenient for - // passing to read(), recv(), or similar. You must call wroteBytes() as soon - // as data is written or the buffer will not be aware that data has changed. - uint8_t* getWritePtr(uint32_t len) { - ensureCanWrite(len); - return wBase_; - } - - // Informs the buffer that the client has written 'len' bytes into storage - // that had been provided by getWritePtr(). - void wroteBytes(uint32_t len); - - protected: - void swap(TMemoryBuffer& that) { - using std::swap; - swap(buffer_, that.buffer_); - swap(bufferSize_, that.bufferSize_); - - swap(rBase_, that.rBase_); - swap(rBound_, that.rBound_); - swap(wBase_, that.wBase_); - swap(wBound_, that.wBound_); - - swap(owner_, that.owner_); - } - - // Make sure there's at least 'len' bytes available for writing. - void ensureCanWrite(uint32_t len); - - // Compute the position and available data for reading. - void computeRead(uint32_t len, uint8_t** out_start, uint32_t* out_give); - - uint32_t readSlow(uint8_t* buf, uint32_t len); - - void writeSlow(const uint8_t* buf, uint32_t len); - - const uint8_t* borrowSlow(uint8_t* buf, uint32_t* len); - - // Data buffer - uint8_t* buffer_; - - // Allocated buffer size - uint32_t bufferSize_; - - // Is this object the owner of the buffer? - bool owner_; - - // Don't forget to update constrctors, initCommon, and swap if - // you add new members. -}; - -}}} // apache::thrift::transport - -#endif // #ifndef _THRIFT_TRANSPORT_TBUFFERTRANSPORTS_H_ diff --git service/include/thrift/transport/TFDTransport.h service/include/thrift/transport/TFDTransport.h deleted file mode 100644 index bda5d82..0000000 --- service/include/thrift/transport/TFDTransport.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_TRANSPORT_TFDTRANSPORT_H_ -#define _THRIFT_TRANSPORT_TFDTRANSPORT_H_ 1 - -#include -#include - -#include "TTransport.h" -#include "TServerSocket.h" - -namespace apache { namespace thrift { namespace transport { - -/** - * Dead-simple wrapper around a file descriptor. - * - */ -class TFDTransport : public TTransport { - public: - enum ClosePolicy - { NO_CLOSE_ON_DESTROY = 0 - , CLOSE_ON_DESTROY = 1 - }; - - TFDTransport(int fd, ClosePolicy close_policy = NO_CLOSE_ON_DESTROY) - : fd_(fd) - , close_policy_(close_policy) - {} - - ~TFDTransport() { - if (close_policy_ == CLOSE_ON_DESTROY) { - close(); - } - } - - bool isOpen() { return fd_ >= 0; } - - void open() {} - - void close(); - - uint32_t read(uint8_t* buf, uint32_t len); - - void write(const uint8_t* buf, uint32_t len); - - void setFD(int fd) { fd_ = fd; } - int getFD() { return fd_; } - - protected: - int fd_; - ClosePolicy close_policy_; -}; - -}}} // apache::thrift::transport - -#endif // #ifndef _THRIFT_TRANSPORT_TFDTRANSPORT_H_ diff --git service/include/thrift/transport/TFileTransport.h service/include/thrift/transport/TFileTransport.h deleted file mode 100644 index b08c5c8..0000000 --- service/include/thrift/transport/TFileTransport.h +++ /dev/null @@ -1,442 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_TRANSPORT_TFILETRANSPORT_H_ -#define _THRIFT_TRANSPORT_TFILETRANSPORT_H_ 1 - -#include "TTransport.h" -#include "Thrift.h" -#include "TProcessor.h" - -#include -#include - -#include - -#include - -namespace apache { namespace thrift { namespace transport { - -using apache::thrift::TProcessor; -using apache::thrift::protocol::TProtocolFactory; - -// Data pertaining to a single event -typedef struct eventInfo { - uint8_t* eventBuff_; - uint32_t eventSize_; - uint32_t eventBuffPos_; - - eventInfo():eventBuff_(NULL), eventSize_(0), eventBuffPos_(0){}; - ~eventInfo() { - if (eventBuff_) { - delete[] eventBuff_; - } - } -} eventInfo; - -// information about current read state -typedef struct readState { - eventInfo* event_; - - // keep track of event size - uint8_t eventSizeBuff_[4]; - uint8_t eventSizeBuffPos_; - bool readingSize_; - - // read buffer variables - int32_t bufferPtr_; - int32_t bufferLen_; - - // last successful dispatch point - int32_t lastDispatchPtr_; - - void resetState(uint32_t lastDispatchPtr) { - readingSize_ = true; - eventSizeBuffPos_ = 0; - lastDispatchPtr_ = lastDispatchPtr; - } - - void resetAllValues() { - resetState(0); - bufferPtr_ = 0; - bufferLen_ = 0; - if (event_) { - delete(event_); - } - event_ = 0; - } - - readState() { - event_ = 0; - resetAllValues(); - } - - ~readState() { - if (event_) { - delete(event_); - } - } - -} readState; - -/** - * TFileTransportBuffer - buffer class used by TFileTransport for queueing up events - * to be written to disk. Should be used in the following way: - * 1) Buffer created - * 2) Buffer written to (addEvent) - * 3) Buffer read from (getNext) - * 4) Buffer reset (reset) - * 5) Go back to 2, or destroy buffer - * - * The buffer should never be written to after it is read from, unless it is reset first. - * Note: The above rules are enforced mainly for debugging its sole client TFileTransport - * which uses the buffer in this way. - * - */ -class TFileTransportBuffer { - public: - TFileTransportBuffer(uint32_t size); - ~TFileTransportBuffer(); - - bool addEvent(eventInfo *event); - eventInfo* getNext(); - void reset(); - bool isFull(); - bool isEmpty(); - - private: - TFileTransportBuffer(); // should not be used - - enum mode { - WRITE, - READ - }; - mode bufferMode_; - - uint32_t writePoint_; - uint32_t readPoint_; - uint32_t size_; - eventInfo** buffer_; -}; - -/** - * Abstract interface for transports used to read files - */ -class TFileReaderTransport : virtual public TTransport { - public: - virtual int32_t getReadTimeout() = 0; - virtual void setReadTimeout(int32_t readTimeout) = 0; - - virtual uint32_t getNumChunks() = 0; - virtual uint32_t getCurChunk() = 0; - virtual void seekToChunk(int32_t chunk) = 0; - virtual void seekToEnd() = 0; -}; - -/** - * Abstract interface for transports used to write files - */ -class TFileWriterTransport : virtual public TTransport { - public: - virtual uint32_t getChunkSize() = 0; - virtual void setChunkSize(uint32_t chunkSize) = 0; -}; - -/** - * File implementation of a transport. Reads and writes are done to a - * file on disk. - * - */ -class TFileTransport : public TFileReaderTransport, - public TFileWriterTransport { - public: - TFileTransport(std::string path, bool readOnly=false); - ~TFileTransport(); - - // TODO: what is the correct behaviour for this? - // the log file is generally always open - bool isOpen() { - return true; - } - - void write(const uint8_t* buf, uint32_t len); - void flush(); - - uint32_t readAll(uint8_t* buf, uint32_t len); - uint32_t read(uint8_t* buf, uint32_t len); - - // log-file specific functions - void seekToChunk(int32_t chunk); - void seekToEnd(); - uint32_t getNumChunks(); - uint32_t getCurChunk(); - - // for changing the output file - void resetOutputFile(int fd, std::string filename, int64_t offset); - - // Setter/Getter functions for user-controllable options - void setReadBuffSize(uint32_t readBuffSize) { - if (readBuffSize) { - readBuffSize_ = readBuffSize; - } - } - uint32_t getReadBuffSize() { - return readBuffSize_; - } - - static const int32_t TAIL_READ_TIMEOUT = -1; - static const int32_t NO_TAIL_READ_TIMEOUT = 0; - void setReadTimeout(int32_t readTimeout) { - readTimeout_ = readTimeout; - } - int32_t getReadTimeout() { - return readTimeout_; - } - - void setChunkSize(uint32_t chunkSize) { - if (chunkSize) { - chunkSize_ = chunkSize; - } - } - uint32_t getChunkSize() { - return chunkSize_; - } - - void setEventBufferSize(uint32_t bufferSize) { - if (bufferAndThreadInitialized_) { - GlobalOutput("Cannot change the buffer size after writer thread started"); - return; - } - eventBufferSize_ = bufferSize; - } - - uint32_t getEventBufferSize() { - return eventBufferSize_; - } - - void setFlushMaxUs(uint32_t flushMaxUs) { - if (flushMaxUs) { - flushMaxUs_ = flushMaxUs; - } - } - uint32_t getFlushMaxUs() { - return flushMaxUs_; - } - - void setFlushMaxBytes(uint32_t flushMaxBytes) { - if (flushMaxBytes) { - flushMaxBytes_ = flushMaxBytes; - } - } - uint32_t getFlushMaxBytes() { - return flushMaxBytes_; - } - - void setMaxEventSize(uint32_t maxEventSize) { - maxEventSize_ = maxEventSize; - } - uint32_t getMaxEventSize() { - return maxEventSize_; - } - - void setMaxCorruptedEvents(uint32_t maxCorruptedEvents) { - maxCorruptedEvents_ = maxCorruptedEvents; - } - uint32_t getMaxCorruptedEvents() { - return maxCorruptedEvents_; - } - - void setEofSleepTimeUs(uint32_t eofSleepTime) { - if (eofSleepTime) { - eofSleepTime_ = eofSleepTime; - } - } - uint32_t getEofSleepTimeUs() { - return eofSleepTime_; - } - - private: - // helper functions for writing to a file - void enqueueEvent(const uint8_t* buf, uint32_t eventLen, bool blockUntilFlush); - bool swapEventBuffers(struct timespec* deadline); - bool initBufferAndWriteThread(); - - // control for writer thread - static void* startWriterThread(void* ptr) { - (((TFileTransport*)ptr)->writerThread()); - return 0; - } - void writerThread(); - - // helper functions for reading from a file - eventInfo* readEvent(); - - // event corruption-related functions - bool isEventCorrupted(); - void performRecovery(); - - // Utility functions - void openLogFile(); - void getNextFlushTime(struct timespec* ts_next_flush); - - // Class variables - readState readState_; - uint8_t* readBuff_; - eventInfo* currentEvent_; - - uint32_t readBuffSize_; - static const uint32_t DEFAULT_READ_BUFF_SIZE = 1 * 1024 * 1024; - - int32_t readTimeout_; - static const int32_t DEFAULT_READ_TIMEOUT_MS = 200; - - // size of chunks that file will be split up into - uint32_t chunkSize_; - static const uint32_t DEFAULT_CHUNK_SIZE = 16 * 1024 * 1024; - - // size of event buffers - uint32_t eventBufferSize_; - static const uint32_t DEFAULT_EVENT_BUFFER_SIZE = 10000; - - // max number of microseconds that can pass without flushing - uint32_t flushMaxUs_; - static const uint32_t DEFAULT_FLUSH_MAX_US = 3000000; - - // max number of bytes that can be written without flushing - uint32_t flushMaxBytes_; - static const uint32_t DEFAULT_FLUSH_MAX_BYTES = 1000 * 1024; - - // max event size - uint32_t maxEventSize_; - static const uint32_t DEFAULT_MAX_EVENT_SIZE = 0; - - // max number of corrupted events per chunk - uint32_t maxCorruptedEvents_; - static const uint32_t DEFAULT_MAX_CORRUPTED_EVENTS = 0; - - // sleep duration when EOF is hit - uint32_t eofSleepTime_; - static const uint32_t DEFAULT_EOF_SLEEP_TIME_US = 500 * 1000; - - // sleep duration when a corrupted event is encountered - uint32_t corruptedEventSleepTime_; - static const uint32_t DEFAULT_CORRUPTED_SLEEP_TIME_US = 1 * 1000 * 1000; - - // writer thread id - pthread_t writerThreadId_; - - // buffers to hold data before it is flushed. Each element of the buffer stores a msg that - // needs to be written to the file. The buffers are swapped by the writer thread. - TFileTransportBuffer *dequeueBuffer_; - TFileTransportBuffer *enqueueBuffer_; - - // conditions used to block when the buffer is full or empty - pthread_cond_t notFull_, notEmpty_; - volatile bool closing_; - - // To keep track of whether the buffer has been flushed - pthread_cond_t flushed_; - volatile bool forceFlush_; - - // Mutex that is grabbed when enqueueing and swapping the read/write buffers - pthread_mutex_t mutex_; - - // File information - std::string filename_; - int fd_; - - // Whether the writer thread and buffers have been initialized - bool bufferAndThreadInitialized_; - - // Offset within the file - off_t offset_; - - // event corruption information - uint32_t lastBadChunk_; - uint32_t numCorruptedEventsInChunk_; - - bool readOnly_; -}; - -// Exception thrown when EOF is hit -class TEOFException : public TTransportException { - public: - TEOFException(): - TTransportException(TTransportException::END_OF_FILE) {}; -}; - - -// wrapper class to process events from a file containing thrift events -class TFileProcessor { - public: - /** - * Constructor that defaults output transport to null transport - * - * @param processor processes log-file events - * @param protocolFactory protocol factory - * @param inputTransport file transport - */ - TFileProcessor(boost::shared_ptr processor, - boost::shared_ptr protocolFactory, - boost::shared_ptr inputTransport); - - TFileProcessor(boost::shared_ptr processor, - boost::shared_ptr inputProtocolFactory, - boost::shared_ptr outputProtocolFactory, - boost::shared_ptr inputTransport); - - /** - * Constructor - * - * @param processor processes log-file events - * @param protocolFactory protocol factory - * @param inputTransport input file transport - * @param output output transport - */ - TFileProcessor(boost::shared_ptr processor, - boost::shared_ptr protocolFactory, - boost::shared_ptr inputTransport, - boost::shared_ptr outputTransport); - - /** - * processes events from the file - * - * @param numEvents number of events to process (0 for unlimited) - * @param tail tails the file if true - */ - void process(uint32_t numEvents, bool tail); - - /** - * process events until the end of the chunk - * - */ - void processChunk(); - - private: - boost::shared_ptr processor_; - boost::shared_ptr inputProtocolFactory_; - boost::shared_ptr outputProtocolFactory_; - boost::shared_ptr inputTransport_; - boost::shared_ptr outputTransport_; -}; - - -}}} // apache::thrift::transport - -#endif // _THRIFT_TRANSPORT_TFILETRANSPORT_H_ diff --git service/include/thrift/transport/THttpClient.h service/include/thrift/transport/THttpClient.h deleted file mode 100644 index f4be4c1..0000000 --- service/include/thrift/transport/THttpClient.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_TRANSPORT_THTTPCLIENT_H_ -#define _THRIFT_TRANSPORT_THTTPCLIENT_H_ 1 - -#include - -namespace apache { namespace thrift { namespace transport { - -/** - * HTTP client implementation of the thrift transport. This was irritating - * to write, but the alternatives in C++ land are daunting. Linking CURL - * requires 23 dynamic libraries last time I checked (WTF?!?). All we have - * here is a VERY basic HTTP/1.1 client which supports HTTP 100 Continue, - * chunked transfer encoding, keepalive, etc. Tested against Apache. - * - */ -class THttpClient : public TTransport { - public: - THttpClient(boost::shared_ptr transport, std::string host, std::string path=""); - - THttpClient(std::string host, int port, std::string path=""); - - virtual ~THttpClient(); - - void open() { - transport_->open(); - } - - bool isOpen() { - return transport_->isOpen(); - } - - bool peek() { - return transport_->peek(); - } - - void close() { - transport_->close(); - } - - uint32_t read(uint8_t* buf, uint32_t len); - - void readEnd(); - - void write(const uint8_t* buf, uint32_t len); - - void flush(); - - private: - void init(); - - protected: - - boost::shared_ptr transport_; - - TMemoryBuffer writeBuffer_; - TMemoryBuffer readBuffer_; - - std::string host_; - std::string path_; - - bool readHeaders_; - bool chunked_; - bool chunkedDone_; - uint32_t chunkSize_; - uint32_t contentLength_; - - char* httpBuf_; - uint32_t httpPos_; - uint32_t httpBufLen_; - uint32_t httpBufSize_; - - uint32_t readMoreData(); - char* readLine(); - - void readHeaders(); - void parseHeader(char* header); - bool parseStatusLine(char* status); - - uint32_t readChunked(); - void readChunkedFooters(); - uint32_t parseChunkSize(char* line); - - uint32_t readContent(uint32_t size); - - void refill(); - void shift(); - -}; - -}}} // apache::thrift::transport - -#endif // #ifndef _THRIFT_TRANSPORT_THTTPCLIENT_H_ diff --git service/include/thrift/transport/TServerSocket.h service/include/thrift/transport/TServerSocket.h deleted file mode 100644 index a6be017..0000000 --- service/include/thrift/transport/TServerSocket.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_TRANSPORT_TSERVERSOCKET_H_ -#define _THRIFT_TRANSPORT_TSERVERSOCKET_H_ 1 - -#include "TServerTransport.h" -#include - -namespace apache { namespace thrift { namespace transport { - -class TSocket; - -/** - * Server socket implementation of TServerTransport. Wrapper around a unix - * socket listen and accept calls. - * - */ -class TServerSocket : public TServerTransport { - public: - TServerSocket(int port); - TServerSocket(int port, int sendTimeout, int recvTimeout); - - ~TServerSocket(); - - void setSendTimeout(int sendTimeout); - void setRecvTimeout(int recvTimeout); - - void setRetryLimit(int retryLimit); - void setRetryDelay(int retryDelay); - - void setTcpSendBuffer(int tcpSendBuffer); - void setTcpRecvBuffer(int tcpRecvBuffer); - - void listen(); - void close(); - - void interrupt(); - - protected: - boost::shared_ptr acceptImpl(); - - private: - int port_; - int serverSocket_; - int acceptBacklog_; - int sendTimeout_; - int recvTimeout_; - int retryLimit_; - int retryDelay_; - int tcpSendBuffer_; - int tcpRecvBuffer_; - - int intSock1_; - int intSock2_; -}; - -}}} // apache::thrift::transport - -#endif // #ifndef _THRIFT_TRANSPORT_TSERVERSOCKET_H_ diff --git service/include/thrift/transport/TServerTransport.h service/include/thrift/transport/TServerTransport.h deleted file mode 100644 index 40bbc6c..0000000 --- service/include/thrift/transport/TServerTransport.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_TRANSPORT_TSERVERTRANSPORT_H_ -#define _THRIFT_TRANSPORT_TSERVERTRANSPORT_H_ 1 - -#include "TTransport.h" -#include "TTransportException.h" -#include - -namespace apache { namespace thrift { namespace transport { - -/** - * Server transport framework. A server needs to have some facility for - * creating base transports to read/write from. - * - */ -class TServerTransport { - public: - virtual ~TServerTransport() {} - - /** - * Starts the server transport listening for new connections. Prior to this - * call most transports will not return anything when accept is called. - * - * @throws TTransportException if we were unable to listen - */ - virtual void listen() {} - - /** - * Gets a new dynamically allocated transport object and passes it to the - * caller. Note that it is the explicit duty of the caller to free the - * allocated object. The returned TTransport object must always be in the - * opened state. NULL should never be returned, instead an Exception should - * always be thrown. - * - * @return A new TTransport object - * @throws TTransportException if there is an error - */ - boost::shared_ptr accept() { - boost::shared_ptr result = acceptImpl(); - if (result == NULL) { - throw TTransportException("accept() may not return NULL"); - } - return result; - } - - /** - * For "smart" TServerTransport implementations that work in a multi - * threaded context this can be used to break out of an accept() call. - * It is expected that the transport will throw a TTransportException - * with the interrupted error code. - */ - virtual void interrupt() {} - - /** - * Closes this transport such that future calls to accept will do nothing. - */ - virtual void close() = 0; - - protected: - TServerTransport() {} - - /** - * Subclasses should implement this function for accept. - * - * @return A newly allocated TTransport object - * @throw TTransportException If an error occurs - */ - virtual boost::shared_ptr acceptImpl() = 0; - -}; - -}}} // apache::thrift::transport - -#endif // #ifndef _THRIFT_TRANSPORT_TSERVERTRANSPORT_H_ diff --git service/include/thrift/transport/TShortReadTransport.h service/include/thrift/transport/TShortReadTransport.h deleted file mode 100644 index 3df8a57..0000000 --- service/include/thrift/transport/TShortReadTransport.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_TRANSPORT_TSHORTREADTRANSPORT_H_ -#define _THRIFT_TRANSPORT_TSHORTREADTRANSPORT_H_ 1 - -#include - -#include - -namespace apache { namespace thrift { namespace transport { namespace test { - -/** - * This class is only meant for testing. It wraps another transport. - * Calls to read are passed through with some probability. Otherwise, - * the read amount is randomly reduced before being passed through. - * - */ -class TShortReadTransport : public TTransport { - public: - TShortReadTransport(boost::shared_ptr transport, double full_prob) - : transport_(transport) - , fullProb_(full_prob) - {} - - bool isOpen() { - return transport_->isOpen(); - } - - bool peek() { - return transport_->peek(); - } - - void open() { - transport_->open(); - } - - void close() { - transport_->close(); - } - - uint32_t read(uint8_t* buf, uint32_t len) { - if (len == 0) { - return 0; - } - - if (rand()/(double)RAND_MAX >= fullProb_) { - len = 1 + rand()%len; - } - return transport_->read(buf, len); - } - - void write(const uint8_t* buf, uint32_t len) { - transport_->write(buf, len); - } - - void flush() { - transport_->flush(); - } - - const uint8_t* borrow(uint8_t* buf, uint32_t* len) { - return transport_->borrow(buf, len); - } - - void consume(uint32_t len) { - return transport_->consume(len); - } - - boost::shared_ptr getUnderlyingTransport() { - return transport_; - } - - protected: - boost::shared_ptr transport_; - double fullProb_; -}; - -}}}} // apache::thrift::transport::test - -#endif // #ifndef _THRIFT_TRANSPORT_TSHORTREADTRANSPORT_H_ diff --git service/include/thrift/transport/TSimpleFileTransport.h service/include/thrift/transport/TSimpleFileTransport.h deleted file mode 100644 index 6cc52ea..0000000 --- service/include/thrift/transport/TSimpleFileTransport.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_TRANSPORT_TSIMPLEFILETRANSPORT_H_ -#define _THRIFT_TRANSPORT_TSIMPLEFILETRANSPORT_H_ 1 - -#include "TFDTransport.h" - -namespace apache { namespace thrift { namespace transport { - -/** - * Dead-simple wrapper around a file. - * - * Writeable files are opened with O_CREAT and O_APPEND - */ -class TSimpleFileTransport : public TFDTransport { - public: - TSimpleFileTransport(const std::string& path, - bool read = true, - bool write = false); -}; - -}}} // apache::thrift::transport - -#endif // _THRIFT_TRANSPORT_TSIMPLEFILETRANSPORT_H_ diff --git service/include/thrift/transport/TSocket.h service/include/thrift/transport/TSocket.h deleted file mode 100644 index b0f445a..0000000 --- service/include/thrift/transport/TSocket.h +++ /dev/null @@ -1,242 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_TRANSPORT_TSOCKET_H_ -#define _THRIFT_TRANSPORT_TSOCKET_H_ 1 - -#include -#include - -#include "TTransport.h" -#include "TServerSocket.h" - -namespace apache { namespace thrift { namespace transport { - -/** - * TCP Socket implementation of the TTransport interface. - * - */ -class TSocket : public TTransport { - /** - * We allow the TServerSocket acceptImpl() method to access the private - * members of a socket so that it can access the TSocket(int socket) - * constructor which creates a socket object from the raw UNIX socket - * handle. - */ - friend class TServerSocket; - - public: - /** - * Constructs a new socket. Note that this does NOT actually connect the - * socket. - * - */ - TSocket(); - - /** - * Constructs a new socket. Note that this does NOT actually connect the - * socket. - * - * @param host An IP address or hostname to connect to - * @param port The port to connect on - */ - TSocket(std::string host, int port); - - /** - * Destroyes the socket object, closing it if necessary. - */ - virtual ~TSocket(); - - /** - * Whether the socket is alive. - * - * @return Is the socket alive? - */ - bool isOpen(); - - /** - * Calls select on the socket to see if there is more data available. - */ - bool peek(); - - /** - * Creates and opens the UNIX socket. - * - * @throws TTransportException If the socket could not connect - */ - virtual void open(); - - /** - * Shuts down communications on the socket. - */ - void close(); - - /** - * Reads from the underlying socket. - */ - uint32_t read(uint8_t* buf, uint32_t len); - - /** - * Writes to the underlying socket. - */ - void write(const uint8_t* buf, uint32_t len); - - /** - * Get the host that the socket is connected to - * - * @return string host identifier - */ - std::string getHost(); - - /** - * Get the port that the socket is connected to - * - * @return int port number - */ - int getPort(); - - /** - * Set the host that socket will connect to - * - * @param host host identifier - */ - void setHost(std::string host); - - /** - * Set the port that socket will connect to - * - * @param port port number - */ - void setPort(int port); - - /** - * Controls whether the linger option is set on the socket. - * - * @param on Whether SO_LINGER is on - * @param linger If linger is active, the number of seconds to linger for - */ - void setLinger(bool on, int linger); - - /** - * Whether to enable/disable Nagle's algorithm. - * - * @param noDelay Whether or not to disable the algorithm. - * @return - */ - void setNoDelay(bool noDelay); - - /** - * Set the connect timeout - */ - void setConnTimeout(int ms); - - /** - * Set the receive timeout - */ - void setRecvTimeout(int ms); - - /** - * Set the send timeout - */ - void setSendTimeout(int ms); - - /** - * Set the max number of recv retries in case of an EAGAIN - * error - */ - void setMaxRecvRetries(int maxRecvRetries); - - /** - * Get socket information formated as a string - */ - std::string getSocketInfo(); - - /** - * Returns the DNS name of the host to which the socket is connected - */ - std::string getPeerHost(); - - /** - * Returns the address of the host to which the socket is connected - */ - std::string getPeerAddress(); - - /** - * Returns the port of the host to which the socket is connected - **/ - int getPeerPort(); - - - protected: - /** - * Constructor to create socket from raw UNIX handle. Never called directly - * but used by the TServerSocket class. - */ - TSocket(int socket); - - /** connect, called by open */ - void openConnection(struct addrinfo *res); - - /** Host to connect to */ - std::string host_; - - /** Peer hostname */ - std::string peerHost_; - - /** Peer address */ - std::string peerAddress_; - - /** Peer port */ - int peerPort_; - - /** Port number to connect on */ - int port_; - - /** Underlying UNIX socket handle */ - int socket_; - - /** Connect timeout in ms */ - int connTimeout_; - - /** Send timeout in ms */ - int sendTimeout_; - - /** Recv timeout in ms */ - int recvTimeout_; - - /** Linger on */ - bool lingerOn_; - - /** Linger val */ - int lingerVal_; - - /** Nodelay */ - bool noDelay_; - - /** Recv EGAIN retries */ - int maxRecvRetries_; - - /** Recv timeout timeval */ - struct timeval recvTimeval_; -}; - -}}} // apache::thrift::transport - -#endif // #ifndef _THRIFT_TRANSPORT_TSOCKET_H_ - diff --git service/include/thrift/transport/TSocketPool.h service/include/thrift/transport/TSocketPool.h deleted file mode 100644 index 8c50669..0000000 --- service/include/thrift/transport/TSocketPool.h +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_TRANSPORT_TSOCKETPOOL_H_ -#define _THRIFT_TRANSPORT_TSOCKETPOOL_H_ 1 - -#include -#include "TSocket.h" - -namespace apache { namespace thrift { namespace transport { - - /** - * Class to hold server information for TSocketPool - * - */ -class TSocketPoolServer { - - public: - /** - * Default constructor for server info - */ - TSocketPoolServer(); - - /** - * Constructor for TSocketPool server - */ - TSocketPoolServer(const std::string &host, int port); - - // Host name - std::string host_; - - // Port to connect on - int port_; - - // Socket for the server - int socket_; - - // Last time connecting to this server failed - int lastFailTime_; - - // Number of consecutive times connecting to this server failed - int consecutiveFailures_; -}; - -/** - * TCP Socket implementation of the TTransport interface. - * - */ -class TSocketPool : public TSocket { - - public: - - /** - * Socket pool constructor - */ - TSocketPool(); - - /** - * Socket pool constructor - * - * @param hosts list of host names - * @param ports list of port names - */ - TSocketPool(const std::vector &hosts, - const std::vector &ports); - - /** - * Socket pool constructor - * - * @param servers list of pairs of host name and port - */ - TSocketPool(const std::vector >& servers); - - /** - * Socket pool constructor - * - * @param servers list of TSocketPoolServers - */ - TSocketPool(const std::vector< boost::shared_ptr >& servers); - - /** - * Socket pool constructor - * - * @param host single host - * @param port single port - */ - TSocketPool(const std::string& host, int port); - - /** - * Destroyes the socket object, closing it if necessary. - */ - virtual ~TSocketPool(); - - /** - * Add a server to the pool - */ - void addServer(const std::string& host, int port); - - /** - * Set list of servers in this pool - */ - void setServers(const std::vector< boost::shared_ptr >& servers); - - /** - * Get list of servers in this pool - */ - void getServers(std::vector< boost::shared_ptr >& servers); - - /** - * Sets how many times to keep retrying a host in the connect function. - */ - void setNumRetries(int numRetries); - - /** - * Sets how long to wait until retrying a host if it was marked down - */ - void setRetryInterval(int retryInterval); - - /** - * Sets how many times to keep retrying a host before marking it as down. - */ - void setMaxConsecutiveFailures(int maxConsecutiveFailures); - - /** - * Turns randomization in connect order on or off. - */ - void setRandomize(bool randomize); - - /** - * Whether to always try the last server. - */ - void setAlwaysTryLast(bool alwaysTryLast); - - /** - * Creates and opens the UNIX socket. - */ - void open(); - - /* - * Closes the UNIX socket - */ - void close(); - - protected: - - void setCurrentServer(const boost::shared_ptr &server); - - /** List of servers to connect to */ - std::vector< boost::shared_ptr > servers_; - - /** Current server */ - boost::shared_ptr currentServer_; - - /** How many times to retry each host in connect */ - int numRetries_; - - /** Retry interval in seconds, how long to not try a host if it has been - * marked as down. - */ - int retryInterval_; - - /** Max consecutive failures before marking a host down. */ - int maxConsecutiveFailures_; - - /** Try hosts in order? or Randomized? */ - bool randomize_; - - /** Always try last host, even if marked down? */ - bool alwaysTryLast_; -}; - -}}} // apache::thrift::transport - -#endif // #ifndef _THRIFT_TRANSPORT_TSOCKETPOOL_H_ - diff --git service/include/thrift/transport/TTransport.h service/include/thrift/transport/TTransport.h deleted file mode 100644 index eb0d5df..0000000 --- service/include/thrift/transport/TTransport.h +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_TRANSPORT_TTRANSPORT_H_ -#define _THRIFT_TRANSPORT_TTRANSPORT_H_ 1 - -#include -#include -#include -#include - -namespace apache { namespace thrift { namespace transport { - -/** - * Generic interface for a method of transporting data. A TTransport may be - * capable of either reading or writing, but not necessarily both. - * - */ -class TTransport { - public: - /** - * Virtual deconstructor. - */ - virtual ~TTransport() {} - - /** - * Whether this transport is open. - */ - virtual bool isOpen() { - return false; - } - - /** - * Tests whether there is more data to read or if the remote side is - * still open. By default this is true whenever the transport is open, - * but implementations should add logic to test for this condition where - * possible (i.e. on a socket). - * This is used by a server to check if it should listen for another - * request. - */ - virtual bool peek() { - return isOpen(); - } - - /** - * Opens the transport for communications. - * - * @return bool Whether the transport was successfully opened - * @throws TTransportException if opening failed - */ - virtual void open() { - throw TTransportException(TTransportException::NOT_OPEN, "Cannot open base TTransport."); - } - - /** - * Closes the transport. - */ - virtual void close() { - throw TTransportException(TTransportException::NOT_OPEN, "Cannot close base TTransport."); - } - - /** - * Attempt to read up to the specified number of bytes into the string. - * - * @param buf Reference to the location to write the data - * @param len How many bytes to read - * @return How many bytes were actually read - * @throws TTransportException If an error occurs - */ - virtual uint32_t read(uint8_t* /* buf */, uint32_t /* len */) { - throw TTransportException(TTransportException::NOT_OPEN, "Base TTransport cannot read."); - } - - /** - * Reads the given amount of data in its entirety no matter what. - * - * @param s Reference to location for read data - * @param len How many bytes to read - * @return How many bytes read, which must be equal to size - * @throws TTransportException If insufficient data was read - */ - virtual uint32_t readAll(uint8_t* buf, uint32_t len) { - uint32_t have = 0; - uint32_t get = 0; - - while (have < len) { - get = read(buf+have, len-have); - if (get <= 0) { - throw TTransportException("No more data to read."); - } - have += get; - } - - return have; - } - - /** - * Called when read is completed. - * This can be over-ridden to perform a transport-specific action - * e.g. logging the request to a file - * - */ - virtual void readEnd() { - // default behaviour is to do nothing - return; - } - - /** - * Writes the string in its entirety to the buffer. - * - * @param buf The data to write out - * @throws TTransportException if an error occurs - */ - virtual void write(const uint8_t* /* buf */, uint32_t /* len */) { - throw TTransportException(TTransportException::NOT_OPEN, "Base TTransport cannot write."); - } - - /** - * Called when write is completed. - * This can be over-ridden to perform a transport-specific action - * at the end of a request. - * - */ - virtual void writeEnd() { - // default behaviour is to do nothing - return; - } - - /** - * Flushes any pending data to be written. Typically used with buffered - * transport mechanisms. - * - * @throws TTransportException if an error occurs - */ - virtual void flush() {} - - /** - * Attempts to return a pointer to \c len bytes, possibly copied into \c buf. - * Does not consume the bytes read (i.e.: a later read will return the same - * data). This method is meant to support protocols that need to read - * variable-length fields. They can attempt to borrow the maximum amount of - * data that they will need, then consume (see next method) what they - * actually use. Some transports will not support this method and others - * will fail occasionally, so protocols must be prepared to use read if - * borrow fails. - * - * @oaram buf A buffer where the data can be stored if needed. - * If borrow doesn't return buf, then the contents of - * buf after the call are undefined. - * @param len *len should initially contain the number of bytes to borrow. - * If borrow succeeds, *len will contain the number of bytes - * available in the returned pointer. This will be at least - * what was requested, but may be more if borrow returns - * a pointer to an internal buffer, rather than buf. - * If borrow fails, the contents of *len are undefined. - * @return If the borrow succeeds, return a pointer to the borrowed data. - * This might be equal to \c buf, or it might be a pointer into - * the transport's internal buffers. - * @throws TTransportException if an error occurs - */ - virtual const uint8_t* borrow(uint8_t* /* buf */, uint32_t* /* len */) { - return NULL; - } - - /** - * Remove len bytes from the transport. This should always follow a borrow - * of at least len bytes, and should always succeed. - * TODO(dreiss): Is there any transport that could borrow but fail to - * consume, or that would require a buffer to dump the consumed data? - * - * @param len How many bytes to consume - * @throws TTransportException If an error occurs - */ - virtual void consume(uint32_t /* len */) { - throw TTransportException(TTransportException::NOT_OPEN, "Base TTransport cannot consume."); - } - - protected: - /** - * Simple constructor. - */ - TTransport() {} -}; - -/** - * Generic factory class to make an input and output transport out of a - * source transport. Commonly used inside servers to make input and output - * streams out of raw clients. - * - */ -class TTransportFactory { - public: - TTransportFactory() {} - - virtual ~TTransportFactory() {} - - /** - * Default implementation does nothing, just returns the transport given. - */ - virtual boost::shared_ptr getTransport(boost::shared_ptr trans) { - return trans; - } - -}; - -}}} // apache::thrift::transport - -#endif // #ifndef _THRIFT_TRANSPORT_TTRANSPORT_H_ diff --git service/include/thrift/transport/TTransportException.h service/include/thrift/transport/TTransportException.h deleted file mode 100644 index 330785c..0000000 --- service/include/thrift/transport/TTransportException.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_TRANSPORT_TTRANSPORTEXCEPTION_H_ -#define _THRIFT_TRANSPORT_TTRANSPORTEXCEPTION_H_ 1 - -#include -#include - -namespace apache { namespace thrift { namespace transport { - -/** - * Class to encapsulate all the possible types of transport errors that may - * occur in various transport systems. This provides a sort of generic - * wrapper around the shitty UNIX E_ error codes that lets a common code - * base of error handling to be used for various types of transports, i.e. - * pipes etc. - * - */ -class TTransportException : public apache::thrift::TException { - public: - /** - * Error codes for the various types of exceptions. - */ - enum TTransportExceptionType - { UNKNOWN = 0 - , NOT_OPEN = 1 - , ALREADY_OPEN = 2 - , TIMED_OUT = 3 - , END_OF_FILE = 4 - , INTERRUPTED = 5 - , BAD_ARGS = 6 - , CORRUPTED_DATA = 7 - , INTERNAL_ERROR = 8 - }; - - TTransportException() : - apache::thrift::TException(), - type_(UNKNOWN) {} - - TTransportException(TTransportExceptionType type) : - apache::thrift::TException(), - type_(type) {} - - TTransportException(const std::string& message) : - apache::thrift::TException(message), - type_(UNKNOWN) {} - - TTransportException(TTransportExceptionType type, const std::string& message) : - apache::thrift::TException(message), - type_(type) {} - - TTransportException(TTransportExceptionType type, - const std::string& message, - int errno_copy) : - apache::thrift::TException(message + ": " + TOutput::strerror_s(errno_copy)), - type_(type) {} - - virtual ~TTransportException() throw() {} - - /** - * Returns an error code that provides information about the type of error - * that has occurred. - * - * @return Error code - */ - TTransportExceptionType getType() const throw() { - return type_; - } - - virtual const char* what() const throw() { - if (message_.empty()) { - switch (type_) { - case UNKNOWN : return "TTransportException: Unknown transport exception"; - case NOT_OPEN : return "TTransportException: Transport not open"; - case ALREADY_OPEN : return "TTransportException: Transport already open"; - case TIMED_OUT : return "TTransportException: Timed out"; - case END_OF_FILE : return "TTransportException: End of file"; - case INTERRUPTED : return "TTransportException: Interrupted"; - case BAD_ARGS : return "TTransportException: Invalid arguments"; - case CORRUPTED_DATA : return "TTransportException: Corrupted Data"; - case INTERNAL_ERROR : return "TTransportException: Internal error"; - default : return "TTransportException: (Invalid exception type)"; - } - } else { - return message_.c_str(); - } - } - - protected: - /** Just like strerror_r but returns a C++ string object. */ - std::string strerror_s(int errno_copy); - - /** Error code */ - TTransportExceptionType type_; - -}; - -}}} // apache::thrift::transport - -#endif // #ifndef _THRIFT_TRANSPORT_TTRANSPORTEXCEPTION_H_ diff --git service/include/thrift/transport/TTransportUtils.h service/include/thrift/transport/TTransportUtils.h deleted file mode 100644 index d65c916..0000000 --- service/include/thrift/transport/TTransportUtils.h +++ /dev/null @@ -1,287 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_TRANSPORT_TTRANSPORTUTILS_H_ -#define _THRIFT_TRANSPORT_TTRANSPORTUTILS_H_ 1 - -#include -#include -#include -#include -#include -// Include the buffered transports that used to be defined here. -#include -#include - -namespace apache { namespace thrift { namespace transport { - -/** - * The null transport is a dummy transport that doesn't actually do anything. - * It's sort of an analogy to /dev/null, you can never read anything from it - * and it will let you write anything you want to it, though it won't actually - * go anywhere. - * - */ -class TNullTransport : public TTransport { - public: - TNullTransport() {} - - ~TNullTransport() {} - - bool isOpen() { - return true; - } - - void open() {} - - void write(const uint8_t* /* buf */, uint32_t /* len */) { - return; - } - -}; - - -/** - * TPipedTransport. This transport allows piping of a request from one - * transport to another either when readEnd() or writeEnd(). The typical - * use case for this is to log a request or a reply to disk. - * The underlying buffer expands to a keep a copy of the entire - * request/response. - * - */ -class TPipedTransport : virtual public TTransport { - public: - TPipedTransport(boost::shared_ptr srcTrans, - boost::shared_ptr dstTrans) : - srcTrans_(srcTrans), - dstTrans_(dstTrans), - rBufSize_(512), rPos_(0), rLen_(0), - wBufSize_(512), wLen_(0) { - - // default is to to pipe the request when readEnd() is called - pipeOnRead_ = true; - pipeOnWrite_ = false; - - rBuf_ = (uint8_t*) std::malloc(sizeof(uint8_t) * rBufSize_); - wBuf_ = (uint8_t*) std::malloc(sizeof(uint8_t) * wBufSize_); - } - - TPipedTransport(boost::shared_ptr srcTrans, - boost::shared_ptr dstTrans, - uint32_t sz) : - srcTrans_(srcTrans), - dstTrans_(dstTrans), - rBufSize_(512), rPos_(0), rLen_(0), - wBufSize_(sz), wLen_(0) { - - rBuf_ = (uint8_t*) std::malloc(sizeof(uint8_t) * rBufSize_); - wBuf_ = (uint8_t*) std::malloc(sizeof(uint8_t) * wBufSize_); - } - - ~TPipedTransport() { - std::free(rBuf_); - std::free(wBuf_); - } - - bool isOpen() { - return srcTrans_->isOpen(); - } - - bool peek() { - if (rPos_ >= rLen_) { - // Double the size of the underlying buffer if it is full - if (rLen_ == rBufSize_) { - rBufSize_ *=2; - rBuf_ = (uint8_t *)std::realloc(rBuf_, sizeof(uint8_t) * rBufSize_); - } - - // try to fill up the buffer - rLen_ += srcTrans_->read(rBuf_+rPos_, rBufSize_ - rPos_); - } - return (rLen_ > rPos_); - } - - - void open() { - srcTrans_->open(); - } - - void close() { - srcTrans_->close(); - } - - void setPipeOnRead(bool pipeVal) { - pipeOnRead_ = pipeVal; - } - - void setPipeOnWrite(bool pipeVal) { - pipeOnWrite_ = pipeVal; - } - - uint32_t read(uint8_t* buf, uint32_t len); - - void readEnd() { - - if (pipeOnRead_) { - dstTrans_->write(rBuf_, rPos_); - dstTrans_->flush(); - } - - srcTrans_->readEnd(); - - // If requests are being pipelined, copy down our read-ahead data, - // then reset our state. - int read_ahead = rLen_ - rPos_; - memcpy(rBuf_, rBuf_ + rPos_, read_ahead); - rPos_ = 0; - rLen_ = read_ahead; - } - - void write(const uint8_t* buf, uint32_t len); - - void writeEnd() { - if (pipeOnWrite_) { - dstTrans_->write(wBuf_, wLen_); - dstTrans_->flush(); - } - } - - void flush(); - - boost::shared_ptr getTargetTransport() { - return dstTrans_; - } - - protected: - boost::shared_ptr srcTrans_; - boost::shared_ptr dstTrans_; - - uint8_t* rBuf_; - uint32_t rBufSize_; - uint32_t rPos_; - uint32_t rLen_; - - uint8_t* wBuf_; - uint32_t wBufSize_; - uint32_t wLen_; - - bool pipeOnRead_; - bool pipeOnWrite_; -}; - - -/** - * Wraps a transport into a pipedTransport instance. - * - */ -class TPipedTransportFactory : public TTransportFactory { - public: - TPipedTransportFactory() {} - TPipedTransportFactory(boost::shared_ptr dstTrans) { - initializeTargetTransport(dstTrans); - } - virtual ~TPipedTransportFactory() {} - - /** - * Wraps the base transport into a piped transport. - */ - virtual boost::shared_ptr getTransport(boost::shared_ptr srcTrans) { - return boost::shared_ptr(new TPipedTransport(srcTrans, dstTrans_)); - } - - virtual void initializeTargetTransport(boost::shared_ptr dstTrans) { - if (dstTrans_.get() == NULL) { - dstTrans_ = dstTrans; - } else { - throw TException("Target transport already initialized"); - } - } - - protected: - boost::shared_ptr dstTrans_; -}; - -/** - * TPipedFileTransport. This is just like a TTransport, except that - * it is a templatized class, so that clients who rely on a specific - * TTransport can still access the original transport. - * - */ -class TPipedFileReaderTransport : public TPipedTransport, - public TFileReaderTransport { - public: - TPipedFileReaderTransport(boost::shared_ptr srcTrans, boost::shared_ptr dstTrans); - - ~TPipedFileReaderTransport(); - - // TTransport functions - bool isOpen(); - bool peek(); - void open(); - void close(); - uint32_t read(uint8_t* buf, uint32_t len); - uint32_t readAll(uint8_t* buf, uint32_t len); - void readEnd(); - void write(const uint8_t* buf, uint32_t len); - void writeEnd(); - void flush(); - - // TFileReaderTransport functions - int32_t getReadTimeout(); - void setReadTimeout(int32_t readTimeout); - uint32_t getNumChunks(); - uint32_t getCurChunk(); - void seekToChunk(int32_t chunk); - void seekToEnd(); - - protected: - // shouldn't be used - TPipedFileReaderTransport(); - boost::shared_ptr srcTrans_; -}; - -/** - * Creates a TPipedFileReaderTransport from a filepath and a destination transport - * - */ -class TPipedFileReaderTransportFactory : public TPipedTransportFactory { - public: - TPipedFileReaderTransportFactory() {} - TPipedFileReaderTransportFactory(boost::shared_ptr dstTrans) - : TPipedTransportFactory(dstTrans) - {} - virtual ~TPipedFileReaderTransportFactory() {} - - boost::shared_ptr getTransport(boost::shared_ptr srcTrans) { - boost::shared_ptr pFileReaderTransport = boost::dynamic_pointer_cast(srcTrans); - if (pFileReaderTransport.get() != NULL) { - return getFileReaderTransport(pFileReaderTransport); - } else { - return boost::shared_ptr(); - } - } - - boost::shared_ptr getFileReaderTransport(boost::shared_ptr srcTrans) { - return boost::shared_ptr(new TPipedFileReaderTransport(srcTrans, dstTrans_)); - } -}; - -}}} // apache::thrift::transport - -#endif // #ifndef _THRIFT_TRANSPORT_TTRANSPORTUTILS_H_ diff --git service/include/thrift/transport/TZlibTransport.h service/include/thrift/transport/TZlibTransport.h deleted file mode 100644 index 1439d9d..0000000 --- service/include/thrift/transport/TZlibTransport.h +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_TRANSPORT_TZLIBTRANSPORT_H_ -#define _THRIFT_TRANSPORT_TZLIBTRANSPORT_H_ 1 - -#include -#include - -struct z_stream_s; - -namespace apache { namespace thrift { namespace transport { - -class TZlibTransportException : public TTransportException { - public: - TZlibTransportException(int status, const char* msg) : - TTransportException(TTransportException::INTERNAL_ERROR, - errorMessage(status, msg)), - zlib_status_(status), - zlib_msg_(msg == NULL ? "(null)" : msg) {} - - virtual ~TZlibTransportException() throw() {} - - int getZlibStatus() { return zlib_status_; } - std::string getZlibMessage() { return zlib_msg_; } - - static std::string errorMessage(int status, const char* msg) { - std::string rv = "zlib error: "; - if (msg) { - rv += msg; - } else { - rv += "(no message)"; - } - rv += " (status = "; - rv += boost::lexical_cast(status); - rv += ")"; - return rv; - } - - int zlib_status_; - std::string zlib_msg_; -}; - -/** - * This transport uses zlib's compressed format on the "far" side. - * - * There are two kinds of TZlibTransport objects: - * - Standalone objects are used to encode self-contained chunks of data - * (like structures). They include checksums. - * - Non-standalone transports are used for RPC. They are not implemented yet. - * - * TODO(dreiss): Don't do an extra copy of the compressed data if - * the underlying transport is TBuffered or TMemory. - * - */ -class TZlibTransport : public TTransport { - public: - - /** - * @param transport The transport to read compressed data from - * and write compressed data to. - * @param use_for_rpc True if this object will be used for RPC, - * false if this is a standalone object. - * @param urbuf_size Uncompressed buffer size for reading. - * @param crbuf_size Compressed buffer size for reading. - * @param uwbuf_size Uncompressed buffer size for writing. - * @param cwbuf_size Compressed buffer size for writing. - * - * TODO(dreiss): Write a constructor that isn't a pain. - */ - TZlibTransport(boost::shared_ptr transport, - bool use_for_rpc, - int urbuf_size = DEFAULT_URBUF_SIZE, - int crbuf_size = DEFAULT_CRBUF_SIZE, - int uwbuf_size = DEFAULT_UWBUF_SIZE, - int cwbuf_size = DEFAULT_CWBUF_SIZE) : - transport_(transport), - standalone_(!use_for_rpc), - urpos_(0), - uwpos_(0), - input_ended_(false), - output_flushed_(false), - urbuf_size_(urbuf_size), - crbuf_size_(crbuf_size), - uwbuf_size_(uwbuf_size), - cwbuf_size_(cwbuf_size), - urbuf_(NULL), - crbuf_(NULL), - uwbuf_(NULL), - cwbuf_(NULL), - rstream_(NULL), - wstream_(NULL) - { - - if (!standalone_) { - throw TTransportException( - TTransportException::BAD_ARGS, - "TZLibTransport has not been tested for RPC."); - } - - if (uwbuf_size_ < MIN_DIRECT_DEFLATE_SIZE) { - // Have to copy this into a local because of a linking issue. - int minimum = MIN_DIRECT_DEFLATE_SIZE; - throw TTransportException( - TTransportException::BAD_ARGS, - "TZLibTransport: uncompressed write buffer must be at least" - + boost::lexical_cast(minimum) + "."); - } - - try { - urbuf_ = new uint8_t[urbuf_size]; - crbuf_ = new uint8_t[crbuf_size]; - uwbuf_ = new uint8_t[uwbuf_size]; - cwbuf_ = new uint8_t[cwbuf_size]; - - // Don't call this outside of the constructor. - initZlib(); - - } catch (...) { - delete[] urbuf_; - delete[] crbuf_; - delete[] uwbuf_; - delete[] cwbuf_; - throw; - } - } - - // Don't call this outside of the constructor. - void initZlib(); - - ~TZlibTransport(); - - bool isOpen(); - - void open() { - transport_->open(); - } - - void close() { - transport_->close(); - } - - uint32_t read(uint8_t* buf, uint32_t len); - - void write(const uint8_t* buf, uint32_t len); - - void flush(); - - const uint8_t* borrow(uint8_t* buf, uint32_t* len); - - void consume(uint32_t len); - - void verifyChecksum(); - - /** - * TODO(someone_smart): Choose smart defaults. - */ - static const int DEFAULT_URBUF_SIZE = 128; - static const int DEFAULT_CRBUF_SIZE = 1024; - static const int DEFAULT_UWBUF_SIZE = 128; - static const int DEFAULT_CWBUF_SIZE = 1024; - - protected: - - inline void checkZlibRv(int status, const char* msg); - inline void checkZlibRvNothrow(int status, const char* msg); - inline int readAvail(); - void flushToZlib(const uint8_t* buf, int len, bool finish = false); - - // Writes smaller than this are buffered up. - // Larger (or equal) writes are dumped straight to zlib. - static const int MIN_DIRECT_DEFLATE_SIZE = 32; - - boost::shared_ptr transport_; - bool standalone_; - - int urpos_; - int uwpos_; - - /// True iff zlib has reached the end of a stream. - /// This is only ever true in standalone protcol objects. - bool input_ended_; - /// True iff we have flushed the output stream. - /// This is only ever true in standalone protcol objects. - bool output_flushed_; - - int urbuf_size_; - int crbuf_size_; - int uwbuf_size_; - int cwbuf_size_; - - uint8_t* urbuf_; - uint8_t* crbuf_; - uint8_t* uwbuf_; - uint8_t* cwbuf_; - - struct z_stream_s* rstream_; - struct z_stream_s* wstream_; -}; - -}}} // apache::thrift::transport - -#endif // #ifndef _THRIFT_TRANSPORT_TZLIBTRANSPORT_H_ diff --git service/src/java/org/apache/hadoop/hive/service/HiveServer.java service/src/java/org/apache/hadoop/hive/service/HiveServer.java index 89cf336..b7a2687 100644 --- service/src/java/org/apache/hadoop/hive/service/HiveServer.java +++ service/src/java/org/apache/hadoop/hive/service/HiveServer.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import com.facebook.fb303.fb_status; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.hive.conf.HiveConf; @@ -145,7 +146,7 @@ public class HiveServer extends ThriftHive { JobTracker.State jbs = cs.getJobTrackerState(); // Convert the ClusterStatus to its Thrift equivalent: HiveClusterStatus - int state; + JobTrackerState state; switch (jbs) { case INITIALIZING: state = JobTrackerState.INITIALIZING; @@ -321,8 +322,8 @@ public class HiveServer extends ThriftHive { * Return the status of the server. */ @Override - public int getStatus() { - return 0; + public fb_status getStatus() { + return fb_status.ALIVE; } /**