incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [24/92] [abbrv] [partial] Fixed BLUR-126.
Date Tue, 11 Jun 2013 02:41:10 GMT
http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b0e26648/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/TSerializer.java
----------------------------------------------------------------------
diff --git a/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/TSerializer.java b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/TSerializer.java
new file mode 100644
index 0000000..4547404
--- /dev/null
+++ b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/TSerializer.java
@@ -0,0 +1,110 @@
+/*
+ * 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.
+ */
+
+package org.apache.blur.thirdparty.thrift_0_9_0;
+
+import java.io.ByteArrayOutputStream;
+import java.io.UnsupportedEncodingException;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.protocol.TBinaryProtocol;
+import org.apache.blur.thirdparty.thrift_0_9_0.protocol.TProtocol;
+import org.apache.blur.thirdparty.thrift_0_9_0.protocol.TProtocolFactory;
+import org.apache.blur.thirdparty.thrift_0_9_0.transport.TIOStreamTransport;
+
+/**
+ * Generic utility for easily serializing objects into a byte array or Java
+ * String.
+ *
+ */
+public class TSerializer {
+
+  /**
+   * This is the byte array that data is actually serialized into
+   */
+  private final ByteArrayOutputStream baos_ = new ByteArrayOutputStream();
+
+  /**
+   * This transport wraps that byte array
+   */
+  private final TIOStreamTransport transport_ = new TIOStreamTransport(baos_);
+
+  /**
+   * Internal protocol used for serializing objects.
+   */
+  private TProtocol protocol_;
+
+  /**
+   * Create a new TSerializer that uses the TBinaryProtocol by default.
+   */
+  public TSerializer() {
+    this(new TBinaryProtocol.Factory());
+  }
+
+  /**
+   * Create a new TSerializer. It will use the TProtocol specified by the
+   * factory that is passed in.
+   *
+   * @param protocolFactory Factory to create a protocol
+   */
+  public TSerializer(TProtocolFactory protocolFactory) {
+    protocol_ = protocolFactory.getProtocol(transport_);
+  }
+
+  /**
+   * Serialize the Thrift object into a byte array. The process is simple,
+   * just clear the byte array output, write the object into it, and grab the
+   * raw bytes.
+   *
+   * @param base The object to serialize
+   * @return Serialized object in byte[] format
+   */
+  public byte[] serialize(TBase base) throws TException {
+    baos_.reset();
+    base.write(protocol_);
+    return baos_.toByteArray();
+  }
+
+  /**
+   * Serialize the Thrift object into a Java string, using a specified
+   * character set for encoding.
+   *
+   * @param base The object to serialize
+   * @param charset Valid JVM charset
+   * @return Serialized object as a String
+   */
+  public String toString(TBase base, String charset) throws TException {
+    try {
+      return new String(serialize(base), charset);
+    } catch (UnsupportedEncodingException uex) {
+      throw new TException("JVM DOES NOT SUPPORT ENCODING: " + charset);
+    }
+  }
+
+  /**
+   * Serialize the Thrift object into a Java string, using the default JVM
+   * charset encoding.
+   *
+   * @param base The object to serialize
+   * @return Serialized object as a String
+   */
+  public String toString(TBase base) throws TException {
+    return new String(serialize(base));
+  }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b0e26648/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/TServiceClient.java
----------------------------------------------------------------------
diff --git a/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/TServiceClient.java b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/TServiceClient.java
new file mode 100644
index 0000000..e028e5b
--- /dev/null
+++ b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/TServiceClient.java
@@ -0,0 +1,81 @@
+/*
+ * 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.
+ */
+
+package org.apache.blur.thirdparty.thrift_0_9_0;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.protocol.TMessage;
+import org.apache.blur.thirdparty.thrift_0_9_0.protocol.TMessageType;
+import org.apache.blur.thirdparty.thrift_0_9_0.protocol.TProtocol;
+
+/**
+ * A TServiceClient is used to communicate with a TService implementation
+ * across protocols and transports.
+ */
+public abstract class TServiceClient {
+  public TServiceClient(TProtocol prot) {
+    this(prot, prot);
+  }
+
+  public TServiceClient(TProtocol iprot, TProtocol oprot) {
+    iprot_ = iprot;
+    oprot_ = oprot;
+  }
+
+  protected TProtocol iprot_;
+  protected TProtocol oprot_;
+
+  protected int seqid_;
+
+  /**
+   * Get the TProtocol being used as the input (read) protocol.
+   * @return the TProtocol being used as the input (read) protocol.
+   */
+  public TProtocol getInputProtocol() {
+    return this.iprot_;
+  }
+
+  /**
+   * Get the TProtocol being used as the output (write) protocol.
+   * @return the TProtocol being used as the output (write) protocol.
+   */
+  public TProtocol getOutputProtocol() {
+    return this.oprot_;
+  }
+
+  protected void sendBase(String methodName, TBase args) throws TException {
+    oprot_.writeMessageBegin(new TMessage(methodName, TMessageType.CALL, ++seqid_));
+    args.write(oprot_);
+    oprot_.writeMessageEnd();
+    oprot_.getTransport().flush();
+  }
+
+  protected void receiveBase(TBase result, String methodName) throws TException {
+    TMessage msg = iprot_.readMessageBegin();
+    if (msg.type == TMessageType.EXCEPTION) {
+      TApplicationException x = TApplicationException.read(iprot_);
+      iprot_.readMessageEnd();
+      throw x;
+    }
+    if (msg.seqid != seqid_) {
+      throw new TApplicationException(TApplicationException.BAD_SEQUENCE_ID, methodName + " failed: out of sequence response");
+    }
+    result.read(iprot_);
+    iprot_.readMessageEnd();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b0e26648/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/TServiceClientFactory.java
----------------------------------------------------------------------
diff --git a/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/TServiceClientFactory.java b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/TServiceClientFactory.java
new file mode 100644
index 0000000..d2639df
--- /dev/null
+++ b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/TServiceClientFactory.java
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+
+package org.apache.blur.thirdparty.thrift_0_9_0;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.protocol.TProtocol;
+
+/**
+ * A TServiceClientFactory provides a general way to get a TServiceClient
+ * connected to a remote TService via a protocol.
+ * @param <T>
+ */
+public interface TServiceClientFactory<T extends TServiceClient> {
+  /**
+   * Get a brand-new T using <i>prot</i> as both the input and output protocol.
+   * @param prot
+   * @return A brand-new T using <i>prot</i> as both the input and output protocol.
+   */
+  public T getClient(TProtocol prot);
+
+  /**
+   * Get a brand new T using the specified input and output protocols. The
+   * input and output protocols may be the same instance.
+   * @param iprot
+   * @param oprot
+   * @return a brand new T using the specified input and output protocols
+   */
+  public T getClient(TProtocol iprot, TProtocol oprot);
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b0e26648/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/TUnion.java
----------------------------------------------------------------------
diff --git a/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/TUnion.java b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/TUnion.java
new file mode 100644
index 0000000..93786f4
--- /dev/null
+++ b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/TUnion.java
@@ -0,0 +1,279 @@
+/**
+ * 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.
+ */
+package org.apache.blur.thirdparty.thrift_0_9_0;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.protocol.TField;
+import org.apache.blur.thirdparty.thrift_0_9_0.protocol.TProtocol;
+import org.apache.blur.thirdparty.thrift_0_9_0.protocol.TProtocolException;
+import org.apache.blur.thirdparty.thrift_0_9_0.protocol.TStruct;
+import org.apache.blur.thirdparty.thrift_0_9_0.scheme.IScheme;
+import org.apache.blur.thirdparty.thrift_0_9_0.scheme.SchemeFactory;
+import org.apache.blur.thirdparty.thrift_0_9_0.scheme.StandardScheme;
+import org.apache.blur.thirdparty.thrift_0_9_0.scheme.TupleScheme;
+
+public abstract class TUnion<T extends TUnion<?,?>, F extends TFieldIdEnum> implements TBase<T, F> {
+
+  protected Object value_;
+  protected F setField_;
+
+  protected TUnion() {
+    setField_ = null;
+    value_ = null;
+  }
+  
+  private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
+  static {
+    schemes.put(StandardScheme.class, new TUnionStandardSchemeFactory());
+    schemes.put(TupleScheme.class, new TUnionTupleSchemeFactory());
+  }
+
+  protected TUnion(F setField, Object value) {
+    setFieldValue(setField, value);
+  }
+
+  protected TUnion(TUnion<T, F> other) {
+    if (!other.getClass().equals(this.getClass())) {
+      throw new ClassCastException();
+    }
+    setField_ = other.setField_;
+    value_ = deepCopyObject(other.value_);
+  }
+
+  private static Object deepCopyObject(Object o) {
+    if (o instanceof TBase) {
+      return ((TBase)o).deepCopy();
+    } else if (o instanceof ByteBuffer) {
+      return TBaseHelper.copyBinary((ByteBuffer)o);
+    } else if (o instanceof List) {
+      return deepCopyList((List)o);
+    } else if (o instanceof Set) {
+      return deepCopySet((Set)o);
+    } else if (o instanceof Map) {
+      return deepCopyMap((Map)o);
+    } else {
+      return o;
+    }
+  }
+
+  private static Map deepCopyMap(Map<Object, Object> map) {
+    Map copy = new HashMap();
+    for (Map.Entry<Object, Object> entry : map.entrySet()) {
+      copy.put(deepCopyObject(entry.getKey()), deepCopyObject(entry.getValue()));
+    }
+    return copy;
+  }
+
+  private static Set deepCopySet(Set set) {
+    Set copy = new HashSet();
+    for (Object o : set) {
+      copy.add(deepCopyObject(o));
+    }
+    return copy;
+  }
+
+  private static List deepCopyList(List list) {
+    List copy = new ArrayList(list.size());
+    for (Object o : list) {
+      copy.add(deepCopyObject(o));
+    }
+    return copy;
+  }
+
+  public F getSetField() {
+    return setField_;
+  }
+
+  public Object getFieldValue() {
+    return value_;
+  }
+
+  public Object getFieldValue(F fieldId) {
+    if (fieldId != setField_) {
+      throw new IllegalArgumentException("Cannot get the value of field " + fieldId + " because union's set field is " + setField_);
+    }
+
+    return getFieldValue();
+  }
+
+  public Object getFieldValue(int fieldId) {
+    return getFieldValue(enumForId((short)fieldId));
+  }
+
+  public boolean isSet() {
+    return setField_ != null;
+  }
+
+  public boolean isSet(F fieldId) {
+    return setField_ == fieldId;
+  }
+
+  public boolean isSet(int fieldId) {
+    return isSet(enumForId((short)fieldId));
+  }
+
+  public void read(TProtocol iprot) throws TException {
+    schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
+  }
+
+  public void setFieldValue(F fieldId, Object value) {
+    checkType(fieldId, value);
+    setField_ = fieldId;
+    value_ = value;
+  }
+
+  public void setFieldValue(int fieldId, Object value) {
+    setFieldValue(enumForId((short)fieldId), value);
+  }
+
+  public void write(TProtocol oprot) throws TException {
+    schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
+  }
+
+  /**
+   * Implementation should be generated so that we can efficiently type check 
+   * various values.
+   * @param setField
+   * @param value
+   */
+  protected abstract void checkType(F setField, Object value) throws ClassCastException;
+
+  /**
+   * Implementation should be generated to read the right stuff from the wire 
+   * based on the field header. 
+   * @param field
+   * @return read Object based on the field header, as specified by the argument.
+   */
+  protected abstract Object standardSchemeReadValue(TProtocol iprot, TField field) throws TException;
+  protected abstract void standardSchemeWriteValue(TProtocol oprot) throws TException;
+  
+  protected abstract Object tupleSchemeReadValue(TProtocol iprot, short fieldID) throws TException;
+  protected abstract void tupleSchemeWriteValue(TProtocol oprot) throws TException;
+
+  protected abstract TStruct getStructDesc();
+
+  protected abstract TField getFieldDesc(F setField);
+
+  protected abstract F enumForId(short id);
+
+  @Override
+  public String toString() {
+    StringBuilder sb = new StringBuilder();
+    sb.append("<");
+    sb.append(this.getClass().getSimpleName());
+    sb.append(" ");
+
+    if (getSetField() != null) {
+      Object v = getFieldValue();
+      sb.append(getFieldDesc(getSetField()).name);
+      sb.append(":");
+      if(v instanceof ByteBuffer) {
+        TBaseHelper.toString((ByteBuffer)v, sb);
+      } else {
+        sb.append(v.toString());
+      }
+    }
+    sb.append(">");
+    return sb.toString();
+  }
+
+  public final void clear() {
+    this.setField_ = null;
+    this.value_ = null;
+  }
+  
+  private static class TUnionStandardSchemeFactory implements SchemeFactory {
+    public TUnionStandardScheme getScheme() {
+      return new TUnionStandardScheme();
+    }
+  }
+  
+  private static class TUnionStandardScheme extends StandardScheme<TUnion> {
+
+    @Override
+    public void read(TProtocol iprot, TUnion struct) throws TException {
+      struct.setField_ = null;
+      struct.value_ = null;
+
+      iprot.readStructBegin();
+
+      TField field = iprot.readFieldBegin();
+
+      struct.value_ = struct.standardSchemeReadValue(iprot, field);
+      if (struct.value_ != null) {
+        struct.setField_ = struct.enumForId(field.id);
+      }
+
+      iprot.readFieldEnd();
+      // this is so that we will eat the stop byte. we could put a check here to
+      // make sure that it actually *is* the stop byte, but it's faster to do it
+      // this way.
+      iprot.readFieldBegin();
+      iprot.readStructEnd();
+    }
+
+    @Override
+    public void write(TProtocol oprot, TUnion struct) throws TException {
+      if (struct.getSetField() == null || struct.getFieldValue() == null) {
+        throw new TProtocolException("Cannot write a TUnion with no set value!");
+      }
+      oprot.writeStructBegin(struct.getStructDesc());
+      oprot.writeFieldBegin(struct.getFieldDesc(struct.setField_));
+      struct.standardSchemeWriteValue(oprot);
+      oprot.writeFieldEnd();
+      oprot.writeFieldStop();
+      oprot.writeStructEnd();
+    }
+  }
+  
+  private static class TUnionTupleSchemeFactory implements SchemeFactory {
+    public TUnionTupleScheme getScheme() {
+      return new TUnionTupleScheme();
+    }
+  }
+  
+  private static class TUnionTupleScheme extends TupleScheme<TUnion> {
+
+    @Override
+    public void read(TProtocol iprot, TUnion struct) throws TException {
+      struct.setField_ = null;
+      struct.value_ = null;
+      short fieldID = iprot.readI16();
+      struct.value_ = struct.tupleSchemeReadValue(iprot, fieldID);
+      if (struct.value_ != null) {
+        struct.setField_ = struct.enumForId(fieldID);
+      }
+    }
+
+    @Override
+    public void write(TProtocol oprot, TUnion struct) throws TException {
+      if (struct.getSetField() == null || struct.getFieldValue() == null) {
+        throw new TProtocolException("Cannot write a TUnion with no set value!");
+      }
+      oprot.writeI16(struct.setField_.getThriftFieldId());
+      struct.tupleSchemeWriteValue(oprot);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b0e26648/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/async/AsyncMethodCallback.java
----------------------------------------------------------------------
diff --git a/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/async/AsyncMethodCallback.java b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/async/AsyncMethodCallback.java
new file mode 100644
index 0000000..4c91157
--- /dev/null
+++ b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/async/AsyncMethodCallback.java
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+package org.apache.blur.thirdparty.thrift_0_9_0.async;
+
+
+public interface AsyncMethodCallback<T> {
+  /**
+   * This method will be called when the remote side has completed invoking
+   * your method call and the result is fully read. For oneway method calls,
+   * this method will be called as soon as we have completed writing out the
+   * request.
+   * @param response
+   */
+  public void onComplete(T response);
+
+  /**
+   * This method will be called when there is an unexpected clientside
+   * exception. This does not include application-defined exceptions that
+   * appear in the IDL, but rather things like IOExceptions.
+   * @param exception
+   */
+  public void onError(Exception exception);
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b0e26648/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/async/TAsyncClient.java
----------------------------------------------------------------------
diff --git a/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/async/TAsyncClient.java b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/async/TAsyncClient.java
new file mode 100644
index 0000000..7e2983b
--- /dev/null
+++ b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/async/TAsyncClient.java
@@ -0,0 +1,102 @@
+/*
+ * 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.
+ */
+package org.apache.blur.thirdparty.thrift_0_9_0.async;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.protocol.TProtocolFactory;
+import org.apache.blur.thirdparty.thrift_0_9_0.transport.TNonblockingTransport;
+
+public abstract class TAsyncClient {
+  protected final TProtocolFactory ___protocolFactory;
+  protected final TNonblockingTransport ___transport;
+  protected final TAsyncClientManager ___manager;
+  protected TAsyncMethodCall ___currentMethod;
+  private Exception ___error;
+  private long ___timeout;
+
+  public TAsyncClient(TProtocolFactory protocolFactory, TAsyncClientManager manager, TNonblockingTransport transport) {
+    this(protocolFactory, manager, transport, 0);
+  }
+
+  public TAsyncClient(TProtocolFactory protocolFactory, TAsyncClientManager manager, TNonblockingTransport transport, long timeout) {
+    this.___protocolFactory = protocolFactory;
+    this.___manager = manager;
+    this.___transport = transport;
+    this.___timeout = timeout;
+  }
+
+  public TProtocolFactory getProtocolFactory() {
+    return ___protocolFactory;
+  }
+
+  public long getTimeout() {
+    return ___timeout;
+  }
+
+  public boolean hasTimeout() {
+    return ___timeout > 0;
+  }
+
+  public void setTimeout(long timeout) {
+    this.___timeout = timeout;
+  }
+
+  /**
+   * Is the client in an error state?
+   * @return If client in an error state?
+   */
+  public boolean hasError() {
+    return ___error != null;
+  }
+
+  /**
+   * Get the client's error - returns null if no error
+   * @return Get the client's error. <br /> returns null if no error
+   */
+  public Exception getError() {
+    return ___error;
+  }
+
+  protected void checkReady() {
+    // Ensure we are not currently executing a method
+    if (___currentMethod != null) {
+      throw new IllegalStateException("Client is currently executing another method: " + ___currentMethod.getClass().getName());
+    }
+
+    // Ensure we're not in an error state
+    if (___error != null) {
+      throw new IllegalStateException("Client has an error!", ___error);
+    }
+  }
+
+  /**
+   * Called by delegate method when finished
+   */
+  protected void onComplete() {
+    ___currentMethod = null;
+  }
+
+  /**
+   * Called by delegate method on error
+   */
+  protected void onError(Exception exception) {
+    ___transport.close();
+    ___currentMethod = null;
+    ___error = exception;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b0e26648/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/async/TAsyncClientFactory.java
----------------------------------------------------------------------
diff --git a/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/async/TAsyncClientFactory.java b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/async/TAsyncClientFactory.java
new file mode 100644
index 0000000..034615c
--- /dev/null
+++ b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/async/TAsyncClientFactory.java
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+package org.apache.blur.thirdparty.thrift_0_9_0.async;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.transport.TNonblockingTransport;
+
+public interface TAsyncClientFactory<T extends TAsyncClient> {
+  public T getAsyncClient(TNonblockingTransport transport);
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b0e26648/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/async/TAsyncClientManager.java
----------------------------------------------------------------------
diff --git a/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/async/TAsyncClientManager.java b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/async/TAsyncClientManager.java
new file mode 100644
index 0000000..f273f88
--- /dev/null
+++ b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/async/TAsyncClientManager.java
@@ -0,0 +1,194 @@
+/*
+ * 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.
+ */
+package org.apache.blur.thirdparty.thrift_0_9_0.async;
+
+import java.io.IOException;
+import java.nio.channels.ClosedSelectorException;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
+import java.nio.channels.spi.SelectorProvider;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.TreeSet;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.TimeoutException;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.TException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Contains selector thread which transitions method call objects
+ */
+public class TAsyncClientManager {
+  private static final Logger LOGGER = LoggerFactory.getLogger(TAsyncClientManager.class.getName());
+
+  private final SelectThread selectThread;
+  private final ConcurrentLinkedQueue<TAsyncMethodCall> pendingCalls = new ConcurrentLinkedQueue<TAsyncMethodCall>();
+
+  public TAsyncClientManager() throws IOException {
+    this.selectThread = new SelectThread();
+    selectThread.start();
+  }
+
+  public void call(TAsyncMethodCall method) throws TException {
+    if (!isRunning()) {
+      throw new TException("SelectThread is not running");
+    }
+    method.prepareMethodCall();
+    pendingCalls.add(method);
+    selectThread.getSelector().wakeup();
+  }
+
+  public void stop() {
+    selectThread.finish();
+  }
+
+  public boolean isRunning() {
+    return selectThread.isAlive();
+  }
+
+  private class SelectThread extends Thread {
+    private final Selector selector;
+    private volatile boolean running;
+    private final TreeSet<TAsyncMethodCall> timeoutWatchSet = new TreeSet<TAsyncMethodCall>(new TAsyncMethodCallTimeoutComparator());
+
+    public SelectThread() throws IOException {
+      this.selector = SelectorProvider.provider().openSelector();
+      this.running = true;
+      this.setName("TAsyncClientManager#SelectorThread " + this.getId());
+
+      // We don't want to hold up the JVM when shutting down
+      setDaemon(true);
+    }
+
+    public Selector getSelector() {
+      return selector;
+    }
+
+    public void finish() {
+      running = false;
+      selector.wakeup();
+    }
+
+    public void run() {
+      while (running) {
+        try {
+          try {
+            if (timeoutWatchSet.size() == 0) {
+              // No timeouts, so select indefinitely
+              selector.select();
+            } else {
+              // We have a timeout pending, so calculate the time until then and select appropriately
+              long nextTimeout = timeoutWatchSet.first().getTimeoutTimestamp();
+              long selectTime = nextTimeout - System.currentTimeMillis();
+              if (selectTime > 0) {
+                // Next timeout is in the future, select and wake up then
+                selector.select(selectTime);
+              } else {
+                // Next timeout is now or in past, select immediately so we can time out
+                selector.selectNow();
+              }
+            }
+          } catch (IOException e) {
+            LOGGER.error("Caught IOException in TAsyncClientManager!", e);
+          }
+          transitionMethods();
+          timeoutMethods();
+          startPendingMethods();
+        } catch (Exception exception) {
+          LOGGER.error("Ignoring uncaught exception in SelectThread", exception);
+        }
+      }
+    }
+
+    // Transition methods for ready keys
+    private void transitionMethods() {
+      try {
+        Iterator<SelectionKey> keys = selector.selectedKeys().iterator();
+        while (keys.hasNext()) {
+          SelectionKey key = keys.next();
+          keys.remove();
+          if (!key.isValid()) {
+            // this can happen if the method call experienced an error and the
+            // key was cancelled. can also happen if we timeout a method, which
+            // results in a channel close.
+            // just skip
+            continue;
+          }
+          TAsyncMethodCall methodCall = (TAsyncMethodCall)key.attachment();
+          methodCall.transition(key);
+
+          // If done or error occurred, remove from timeout watch set
+          if (methodCall.isFinished() || methodCall.getClient().hasError()) {
+            timeoutWatchSet.remove(methodCall);
+          }
+        }
+      } catch (ClosedSelectorException e) {
+        LOGGER.error("Caught ClosedSelectorException in TAsyncClientManager!", e);
+      }
+    }
+
+    // Timeout any existing method calls
+    private void timeoutMethods() {
+      Iterator<TAsyncMethodCall> iterator = timeoutWatchSet.iterator();
+      long currentTime = System.currentTimeMillis();
+      while (iterator.hasNext()) {
+        TAsyncMethodCall methodCall = iterator.next();
+        if (currentTime >= methodCall.getTimeoutTimestamp()) {
+          iterator.remove();
+          methodCall.onError(new TimeoutException("Operation " + methodCall.getClass() + " timed out after " + (currentTime - methodCall.getStartTime()) + " ms."));
+        } else {
+          break;
+        }
+      }
+    }
+
+    // Start any new calls
+    private void startPendingMethods() {
+      TAsyncMethodCall methodCall;
+      while ((methodCall = pendingCalls.poll()) != null) {
+        // Catch registration errors. method will catch transition errors and cleanup.
+        try {
+          methodCall.start(selector);
+
+          // If timeout specified and first transition went smoothly, add to timeout watch set
+          TAsyncClient client = methodCall.getClient();
+          if (client.hasTimeout() && !client.hasError()) {
+            timeoutWatchSet.add(methodCall);
+          }
+        } catch (Exception exception) {
+          LOGGER.warn("Caught exception in TAsyncClientManager!", exception);
+          methodCall.onError(exception);
+        }
+      }
+    }
+  }
+
+  /** Comparator used in TreeSet */
+  private static class TAsyncMethodCallTimeoutComparator implements Comparator<TAsyncMethodCall> {
+    public int compare(TAsyncMethodCall left, TAsyncMethodCall right) {
+      if (left.getTimeoutTimestamp() == right.getTimeoutTimestamp()) {
+        return (int)(left.getSequenceId() - right.getSequenceId());
+      } else {
+        return (int)(left.getTimeoutTimestamp() - right.getTimeoutTimestamp());
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b0e26648/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/async/TAsyncMethodCall.java
----------------------------------------------------------------------
diff --git a/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/async/TAsyncMethodCall.java b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/async/TAsyncMethodCall.java
new file mode 100644
index 0000000..beb2218
--- /dev/null
+++ b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/async/TAsyncMethodCall.java
@@ -0,0 +1,270 @@
+/*
+ * 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.
+ */
+package org.apache.blur.thirdparty.thrift_0_9_0.async;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.TException;
+import org.apache.blur.thirdparty.thrift_0_9_0.protocol.TProtocol;
+import org.apache.blur.thirdparty.thrift_0_9_0.protocol.TProtocolFactory;
+import org.apache.blur.thirdparty.thrift_0_9_0.transport.TFramedTransport;
+import org.apache.blur.thirdparty.thrift_0_9_0.transport.TMemoryBuffer;
+import org.apache.blur.thirdparty.thrift_0_9_0.transport.TNonblockingTransport;
+import org.apache.blur.thirdparty.thrift_0_9_0.transport.TTransportException;
+
+/**
+ * Encapsulates an async method call
+ * Need to generate:
+ *   - private void write_args(TProtocol protocol)
+ *   - public T getResult() throws <Exception_1>, <Exception_2>, ...
+ * @param <T>
+ */
+public abstract class TAsyncMethodCall<T> {
+
+  private static final int INITIAL_MEMORY_BUFFER_SIZE = 128;
+  private static AtomicLong sequenceIdCounter = new AtomicLong(0);
+
+  public static enum State {
+    CONNECTING,
+    WRITING_REQUEST_SIZE,
+    WRITING_REQUEST_BODY,
+    READING_RESPONSE_SIZE,
+    READING_RESPONSE_BODY,
+    RESPONSE_READ,
+    ERROR;
+  }
+
+  /**
+   * Next step in the call, initialized by start()
+   */
+  private State state = null;
+
+  protected final TNonblockingTransport transport;
+  private final TProtocolFactory protocolFactory;
+  protected final TAsyncClient client;
+  private final AsyncMethodCallback<T> callback;
+  private final boolean isOneway;
+  private long sequenceId;
+  
+  private ByteBuffer sizeBuffer;
+  private final byte[] sizeBufferArray = new byte[4];
+  private ByteBuffer frameBuffer;
+
+  private long startTime = System.currentTimeMillis();
+
+  protected TAsyncMethodCall(TAsyncClient client, TProtocolFactory protocolFactory, TNonblockingTransport transport, AsyncMethodCallback<T> callback, boolean isOneway) {
+    this.transport = transport;
+    this.callback = callback;
+    this.protocolFactory = protocolFactory;
+    this.client = client;
+    this.isOneway = isOneway;
+    this.sequenceId = TAsyncMethodCall.sequenceIdCounter.getAndIncrement();
+  }
+
+  protected State getState() {
+    return state;
+  }
+
+  protected boolean isFinished() {
+    return state == State.RESPONSE_READ;
+  }
+
+  protected long getStartTime() {
+    return startTime;
+  }
+  
+  protected long getSequenceId() {
+    return sequenceId;
+  }
+
+  public TAsyncClient getClient() {
+    return client;
+  }
+  
+  public boolean hasTimeout() {
+    return client.hasTimeout();
+  }
+  
+  public long getTimeoutTimestamp() {
+    return client.getTimeout() + startTime;
+  }
+
+  protected abstract void write_args(TProtocol protocol) throws TException;
+
+  /**
+   * Initialize buffers.
+   * @throws TException if buffer initialization fails
+   */
+  protected void prepareMethodCall() throws TException {
+    TMemoryBuffer memoryBuffer = new TMemoryBuffer(INITIAL_MEMORY_BUFFER_SIZE);
+    TProtocol protocol = protocolFactory.getProtocol(memoryBuffer);
+    write_args(protocol);
+
+    int length = memoryBuffer.length();
+    frameBuffer = ByteBuffer.wrap(memoryBuffer.getArray(), 0, length);
+
+    TFramedTransport.encodeFrameSize(length, sizeBufferArray);
+    sizeBuffer = ByteBuffer.wrap(sizeBufferArray);
+  }
+
+  /**
+   * Register with selector and start first state, which could be either connecting or writing.
+   * @throws IOException if register or starting fails
+   */
+  void start(Selector sel) throws IOException {
+    SelectionKey key;
+    if (transport.isOpen()) {
+      state = State.WRITING_REQUEST_SIZE;
+      key = transport.registerSelector(sel, SelectionKey.OP_WRITE);
+    } else {
+      state = State.CONNECTING;
+      key = transport.registerSelector(sel, SelectionKey.OP_CONNECT);
+
+      // non-blocking connect can complete immediately,
+      // in which case we should not expect the OP_CONNECT
+      if (transport.startConnect()) {
+        registerForFirstWrite(key);
+      }
+    }
+
+    key.attach(this);
+  }
+
+  void registerForFirstWrite(SelectionKey key) throws IOException {
+    state = State.WRITING_REQUEST_SIZE;
+    key.interestOps(SelectionKey.OP_WRITE);
+  }
+
+  protected ByteBuffer getFrameBuffer() {
+    return frameBuffer;
+  }
+
+  /**
+   * Transition to next state, doing whatever work is required. Since this
+   * method is only called by the selector thread, we can make changes to our
+   * select interests without worrying about concurrency.
+   * @param key
+   */
+  protected void transition(SelectionKey key) {
+    // Ensure key is valid
+    if (!key.isValid()) {
+      key.cancel();
+      Exception e = new TTransportException("Selection key not valid!");
+      onError(e);
+      return;
+    }
+
+    // Transition function
+    try {
+      switch (state) {
+        case CONNECTING:
+          doConnecting(key);
+          break;
+        case WRITING_REQUEST_SIZE:
+          doWritingRequestSize();
+          break;
+        case WRITING_REQUEST_BODY:
+          doWritingRequestBody(key);
+          break;
+        case READING_RESPONSE_SIZE:
+          doReadingResponseSize();
+          break;
+        case READING_RESPONSE_BODY:
+          doReadingResponseBody(key);
+          break;
+        default: // RESPONSE_READ, ERROR, or bug
+          throw new IllegalStateException("Method call in state " + state
+              + " but selector called transition method. Seems like a bug...");
+      }
+    } catch (Exception e) {
+      key.cancel();
+      key.attach(null);
+      onError(e);
+    }
+  }
+
+  protected void onError(Exception e) {
+    client.onError(e);
+    callback.onError(e);
+    state = State.ERROR;
+  }
+
+  private void doReadingResponseBody(SelectionKey key) throws IOException {
+    if (transport.read(frameBuffer) < 0) {
+      throw new IOException("Read call frame failed");
+    }
+    if (frameBuffer.remaining() == 0) {
+      cleanUpAndFireCallback(key);
+    }
+  }
+
+  private void cleanUpAndFireCallback(SelectionKey key) {
+    state = State.RESPONSE_READ;
+    key.interestOps(0);
+    // this ensures that the TAsyncMethod instance doesn't hang around
+    key.attach(null);
+    client.onComplete();
+    callback.onComplete((T)this);
+  }
+
+  private void doReadingResponseSize() throws IOException {
+    if (transport.read(sizeBuffer) < 0) {
+      throw new IOException("Read call frame size failed");
+    }
+    if (sizeBuffer.remaining() == 0) {
+      state = State.READING_RESPONSE_BODY;
+      frameBuffer = ByteBuffer.allocate(TFramedTransport.decodeFrameSize(sizeBufferArray));
+    }
+  }
+
+  private void doWritingRequestBody(SelectionKey key) throws IOException {
+    if (transport.write(frameBuffer) < 0) {
+      throw new IOException("Write call frame failed");
+    }
+    if (frameBuffer.remaining() == 0) {
+      if (isOneway) {
+        cleanUpAndFireCallback(key);
+      } else {
+        state = State.READING_RESPONSE_SIZE;
+        sizeBuffer.rewind();  // Prepare to read incoming frame size
+        key.interestOps(SelectionKey.OP_READ);
+      }
+    }
+  }
+
+  private void doWritingRequestSize() throws IOException {
+    if (transport.write(sizeBuffer) < 0) {
+      throw new IOException("Write call frame size failed");
+    }
+    if (sizeBuffer.remaining() == 0) {
+      state = State.WRITING_REQUEST_BODY;
+    }
+  }
+
+  private void doConnecting(SelectionKey key) throws IOException {
+    if (!key.isConnectable() || !transport.finishConnect()) {
+      throw new IOException("not connectable or finishConnect returned false after we got an OP_CONNECT");
+    }
+    registerForFirstWrite(key);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b0e26648/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/meta_data/EnumMetaData.java
----------------------------------------------------------------------
diff --git a/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/meta_data/EnumMetaData.java b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/meta_data/EnumMetaData.java
new file mode 100644
index 0000000..47d3a18
--- /dev/null
+++ b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/meta_data/EnumMetaData.java
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+
+package org.apache.blur.thirdparty.thrift_0_9_0.meta_data;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.TEnum;
+
+public class EnumMetaData extends FieldValueMetaData {
+  public final Class<? extends TEnum> enumClass;
+  
+  public EnumMetaData(byte type, Class<? extends TEnum> sClass){
+    super(type);
+    this.enumClass = sClass;
+  }    
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b0e26648/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/meta_data/FieldMetaData.java
----------------------------------------------------------------------
diff --git a/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/meta_data/FieldMetaData.java b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/meta_data/FieldMetaData.java
new file mode 100644
index 0000000..ff072b8
--- /dev/null
+++ b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/meta_data/FieldMetaData.java
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+
+package org.apache.blur.thirdparty.thrift_0_9_0.meta_data;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.TBase;
+import org.apache.blur.thirdparty.thrift_0_9_0.TFieldIdEnum;
+
+/**
+ * This class is used to store meta data about thrift fields. Every field in a
+ * a struct should have a corresponding instance of this class describing it.
+ *
+ */
+public class FieldMetaData implements java.io.Serializable {
+  public final String fieldName;
+  public final byte requirementType;
+  public final FieldValueMetaData valueMetaData;
+  private static Map<Class<? extends TBase>, Map<? extends TFieldIdEnum, FieldMetaData>> structMap;
+  
+  static {
+    structMap = new HashMap<Class<? extends TBase>, Map<? extends TFieldIdEnum, FieldMetaData>>();
+  }
+  
+  public FieldMetaData(String name, byte req, FieldValueMetaData vMetaData){
+    this.fieldName = name;
+    this.requirementType = req;
+    this.valueMetaData = vMetaData;
+  }
+  
+  public static void addStructMetaDataMap(Class<? extends TBase> sClass, Map<? extends TFieldIdEnum, FieldMetaData> map){
+    structMap.put(sClass, map);
+  }
+
+  /**
+   * Returns a map with metadata (i.e. instances of FieldMetaData) that
+   * describe the fields of the given class.
+   *
+   * @param sClass The TBase class for which the metadata map is requested
+   */
+  public static Map<? extends TFieldIdEnum, FieldMetaData> getStructMetaDataMap(Class<? extends TBase> sClass){
+    if (!structMap.containsKey(sClass)){ // Load class if it hasn't been loaded
+      try{
+        sClass.newInstance();
+      } catch (InstantiationException e){
+        throw new RuntimeException("InstantiationException for TBase class: " + sClass.getName() + ", message: " + e.getMessage());
+      } catch (IllegalAccessException e){
+        throw new RuntimeException("IllegalAccessException for TBase class: " + sClass.getName() + ", message: " + e.getMessage());
+      }
+    }
+    return structMap.get(sClass);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b0e26648/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/meta_data/FieldValueMetaData.java
----------------------------------------------------------------------
diff --git a/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/meta_data/FieldValueMetaData.java b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/meta_data/FieldValueMetaData.java
new file mode 100644
index 0000000..bb47e44
--- /dev/null
+++ b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/meta_data/FieldValueMetaData.java
@@ -0,0 +1,72 @@
+/*
+ * 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.
+ */
+
+package org.apache.blur.thirdparty.thrift_0_9_0.meta_data;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.protocol.TType;
+
+/**
+ * FieldValueMetaData and collection of subclasses to store metadata about
+ * the value(s) of a field
+ */
+public class FieldValueMetaData implements java.io.Serializable {
+  public final byte type;  
+
+  private final boolean isTypedefType;
+  private final String typedefName;
+  private final boolean isBinary;
+
+  public FieldValueMetaData(byte type, boolean binary) {
+    this.type = type;
+    this.isTypedefType = false;
+    this.typedefName = null;
+    this.isBinary = binary;
+  }
+
+  public FieldValueMetaData(byte type) {
+    this(type, false);
+  }
+
+  public FieldValueMetaData(byte type, String typedefName) {
+    this.type = type;
+    this.isTypedefType = true;
+    this.typedefName = typedefName;
+    this.isBinary = false;
+  }
+
+  public boolean isTypedef() {
+    return isTypedefType;
+  }
+
+  public String getTypedefName() {
+    return typedefName;
+  }
+
+  public boolean isStruct() {
+    return type == TType.STRUCT; 
+  }
+
+  public boolean isContainer() {
+    return type == TType.LIST || type == TType.MAP || type == TType.SET;
+  }
+
+  public boolean isBinary() {
+    return isBinary;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b0e26648/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/meta_data/ListMetaData.java
----------------------------------------------------------------------
diff --git a/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/meta_data/ListMetaData.java b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/meta_data/ListMetaData.java
new file mode 100644
index 0000000..9781eeb
--- /dev/null
+++ b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/meta_data/ListMetaData.java
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+package org.apache.blur.thirdparty.thrift_0_9_0.meta_data;
+
+public class ListMetaData extends FieldValueMetaData {
+  public final FieldValueMetaData elemMetaData;
+  
+  public ListMetaData(byte type, FieldValueMetaData eMetaData){
+    super(type);
+    this.elemMetaData = eMetaData;
+  }    
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b0e26648/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/meta_data/MapMetaData.java
----------------------------------------------------------------------
diff --git a/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/meta_data/MapMetaData.java b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/meta_data/MapMetaData.java
new file mode 100644
index 0000000..5a495e8
--- /dev/null
+++ b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/meta_data/MapMetaData.java
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+
+package org.apache.blur.thirdparty.thrift_0_9_0.meta_data;
+
+public class MapMetaData extends FieldValueMetaData {
+  public final FieldValueMetaData keyMetaData;
+  public final FieldValueMetaData valueMetaData;
+  
+  public MapMetaData(byte type, FieldValueMetaData kMetaData, FieldValueMetaData vMetaData){
+    super(type);
+    this.keyMetaData = kMetaData;
+    this.valueMetaData = vMetaData;
+  }    
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b0e26648/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/meta_data/SetMetaData.java
----------------------------------------------------------------------
diff --git a/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/meta_data/SetMetaData.java b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/meta_data/SetMetaData.java
new file mode 100644
index 0000000..86094ae
--- /dev/null
+++ b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/meta_data/SetMetaData.java
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+package org.apache.blur.thirdparty.thrift_0_9_0.meta_data;
+
+public class SetMetaData extends FieldValueMetaData {
+  public final FieldValueMetaData elemMetaData;
+  
+  public SetMetaData(byte type, FieldValueMetaData eMetaData){
+    super(type);
+    this.elemMetaData = eMetaData;
+  }    
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b0e26648/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/meta_data/StructMetaData.java
----------------------------------------------------------------------
diff --git a/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/meta_data/StructMetaData.java b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/meta_data/StructMetaData.java
new file mode 100644
index 0000000..9e50379
--- /dev/null
+++ b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/meta_data/StructMetaData.java
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+
+package org.apache.blur.thirdparty.thrift_0_9_0.meta_data;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.TBase;
+
+public class StructMetaData extends FieldValueMetaData {
+  public final Class<? extends TBase> structClass;
+  
+  public StructMetaData(byte type, Class<? extends TBase> sClass){
+    super(type);
+    this.structClass = sClass;
+  }    
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b0e26648/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TBase64Utils.java
----------------------------------------------------------------------
diff --git a/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TBase64Utils.java b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TBase64Utils.java
new file mode 100644
index 0000000..42b72fd
--- /dev/null
+++ b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TBase64Utils.java
@@ -0,0 +1,127 @@
+/*
+ * 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.
+ */
+
+package org.apache.blur.thirdparty.thrift_0_9_0.protocol;
+
+/**
+ * Class for encoding and decoding Base64 data.
+ *
+ * This class is kept at package level because the interface does no input
+ * validation and is therefore too low-level for generalized reuse.
+ *
+ * Note also that the encoding does not pad with equal signs , as discussed in
+ * section 2.2 of the RFC (http://www.faqs.org/rfcs/rfc3548.html). Furthermore,
+ * bad data encountered when decoding is neither rejected or ignored but simply
+ * results in bad decoded data -- this is not in compliance with the RFC but is
+ * done in the interest of performance.
+ *
+ */
+class TBase64Utils {
+
+  private static final String ENCODE_TABLE =
+    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+  /**
+   * Encode len bytes of data in src at offset srcOff, storing the result into
+   * dst at offset dstOff. len must be 1, 2, or 3. dst must have at least len+1
+   * bytes of space at dstOff. src and dst should not be the same object. This
+   * method does no validation of the input values in the interest of
+   * performance.
+   *
+   * @param src  the source of bytes to encode
+   * @param srcOff  the offset into the source to read the unencoded bytes
+   * @param len  the number of bytes to encode (must be 1, 2, or 3).
+   * @param dst  the destination for the encoding
+   * @param dstOff  the offset into the destination to place the encoded bytes
+   */
+  static final void encode(byte[] src, int srcOff, int len,  byte[] dst,
+                           int dstOff) {
+    dst[dstOff] = (byte)ENCODE_TABLE.charAt((src[srcOff] >> 2) & 0x3F);
+    if (len == 3) {
+      dst[dstOff + 1] =
+        (byte)ENCODE_TABLE.charAt(
+                         ((src[srcOff] << 4) & 0x30) | ((src[srcOff+1] >> 4) & 0x0F));
+      dst[dstOff + 2] =
+        (byte)ENCODE_TABLE.charAt(
+                         ((src[srcOff+1] << 2) & 0x3C) | ((src[srcOff+2] >> 6) & 0x03));
+      dst[dstOff + 3] =
+        (byte)ENCODE_TABLE.charAt(src[srcOff+2] & 0x3F);
+    }
+    else if (len == 2) {
+      dst[dstOff+1] =
+        (byte)ENCODE_TABLE.charAt(
+                          ((src[srcOff] << 4) & 0x30) | ((src[srcOff+1] >> 4) & 0x0F));
+      dst[dstOff + 2] =
+        (byte)ENCODE_TABLE.charAt((src[srcOff+1] << 2) & 0x3C);
+    }
+    else { // len == 1) {
+      dst[dstOff + 1] =
+        (byte)ENCODE_TABLE.charAt((src[srcOff] << 4) & 0x30);
+    }
+  }
+
+  private static final byte[] DECODE_TABLE = {
+    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,
+    52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1,
+    -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,
+    15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,
+    -1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,
+    41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1,
+    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+  };
+
+  /**
+   * Decode len bytes of data in src at offset srcOff, storing the result into
+   * dst at offset dstOff. len must be 2, 3, or 4. dst must have at least len-1
+   * bytes of space at dstOff. src and dst may be the same object as long as
+   * dstoff <= srcOff. This method does no validation of the input values in
+   * the interest of performance.
+   *
+   * @param src  the source of bytes to decode
+   * @param srcOff  the offset into the source to read the encoded bytes
+   * @param len  the number of bytes to decode (must be 2, 3, or 4)
+   * @param dst  the destination for the decoding
+   * @param dstOff  the offset into the destination to place the decoded bytes
+   */
+  static final void decode(byte[] src, int srcOff, int len,  byte[] dst,
+                           int dstOff) {
+    dst[dstOff] = (byte)
+      ((DECODE_TABLE[src[srcOff] & 0x0FF] << 2) |
+       (DECODE_TABLE[src[srcOff+1] & 0x0FF] >> 4));
+    if (len > 2) {
+      dst[dstOff+1] = (byte)
+        (((DECODE_TABLE[src[srcOff+1] & 0x0FF] << 4) & 0xF0) |
+         (DECODE_TABLE[src[srcOff+2] & 0x0FF] >> 2));
+      if (len > 3) {
+        dst[dstOff+2] = (byte)
+          (((DECODE_TABLE[src[srcOff+2] & 0x0FF] << 6) & 0xC0) |
+           DECODE_TABLE[src[srcOff+3] & 0x0FF]);
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b0e26648/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TBinaryProtocol.java
----------------------------------------------------------------------
diff --git a/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TBinaryProtocol.java b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TBinaryProtocol.java
new file mode 100644
index 0000000..2ead2a0
--- /dev/null
+++ b/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TBinaryProtocol.java
@@ -0,0 +1,398 @@
+/*
+ * 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.
+ */
+
+package org.apache.blur.thirdparty.thrift_0_9_0.protocol;
+
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.TException;
+import org.apache.blur.thirdparty.thrift_0_9_0.transport.TTransport;
+
+/**
+ * Binary protocol implementation for thrift.
+ *
+ */
+public class TBinaryProtocol extends TProtocol {
+  private static final TStruct ANONYMOUS_STRUCT = new TStruct();
+
+  protected static final int VERSION_MASK = 0xffff0000;
+  protected static final int VERSION_1 = 0x80010000;
+
+  protected boolean strictRead_ = false;
+  protected boolean strictWrite_ = true;
+
+  protected int readLength_;
+  protected boolean checkReadLength_ = false;
+
+  /**
+   * Factory
+   */
+  public static class Factory implements TProtocolFactory {
+    protected boolean strictRead_ = false;
+    protected boolean strictWrite_ = true;
+    protected int readLength_;
+
+    public Factory() {
+      this(false, true);
+    }
+
+    public Factory(boolean strictRead, boolean strictWrite) {
+      this(strictRead, strictWrite, 0);
+    }
+
+    public Factory(boolean strictRead, boolean strictWrite, int readLength) {
+      strictRead_ = strictRead;
+      strictWrite_ = strictWrite;
+      readLength_ = readLength;
+    }
+
+    public TProtocol getProtocol(TTransport trans) {
+      TBinaryProtocol proto = new TBinaryProtocol(trans, strictRead_, strictWrite_);
+      if (readLength_ != 0) {
+        proto.setReadLength(readLength_);
+      }
+      return proto;
+    }
+  }
+
+  /**
+   * Constructor
+   */
+  public TBinaryProtocol(TTransport trans) {
+    this(trans, false, true);
+  }
+
+  public TBinaryProtocol(TTransport trans, boolean strictRead, boolean strictWrite) {
+    super(trans);
+    strictRead_ = strictRead;
+    strictWrite_ = strictWrite;
+  }
+
+  public void writeMessageBegin(TMessage message) throws TException {
+    if (strictWrite_) {
+      int version = VERSION_1 | message.type;
+      writeI32(version);
+      writeString(message.name);
+      writeI32(message.seqid);
+    } else {
+      writeString(message.name);
+      writeByte(message.type);
+      writeI32(message.seqid);
+    }
+  }
+
+  public void writeMessageEnd() {}
+
+  public void writeStructBegin(TStruct struct) {}
+
+  public void writeStructEnd() {}
+
+  public void writeFieldBegin(TField field) throws TException {
+    writeByte(field.type);
+    writeI16(field.id);
+  }
+
+  public void writeFieldEnd() {}
+
+  public void writeFieldStop() throws TException {
+    writeByte(TType.STOP);
+  }
+
+  public void writeMapBegin(TMap map) throws TException {
+    writeByte(map.keyType);
+    writeByte(map.valueType);
+    writeI32(map.size);
+  }
+
+  public void writeMapEnd() {}
+
+  public void writeListBegin(TList list) throws TException {
+    writeByte(list.elemType);
+    writeI32(list.size);
+  }
+
+  public void writeListEnd() {}
+
+  public void writeSetBegin(TSet set) throws TException {
+    writeByte(set.elemType);
+    writeI32(set.size);
+  }
+
+  public void writeSetEnd() {}
+
+  public void writeBool(boolean b) throws TException {
+    writeByte(b ? (byte)1 : (byte)0);
+  }
+
+  private byte [] bout = new byte[1];
+  public void writeByte(byte b) throws TException {
+    bout[0] = b;
+    trans_.write(bout, 0, 1);
+  }
+
+  private byte[] i16out = new byte[2];
+  public void writeI16(short i16) throws TException {
+    i16out[0] = (byte)(0xff & (i16 >> 8));
+    i16out[1] = (byte)(0xff & (i16));
+    trans_.write(i16out, 0, 2);
+  }
+
+  private byte[] i32out = new byte[4];
+  public void writeI32(int i32) throws TException {
+    i32out[0] = (byte)(0xff & (i32 >> 24));
+    i32out[1] = (byte)(0xff & (i32 >> 16));
+    i32out[2] = (byte)(0xff & (i32 >> 8));
+    i32out[3] = (byte)(0xff & (i32));
+    trans_.write(i32out, 0, 4);
+  }
+
+  private byte[] i64out = new byte[8];
+  public void writeI64(long i64) throws TException {
+    i64out[0] = (byte)(0xff & (i64 >> 56));
+    i64out[1] = (byte)(0xff & (i64 >> 48));
+    i64out[2] = (byte)(0xff & (i64 >> 40));
+    i64out[3] = (byte)(0xff & (i64 >> 32));
+    i64out[4] = (byte)(0xff & (i64 >> 24));
+    i64out[5] = (byte)(0xff & (i64 >> 16));
+    i64out[6] = (byte)(0xff & (i64 >> 8));
+    i64out[7] = (byte)(0xff & (i64));
+    trans_.write(i64out, 0, 8);
+  }
+
+  public void writeDouble(double dub) throws TException {
+    writeI64(Double.doubleToLongBits(dub));
+  }
+
+  public void writeString(String str) throws TException {
+    try {
+      byte[] dat = str.getBytes("UTF-8");
+      writeI32(dat.length);
+      trans_.write(dat, 0, dat.length);
+    } catch (UnsupportedEncodingException uex) {
+      throw new TException("JVM DOES NOT SUPPORT UTF-8");
+    }
+  }
+
+  public void writeBinary(ByteBuffer bin) throws TException {
+    int length = bin.limit() - bin.position();
+    writeI32(length);
+    trans_.write(bin.array(), bin.position() + bin.arrayOffset(), length);
+  }
+
+  /**
+   * Reading methods.
+   */
+
+  public TMessage readMessageBegin() throws TException {
+    int size = readI32();
+    if (size < 0) {
+      int version = size & VERSION_MASK;
+      if (version != VERSION_1) {
+        throw new TProtocolException(TProtocolException.BAD_VERSION, "Bad version in readMessageBegin");
+      }
+      return new TMessage(readString(), (byte)(size & 0x000000ff), readI32());
+    } else {
+      if (strictRead_) {
+        throw new TProtocolException(TProtocolException.BAD_VERSION, "Missing version in readMessageBegin, old client?");
+      }
+      return new TMessage(readStringBody(size), readByte(), readI32());
+    }
+  }
+
+  public void readMessageEnd() {}
+
+  public TStruct readStructBegin() {
+    return ANONYMOUS_STRUCT;
+  }
+
+  public void readStructEnd() {}
+
+  public TField readFieldBegin() throws TException {
+    byte type = readByte();
+    short id = type == TType.STOP ? 0 : readI16();
+    return new TField("", type, id);
+  }
+
+  public void readFieldEnd() {}
+
+  public TMap readMapBegin() throws TException {
+    return new TMap(readByte(), readByte(), readI32());
+  }
+
+  public void readMapEnd() {}
+
+  public TList readListBegin() throws TException {
+    return new TList(readByte(), readI32());
+  }
+
+  public void readListEnd() {}
+
+  public TSet readSetBegin() throws TException {
+    return new TSet(readByte(), readI32());
+  }
+
+  public void readSetEnd() {}
+
+  public boolean readBool() throws TException {
+    return (readByte() == 1);
+  }
+
+  private byte[] bin = new byte[1];
+  public byte readByte() throws TException {
+    if (trans_.getBytesRemainingInBuffer() >= 1) {
+      byte b = trans_.getBuffer()[trans_.getBufferPosition()];
+      trans_.consumeBuffer(1);
+      return b;
+    }
+    readAll(bin, 0, 1);
+    return bin[0];
+  }
+
+  private byte[] i16rd = new byte[2];
+  public short readI16() throws TException {
+    byte[] buf = i16rd;
+    int off = 0;
+
+    if (trans_.getBytesRemainingInBuffer() >= 2) {
+      buf = trans_.getBuffer();
+      off = trans_.getBufferPosition();
+      trans_.consumeBuffer(2);
+    } else {
+      readAll(i16rd, 0, 2);
+    }
+
+    return
+      (short)
+      (((buf[off] & 0xff) << 8) |
+       ((buf[off+1] & 0xff)));
+  }
+
+  private byte[] i32rd = new byte[4];
+  public int readI32() throws TException {
+    byte[] buf = i32rd;
+    int off = 0;
+
+    if (trans_.getBytesRemainingInBuffer() >= 4) {
+      buf = trans_.getBuffer();
+      off = trans_.getBufferPosition();
+      trans_.consumeBuffer(4);
+    } else {
+      readAll(i32rd, 0, 4);
+    }
+    return
+      ((buf[off] & 0xff) << 24) |
+      ((buf[off+1] & 0xff) << 16) |
+      ((buf[off+2] & 0xff) <<  8) |
+      ((buf[off+3] & 0xff));
+  }
+
+  private byte[] i64rd = new byte[8];
+  public long readI64() throws TException {
+    byte[] buf = i64rd;
+    int off = 0;
+
+    if (trans_.getBytesRemainingInBuffer() >= 8) {
+      buf = trans_.getBuffer();
+      off = trans_.getBufferPosition();
+      trans_.consumeBuffer(8);
+    } else {
+      readAll(i64rd, 0, 8);
+    }
+
+    return
+      ((long)(buf[off]   & 0xff) << 56) |
+      ((long)(buf[off+1] & 0xff) << 48) |
+      ((long)(buf[off+2] & 0xff) << 40) |
+      ((long)(buf[off+3] & 0xff) << 32) |
+      ((long)(buf[off+4] & 0xff) << 24) |
+      ((long)(buf[off+5] & 0xff) << 16) |
+      ((long)(buf[off+6] & 0xff) <<  8) |
+      ((long)(buf[off+7] & 0xff));
+  }
+
+  public double readDouble() throws TException {
+    return Double.longBitsToDouble(readI64());
+  }
+
+  public String readString() throws TException {
+    int size = readI32();
+
+    if (trans_.getBytesRemainingInBuffer() >= size) {
+      try {
+        String s = new String(trans_.getBuffer(), trans_.getBufferPosition(), size, "UTF-8");
+        trans_.consumeBuffer(size);
+        return s;
+      } catch (UnsupportedEncodingException e) {
+        throw new TException("JVM DOES NOT SUPPORT UTF-8");
+      }
+    }
+
+    return readStringBody(size);
+  }
+
+  public String readStringBody(int size) throws TException {
+    try {
+      checkReadLength(size);
+      byte[] buf = new byte[size];
+      trans_.readAll(buf, 0, size);
+      return new String(buf, "UTF-8");
+    } catch (UnsupportedEncodingException uex) {
+      throw new TException("JVM DOES NOT SUPPORT UTF-8");
+    }
+  }
+
+  public ByteBuffer readBinary() throws TException {
+    int size = readI32();
+    checkReadLength(size);
+
+    if (trans_.getBytesRemainingInBuffer() >= size) {
+      ByteBuffer bb = ByteBuffer.wrap(trans_.getBuffer(), trans_.getBufferPosition(), size);
+      trans_.consumeBuffer(size);
+      return bb;
+    }
+
+    byte[] buf = new byte[size];
+    trans_.readAll(buf, 0, size);
+    return ByteBuffer.wrap(buf);
+  }
+
+  private int readAll(byte[] buf, int off, int len) throws TException {
+    checkReadLength(len);
+    return trans_.readAll(buf, off, len);
+  }
+
+  public void setReadLength(int readLength) {
+    readLength_ = readLength;
+    checkReadLength_ = true;
+  }
+
+  protected void checkReadLength(int length) throws TException {
+    if (length < 0) {
+      throw new TProtocolException("Negative length: " + length);
+    }
+    if (checkReadLength_) {
+      readLength_ -= length;
+      if (readLength_ < 0) {
+        throw new TProtocolException("Message length exceeded: " + length);
+      }
+    }
+  }
+
+}


Mime
View raw message