You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by zs...@apache.org on 2008/12/08 05:25:51 UTC

svn commit: r724247 [1/6] - in /hadoop/hive/trunk/service: ./ if/ include/ include/thrift/ include/thrift/concurrency/ include/thrift/fb303/ include/thrift/fb303/if/ include/thrift/if/ include/thrift/processor/ include/thrift/protocol/ include/thrift/s...

Author: zshao
Date: Sun Dec  7 20:25:22 2008
New Revision: 724247

URL: http://svn.apache.org/viewvc?rev=724247&view=rev
Log:
HIVE-73. Missed files service/* for Thrift Server and Client for Hive (Raghu through zshao).

Added:
    hadoop/hive/trunk/service/
    hadoop/hive/trunk/service/build.xml
    hadoop/hive/trunk/service/if/
    hadoop/hive/trunk/service/if/hive_service.thrift
    hadoop/hive/trunk/service/include/
    hadoop/hive/trunk/service/include/thrift/
    hadoop/hive/trunk/service/include/thrift/TLogging.h
    hadoop/hive/trunk/service/include/thrift/TProcessor.h
    hadoop/hive/trunk/service/include/thrift/TReflectionLocal.h
    hadoop/hive/trunk/service/include/thrift/Thrift.h
    hadoop/hive/trunk/service/include/thrift/concurrency/
    hadoop/hive/trunk/service/include/thrift/concurrency/Exception.h
    hadoop/hive/trunk/service/include/thrift/concurrency/Monitor.h
    hadoop/hive/trunk/service/include/thrift/concurrency/Mutex.h
    hadoop/hive/trunk/service/include/thrift/concurrency/PosixThreadFactory.h
    hadoop/hive/trunk/service/include/thrift/concurrency/Thread.h
    hadoop/hive/trunk/service/include/thrift/concurrency/ThreadManager.h
    hadoop/hive/trunk/service/include/thrift/concurrency/TimerManager.h
    hadoop/hive/trunk/service/include/thrift/concurrency/Util.h
    hadoop/hive/trunk/service/include/thrift/config.h
    hadoop/hive/trunk/service/include/thrift/fb303/
    hadoop/hive/trunk/service/include/thrift/fb303/FacebookBase.h
    hadoop/hive/trunk/service/include/thrift/fb303/FacebookService.h
    hadoop/hive/trunk/service/include/thrift/fb303/ServiceTracker.h
    hadoop/hive/trunk/service/include/thrift/fb303/fb303_constants.h
    hadoop/hive/trunk/service/include/thrift/fb303/fb303_types.h
    hadoop/hive/trunk/service/include/thrift/fb303/if/
    hadoop/hive/trunk/service/include/thrift/fb303/if/fb303.thrift
    hadoop/hive/trunk/service/include/thrift/if/
    hadoop/hive/trunk/service/include/thrift/if/reflection_limited.thrift
    hadoop/hive/trunk/service/include/thrift/processor/
    hadoop/hive/trunk/service/include/thrift/processor/PeekProcessor.h
    hadoop/hive/trunk/service/include/thrift/processor/StatsProcessor.h
    hadoop/hive/trunk/service/include/thrift/protocol/
    hadoop/hive/trunk/service/include/thrift/protocol/TBinaryProtocol.h
    hadoop/hive/trunk/service/include/thrift/protocol/TDebugProtocol.h
    hadoop/hive/trunk/service/include/thrift/protocol/TDenseProtocol.h
    hadoop/hive/trunk/service/include/thrift/protocol/TOneWayProtocol.h
    hadoop/hive/trunk/service/include/thrift/protocol/TProtocol.h
    hadoop/hive/trunk/service/include/thrift/protocol/TProtocolException.h
    hadoop/hive/trunk/service/include/thrift/reflection_limited_types.h
    hadoop/hive/trunk/service/include/thrift/server/
    hadoop/hive/trunk/service/include/thrift/server/TNonblockingServer.h
    hadoop/hive/trunk/service/include/thrift/server/TServer.h
    hadoop/hive/trunk/service/include/thrift/server/TSimpleServer.h
    hadoop/hive/trunk/service/include/thrift/server/TThreadPoolServer.h
    hadoop/hive/trunk/service/include/thrift/server/TThreadedServer.h
    hadoop/hive/trunk/service/include/thrift/transport/
    hadoop/hive/trunk/service/include/thrift/transport/TFileTransport.h
    hadoop/hive/trunk/service/include/thrift/transport/THttpClient.h
    hadoop/hive/trunk/service/include/thrift/transport/TServerSocket.h
    hadoop/hive/trunk/service/include/thrift/transport/TServerTransport.h
    hadoop/hive/trunk/service/include/thrift/transport/TSocket.h
    hadoop/hive/trunk/service/include/thrift/transport/TSocketPool.h
    hadoop/hive/trunk/service/include/thrift/transport/TTransport.h
    hadoop/hive/trunk/service/include/thrift/transport/TTransportException.h
    hadoop/hive/trunk/service/include/thrift/transport/TTransportUtils.h
    hadoop/hive/trunk/service/include/thrift/transport/TZlibTransport.h
    hadoop/hive/trunk/service/src/
    hadoop/hive/trunk/service/src/gen-javabean/
    hadoop/hive/trunk/service/src/gen-javabean/org/
    hadoop/hive/trunk/service/src/gen-javabean/org/apache/
    hadoop/hive/trunk/service/src/gen-javabean/org/apache/hadoop/
    hadoop/hive/trunk/service/src/gen-javabean/org/apache/hadoop/hive/
    hadoop/hive/trunk/service/src/gen-javabean/org/apache/hadoop/hive/service/
    hadoop/hive/trunk/service/src/gen-javabean/org/apache/hadoop/hive/service/Constants.java
    hadoop/hive/trunk/service/src/gen-javabean/org/apache/hadoop/hive/service/HiveServerException.java
    hadoop/hive/trunk/service/src/gen-javabean/org/apache/hadoop/hive/service/ThriftHive.java
    hadoop/hive/trunk/service/src/gen-php/
    hadoop/hive/trunk/service/src/gen-php/ThriftHive.php
    hadoop/hive/trunk/service/src/gen-php/hive_service_types.php
    hadoop/hive/trunk/service/src/gen-py/
    hadoop/hive/trunk/service/src/gen-py/__init__.py
    hadoop/hive/trunk/service/src/gen-py/hive/
    hadoop/hive/trunk/service/src/gen-py/hive/ThriftHive-remote   (with props)
    hadoop/hive/trunk/service/src/gen-py/hive/ThriftHive.py
    hadoop/hive/trunk/service/src/gen-py/hive/__init__.py
    hadoop/hive/trunk/service/src/gen-py/hive/constants.py
    hadoop/hive/trunk/service/src/gen-py/hive/ttypes.py
    hadoop/hive/trunk/service/src/gen-py/hive_service/
    hadoop/hive/trunk/service/src/gen-py/hive_service/ThriftHive-remote
    hadoop/hive/trunk/service/src/gen-py/hive_service/ThriftHive.py
    hadoop/hive/trunk/service/src/gen-py/hive_service/__init__.py
    hadoop/hive/trunk/service/src/gen-py/hive_service/constants.py
    hadoop/hive/trunk/service/src/gen-py/hive_service/ttypes.py
    hadoop/hive/trunk/service/src/java/
    hadoop/hive/trunk/service/src/java/org/
    hadoop/hive/trunk/service/src/java/org/apache/
    hadoop/hive/trunk/service/src/java/org/apache/hadoop/
    hadoop/hive/trunk/service/src/java/org/apache/hadoop/hive/
    hadoop/hive/trunk/service/src/java/org/apache/hadoop/hive/service/
    hadoop/hive/trunk/service/src/java/org/apache/hadoop/hive/service/HiveClient.java
    hadoop/hive/trunk/service/src/java/org/apache/hadoop/hive/service/HiveInterface.java
    hadoop/hive/trunk/service/src/java/org/apache/hadoop/hive/service/HiveServer.java
    hadoop/hive/trunk/service/src/test/
    hadoop/hive/trunk/service/src/test/org/
    hadoop/hive/trunk/service/src/test/org/apache/
    hadoop/hive/trunk/service/src/test/org/apache/hadoop/
    hadoop/hive/trunk/service/src/test/org/apache/hadoop/hive/
    hadoop/hive/trunk/service/src/test/org/apache/hadoop/hive/service/
    hadoop/hive/trunk/service/src/test/org/apache/hadoop/hive/service/TestHiveServer.java

Added: hadoop/hive/trunk/service/build.xml
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/service/build.xml?rev=724247&view=auto
==============================================================================
--- hadoop/hive/trunk/service/build.xml (added)
+++ hadoop/hive/trunk/service/build.xml Sun Dec  7 20:25:22 2008
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+   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.
+-->
+
+<project name="service" default="jar">
+  <property name="src.dir" value="${basedir}/src"/>
+
+  <!--
+    Override properties defined in ../build-common.xml.
+  -->
+  <property name="test.junit.output.format" value="plain"/>
+  <property name="test.output" value="false"/>
+  <property name="test.junit.output.usefile" value="false"/>
+
+
+  <import file="../build-common.xml"/>
+
+  <target name="thriftif">
+    <echo>Executing thrift (which needs to be in your path) to build java metastore APIs.... </echo>
+    <exec executable="thrift"  failonerror="true" dir=".">
+      <arg line="--gen java:beans -php --gen py -I ${basedir}/include -I ${basedir}/.. -o ${src.dir} if/hive_service.thrift " />
+    </exec>
+  </target>
+
+  <target name="core-compile" depends="init">
+    <javac
+     encoding="${build.encoding}"
+     srcdir="${src.dir}/java:${src.dir}/gen-javabean"
+     includes="**/*.java"
+     destdir="${build.classes}"
+     debug="${javac.debug}"
+     deprecation="${javac.deprecation}"
+     >
+      <classpath refid="classpath"/>
+    </javac>
+  </target>
+ 
+  <target name="compile" depends="thriftif,core-compile">
+  </target>
+
+  <target name="clean">
+      <delete dir="${build.classes}/../"/>
+  </target>
+</project>

Added: hadoop/hive/trunk/service/if/hive_service.thrift
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/service/if/hive_service.thrift?rev=724247&view=auto
==============================================================================
--- hadoop/hive/trunk/service/if/hive_service.thrift (added)
+++ hadoop/hive/trunk/service/if/hive_service.thrift Sun Dec  7 20:25:22 2008
@@ -0,0 +1,57 @@
+#!/usr/local/bin/thrift -java
+
+# 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.
+
+#
+# Thrift Service that the hive service is built on
+#
+
+#
+# TODO: include/thrift is shared among different components. It
+# should not be under metastore.
+
+include "thrift/fb303/if/fb303.thrift"
+include "metastore/if/hive_metastore.thrift"
+
+namespace java org.apache.hadoop.hive.service
+namespace php hive
+namespace py hive
+
+exception HiveServerException {
+  string message
+}
+
+# Interface for Thrift Hive Server
+service ThriftHive extends hive_metastore.ThriftHiveMetastore {
+  # Execute a query. Takes a HiveQL string
+  void execute(1:string query) throws(1:HiveServerException ex)
+
+  # Fetch one row. This row is the serialized form
+  # of the result of the query
+  string fetchOne() throws(1:HiveServerException ex)
+
+  # Fetch a given number of rows or remaining number of
+  # rows whichever is smaller.
+  list<string> fetchN(1:i32 numRows) throws(1:HiveServerException ex)
+
+  # Fetch all rows of the query result
+  list<string> fetchAll() throws(1:HiveServerException ex)
+
+  # Get the Thrift DDL string of the query result
+  string getSchema() throws(1:HiveServerException ex)
+
+}

Added: hadoop/hive/trunk/service/include/thrift/TLogging.h
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/service/include/thrift/TLogging.h?rev=724247&view=auto
==============================================================================
--- hadoop/hive/trunk/service/include/thrift/TLogging.h (added)
+++ hadoop/hive/trunk/service/include/thrift/TLogging.h Sun Dec  7 20:25:22 2008
@@ -0,0 +1,151 @@
+// Copyright (c) 2006- Facebook
+// Distributed under the Thrift Software License
+//
+// See accompanying file LICENSE or visit the Thrift site at:
+// http://developers.facebook.com/thrift/
+
+#ifndef _THRIFT_TLOGGING_H_
+#define _THRIFT_TLOGGING_H_ 1
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/**
+ * Contains utility macros for debugging and logging.
+ *
+ * @author Aditya Agarwal
+ */
+
+#ifndef HAVE_CLOCK_GETTIME
+#include <time.h>
+#else
+#include <sys/time.h>
+#endif
+
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#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_

Added: hadoop/hive/trunk/service/include/thrift/TProcessor.h
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/service/include/thrift/TProcessor.h?rev=724247&view=auto
==============================================================================
--- hadoop/hive/trunk/service/include/thrift/TProcessor.h (added)
+++ hadoop/hive/trunk/service/include/thrift/TProcessor.h Sun Dec  7 20:25:22 2008
@@ -0,0 +1,41 @@
+// Copyright (c) 2006- Facebook
+// Distributed under the Thrift Software License
+//
+// See accompanying file LICENSE or visit the Thrift site at:
+// http://developers.facebook.com/thrift/
+
+#ifndef _THRIFT_TPROCESSOR_H_
+#define _THRIFT_TPROCESSOR_H_ 1
+
+#include <string>
+#include <protocol/TProtocol.h>
+#include <boost/shared_ptr.hpp>
+
+namespace facebook { 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.
+ *
+ * @author Mark Slee <mc...@facebook.com>
+ */
+class TProcessor {
+ public:
+  virtual ~TProcessor() {}
+
+  virtual bool process(boost::shared_ptr<protocol::TProtocol> in,
+                       boost::shared_ptr<protocol::TProtocol> out) = 0;
+
+  bool process(boost::shared_ptr<facebook::thrift::protocol::TProtocol> io) {
+    return process(io, io);
+  }
+
+ protected:
+  TProcessor() {}
+};
+
+}} // facebook::thrift
+
+#endif // #ifndef _THRIFT_PROCESSOR_H_

Added: hadoop/hive/trunk/service/include/thrift/TReflectionLocal.h
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/service/include/thrift/TReflectionLocal.h?rev=724247&view=auto
==============================================================================
--- hadoop/hive/trunk/service/include/thrift/TReflectionLocal.h (added)
+++ hadoop/hive/trunk/service/include/thrift/TReflectionLocal.h Sun Dec  7 20:25:22 2008
@@ -0,0 +1,84 @@
+// Copyright (c) 2006- Facebook
+// Distributed under the Thrift Software License
+//
+// See accompanying file LICENSE or visit the Thrift site at:
+// http://developers.facebook.com/thrift/
+
+#ifndef _THRIFT_TREFLECTIONLOCAL_H_
+#define _THRIFT_TREFLECTIONLOCAL_H_ 1
+
+#include <stdint.h>
+#include <cstring>
+#include <protocol/TProtocol.h>
+
+/**
+ * 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).
+ *
+ * @author David Reiss <dr...@facebook.com>
+ */
+
+namespace facebook { namespace thrift { namespace reflection { namespace local {
+
+using facebook::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;
+  }
+
+};
+
+}}}} // facebook::thrift::reflection::local
+
+#endif // #ifndef _THRIFT_TREFLECTIONLOCAL_H_

Added: hadoop/hive/trunk/service/include/thrift/Thrift.h
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/service/include/thrift/Thrift.h?rev=724247&view=auto
==============================================================================
--- hadoop/hive/trunk/service/include/thrift/Thrift.h (added)
+++ hadoop/hive/trunk/service/include/thrift/Thrift.h Sun Dec  7 20:25:22 2008
@@ -0,0 +1,162 @@
+// Copyright (c) 2006- Facebook
+// Distributed under the Thrift Software License
+//
+// See accompanying file LICENSE or visit the Thrift site at:
+// http://developers.facebook.com/thrift/
+
+#ifndef _THRIFT_THRIFT_H_
+#define _THRIFT_THRIFT_H_ 1
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <netinet/in.h>
+#ifdef HAVE_INTTYPES_H
+#include <inttypes.h>
+#endif
+#include <string>
+#include <map>
+#include <list>
+#include <set>
+#include <vector>
+#include <exception>
+
+#include "TLogging.h"
+
+namespace facebook { namespace thrift {
+
+class TOutput {
+ public:
+  TOutput() : f_(&perrorTimeWrapper) {}
+
+  inline void setOutputFunction(void (*function)(const char *)){
+    f_ = function;
+  }
+
+  inline void operator()(const char *message){
+    f_(message);
+  }
+
+  inline static void perrorTimeWrapper(const char* msg) {
+    time_t now;
+    char dbgtime[25];
+    time(&now);
+    ctime_r(&now, dbgtime);
+    dbgtime[24] = 0;
+    fprintf(stderr, "%s ", dbgtime);
+    perror(msg);
+  }
+ 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;
+}}
+
+
+}} // facebook::thrift
+
+#endif // #ifndef _THRIFT_THRIFT_H_

Added: hadoop/hive/trunk/service/include/thrift/concurrency/Exception.h
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/service/include/thrift/concurrency/Exception.h?rev=724247&view=auto
==============================================================================
--- hadoop/hive/trunk/service/include/thrift/concurrency/Exception.h (added)
+++ hadoop/hive/trunk/service/include/thrift/concurrency/Exception.h Sun Dec  7 20:25:22 2008
@@ -0,0 +1,47 @@
+// Copyright (c) 2006- Facebook
+// Distributed under the Thrift Software License
+//
+// See accompanying file LICENSE or visit the Thrift site at:
+// http://developers.facebook.com/thrift/
+
+#ifndef _THRIFT_CONCURRENCY_EXCEPTION_H_
+#define _THRIFT_CONCURRENCY_EXCEPTION_H_ 1
+
+#include <exception>
+#include <Thrift.h>
+
+namespace facebook { namespace thrift { namespace concurrency {
+
+class NoSuchTaskException : public facebook::thrift::TException {};
+
+class UncancellableTaskException : public facebook::thrift::TException {};
+
+class InvalidArgumentException : public facebook::thrift::TException {};
+
+class IllegalStateException : public facebook::thrift::TException {};
+
+class TimedOutException : public facebook::thrift::TException {
+public:                                            
+  TimedOutException():TException("TimedOutException"){};
+  TimedOutException(const std::string& message ) : 
+    TException(message) {}
+};
+
+class TooManyPendingTasksException : public facebook::thrift::TException {
+public:                                            
+  TooManyPendingTasksException():TException("TooManyPendingTasksException"){};
+  TooManyPendingTasksException(const std::string& message ) : 
+    TException(message) {}
+};
+
+class SystemResourceException : public facebook::thrift::TException {
+public:
+    SystemResourceException() {}
+
+    SystemResourceException(const std::string& message) :
+        TException(message) {}
+};
+
+}}} // facebook::thrift::concurrency
+
+#endif // #ifndef _THRIFT_CONCURRENCY_EXCEPTION_H_

Added: hadoop/hive/trunk/service/include/thrift/concurrency/Monitor.h
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/service/include/thrift/concurrency/Monitor.h?rev=724247&view=auto
==============================================================================
--- hadoop/hive/trunk/service/include/thrift/concurrency/Monitor.h (added)
+++ hadoop/hive/trunk/service/include/thrift/concurrency/Monitor.h Sun Dec  7 20:25:22 2008
@@ -0,0 +1,72 @@
+// Copyright (c) 2006- Facebook
+// Distributed under the Thrift Software License
+//
+// See accompanying file LICENSE or visit the Thrift site at:
+// http://developers.facebook.com/thrift/
+
+#ifndef _THRIFT_CONCURRENCY_MONITOR_H_
+#define _THRIFT_CONCURRENCY_MONITOR_H_ 1
+
+#include "Exception.h"
+
+namespace facebook { 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.
+ *
+ * @author marc
+ * @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_;
+};
+
+
+}}} // facebook::thrift::concurrency
+
+#endif // #ifndef _THRIFT_CONCURRENCY_MONITOR_H_

Added: hadoop/hive/trunk/service/include/thrift/concurrency/Mutex.h
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/service/include/thrift/concurrency/Mutex.h?rev=724247&view=auto
==============================================================================
--- hadoop/hive/trunk/service/include/thrift/concurrency/Mutex.h (added)
+++ hadoop/hive/trunk/service/include/thrift/concurrency/Mutex.h Sun Dec  7 20:25:22 2008
@@ -0,0 +1,94 @@
+// Copyright (c) 2006- Facebook
+// Distributed under the Thrift Software License
+//
+// See accompanying file LICENSE or visit the Thrift site at:
+// http://developers.facebook.com/thrift/
+
+#ifndef _THRIFT_CONCURRENCY_MUTEX_H_
+#define _THRIFT_CONCURRENCY_MUTEX_H_ 1
+
+#include <boost/shared_ptr.hpp>
+
+namespace facebook { namespace thrift { namespace concurrency { 
+
+/**
+ * A simple mutex class
+ *
+ * @author marc
+ * @version $Id:$
+ */
+class Mutex {
+ public:
+  Mutex();
+  virtual ~Mutex() {}
+  virtual void lock() const;
+  virtual bool trylock() const;
+  virtual void unlock() const;
+
+ private:
+
+  class impl;
+  boost::shared_ptr<impl> 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> 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);"
+// 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)
+
+
+}}} // facebook::thrift::concurrency
+
+#endif // #ifndef _THRIFT_CONCURRENCY_MUTEX_H_

Added: hadoop/hive/trunk/service/include/thrift/concurrency/PosixThreadFactory.h
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/service/include/thrift/concurrency/PosixThreadFactory.h?rev=724247&view=auto
==============================================================================
--- hadoop/hive/trunk/service/include/thrift/concurrency/PosixThreadFactory.h (added)
+++ hadoop/hive/trunk/service/include/thrift/concurrency/PosixThreadFactory.h Sun Dec  7 20:25:22 2008
@@ -0,0 +1,118 @@
+// Copyright (c) 2006- Facebook
+// Distributed under the Thrift Software License
+//
+// See accompanying file LICENSE or visit the Thrift site at:
+// http://developers.facebook.com/thrift/
+
+#ifndef _THRIFT_CONCURRENCY_POSIXTHREADFACTORY_H_
+#define _THRIFT_CONCURRENCY_POSIXTHREADFACTORY_H_ 1
+
+#include "Thread.h"
+
+#include <boost/shared_ptr.hpp>
+
+namespace facebook { namespace thrift { namespace concurrency {
+
+/**
+ * A thread factory to create posix threads
+ *
+ * @author marc
+ * @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<Thread> newThread(boost::shared_ptr<Runnable> 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> impl_;
+};
+
+}}} // facebook::thrift::concurrency
+
+#endif // #ifndef _THRIFT_CONCURRENCY_POSIXTHREADFACTORY_H_

Added: hadoop/hive/trunk/service/include/thrift/concurrency/Thread.h
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/service/include/thrift/concurrency/Thread.h?rev=724247&view=auto
==============================================================================
--- hadoop/hive/trunk/service/include/thrift/concurrency/Thread.h (added)
+++ hadoop/hive/trunk/service/include/thrift/concurrency/Thread.h Sun Dec  7 20:25:22 2008
@@ -0,0 +1,112 @@
+// Copyright (c) 2006- Facebook
+// Distributed under the Thrift Software License
+//
+// See accompanying file LICENSE or visit the Thrift site at:
+// http://developers.facebook.com/thrift/
+
+#ifndef _THRIFT_CONCURRENCY_THREAD_H_
+#define _THRIFT_CONCURRENCY_THREAD_H_ 1
+
+#include <boost/shared_ptr.hpp>
+#include <boost/weak_ptr.hpp>
+
+namespace facebook { namespace thrift { namespace concurrency {
+
+class Thread;
+
+/**
+ * Minimal runnable class.  More or less analogous to java.lang.Runnable.
+ *
+ * @author marc
+ * @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> 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<Thread> value) { thread_ = value; }
+
+ private:
+  boost::weak_ptr<Thread> 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 facebook::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> runnable() const { return _runnable; }
+
+ protected:
+  virtual void runnable(boost::shared_ptr<Runnable> value) { _runnable = value; }
+
+ private:
+  boost::shared_ptr<Runnable> _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<Thread> newThread(boost::shared_ptr<Runnable> 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;
+};
+
+}}} // facebook::thrift::concurrency
+
+#endif // #ifndef _THRIFT_CONCURRENCY_THREAD_H_

Added: hadoop/hive/trunk/service/include/thrift/concurrency/ThreadManager.h
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/service/include/thrift/concurrency/ThreadManager.h?rev=724247&view=auto
==============================================================================
--- hadoop/hive/trunk/service/include/thrift/concurrency/ThreadManager.h (added)
+++ hadoop/hive/trunk/service/include/thrift/concurrency/ThreadManager.h Sun Dec  7 20:25:22 2008
@@ -0,0 +1,157 @@
+// Copyright (c) 2006- Facebook
+// Distributed under the Thrift Software License
+//
+// See accompanying file LICENSE or visit the Thrift site at:
+// http://developers.facebook.com/thrift/
+
+#ifndef _THRIFT_CONCURRENCY_THREADMANAGER_H_
+#define _THRIFT_CONCURRENCY_THREADMANAGER_H_ 1
+
+#include <boost/shared_ptr.hpp>
+#include <sys/types.h>
+#include "Thread.h"
+
+namespace facebook { namespace thrift { namespace concurrency {
+
+/**
+ * Thread Pool Manager and related classes
+ *
+ * @author marc
+ * @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> threadFactory() const = 0;
+
+  virtual void threadFactory(boost::shared_ptr<ThreadFactory> 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_ptr<Runnable>task, int64_t timeout=0LL) = 0;
+
+  /**
+   * Removes a pending task
+   */
+  virtual void remove(boost::shared_ptr<Runnable> task) = 0;
+
+  static boost::shared_ptr<ThreadManager> 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<ThreadManager> newSimpleThreadManager(size_t count=4, size_t pendingTaskCountMax=0);
+
+  class Task;
+
+  class Worker;
+
+  class Impl;
+};
+
+}}} // facebook::thrift::concurrency
+
+#endif // #ifndef _THRIFT_CONCURRENCY_THREADMANAGER_H_

Added: hadoop/hive/trunk/service/include/thrift/concurrency/TimerManager.h
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/service/include/thrift/concurrency/TimerManager.h?rev=724247&view=auto
==============================================================================
--- hadoop/hive/trunk/service/include/thrift/concurrency/TimerManager.h (added)
+++ hadoop/hive/trunk/service/include/thrift/concurrency/TimerManager.h Sun Dec  7 20:25:22 2008
@@ -0,0 +1,108 @@
+// Copyright (c) 2006- Facebook
+// Distributed under the Thrift Software License
+//
+// See accompanying file LICENSE or visit the Thrift site at:
+// http://developers.facebook.com/thrift/
+
+#ifndef _THRIFT_CONCURRENCY_TIMERMANAGER_H_
+#define _THRIFT_CONCURRENCY_TIMERMANAGER_H_ 1
+
+#include "Exception.h"
+#include "Monitor.h"
+#include "Thread.h"
+
+#include <boost/shared_ptr.hpp>
+#include <map>
+#include <time.h>
+
+namespace facebook { namespace thrift { namespace concurrency { 
+
+/**
+ * Timer Manager 
+ * 
+ * This class dispatches timer tasks when they fall due.
+ *  
+ * @author marc
+ * @version $Id:$
+ */
+class TimerManager {
+
+ public:
+
+  TimerManager();
+
+  virtual ~TimerManager();
+
+  virtual boost::shared_ptr<const ThreadFactory> threadFactory() const;
+
+  virtual void threadFactory(boost::shared_ptr<const ThreadFactory> 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<Runnable> 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<Runnable> 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<Runnable> task);
+
+  enum STATE {
+    UNINITIALIZED,
+    STARTING,
+    STARTED,
+    STOPPING,
+    STOPPED
+  };
+  
+  virtual const STATE state() const;
+
+ private:
+  boost::shared_ptr<const ThreadFactory> threadFactory_;
+  class Task;
+  friend class Task;
+  std::multimap<int64_t, boost::shared_ptr<Task> > taskMap_;
+  size_t taskCount_;
+  Monitor monitor_;
+  STATE state_;
+  class Dispatcher;
+  friend class Dispatcher;
+  boost::shared_ptr<Dispatcher> dispatcher_;
+  boost::shared_ptr<Thread> dispatcherThread_;
+};
+
+}}} // facebook::thrift::concurrency
+
+#endif // #ifndef _THRIFT_CONCURRENCY_TIMERMANAGER_H_

Added: hadoop/hive/trunk/service/include/thrift/concurrency/Util.h
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/service/include/thrift/concurrency/Util.h?rev=724247&view=auto
==============================================================================
--- hadoop/hive/trunk/service/include/thrift/concurrency/Util.h (added)
+++ hadoop/hive/trunk/service/include/thrift/concurrency/Util.h Sun Dec  7 20:25:22 2008
@@ -0,0 +1,91 @@
+// Copyright (c) 2006- Facebook
+// Distributed under the Thrift Software License
+//
+// See accompanying file LICENSE or visit the Thrift site at:
+// http://developers.facebook.com/thrift/
+
+#ifndef _THRIFT_CONCURRENCY_UTIL_H_
+#define _THRIFT_CONCURRENCY_UTIL_H_ 1
+
+#include <config.h>
+
+#include <assert.h>
+#include <stddef.h>
+#if defined(HAVE_CLOCK_GETTIME)
+#include <time.h>
+#else // defined(HAVE_CLOCK_GETTIME)
+#include <sys/time.h>
+#endif // defined(HAVE_CLOCK_GETTIME)
+
+namespace facebook { 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.
+ *
+ * @author marc
+ * @version $Id:$
+ */
+class Util {
+
+  static const int64_t NS_PER_S = 1000000000LL;
+  static const int64_t MS_PER_S = 1000LL;
+  static const int64_t NS_PER_MS = 1000000LL;
+
+ public:
+
+  /**
+   * Converts timespec to milliseconds
+   *
+   * @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
+  }
+
+  /**
+   * Converts 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) +
+      (value.tv_nsec % NS_PER_MS >= 500000 ? 1 : 0);
+  }
+
+  /**
+   * Get current time as milliseconds from epoch
+   */
+  static const int64_t currentTime() {
+#if defined(HAVE_CLOCK_GETTIME)
+    struct timespec now;
+    int ret = clock_gettime(CLOCK_REALTIME, &now);
+    assert(ret == 0);
+    return
+      (now.tv_sec * MS_PER_S) +
+      (now.tv_nsec / NS_PER_MS) +
+      (now.tv_nsec % NS_PER_MS >= 500000 ? 1 : 0) ;
+#elif defined(HAVE_GETTIMEOFDAY)
+    struct timeval now;
+    int ret = gettimeofday(&now, NULL);
+    assert(ret == 0);
+    return
+      (((int64_t)now.tv_sec) * MS_PER_S) +
+      (now.tv_usec / MS_PER_S) +
+      (now.tv_usec % MS_PER_S >= 500 ? 1 : 0);
+#endif // defined(HAVE_GETTIMEDAY)
+  }
+
+};
+
+}}} // facebook::thrift::concurrency
+
+#endif // #ifndef _THRIFT_CONCURRENCY_UTIL_H_

Added: hadoop/hive/trunk/service/include/thrift/config.h
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/service/include/thrift/config.h?rev=724247&view=auto
==============================================================================
--- hadoop/hive/trunk/service/include/thrift/config.h (added)
+++ hadoop/hive/trunk/service/include/thrift/config.h Sun Dec  7 20:25:22 2008
@@ -0,0 +1,260 @@
+/* config.h.  Generated by configure.  */
+/* config.hin.  Generated from configure.ac by autoheader.  */
+
+/* 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 <alloca.h> and it should be used (not on Ultrix).
+   */
+#define HAVE_ALLOCA_H 1
+
+/* Define to 1 if you have the <arpa/inet.h> 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 <dlfcn.h> 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 <endian.h> header file. */
+#define HAVE_ENDIAN_H 1
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#define HAVE_FCNTL_H 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 <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* define if libevent is available */
+#define HAVE_LIBEVENT 
+
+/* Define to 1 if you have the <libintl.h> 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 your system has a GNU libc compatible `malloc' function, and
+   to 0 otherwise. */
+#define HAVE_MALLOC 1
+
+/* Define to 1 if you have the <malloc.h> 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 <memory.h> 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 <netdb.h> header file. */
+#define HAVE_NETDB_H 1
+
+/* Define to 1 if you have the <netinet/in.h> header file. */
+#define HAVE_NETINET_IN_H 1
+
+/* Define to 1 if you have the <pthread.h> header file. */
+#define HAVE_PTHREAD_H 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 `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 <stddef.h> header file. */
+#define HAVE_STDDEF_H 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdlib.h> 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_r' function. */
+#define HAVE_STRERROR_R 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> 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 <sys/select.h> header file. */
+#define HAVE_SYS_SELECT_H 1
+
+/* Define to 1 if you have the <sys/socket.h> header file. */
+#define HAVE_SYS_SOCKET_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+#define HAVE_SYS_TIME_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <unistd.h> 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 */
+
+/* Define to 1 if `lstat' dereferences a symlink specified with a trailing
+   slash. */
+#define LSTAT_FOLLOWS_SLASHED_SYMLINK 1
+
+/* 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 20070917"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "thrift"
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "20070917"
+
+/* 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 *)
+
+/* 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 run-time.
+	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 <sys/time.h> and <time.h>. */
+#define TIME_WITH_SYS_TIME 1
+
+/* Version number of package */
+#define VERSION "20070917"
+
+/* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a
+   `char[]'. */
+#define YYTEXT_POINTER 1
+
+/* 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 rpl_malloc if the replacement function should be used. */
+/* #undef malloc */
+
+/* Define to `int' if <sys/types.h> does not define. */
+/* #undef mode_t */
+
+/* Define to `long' if <sys/types.h> does not define. */
+/* #undef off_t */
+
+/* Define to rpl_realloc if the replacement function should be used. */
+/* #undef realloc */
+
+/* Define to `unsigned' if <sys/types.h> does not define. */
+/* #undef size_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 */

Added: hadoop/hive/trunk/service/include/thrift/fb303/FacebookBase.h
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/service/include/thrift/fb303/FacebookBase.h?rev=724247&view=auto
==============================================================================
--- hadoop/hive/trunk/service/include/thrift/fb303/FacebookBase.h (added)
+++ hadoop/hive/trunk/service/include/thrift/fb303/FacebookBase.h Sun Dec  7 20:25:22 2008
@@ -0,0 +1,96 @@
+// Copyright (c) 2006- Facebook
+// Distributed under the Thrift Software License
+//
+// See accompanying file LICENSE or visit the Thrift site at:
+// http://developers.facebook.com/thrift/
+
+#ifndef _FACEBOOK_TB303_FACEBOOKBASE_H_
+#define _FACEBOOK_TB303_FACEBOOKBASE_H_ 1
+
+#include "FacebookService.h"
+
+#include "thrift/server/TServer.h"
+#include "thrift/concurrency/Mutex.h"
+
+#include <time.h>
+#include <string>
+#include <map>
+
+namespace facebook { namespace fb303 {
+
+using facebook::thrift::concurrency::Mutex;
+using facebook::thrift::concurrency::ReadWriteMutex;
+using facebook::thrift::server::TServer;
+
+struct ReadWriteInt : ReadWriteMutex {int64_t value;};
+struct ReadWriteCounterMap : ReadWriteMutex,
+                             std::map<std::string, ReadWriteInt> {};
+
+typedef void (*get_static_limref_ptr)(facebook::thrift::reflection::limited::Service &);
+
+/**
+ * Base Facebook service implementation in C++.
+ *
+ * @author Mark Slee <mc...@facebook.com>
+ */
+class FacebookBase : virtual public FacebookServiceIf {
+ protected:
+  FacebookBase(std::string name, get_static_limref_ptr reflect_lim = NULL);
+  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<std::string, std::string> & _return);
+
+  int64_t aliveSince();
+
+  void getLimitedReflection(facebook::thrift::reflection::limited::Service& _return) {
+    _return = reflection_limited_;
+  }
+
+  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<std::string, int64_t>& _return);
+  int64_t getCounter(const std::string& key);
+
+  /**
+   * Set server handle for shutdown method
+   */
+  void setServer(boost::shared_ptr<TServer> server) {
+    server_ = server;
+  }
+
+ private:
+
+  std::string name_;
+  facebook::thrift::reflection::limited::Service reflection_limited_;
+  int64_t aliveSince_;
+
+  std::map<std::string, std::string> options_;
+  Mutex optionsLock_;
+
+  ReadWriteCounterMap counters_;
+
+  boost::shared_ptr<TServer> server_;
+
+};
+
+}} // facebook::tb303
+
+#endif // _FACEBOOK_TB303_FACEBOOKBASE_H_