manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1202068 - in /incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common: BufferPointer.java CharacterArray.java CharacterValue.java IntegerValue.java LongValue.java StringValue.java
Date Tue, 15 Nov 2011 06:57:25 GMT
Author: kwright
Date: Tue Nov 15 06:57:24 2011
New Revision: 1202068

URL: http://svn.apache.org/viewvc?rev=1202068&view=rev
Log:
Revamp basic building blocks for better efficiency

Added:
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/BufferPointer.java
  (with props)
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/CharacterArray.java
  (with props)
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/CharacterValue.java
  (with props)
Modified:
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/IntegerValue.java
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/LongValue.java
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/StringValue.java

Added: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/BufferPointer.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/BufferPointer.java?rev=1202068&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/BufferPointer.java
(added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/BufferPointer.java
Tue Nov 15 06:57:24 2011
@@ -0,0 +1,48 @@
+/* $Id$ */
+
+/**
+* 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.warthog.common;
+
+/** A byte buffer and offset, for serialization. */
+public class BufferPointer
+{
+  /** The buffer */
+  protected byte[] buffer;
+  /** The pointer */
+  protected int pointer = 0;
+  
+  /** Constructor */
+  public BufferPointer(byte[] buffer)
+  {
+    this.buffer = buffer;
+  }
+  
+  /** Get the value at the current pointer and advance */
+  public byte readValue()
+  {
+    return buffer[pointer++];
+  }
+  
+  /** Write a value to the current pointer and advance */
+  public void writeValue(byte value)
+  {
+    buffer[pointer++] = value;
+  }
+  
+}
\ No newline at end of file

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/BufferPointer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/BufferPointer.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/CharacterArray.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/CharacterArray.java?rev=1202068&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/CharacterArray.java
(added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/CharacterArray.java
Tue Nov 15 06:57:24 2011
@@ -0,0 +1,82 @@
+/* $Id$ */
+
+/**
+* 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.warthog.common;
+
+import org.apache.warthog.interfaces.*;
+
+/** Character array, serializable.
+*/
+public class CharacterArray implements WHValue
+{
+  char[] value;
+  
+  public CharacterArray(char[] value)
+  {
+    this.value = value;
+  }
+  
+  public CharacterArray()
+  {
+  }
+  
+  public CharacterArray(byte[] bytes)
+  {
+    value = readObject(new BufferPointer(bytes));
+  }
+  
+  public byte[] serializeObject()
+  {
+    byte[] rval = new byte[sizeObject(value.length)];
+    writeObject(new BufferPointer(rval),value);
+    return rval;
+  }
+  
+  public char[] getValue()
+  {
+    return value;
+  }
+  
+  public static char[] readObject(BufferPointer bp)
+  {
+    int size = IntegerValue.readObject(bp);
+    char[] rval = new char[size];
+    for (int i = 0 ; i < size ; i++)
+    {
+      rval[i] = CharacterValue.readObject(bp);
+    }
+    return rval;
+  }
+  
+  public static int sizeObject(int size)
+  {
+    return IntegerValue.sizeObject() + CharacterValue.sizeObject() * size;
+  }
+  
+  public static void writeObject(BufferPointer bp, char[] value)
+  {
+    IntegerValue.writeObject(bp,value.length);
+    for (int i = 0 ; i < value.length ; i++)
+    {
+      CharacterValue.writeObject(bp,value[i]);
+    }
+  }
+}
+
+

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/CharacterArray.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/CharacterArray.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/CharacterValue.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/CharacterValue.java?rev=1202068&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/CharacterValue.java
(added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/CharacterValue.java
Tue Nov 15 06:57:24 2011
@@ -0,0 +1,75 @@
+/* $Id$ */
+
+/**
+* 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.warthog.common;
+
+import org.apache.warthog.interfaces.*;
+
+/** Character value, serializable.
+*/
+public class CharacterValue implements WHValue
+{
+  char value;
+  
+  public CharacterValue(char value)
+  {
+    this.value = value;
+  }
+  
+  public CharacterValue()
+  {
+  }
+  
+  public CharacterValue(byte[] bytes)
+  {
+    value = readObject(new BufferPointer(bytes));
+  }
+  
+  public byte[] serializeObject()
+  {
+    byte[] rval = new byte[sizeObject()];
+    writeObject(new BufferPointer(rval),value);
+    return rval;
+  }
+  
+  public char getValue()
+  {
+    return value;
+  }
+  
+  public static char readObject(BufferPointer bp)
+  {
+    int value = (((int)bp.readValue()) & 0xff);
+    value += ((((int)bp.readValue()) << 8) & 0xff00);
+    return (char)value;
+  }
+  
+  public static int sizeObject()
+  {
+    return 2;
+  }
+  
+  public static void writeObject(BufferPointer bp, char value)
+  {
+    bp.writeValue((byte)(((int)value) & 0xff));
+    bp.writeValue((byte)((((int)value) >> 8) & 0xff));
+  }
+}
+
+

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/CharacterValue.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/CharacterValue.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/IntegerValue.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/IntegerValue.java?rev=1202068&r1=1202067&r2=1202068&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/IntegerValue.java
(original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/IntegerValue.java
Tue Nov 15 06:57:24 2011
@@ -38,13 +38,13 @@ public class IntegerValue implements WHV
   
   public IntegerValue(byte[] bytes)
   {
-    readObject(bytes,0);
+    value = readObject(new BufferPointer(bytes));
   }
   
   public byte[] serializeObject()
   {
     byte[] rval = new byte[sizeObject()];
-    writeObject(rval,0);
+    writeObject(new BufferPointer(rval),value);
     return rval;
   }
   
@@ -53,13 +53,13 @@ public class IntegerValue implements WHV
     return value;
   }
   
-  public int readObject(byte[] bytes, int offset)
+  public static int readObject(BufferPointer bp)
   {
-    value = (((int)bytes[offset]) & 0xff) +
-              ((((int)bytes[offset+1]) << 8) & 0xff00) +
-              ((((int)bytes[offset+2]) << 16) & 0xff0000) +
-              ((((int)bytes[offset+3]) << 24) & 0xff000000);
-    return offset + 4;
+    int value = (((int)bp.readValue()) & 0xff);
+    value += ((((int)bp.readValue()) << 8) & 0xff00);
+    value += ((((int)bp.readValue()) << 16) & 0xff0000);
+    value += ((((int)bp.readValue()) << 24) & 0xff000000);
+    return value;
   }
   
   public static int sizeObject()
@@ -67,13 +67,12 @@ public class IntegerValue implements WHV
     return 4;
   }
   
-  public int writeObject(byte[] bytes, int offset)
+  public static void writeObject(BufferPointer bp, int value)
   {
-    bytes[offset] = (byte)(value & 0xff);
-    bytes[offset+1] = (byte)((value >> 8) & 0xff);
-    bytes[offset+2] = (byte)((value >> 16) & 0xff);
-    bytes[offset+3] = (byte)((value >> 24) & 0xff);
-    return offset + 4;
+    bp.writeValue((byte)(value & 0xff));
+    bp.writeValue((byte)((value >> 8) & 0xff));
+    bp.writeValue((byte)((value >> 16) & 0xff));
+    bp.writeValue((byte)((value >> 24) & 0xff));
   }
 }
 

Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/LongValue.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/LongValue.java?rev=1202068&r1=1202067&r2=1202068&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/LongValue.java
(original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/LongValue.java
Tue Nov 15 06:57:24 2011
@@ -38,13 +38,13 @@ public class LongValue implements WHValu
   
   public LongValue(byte[] bytes)
   {
-    readObject(bytes,0);
+    value = readObject(new BufferPointer(bytes));
   }
   
   public byte[] serializeObject()
   {
     byte[] rval = new byte[sizeObject()];
-    writeObject(rval,0);
+    writeObject(new BufferPointer(rval),value);
     return rval;
   }
   
@@ -53,17 +53,17 @@ public class LongValue implements WHValu
     return value;
   }
   
-  public int readObject(byte[] bytes, int offset)
+  public static long readObject(BufferPointer bp)
   {
-    value = (((long)bytes[offset]) & 0xffL) +
-              ((((long)bytes[offset+1]) << 8) & 0xff00L) +
-              ((((long)bytes[offset+2]) << 16) & 0xff0000L) +
-              ((((long)bytes[offset+3]) << 24) & 0xff000000L) +
-              ((((long)bytes[offset+4]) << 32) & 0xff00000000L) +
-              ((((long)bytes[offset+5]) << 40) & 0xff0000000000L) +
-              ((((long)bytes[offset+6]) << 48) & 0xff000000000000L) +
-              ((((long)bytes[offset+7]) << 56) & 0xff00000000000000L);
-    return offset + 8;
+    long value = (((long)bp.readValue()) & 0xffL);
+    value += ((((long)bp.readValue()) << 8) & 0xff00L);
+    value += ((((long)bp.readValue()) << 16) & 0xff0000L);
+    value += ((((long)bp.readValue()) << 24) & 0xff000000L);
+    value += ((((long)bp.readValue()) << 32) & 0xff00000000L);
+    value += ((((long)bp.readValue()) << 40) & 0xff0000000000L);
+    value += ((((long)bp.readValue()) << 48) & 0xff000000000000L);
+    value += ((((long)bp.readValue()) << 56) & 0xff00000000000000L);
+    return value;
   }
   
   public static int sizeObject()
@@ -71,17 +71,16 @@ public class LongValue implements WHValu
     return 8;
   }
   
-  public int writeObject(byte[] bytes, int offset)
+  public static void writeObject(BufferPointer bp, long value)
   {
-    bytes[offset] = (byte)(value & 0xffL);
-    bytes[offset+1] = (byte)((value >> 8) & 0xffL);
-    bytes[offset+2] = (byte)((value >> 16) & 0xffL);
-    bytes[offset+3] = (byte)((value >> 24) & 0xffL);
-    bytes[offset+4] = (byte)((value >> 32) & 0xffL);
-    bytes[offset+5] = (byte)((value >> 40) & 0xffL);
-    bytes[offset+6] = (byte)((value >> 48) & 0xffL);
-    bytes[offset+7] = (byte)((value >> 56) & 0xffL);
-    return offset + 8;
+    bp.writeValue((byte)(value & 0xffL));
+    bp.writeValue((byte)((value >> 8) & 0xffL));
+    bp.writeValue((byte)((value >> 16) & 0xffL));
+    bp.writeValue((byte)((value >> 24) & 0xffL));
+    bp.writeValue((byte)((value >> 32) & 0xffL));
+    bp.writeValue((byte)((value >> 40) & 0xffL));
+    bp.writeValue((byte)((value >> 48) & 0xffL));
+    bp.writeValue((byte)((value >> 56) & 0xffL));
   }
 }
 

Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/StringValue.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/StringValue.java?rev=1202068&r1=1202067&r2=1202068&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/StringValue.java
(original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/StringValue.java
Tue Nov 15 06:57:24 2011
@@ -21,25 +21,10 @@ package org.apache.warthog.common;
 
 import org.apache.warthog.interfaces.*;
 
-import java.nio.charset.Charset;
-
 /** This object represents a string that can be stored in the key/value store.
 */
 public class StringValue implements WHValue
 {
-  protected static Charset UTF_8;
-  
-  static
-  {
-    try
-    {
-      UTF_8 = Charset.forName("utf-8");
-    }
-    catch (Exception e)
-    {
-    }
-  }
-  
   protected String value;
   
   public StringValue(String value)
@@ -52,6 +37,11 @@ public class StringValue implements WHVa
     value = null;
   }
 
+  public StringValue(byte[] bytes)
+  {
+    value = readObject(new BufferPointer(bytes));
+  }
+  
   public String getValue()
   {
     return value;
@@ -59,34 +49,25 @@ public class StringValue implements WHVa
 
   public byte[] serializeObject()
   {
-    byte[] rval = new byte[sizeObject()];
-    writeObject(rval,0);
+    byte[] rval = new byte[sizeObject(value)];
+    writeObject(new BufferPointer(rval),value);
     return rval;
   }
 
-  public int readObject(byte[] bytes, int offset)
+  public static String readObject(BufferPointer bp)
   {
-    IntegerValue iv = new IntegerValue();
-    offset = iv.readObject(bytes,offset);
-    int lengthValue = iv.getValue();
-    value = new String(bytes,offset,lengthValue,UTF_8);
-    offset += lengthValue;
-    return offset;
+    char[] array = CharacterArray.readObject(bp);
+    return new String(array);
   }
   
-  public int sizeObject()
+  public static int sizeObject(String value)
   {
-    return IntegerValue.sizeObject() + value.getBytes(UTF_8).length;
+    return CharacterArray.sizeObject(value.length());
   }
   
-  public int writeObject(byte[] bytes, int offset)
+  public static void writeObject(BufferPointer bp, String value)
   {
-    byte[] utf8 = value.getBytes(UTF_8);
-    IntegerValue iv = new IntegerValue(utf8.length);
-    offset = iv.writeObject(bytes,offset);
-    System.arraycopy(utf8,0,bytes,offset,utf8.length);
-    offset += utf8.length;
-    return offset;
+    CharacterArray.writeObject(bp,value.toCharArray());
   }
 
 }
\ No newline at end of file



Mime
View raw message