incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [15/19] Thrift re-package, sorry for the huge commit.
Date Thu, 23 May 2013 19:39:54 GMT
http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/9f63daff/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TMap.java
----------------------------------------------------------------------
diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TMap.java b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TMap.java
new file mode 100644
index 0000000..9a22bd2
--- /dev/null
+++ b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TMap.java
@@ -0,0 +1,40 @@
+/*
+ * 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;
+
+/**
+ * Helper class that encapsulates map metadata.
+ *
+ */
+public final class TMap {
+  public TMap() {
+    this(TType.STOP, TType.STOP, 0);
+  }
+
+  public TMap(byte k, byte v, int s) {
+    keyType = k;
+    valueType = v;
+    size = s;
+  }
+
+  public final byte  keyType;
+  public final byte  valueType;
+  public final int   size;
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/9f63daff/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TMessage.java
----------------------------------------------------------------------
diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TMessage.java b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TMessage.java
new file mode 100644
index 0000000..cc94af7
--- /dev/null
+++ b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TMessage.java
@@ -0,0 +1,57 @@
+/*
+ * 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;
+
+/**
+ * Helper class that encapsulates struct metadata.
+ *
+ */
+public final class TMessage {
+  public TMessage() {
+    this("", TType.STOP, 0);
+  }
+
+  public TMessage(String n, byte t, int s) {
+    name = n;
+    type = t;
+    seqid = s;
+  }
+
+  public final String name;
+  public final byte type;
+  public final int seqid;
+
+  @Override
+  public String toString() {
+    return "<TMessage name:'" + name + "' type: " + type + " seqid:" + seqid + ">";
+  }
+
+  @Override
+  public boolean equals(Object other) {
+    if (other instanceof TMessage) {
+      return equals((TMessage) other);
+    }
+    return false;
+  }
+
+  public boolean equals(TMessage other) {
+    return name.equals(other.name) && type == other.type && seqid == other.seqid;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/9f63daff/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TMessageType.java
----------------------------------------------------------------------
diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TMessageType.java b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TMessageType.java
new file mode 100644
index 0000000..be4ebd8
--- /dev/null
+++ b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TMessageType.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.protocol;
+
+/**
+ * Message type constants in the Thrift protocol.
+ *
+ */
+public final class TMessageType {
+  public static final byte CALL  = 1;
+  public static final byte REPLY = 2;
+  public static final byte EXCEPTION = 3;
+  public static final byte ONEWAY = 4;
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/9f63daff/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TProtocol.java
----------------------------------------------------------------------
diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TProtocol.java b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TProtocol.java
new file mode 100644
index 0000000..41531f5
--- /dev/null
+++ b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TProtocol.java
@@ -0,0 +1,162 @@
+/*
+ * 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.nio.ByteBuffer;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.TException;
+import org.apache.blur.thirdparty.thrift_0_9_0.scheme.IScheme;
+import org.apache.blur.thirdparty.thrift_0_9_0.scheme.StandardScheme;
+import org.apache.blur.thirdparty.thrift_0_9_0.transport.TTransport;
+
+/**
+ * Protocol interface definition.
+ *
+ */
+public abstract class TProtocol {
+
+  /**
+   * Prevent direct instantiation
+   */
+  @SuppressWarnings("unused")
+  private TProtocol() {}
+
+  /**
+   * Transport
+   */
+  protected TTransport trans_;
+
+  /**
+   * Constructor
+   */
+  protected TProtocol(TTransport trans) {
+    trans_ = trans;
+  }
+
+  /**
+   * Transport accessor
+   */
+  public TTransport getTransport() {
+    return trans_;
+  }
+
+  /**
+   * Writing methods.
+   */
+
+  public abstract void writeMessageBegin(TMessage message) throws TException;
+
+  public abstract void writeMessageEnd() throws TException;
+
+  public abstract void writeStructBegin(TStruct struct) throws TException;
+
+  public abstract void writeStructEnd() throws TException;
+
+  public abstract void writeFieldBegin(TField field) throws TException;
+
+  public abstract void writeFieldEnd() throws TException;
+
+  public abstract void writeFieldStop() throws TException;
+
+  public abstract void writeMapBegin(TMap map) throws TException;
+
+  public abstract void writeMapEnd() throws TException;
+
+  public abstract void writeListBegin(TList list) throws TException;
+
+  public abstract void writeListEnd() throws TException;
+
+  public abstract void writeSetBegin(TSet set) throws TException;
+
+  public abstract void writeSetEnd() throws TException;
+
+  public abstract void writeBool(boolean b) throws TException;
+
+  public abstract void writeByte(byte b) throws TException;
+
+  public abstract void writeI16(short i16) throws TException;
+
+  public abstract void writeI32(int i32) throws TException;
+
+  public abstract void writeI64(long i64) throws TException;
+
+  public abstract void writeDouble(double dub) throws TException;
+
+  public abstract void writeString(String str) throws TException;
+
+  public abstract void writeBinary(ByteBuffer buf) throws TException;
+
+  /**
+   * Reading methods.
+   */
+
+  public abstract TMessage readMessageBegin() throws TException;
+
+  public abstract void readMessageEnd() throws TException;
+
+  public abstract TStruct readStructBegin() throws TException;
+
+  public abstract void readStructEnd() throws TException;
+
+  public abstract TField readFieldBegin() throws TException;
+
+  public abstract void readFieldEnd() throws TException;
+
+  public abstract TMap readMapBegin() throws TException;
+
+  public abstract void readMapEnd() throws TException;
+
+  public abstract TList readListBegin() throws TException;
+
+  public abstract void readListEnd() throws TException;
+
+  public abstract TSet readSetBegin() throws TException;
+
+  public abstract void readSetEnd() throws TException;
+
+  public abstract boolean readBool() throws TException;
+
+  public abstract byte readByte() throws TException;
+
+  public abstract short readI16() throws TException;
+
+  public abstract int readI32() throws TException;
+
+  public abstract long readI64() throws TException;
+
+  public abstract double readDouble() throws TException;
+
+  public abstract String readString() throws TException;
+
+  public abstract ByteBuffer readBinary() throws TException;
+
+  /**
+   * Reset any internal state back to a blank slate. This method only needs to
+   * be implemented for stateful protocols.
+   */
+  public void reset() {}
+  
+  /**
+   * Scheme accessor
+   */
+  public Class<? extends IScheme> getScheme() {
+    return StandardScheme.class;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/9f63daff/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TProtocolException.java
----------------------------------------------------------------------
diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TProtocolException.java b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TProtocolException.java
new file mode 100644
index 0000000..3163b19
--- /dev/null
+++ b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TProtocolException.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.protocol;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.TException;
+
+/**
+ * Protocol exceptions.
+ *
+ */
+public class TProtocolException extends TException {
+
+
+  private static final long serialVersionUID = 1L;
+  public static final int UNKNOWN = 0;
+  public static final int INVALID_DATA = 1;
+  public static final int NEGATIVE_SIZE = 2;
+  public static final int SIZE_LIMIT = 3;
+  public static final int BAD_VERSION = 4;
+  public static final int NOT_IMPLEMENTED = 5;
+
+  protected int type_ = UNKNOWN;
+
+  public TProtocolException() {
+    super();
+  }
+
+  public TProtocolException(int type) {
+    super();
+    type_ = type;
+  }
+
+  public TProtocolException(int type, String message) {
+    super(message);
+    type_ = type;
+  }
+
+  public TProtocolException(String message) {
+    super(message);
+  }
+
+  public TProtocolException(int type, Throwable cause) {
+    super(cause);
+    type_ = type;
+  }
+
+  public TProtocolException(Throwable cause) {
+    super(cause);
+  }
+
+  public TProtocolException(String message, Throwable cause) {
+    super(message, cause);
+  }
+
+  public TProtocolException(int type, String message, Throwable cause) {
+    super(message, cause);
+    type_ = type;
+  }
+
+  public int getType() {
+    return type_;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/9f63daff/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TProtocolFactory.java
----------------------------------------------------------------------
diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TProtocolFactory.java b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TProtocolFactory.java
new file mode 100644
index 0000000..52a7dd8
--- /dev/null
+++ b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TProtocolFactory.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.protocol;
+
+import java.io.Serializable;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.transport.TTransport;
+
+/**
+ * Factory interface for constructing protocol instances.
+ */
+public interface TProtocolFactory extends Serializable {
+  public TProtocol getProtocol(TTransport trans);
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/9f63daff/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TProtocolUtil.java
----------------------------------------------------------------------
diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TProtocolUtil.java b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TProtocolUtil.java
new file mode 100644
index 0000000..335818d
--- /dev/null
+++ b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TProtocolUtil.java
@@ -0,0 +1,220 @@
+/*
+ * 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 org.apache.blur.thirdparty.thrift_0_9_0.TException;
+
+/**
+ * Utility class with static methods for interacting with protocol data
+ * streams.
+ *
+ */
+public class TProtocolUtil {
+
+  /**
+   * The maximum recursive depth the skip() function will traverse before
+   * throwing a TException.
+   */
+  private static int maxSkipDepth = Integer.MAX_VALUE;
+
+  /**
+   * Specifies the maximum recursive depth that the skip function will
+   * traverse before throwing a TException.  This is a global setting, so
+   * any call to skip in this JVM will enforce this value.
+   *
+   * @param depth  the maximum recursive depth.  A value of 2 would allow
+   *    the skip function to skip a structure or collection with basic children,
+   *    but it would not permit skipping a struct that had a field containing
+   *    a child struct.  A value of 1 would only allow skipping of simple
+   *    types and empty structs/collections.
+   */
+  public static void setMaxSkipDepth(int depth) {
+    maxSkipDepth = depth;
+  }
+
+  /**
+   * Skips over the next data element from the provided input TProtocol object.
+   *
+   * @param prot  the protocol object to read from
+   * @param type  the next value will be interpreted as this TType value.
+   */
+  public static void skip(TProtocol prot, byte type)
+    throws TException {
+    skip(prot, type, maxSkipDepth);
+  }
+
+  /**
+   * Skips over the next data element from the provided input TProtocol object.
+   *
+   * @param prot  the protocol object to read from
+   * @param type  the next value will be interpreted as this TType value.
+   * @param maxDepth  this function will only skip complex objects to this
+   *   recursive depth, to prevent Java stack overflow.
+   */
+  public static void skip(TProtocol prot, byte type, int maxDepth)
+  throws TException {
+    if (maxDepth <= 0) {
+      throw new TException("Maximum skip depth exceeded");
+    }
+    switch (type) {
+      case TType.BOOL:
+        prot.readBool();
+        break;
+
+      case TType.BYTE:
+        prot.readByte();
+        break;
+
+      case TType.I16:
+        prot.readI16();
+        break;
+
+      case TType.I32:
+        prot.readI32();
+        break;
+
+      case TType.I64:
+        prot.readI64();
+        break;
+
+      case TType.DOUBLE:
+        prot.readDouble();
+        break;
+
+      case TType.STRING:
+        prot.readBinary();
+        break;
+
+      case TType.STRUCT:
+        prot.readStructBegin();
+        while (true) {
+          TField field = prot.readFieldBegin();
+          if (field.type == TType.STOP) {
+            break;
+          }
+          skip(prot, field.type, maxDepth - 1);
+          prot.readFieldEnd();
+        }
+        prot.readStructEnd();
+        break;
+
+      case TType.MAP:
+        TMap map = prot.readMapBegin();
+        for (int i = 0; i < map.size; i++) {
+          skip(prot, map.keyType, maxDepth - 1);
+          skip(prot, map.valueType, maxDepth - 1);
+        }
+        prot.readMapEnd();
+        break;
+
+      case TType.SET:
+        TSet set = prot.readSetBegin();
+        for (int i = 0; i < set.size; i++) {
+          skip(prot, set.elemType, maxDepth - 1);
+        }
+        prot.readSetEnd();
+        break;
+
+      case TType.LIST:
+        TList list = prot.readListBegin();
+        for (int i = 0; i < list.size; i++) {
+          skip(prot, list.elemType, maxDepth - 1);
+        }
+        prot.readListEnd();
+        break;
+
+      default:
+        break;
+    }
+  }
+
+  /**
+   * Attempt to determine the protocol used to serialize some data.
+   *
+   * The guess is based on known specificities of supported protocols.
+   * In some cases, no guess can be done, in that case we return the
+   * fallback TProtocolFactory.
+   * To be certain to correctly detect the protocol, the first encoded
+   * field should have a field id < 256
+   *
+   * @param data The serialized data to guess the protocol for.
+   * @param fallback The TProtocol to return if no guess can be made.
+   * @return a Class implementing TProtocolFactory which can be used to create a deserializer.
+   */
+  public static TProtocolFactory guessProtocolFactory(byte[] data, TProtocolFactory fallback) {
+    //
+    // If the first and last bytes are opening/closing curly braces we guess the protocol as
+    // being TJSONProtocol.
+    // It could not be a TCompactBinary encoding for a field of type 0xb (Map)
+    // with delta id 7 as the last byte for TCompactBinary is always 0.
+    //
+
+    if ('{' == data[0] && '}' == data[data.length - 1]) {
+      return new TJSONProtocol.Factory();
+    }
+
+    //
+    // If the last byte is not 0, then it cannot be TCompactProtocol, it must be
+    // TBinaryProtocol.
+    //
+
+    if (data[data.length - 1] != 0) {
+      return new TBinaryProtocol.Factory();
+    }
+
+    //
+    // A first byte of value > 16 indicates TCompactProtocol was used, and the first byte
+    // encodes a delta field id (id <= 15) and a field type.
+    //
+
+    if (data[0] > 0x10) {
+      return new TCompactProtocol.Factory();
+    }
+
+    //
+    // If the second byte is 0 then it is a field id < 256 encoded by TBinaryProtocol.
+    // It cannot possibly be TCompactProtocol since a value of 0 would imply a field id
+    // of 0 as the zig zag varint encoding would end.
+    //
+
+    if (data.length > 1 && 0 == data[1]) {
+      return new TBinaryProtocol.Factory();
+    }
+
+    //
+    // If bit 7 of the first byte of the field id is set then we have two choices:
+    // 1. A field id > 63 was encoded with TCompactProtocol.
+    // 2. A field id > 0x7fff (32767) was encoded with TBinaryProtocol and the last byte of the
+    //    serialized data is 0.
+    // Option 2 is impossible since field ids are short and thus limited to 32767.
+    //
+
+    if (data.length > 1 && (data[1] & 0x80) != 0) {
+      return new TCompactProtocol.Factory();
+    }
+
+    //
+    // The remaining case is either a field id <= 63 encoded as TCompactProtocol,
+    // one >= 256 encoded with TBinaryProtocol with a last byte at 0, or an empty structure.
+    // As we cannot really decide, we return the fallback protocol.
+    //
+    return fallback;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/9f63daff/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TSet.java
----------------------------------------------------------------------
diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TSet.java b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TSet.java
new file mode 100644
index 0000000..116887d
--- /dev/null
+++ b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TSet.java
@@ -0,0 +1,42 @@
+/*
+ * 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;
+
+/**
+ * Helper class that encapsulates set metadata.
+ *
+ */
+public final class TSet {
+  public TSet() {
+    this(TType.STOP, 0);
+  }
+
+  public TSet(byte t, int s) {
+    elemType = t;
+    size = s;
+  }
+
+  public TSet(TList list) {
+    this(list.elemType, list.size);
+  }
+
+  public final byte elemType;
+  public final int  size;
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/9f63daff/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TSimpleJSONProtocol.java
----------------------------------------------------------------------
diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TSimpleJSONProtocol.java b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TSimpleJSONProtocol.java
new file mode 100644
index 0000000..09d52b6
--- /dev/null
+++ b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TSimpleJSONProtocol.java
@@ -0,0 +1,385 @@
+/*
+ * 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 java.util.Stack;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.TException;
+import org.apache.blur.thirdparty.thrift_0_9_0.transport.TTransport;
+
+/**
+ * JSON protocol implementation for thrift.
+ *
+ * This protocol is write-only and produces a simple output format
+ * suitable for parsing by scripting languages.  It should not be
+ * confused with the full-featured TJSONProtocol.
+ *
+ */
+public class TSimpleJSONProtocol extends TProtocol {
+
+  /**
+   * Factory
+   */
+  public static class Factory implements TProtocolFactory {
+    public TProtocol getProtocol(TTransport trans) {
+      return new TSimpleJSONProtocol(trans);
+    }
+  }
+
+  public static final byte[] COMMA = new byte[] {','};
+  public static final byte[] COLON = new byte[] {':'};
+  public static final byte[] LBRACE = new byte[] {'{'};
+  public static final byte[] RBRACE = new byte[] {'}'};
+  public static final byte[] LBRACKET = new byte[] {'['};
+  public static final byte[] RBRACKET = new byte[] {']'};
+  public static final char QUOTE = '"';
+
+  private static final TStruct ANONYMOUS_STRUCT = new TStruct();
+  private static final TField ANONYMOUS_FIELD = new TField();
+  private static final TMessage EMPTY_MESSAGE = new TMessage();
+  private static final TSet EMPTY_SET = new TSet();
+  private static final TList EMPTY_LIST = new TList();
+  private static final TMap EMPTY_MAP = new TMap();
+
+  protected class Context {
+    protected void write() throws TException {}
+  }
+
+  protected class ListContext extends Context {
+    protected boolean first_ = true;
+
+    protected void write() throws TException {
+      if (first_) {
+        first_ = false;
+      } else {
+        trans_.write(COMMA);
+      }
+    }
+  }
+
+  protected class StructContext extends Context {
+    protected boolean first_ = true;
+    protected boolean colon_ = true;
+
+    protected void write() throws TException {
+      if (first_) {
+        first_ = false;
+        colon_ = true;
+      } else {
+        trans_.write(colon_ ? COLON : COMMA);
+        colon_ = !colon_;
+      }
+    }
+  }
+
+  protected final Context BASE_CONTEXT = new Context();
+
+  /**
+   * Stack of nested contexts that we may be in.
+   */
+  protected Stack<Context> writeContextStack_ = new Stack<Context>();
+
+  /**
+   * Current context that we are in
+   */
+  protected Context writeContext_ = BASE_CONTEXT;
+
+  /**
+   * Push a new write context onto the stack.
+   */
+  protected void pushWriteContext(Context c) {
+    writeContextStack_.push(writeContext_);
+    writeContext_ = c;
+  }
+
+  /**
+   * Pop the last write context off the stack
+   */
+  protected void popWriteContext() {
+    writeContext_ = writeContextStack_.pop();
+  }
+
+  /**
+   * Constructor
+   */
+  public TSimpleJSONProtocol(TTransport trans) {
+    super(trans);
+  }
+
+  public void writeMessageBegin(TMessage message) throws TException {
+    trans_.write(LBRACKET);
+    pushWriteContext(new ListContext());
+    writeString(message.name);
+    writeByte(message.type);
+    writeI32(message.seqid);
+  }
+
+  public void writeMessageEnd() throws TException {
+    popWriteContext();
+    trans_.write(RBRACKET);
+  }
+
+  public void writeStructBegin(TStruct struct) throws TException {
+    writeContext_.write();
+    trans_.write(LBRACE);
+    pushWriteContext(new StructContext());
+  }
+
+  public void writeStructEnd() throws TException {
+    popWriteContext();
+    trans_.write(RBRACE);
+  }
+
+  public void writeFieldBegin(TField field) throws TException {
+    // Note that extra type information is omitted in JSON!
+    writeString(field.name);
+  }
+
+  public void writeFieldEnd() {}
+
+  public void writeFieldStop() {}
+
+  public void writeMapBegin(TMap map) throws TException {
+    writeContext_.write();
+    trans_.write(LBRACE);
+    pushWriteContext(new StructContext());
+    // No metadata!
+  }
+
+  public void writeMapEnd() throws TException {
+    popWriteContext();
+    trans_.write(RBRACE);
+  }
+
+  public void writeListBegin(TList list) throws TException {
+    writeContext_.write();
+    trans_.write(LBRACKET);
+    pushWriteContext(new ListContext());
+    // No metadata!
+  }
+
+  public void writeListEnd() throws TException {
+    popWriteContext();
+    trans_.write(RBRACKET);
+  }
+
+  public void writeSetBegin(TSet set) throws TException {
+    writeContext_.write();
+    trans_.write(LBRACKET);
+    pushWriteContext(new ListContext());
+    // No metadata!
+  }
+
+  public void writeSetEnd() throws TException {
+    popWriteContext();
+    trans_.write(RBRACKET);
+  }
+
+  public void writeBool(boolean b) throws TException {
+    writeByte(b ? (byte)1 : (byte)0);
+  }
+
+  public void writeByte(byte b) throws TException {
+    writeI32(b);
+  }
+
+  public void writeI16(short i16) throws TException {
+    writeI32(i16);
+  }
+
+  public void writeI32(int i32) throws TException {
+    writeContext_.write();
+    _writeStringData(Integer.toString(i32));
+  }
+
+  public void _writeStringData(String s) throws TException {
+    try {
+      byte[] b = s.getBytes("UTF-8");
+      trans_.write(b);
+    } catch (UnsupportedEncodingException uex) {
+      throw new TException("JVM DOES NOT SUPPORT UTF-8");
+    }
+  }
+
+  public void writeI64(long i64) throws TException {
+    writeContext_.write();
+    _writeStringData(Long.toString(i64));
+  }
+
+  public void writeDouble(double dub) throws TException {
+    writeContext_.write();
+    _writeStringData(Double.toString(dub));
+  }
+
+  public void writeString(String str) throws TException {
+    writeContext_.write();
+    int length = str.length();
+    StringBuffer escape = new StringBuffer(length + 16);
+    escape.append(QUOTE);
+    for (int i = 0; i < length; ++i) {
+      char c = str.charAt(i);
+      switch (c) {
+      case '"':
+      case '\\':
+        escape.append('\\');
+        escape.append(c);
+        break;
+      case '\b':
+        escape.append('\\');
+        escape.append('b');
+        break;
+      case '\f':
+        escape.append('\\');
+        escape.append('f');
+        break;
+      case '\n':
+        escape.append('\\');
+        escape.append('n');
+        break;
+      case '\r':
+        escape.append('\\');
+        escape.append('r');
+        break;
+      case '\t':
+        escape.append('\\');
+        escape.append('t');
+        break;
+      default:
+        // Control characters! According to JSON RFC u0020 (space)
+        if (c < ' ') {
+          String hex = Integer.toHexString(c);
+          escape.append('\\');
+          escape.append('u');
+          for (int j = 4; j > hex.length(); --j) {
+            escape.append('0');
+          }
+          escape.append(hex);
+        } else {
+          escape.append(c);
+        }
+        break;
+      }
+    }
+    escape.append(QUOTE);
+    _writeStringData(escape.toString());
+  }
+
+  public void writeBinary(ByteBuffer bin) throws TException {
+    try {
+      // TODO(mcslee): Fix this
+      writeString(new String(bin.array(), bin.position() + bin.arrayOffset(), bin.limit() - bin.position() - bin.arrayOffset(), "UTF-8"));
+    } catch (UnsupportedEncodingException uex) {
+      throw new TException("JVM DOES NOT SUPPORT UTF-8");
+    }
+  }
+
+  /**
+   * Reading methods.
+   */
+
+  public TMessage readMessageBegin() throws TException {
+    // TODO(mcslee): implement
+    return EMPTY_MESSAGE;
+  }
+
+  public void readMessageEnd() {}
+
+  public TStruct readStructBegin() {
+    // TODO(mcslee): implement
+    return ANONYMOUS_STRUCT;
+  }
+
+  public void readStructEnd() {}
+
+  public TField readFieldBegin() throws TException {
+    // TODO(mcslee): implement
+    return ANONYMOUS_FIELD;
+  }
+
+  public void readFieldEnd() {}
+
+  public TMap readMapBegin() throws TException {
+    // TODO(mcslee): implement
+    return EMPTY_MAP;
+  }
+
+  public void readMapEnd() {}
+
+  public TList readListBegin() throws TException {
+    // TODO(mcslee): implement
+    return EMPTY_LIST;
+  }
+
+  public void readListEnd() {}
+
+  public TSet readSetBegin() throws TException {
+    // TODO(mcslee): implement
+    return EMPTY_SET;
+  }
+
+  public void readSetEnd() {}
+
+  public boolean readBool() throws TException {
+    return (readByte() == 1);
+  }
+
+  public byte readByte() throws TException {
+    // TODO(mcslee): implement
+    return 0;
+  }
+
+  public short readI16() throws TException {
+    // TODO(mcslee): implement
+    return 0;
+  }
+
+  public int readI32() throws TException {
+    // TODO(mcslee): implement
+    return 0;
+  }
+
+  public long readI64() throws TException {
+    // TODO(mcslee): implement
+    return 0;
+  }
+
+  public double readDouble() throws TException {
+    // TODO(mcslee): implement
+    return 0;
+  }
+
+  public String readString() throws TException {
+    // TODO(mcslee): implement
+    return "";
+  }
+
+  public String readStringBody(int size) throws TException {
+    // TODO(mcslee): implement
+    return "";
+  }
+
+  public ByteBuffer readBinary() throws TException {
+    // TODO(mcslee): implement
+    return ByteBuffer.wrap(new byte[0]);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/9f63daff/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TStruct.java
----------------------------------------------------------------------
diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TStruct.java b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TStruct.java
new file mode 100644
index 0000000..76922bd
--- /dev/null
+++ b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TStruct.java
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+/**
+ * Helper class that encapsulates struct metadata.
+ *
+ */
+public final class TStruct {
+  public TStruct() {
+    this("");
+  }
+
+  public TStruct(String n) {
+    name = n;
+  }
+
+  public final String name;
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/9f63daff/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TTupleProtocol.java
----------------------------------------------------------------------
diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TTupleProtocol.java b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TTupleProtocol.java
new file mode 100644
index 0000000..d5bfdc1
--- /dev/null
+++ b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TTupleProtocol.java
@@ -0,0 +1,98 @@
+/*
+ * 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.util.BitSet;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.TException;
+import org.apache.blur.thirdparty.thrift_0_9_0.scheme.IScheme;
+import org.apache.blur.thirdparty.thrift_0_9_0.scheme.TupleScheme;
+import org.apache.blur.thirdparty.thrift_0_9_0.transport.TTransport;
+
+public final class TTupleProtocol extends TCompactProtocol {
+  public static class Factory implements TProtocolFactory {
+    public Factory() {}
+
+    public TProtocol getProtocol(TTransport trans) {
+      return new TTupleProtocol(trans);
+    }
+  }
+
+  public TTupleProtocol(TTransport transport) {
+    super(transport);
+  }
+
+  @Override
+  public Class<? extends IScheme> getScheme() {
+    return TupleScheme.class;
+  }
+
+  public void writeBitSet(BitSet bs, int vectorWidth) throws TException {
+    byte[] bytes = toByteArray(bs, vectorWidth);
+    for (byte b : bytes) {
+      writeByte(b);
+    }
+  }
+
+  public BitSet readBitSet(int i) throws TException {
+    int length = (int) Math.ceil(i/8.0);
+    byte[] bytes = new byte[length];
+    for (int j = 0; j < length; j++) {
+      bytes[j] = readByte();
+    }
+    BitSet bs = fromByteArray(bytes);
+    return bs;
+  }
+
+  /**
+   * Returns a bitset containing the values in bytes. The byte-ordering must be
+   * big-endian.
+   */
+  public static BitSet fromByteArray(byte[] bytes) {
+    BitSet bits = new BitSet();
+    for (int i = 0; i < bytes.length * 8; i++) {
+      if ((bytes[bytes.length - i / 8 - 1] & (1 << (i % 8))) > 0) {
+        bits.set(i);
+      }
+    }
+    return bits;
+  }
+
+  /**
+   * Returns a byte array of at least length 1. The most significant bit in the
+   * result is guaranteed not to be a 1 (since BitSet does not support sign
+   * extension). The byte-ordering of the result is big-endian which means the
+   * most significant bit is in element 0. The bit at index 0 of the bit set is
+   * assumed to be the least significant bit.
+   * 
+   * @param bits
+   * @param vectorWidth 
+   * @return a byte array of at least length 1
+   */
+  public static byte[] toByteArray(BitSet bits, int vectorWidth) {
+    byte[] bytes = new byte[(int) Math.ceil(vectorWidth/8.0)];
+    for (int i = 0; i < bits.length(); i++) {
+      if (bits.get(i)) {
+        bytes[bytes.length - i / 8 - 1] |= 1 << (i % 8);
+      }
+    }
+    return bytes;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/9f63daff/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TType.java
----------------------------------------------------------------------
diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TType.java b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TType.java
new file mode 100644
index 0000000..662eaf0
--- /dev/null
+++ b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/protocol/TType.java
@@ -0,0 +1,40 @@
+/*
+ * 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;
+
+/**
+ * Type constants in the Thrift protocol.
+ */
+public final class TType {
+  public static final byte STOP   = 0;
+  public static final byte VOID   = 1;
+  public static final byte BOOL   = 2;
+  public static final byte BYTE   = 3;
+  public static final byte DOUBLE = 4;
+  public static final byte I16    = 6;
+  public static final byte I32    = 8;
+  public static final byte I64    = 10;
+  public static final byte STRING = 11;
+  public static final byte STRUCT = 12;
+  public static final byte MAP    = 13;
+  public static final byte SET    = 14;
+  public static final byte LIST   = 15;
+  public static final byte ENUM   = 16;
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/9f63daff/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/scheme/IScheme.java
----------------------------------------------------------------------
diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/scheme/IScheme.java b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/scheme/IScheme.java
new file mode 100644
index 0000000..f5b26fc
--- /dev/null
+++ b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/scheme/IScheme.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.scheme;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.TBase;
+
+public interface IScheme<T extends TBase> {
+
+  public void read(org.apache.blur.thirdparty.thrift_0_9_0.protocol.TProtocol iproto, T struct) throws org.apache.blur.thirdparty.thrift_0_9_0.TException;
+
+  public void write(org.apache.blur.thirdparty.thrift_0_9_0.protocol.TProtocol oproto, T struct) throws org.apache.blur.thirdparty.thrift_0_9_0.TException;
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/9f63daff/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/scheme/SchemeFactory.java
----------------------------------------------------------------------
diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/scheme/SchemeFactory.java b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/scheme/SchemeFactory.java
new file mode 100644
index 0000000..f20253f
--- /dev/null
+++ b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/scheme/SchemeFactory.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.scheme;
+
+public interface SchemeFactory {
+
+  public <S extends IScheme> S getScheme();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/9f63daff/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/scheme/StandardScheme.java
----------------------------------------------------------------------
diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/scheme/StandardScheme.java b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/scheme/StandardScheme.java
new file mode 100644
index 0000000..54f12de
--- /dev/null
+++ b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/scheme/StandardScheme.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.scheme;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.TBase;
+
+public abstract class StandardScheme<T extends TBase> implements IScheme<T> {
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/9f63daff/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/scheme/TupleScheme.java
----------------------------------------------------------------------
diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/scheme/TupleScheme.java b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/scheme/TupleScheme.java
new file mode 100644
index 0000000..283877a
--- /dev/null
+++ b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/scheme/TupleScheme.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.scheme;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.TBase;
+
+public abstract class TupleScheme<T extends TBase> implements IScheme<T> {
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/9f63daff/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/server/AbstractNonblockingServer.java
----------------------------------------------------------------------
diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/server/AbstractNonblockingServer.java b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/server/AbstractNonblockingServer.java
new file mode 100644
index 0000000..5130527
--- /dev/null
+++ b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/server/AbstractNonblockingServer.java
@@ -0,0 +1,562 @@
+/*
+ * 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.server;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
+import java.nio.channels.spi.SelectorProvider;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.TByteArrayOutputStream;
+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.transport.TFramedTransport;
+import org.apache.blur.thirdparty.thrift_0_9_0.transport.TIOStreamTransport;
+import org.apache.blur.thirdparty.thrift_0_9_0.transport.TMemoryInputTransport;
+import org.apache.blur.thirdparty.thrift_0_9_0.transport.TNonblockingServerTransport;
+import org.apache.blur.thirdparty.thrift_0_9_0.transport.TNonblockingTransport;
+import org.apache.blur.thirdparty.thrift_0_9_0.transport.TTransport;
+import org.apache.blur.thirdparty.thrift_0_9_0.transport.TTransportException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Provides common methods and classes used by nonblocking TServer
+ * implementations.
+ */
+public abstract class AbstractNonblockingServer extends TServer {
+  protected final Logger LOGGER = LoggerFactory.getLogger(getClass().getName());
+
+  public static abstract class AbstractNonblockingServerArgs<T extends AbstractNonblockingServerArgs<T>> extends AbstractServerArgs<T> {
+    public long maxReadBufferBytes = Long.MAX_VALUE;
+
+    public AbstractNonblockingServerArgs(TNonblockingServerTransport transport) {
+      super(transport);
+      transportFactory(new TFramedTransport.Factory());
+    }
+  }
+
+  /**
+   * The maximum amount of memory we will allocate to client IO buffers at a
+   * time. Without this limit, the server will gladly allocate client buffers
+   * right into an out of memory exception, rather than waiting.
+   */
+  private final long MAX_READ_BUFFER_BYTES;
+
+  /**
+   * How many bytes are currently allocated to read buffers.
+   */
+  private final AtomicLong readBufferBytesAllocated = new AtomicLong(0);
+
+  public AbstractNonblockingServer(AbstractNonblockingServerArgs args) {
+    super(args);
+    MAX_READ_BUFFER_BYTES = args.maxReadBufferBytes;
+  }
+
+  /**
+   * Begin accepting connections and processing invocations.
+   */
+  public void serve() {
+    // start any IO threads
+    if (!startThreads()) {
+      return;
+    }
+
+    // start listening, or exit
+    if (!startListening()) {
+      return;
+    }
+
+    setServing(true);
+
+    // this will block while we serve
+    waitForShutdown();
+
+    setServing(false);
+
+    // do a little cleanup
+    stopListening();
+  }
+
+  /**
+   * Starts any threads required for serving.
+   * 
+   * @return true if everything went ok, false if threads could not be started.
+   */
+  protected abstract boolean startThreads();
+
+  /**
+   * A method that will block until when threads handling the serving have been
+   * shut down.
+   */
+  protected abstract void waitForShutdown();
+
+  /**
+   * Have the server transport start accepting connections.
+   * 
+   * @return true if we started listening successfully, false if something went
+   *         wrong.
+   */
+  protected boolean startListening() {
+    try {
+      serverTransport_.listen();
+      return true;
+    } catch (TTransportException ttx) {
+      LOGGER.error("Failed to start listening on server socket!", ttx);
+      return false;
+    }
+  }
+
+  /**
+   * Stop listening for connections.
+   */
+  protected void stopListening() {
+    serverTransport_.close();
+  }
+
+  /**
+   * Perform an invocation. This method could behave several different ways -
+   * invoke immediately inline, queue for separate execution, etc.
+   * 
+   * @return true if invocation was successfully requested, which is not a
+   *         guarantee that invocation has completed. False if the request
+   *         failed.
+   */
+  protected abstract boolean requestInvoke(FrameBuffer frameBuffer);
+
+  /**
+   * An abstract thread that handles selecting on a set of transports and
+   * {@link FrameBuffer FrameBuffers} associated with selected keys
+   * corresponding to requests.
+   */
+  protected abstract class AbstractSelectThread extends Thread {
+    protected final Selector selector;
+
+    // List of FrameBuffers that want to change their selection interests.
+    protected final Set<FrameBuffer> selectInterestChanges = new HashSet<FrameBuffer>();
+
+    public AbstractSelectThread() throws IOException {
+      this.selector = SelectorProvider.provider().openSelector();
+    }
+
+    /**
+     * If the selector is blocked, wake it up.
+     */
+    public void wakeupSelector() {
+      selector.wakeup();
+    }
+
+    /**
+     * Add FrameBuffer to the list of select interest changes and wake up the
+     * selector if it's blocked. When the select() call exits, it'll give the
+     * FrameBuffer a chance to change its interests.
+     */
+    public void requestSelectInterestChange(FrameBuffer frameBuffer) {
+      synchronized (selectInterestChanges) {
+        selectInterestChanges.add(frameBuffer);
+      }
+      // wakeup the selector, if it's currently blocked.
+      selector.wakeup();
+    }
+
+    /**
+     * Check to see if there are any FrameBuffers that have switched their
+     * interest type from read to write or vice versa.
+     */
+    protected void processInterestChanges() {
+      synchronized (selectInterestChanges) {
+        for (FrameBuffer fb : selectInterestChanges) {
+          fb.changeSelectInterests();
+        }
+        selectInterestChanges.clear();
+      }
+    }
+
+    /**
+     * Do the work required to read from a readable client. If the frame is
+     * fully read, then invoke the method call.
+     */
+    protected void handleRead(SelectionKey key) {
+      FrameBuffer buffer = (FrameBuffer) key.attachment();
+      if (!buffer.read()) {
+        cleanupSelectionKey(key);
+        return;
+      }
+
+      // if the buffer's frame read is complete, invoke the method.
+      if (buffer.isFrameFullyRead()) {
+        if (!requestInvoke(buffer)) {
+          cleanupSelectionKey(key);
+        }
+      }
+    }
+
+    /**
+     * Let a writable client get written, if there's data to be written.
+     */
+    protected void handleWrite(SelectionKey key) {
+      FrameBuffer buffer = (FrameBuffer) key.attachment();
+      if (!buffer.write()) {
+        cleanupSelectionKey(key);
+      }
+    }
+
+    /**
+     * Do connection-close cleanup on a given SelectionKey.
+     */
+    protected void cleanupSelectionKey(SelectionKey key) {
+      // remove the records from the two maps
+      FrameBuffer buffer = (FrameBuffer) key.attachment();
+      if (buffer != null) {
+        // close the buffer
+        buffer.close();
+      }
+      // cancel the selection key
+      key.cancel();
+    }
+  } // SelectThread
+
+  /**
+   * Possible states for the FrameBuffer state machine.
+   */
+  private enum FrameBufferState {
+    // in the midst of reading the frame size off the wire
+    READING_FRAME_SIZE,
+    // reading the actual frame data now, but not all the way done yet
+    READING_FRAME,
+    // completely read the frame, so an invocation can now happen
+    READ_FRAME_COMPLETE,
+    // waiting to get switched to listening for write events
+    AWAITING_REGISTER_WRITE,
+    // started writing response data, not fully complete yet
+    WRITING,
+    // another thread wants this framebuffer to go back to reading
+    AWAITING_REGISTER_READ,
+    // we want our transport and selection key invalidated in the selector
+    // thread
+    AWAITING_CLOSE
+  }
+
+  /**
+   * Class that implements a sort of state machine around the interaction with a
+   * client and an invoker. It manages reading the frame size and frame data,
+   * getting it handed off as wrapped transports, and then the writing of
+   * response data back to the client. In the process it manages flipping the
+   * read and write bits on the selection key for its client.
+   */
+  protected class FrameBuffer {
+    // the actual transport hooked up to the client.
+    public final TNonblockingTransport trans_;
+
+    // the SelectionKey that corresponds to our transport
+    private final SelectionKey selectionKey_;
+
+    // the SelectThread that owns the registration of our transport
+    private final AbstractSelectThread selectThread_;
+
+    // where in the process of reading/writing are we?
+    private FrameBufferState state_ = FrameBufferState.READING_FRAME_SIZE;
+
+    // the ByteBuffer we'll be using to write and read, depending on the state
+    private ByteBuffer buffer_;
+
+    private TByteArrayOutputStream response_;
+
+    public FrameBuffer(final TNonblockingTransport trans,
+        final SelectionKey selectionKey,
+        final AbstractSelectThread selectThread) {
+      trans_ = trans;
+      selectionKey_ = selectionKey;
+      selectThread_ = selectThread;
+      buffer_ = ByteBuffer.allocate(4);
+    }
+
+    /**
+     * Give this FrameBuffer a chance to read. The selector loop should have
+     * received a read event for this FrameBuffer.
+     * 
+     * @return true if the connection should live on, false if it should be
+     *         closed
+     */
+    public boolean read() {
+      if (state_ == FrameBufferState.READING_FRAME_SIZE) {
+        // try to read the frame size completely
+        if (!internalRead()) {
+          return false;
+        }
+
+        // if the frame size has been read completely, then prepare to read the
+        // actual frame.
+        if (buffer_.remaining() == 0) {
+          // pull out the frame size as an integer.
+          int frameSize = buffer_.getInt(0);
+          if (frameSize <= 0) {
+            LOGGER.error("Read an invalid frame size of " + frameSize
+                + ". Are you using TFramedTransport on the client side?");
+            return false;
+          }
+
+          // if this frame will always be too large for this server, log the
+          // error and close the connection.
+          if (frameSize > MAX_READ_BUFFER_BYTES) {
+            LOGGER.error("Read a frame size of " + frameSize
+                + ", which is bigger than the maximum allowable buffer size for ALL connections.");
+            return false;
+          }
+
+          // if this frame will push us over the memory limit, then return.
+          // with luck, more memory will free up the next time around.
+          if (readBufferBytesAllocated.get() + frameSize > MAX_READ_BUFFER_BYTES) {
+            return true;
+          }
+
+          // increment the amount of memory allocated to read buffers
+          readBufferBytesAllocated.addAndGet(frameSize + 4);
+
+          // reallocate the readbuffer as a frame-sized buffer
+          buffer_ = ByteBuffer.allocate(frameSize + 4);
+          buffer_.putInt(frameSize);
+
+          state_ = FrameBufferState.READING_FRAME;
+        } else {
+          // this skips the check of READING_FRAME state below, since we can't
+          // possibly go on to that state if there's data left to be read at
+          // this one.
+          return true;
+        }
+      }
+
+      // it is possible to fall through from the READING_FRAME_SIZE section
+      // to READING_FRAME if there's already some frame data available once
+      // READING_FRAME_SIZE is complete.
+
+      if (state_ == FrameBufferState.READING_FRAME) {
+        if (!internalRead()) {
+          return false;
+        }
+
+        // since we're already in the select loop here for sure, we can just
+        // modify our selection key directly.
+        if (buffer_.remaining() == 0) {
+          // get rid of the read select interests
+          selectionKey_.interestOps(0);
+          state_ = FrameBufferState.READ_FRAME_COMPLETE;
+        }
+
+        return true;
+      }
+
+      // if we fall through to this point, then the state must be invalid.
+      LOGGER.error("Read was called but state is invalid (" + state_ + ")");
+      return false;
+    }
+
+    /**
+     * Give this FrameBuffer a chance to write its output to the final client.
+     */
+    public boolean write() {
+      if (state_ == FrameBufferState.WRITING) {
+        try {
+          if (trans_.write(buffer_) < 0) {
+            return false;
+          }
+        } catch (IOException e) {
+          LOGGER.warn("Got an IOException during write!", e);
+          return false;
+        }
+
+        // we're done writing. now we need to switch back to reading.
+        if (buffer_.remaining() == 0) {
+          prepareRead();
+        }
+        return true;
+      }
+
+      LOGGER.error("Write was called, but state is invalid (" + state_ + ")");
+      return false;
+    }
+
+    /**
+     * Give this FrameBuffer a chance to set its interest to write, once data
+     * has come in.
+     */
+    public void changeSelectInterests() {
+      if (state_ == FrameBufferState.AWAITING_REGISTER_WRITE) {
+        // set the OP_WRITE interest
+        selectionKey_.interestOps(SelectionKey.OP_WRITE);
+        state_ = FrameBufferState.WRITING;
+      } else if (state_ == FrameBufferState.AWAITING_REGISTER_READ) {
+        prepareRead();
+      } else if (state_ == FrameBufferState.AWAITING_CLOSE) {
+        close();
+        selectionKey_.cancel();
+      } else {
+        LOGGER.error("changeSelectInterest was called, but state is invalid (" + state_ + ")");
+      }
+    }
+
+    /**
+     * Shut the connection down.
+     */
+    public void close() {
+      // if we're being closed due to an error, we might have allocated a
+      // buffer that we need to subtract for our memory accounting.
+      if (state_ == FrameBufferState.READING_FRAME || state_ == FrameBufferState.READ_FRAME_COMPLETE) {
+        readBufferBytesAllocated.addAndGet(-buffer_.array().length);
+      }
+      trans_.close();
+    }
+
+    /**
+     * Check if this FrameBuffer has a full frame read.
+     */
+    public boolean isFrameFullyRead() {
+      return state_ == FrameBufferState.READ_FRAME_COMPLETE;
+    }
+
+    /**
+     * After the processor has processed the invocation, whatever thread is
+     * managing invocations should call this method on this FrameBuffer so we
+     * know it's time to start trying to write again. Also, if it turns out that
+     * there actually isn't any data in the response buffer, we'll skip trying
+     * to write and instead go back to reading.
+     */
+    public void responseReady() {
+      // the read buffer is definitely no longer in use, so we will decrement
+      // our read buffer count. we do this here as well as in close because
+      // we'd like to free this read memory up as quickly as possible for other
+      // clients.
+      readBufferBytesAllocated.addAndGet(-buffer_.array().length);
+
+      if (response_.len() == 0) {
+        // go straight to reading again. this was probably an oneway method
+        state_ = FrameBufferState.AWAITING_REGISTER_READ;
+        buffer_ = null;
+      } else {
+        buffer_ = ByteBuffer.wrap(response_.get(), 0, response_.len());
+
+        // set state that we're waiting to be switched to write. we do this
+        // asynchronously through requestSelectInterestChange() because there is
+        // a possibility that we're not in the main thread, and thus currently
+        // blocked in select(). (this functionality is in place for the sake of
+        // the HsHa server.)
+        state_ = FrameBufferState.AWAITING_REGISTER_WRITE;
+      }
+      requestSelectInterestChange();
+    }
+
+    /**
+     * Actually invoke the method signified by this FrameBuffer.
+     */
+    public void invoke() {
+      TTransport inTrans = getInputTransport();
+      TProtocol inProt = inputProtocolFactory_.getProtocol(inTrans);
+      TProtocol outProt = outputProtocolFactory_.getProtocol(getOutputTransport());
+
+      try {
+        processorFactory_.getProcessor(inTrans).process(inProt, outProt);
+        responseReady();
+        return;
+      } catch (TException te) {
+        LOGGER.warn("Exception while invoking!", te);
+      } catch (Throwable t) {
+        LOGGER.error("Unexpected throwable while invoking!", t);
+      }
+      // This will only be reached when there is a throwable.
+      state_ = FrameBufferState.AWAITING_CLOSE;
+      requestSelectInterestChange();
+    }
+
+    /**
+     * Wrap the read buffer in a memory-based transport so a processor can read
+     * the data it needs to handle an invocation.
+     */
+    private TTransport getInputTransport() {
+      return inputTransportFactory_.getTransport(new TMemoryInputTransport(buffer_.array()));
+    }
+
+    /**
+     * Get the transport that should be used by the invoker for responding.
+     */
+    private TTransport getOutputTransport() {
+      response_ = new TByteArrayOutputStream();
+      return outputTransportFactory_.getTransport(new TIOStreamTransport(response_));
+    }
+
+    /**
+     * Perform a read into buffer.
+     * 
+     * @return true if the read succeeded, false if there was an error or the
+     *         connection closed.
+     */
+    private boolean internalRead() {
+      try {
+        if (trans_.read(buffer_) < 0) {
+          return false;
+        }
+        return true;
+      } catch (IOException e) {
+        LOGGER.warn("Got an IOException in internalRead!", e);
+        return false;
+      }
+    }
+
+    /**
+     * We're done writing, so reset our interest ops and change state
+     * accordingly.
+     */
+    private void prepareRead() {
+      // we can set our interest directly without using the queue because
+      // we're in the select thread.
+      selectionKey_.interestOps(SelectionKey.OP_READ);
+      // get ready for another go-around
+      buffer_ = ByteBuffer.allocate(4);
+      state_ = FrameBufferState.READING_FRAME_SIZE;
+    }
+
+    /**
+     * When this FrameBuffer needs to change its select interests and execution
+     * might not be in its select thread, then this method will make sure the
+     * interest change gets done when the select thread wakes back up. When the
+     * current thread is this FrameBuffer's select thread, then it just does the
+     * interest change immediately.
+     */
+    private void requestSelectInterestChange() {
+      if (Thread.currentThread() == this.selectThread_) {
+        changeSelectInterests();
+      } else {
+        this.selectThread_.requestSelectInterestChange(this);
+      }
+    }
+  } // FrameBuffer
+
+  public void setServerEventHandler(TServerEventHandler eventHandler) {
+    throw new UnsupportedOperationException("Not supported yet.");
+  }
+
+  public TServerEventHandler getEventHandler() {
+    throw new UnsupportedOperationException("Not supported yet.");
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/9f63daff/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/server/Invocation.java
----------------------------------------------------------------------
diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/server/Invocation.java b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/server/Invocation.java
new file mode 100644
index 0000000..ae3271f
--- /dev/null
+++ b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/server/Invocation.java
@@ -0,0 +1,20 @@
+package org.apache.blur.thirdparty.thrift_0_9_0.server;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.server.AbstractNonblockingServer.FrameBuffer;
+
+/**
+ * An Invocation represents a method call that is prepared to execute, given
+ * an idle worker thread. It contains the input and output protocols the
+ * thread's processor should use to perform the usual Thrift invocation.
+ */
+class Invocation implements Runnable {
+  private final FrameBuffer frameBuffer;
+
+  public Invocation(final FrameBuffer frameBuffer) {
+    this.frameBuffer = frameBuffer;
+  }
+
+  public void run() {
+    frameBuffer.invoke();
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/9f63daff/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/server/ServerContext.java
----------------------------------------------------------------------
diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/server/ServerContext.java b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/server/ServerContext.java
new file mode 100644
index 0000000..b123994
--- /dev/null
+++ b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/server/ServerContext.java
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+/**
+ * Interface for storing server's connection context
+ */
+ 
+package org.apache.blur.thirdparty.thrift_0_9_0.server;
+
+public interface ServerContext {}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/9f63daff/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/server/TExtensibleServlet.java
----------------------------------------------------------------------
diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/server/TExtensibleServlet.java b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/server/TExtensibleServlet.java
new file mode 100644
index 0000000..b27a79b
--- /dev/null
+++ b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/server/TExtensibleServlet.java
@@ -0,0 +1,171 @@
+/*
+ * 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.server;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.TException;
+import org.apache.blur.thirdparty.thrift_0_9_0.TProcessor;
+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;
+import org.apache.blur.thirdparty.thrift_0_9_0.transport.TTransport;
+
+/**
+ * Servlet implementation class ThriftServer, that allows {@link TProcessor} and
+ * {@link TProtocolFactory} to be supplied after the {@link #init()} method has
+ * finished. <br>
+ * Subclasses must implement the abstract methods that return the TProcessor and
+ * two TProtocolFactory. Those methods are guaranteed to be called exactly once,
+ * and that {@link ServletContext} is available.
+ */
+public abstract class TExtensibleServlet extends HttpServlet {
+  private static final long serialVersionUID = 1L;
+
+  private TProcessor processor;
+
+  private TProtocolFactory inFactory;
+
+  private TProtocolFactory outFactory;
+
+  private Collection<Map.Entry<String, String>> customHeaders;
+
+  /**
+   * Returns the appropriate {@link TProcessor}. This will be called <b>once</b> just
+   * after the {@link #init()} method
+   * 
+   * @return
+   */
+  protected abstract TProcessor getProcessor();
+
+  /**
+   * Returns the appropriate in {@link TProtocolFactory}. This will be called
+   * <b>once</b> just after the {@link #init()} method
+   * 
+   * @return
+   */
+  protected abstract TProtocolFactory getInProtocolFactory();
+
+  /**
+   * Returns the appropriate out {@link TProtocolFactory}. This will be called
+   * <b>once</b> just after the {@link #init()} method
+   * 
+   * @return
+   */
+  protected abstract TProtocolFactory getOutProtocolFactory();
+
+  @Override
+  public final void init(ServletConfig config) throws ServletException {
+    super.init(config); //no-args init() happens here
+    this.processor = getProcessor();
+    this.inFactory = getInProtocolFactory();
+    this.outFactory = getOutProtocolFactory();
+    this.customHeaders = new ArrayList<Map.Entry<String, String>>();
+
+    if (processor == null) {
+      throw new ServletException("processor must be set");
+    }
+    if (inFactory == null) {
+      throw new ServletException("inFactory must be set");
+    }
+    if (outFactory == null) {
+      throw new ServletException("outFactory must be set");
+    }
+  }
+
+  /**
+   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
+   *      response)
+   */
+  @Override
+  protected void doPost(HttpServletRequest request, HttpServletResponse response)
+      throws ServletException, IOException {
+    TTransport inTransport = null;
+    TTransport outTransport = null;
+
+    try {
+      response.setContentType("application/x-thrift");
+
+      if (null != this.customHeaders) {
+	for (Map.Entry<String, String> header : this.customHeaders) {
+	  response.addHeader(header.getKey(), header.getValue());
+	}
+      }
+
+      InputStream in = request.getInputStream();
+      OutputStream out = response.getOutputStream();
+
+      TTransport transport = new TIOStreamTransport(in, out);
+      inTransport = transport;
+      outTransport = transport;
+
+      TProtocol inProtocol = inFactory.getProtocol(inTransport);
+      TProtocol outProtocol = inFactory.getProtocol(outTransport);
+
+      processor.process(inProtocol, outProtocol);
+      out.flush();
+    } catch (TException te) {
+      throw new ServletException(te);
+    }
+  }
+
+  /**
+   * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
+   *      response)
+   */
+  @Override
+  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+      throws ServletException, IOException {
+    doPost(req, resp);
+  }
+
+  public void addCustomHeader(final String key, final String value) {
+    this.customHeaders.add(new Map.Entry<String, String>() {
+      public String getKey() {
+	return key;
+      }
+
+      public String getValue() {
+	return value;
+      }
+
+      public String setValue(String value) {
+	return null;
+      }
+    });
+  }
+
+  public void setCustomHeaders(Collection<Map.Entry<String, String>> headers) {
+    this.customHeaders.clear();
+    this.customHeaders.addAll(headers);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/9f63daff/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/server/THsHaServer.java
----------------------------------------------------------------------
diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/server/THsHaServer.java b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/server/THsHaServer.java
new file mode 100644
index 0000000..bdf0ca5
--- /dev/null
+++ b/src/blur-thrift/src/main/java/org/apache/blur/thirdparty/thrift_0_9_0/server/THsHaServer.java
@@ -0,0 +1,168 @@
+/*
+ * 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.server;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.RejectedExecutionException;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.transport.TNonblockingServerTransport;
+
+/**
+ * An extension of the TNonblockingServer to a Half-Sync/Half-Async server.
+ * Like TNonblockingServer, it relies on the use of TFramedTransport.
+ */
+public class THsHaServer extends TNonblockingServer {
+
+  public static class Args extends AbstractNonblockingServerArgs<Args> {
+    private int workerThreads = 5;
+    private int stopTimeoutVal = 60;
+    private TimeUnit stopTimeoutUnit = TimeUnit.SECONDS;
+    private ExecutorService executorService = null;
+
+    public Args(TNonblockingServerTransport transport) {
+      super(transport);
+    }
+
+    public Args workerThreads(int i) {
+      workerThreads = i;
+      return this;
+    }
+
+    public int getWorkerThreads() {
+      return workerThreads;
+    }
+
+    public int getStopTimeoutVal() {
+      return stopTimeoutVal;
+    }
+
+    public Args stopTimeoutVal(int stopTimeoutVal) {
+      this.stopTimeoutVal = stopTimeoutVal;
+      return this;
+    }
+
+    public TimeUnit getStopTimeoutUnit() {
+      return stopTimeoutUnit;
+    }
+
+    public Args stopTimeoutUnit(TimeUnit stopTimeoutUnit) {
+      this.stopTimeoutUnit = stopTimeoutUnit;
+      return this;
+    }
+
+    public ExecutorService getExecutorService() {
+      return executorService;
+    }
+
+    public Args executorService(ExecutorService executorService) {
+      this.executorService = executorService;
+      return this;
+    }
+  }
+
+
+  // This wraps all the functionality of queueing and thread pool management
+  // for the passing of Invocations from the Selector to workers.
+  private final ExecutorService invoker;
+
+  private final Args args;
+
+  /**
+   * Create the server with the specified Args configuration
+   */
+  public THsHaServer(Args args) {
+    super(args);
+
+    invoker = args.executorService == null ? createInvokerPool(args) : args.executorService;
+    this.args = args;
+  }
+
+  /**
+   * @inheritDoc
+   */
+  @Override
+  protected void waitForShutdown() {
+    joinSelector();
+    gracefullyShutdownInvokerPool();
+  }
+
+  /**
+   * Helper to create an invoker pool
+   */
+  protected static ExecutorService createInvokerPool(Args options) {
+    int workerThreads = options.workerThreads;
+    int stopTimeoutVal = options.stopTimeoutVal;
+    TimeUnit stopTimeoutUnit = options.stopTimeoutUnit;
+
+    LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>();
+    ExecutorService invoker = new ThreadPoolExecutor(workerThreads,
+      workerThreads, stopTimeoutVal, stopTimeoutUnit, queue);
+
+    return invoker;
+  }
+
+
+  protected void gracefullyShutdownInvokerPool() {
+    // try to gracefully shut down the executor service
+    invoker.shutdown();
+
+    // Loop until awaitTermination finally does return without a interrupted
+    // exception. If we don't do this, then we'll shut down prematurely. We want
+    // to let the executorService clear it's task queue, closing client sockets
+    // appropriately.
+    long timeoutMS = args.stopTimeoutUnit.toMillis(args.stopTimeoutVal);
+    long now = System.currentTimeMillis();
+    while (timeoutMS >= 0) {
+      try {
+        invoker.awaitTermination(timeoutMS, TimeUnit.MILLISECONDS);
+        break;
+      } catch (InterruptedException ix) {
+        long newnow = System.currentTimeMillis();
+        timeoutMS -= (newnow - now);
+        now = newnow;
+      }
+    }
+  }
+
+  /**
+   * We override the standard invoke method here to queue the invocation for
+   * invoker service instead of immediately invoking. The thread pool takes care
+   * of the rest.
+   */
+  @Override
+  protected boolean requestInvoke(FrameBuffer frameBuffer) {
+    try {
+      Runnable invocation = getRunnable(frameBuffer);
+      invoker.execute(invocation);
+      return true;
+    } catch (RejectedExecutionException rx) {
+      LOGGER.warn("ExecutorService rejected execution!", rx);
+      return false;
+    }
+  }
+
+  protected Runnable getRunnable(FrameBuffer frameBuffer){
+    return new Invocation(frameBuffer);
+  }
+}


Mime
View raw message