Package com.nickrobison.tuple
Class TupleSchema
- java.lang.Object
-
- com.nickrobison.tuple.TupleSchema
-
- Direct Known Subclasses:
DirectTupleSchema
,HeapTupleSchema
public abstract class TupleSchema extends java.lang.Object implements Loader<FastTuple>, Destroyer<FastTuple>
Created by cliff on 5/2/14.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TupleSchema.Builder
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Class
clazz
protected java.lang.String[]
fieldNames
protected java.lang.Class[]
fieldTypes
protected java.lang.Class
iface
protected TuplePool<FastTuple>
pool
-
Constructor Summary
Constructors Modifier Constructor Description protected
TupleSchema(TupleSchema.Builder builder)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static TupleSchema.Builder
builder()
FastTuple[]
createArray(int size)
abstract FastTuple
createTuple()
Allocates a new tuple, completely separate from any pooling.abstract FastTuple[]
createTupleArray(int size)
Allocates an array of tuples.abstract <T> T
createTypedTuple(java.lang.Class<T> clazz)
Allocates a new typed tuple, completely separate from any pooling.abstract <T> T[]
createTypedTupleArray(java.lang.Class<T> clazz, int size)
* Allocates an array of tuples.void
destroyArray(FastTuple[] ary)
abstract void
destroyTuple(FastTuple tuple)
Deallocates memory for a tuple.abstract void
destroyTupleArray(FastTuple[] ary)
Deallocates memory for an array of tuples.abstract <T> void
destroyTypedTuple(T tuple)
Deallocates memory for a typed tuple.abstract <T> void
destroyTypedTupleArray(T[] ary)
Deallocates memory for an array of typed tuples.boolean
equals(java.lang.Object other)
protected abstract void
generateClass()
java.lang.ClassLoader
getClassLoader()
java.lang.String[]
getFieldNames()
java.lang.Class[]
getFieldTypes()
int
hashCode()
TuplePool<FastTuple>
pool()
Returns the tuple pool for this schema.java.lang.String
toString()
java.lang.Class
tupleClass()
-
-
-
Constructor Detail
-
TupleSchema
protected TupleSchema(TupleSchema.Builder builder)
-
-
Method Detail
-
builder
public static TupleSchema.Builder builder()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
tupleClass
public java.lang.Class tupleClass()
-
getFieldNames
public java.lang.String[] getFieldNames()
-
getFieldTypes
public java.lang.Class[] getFieldTypes()
-
generateClass
protected abstract void generateClass() throws java.lang.Exception
- Throws:
java.lang.Exception
-
createTuple
public abstract FastTuple createTuple() throws java.lang.Exception
Allocates a new tuple, completely separate from any pooling.- Returns:
- -
FastTuple
- Throws:
java.lang.Exception
- - Throws an exception if unable to allocate tuple
-
createTypedTuple
public abstract <T> T createTypedTuple(java.lang.Class<T> clazz) throws java.lang.Exception
Allocates a new typed tuple, completely separate from any pooling. Use care to callTupleSchema.Builder.implementInterface(Class)
before using this method- Type Parameters:
T
- -TupleSchema
type parameter- Parameters:
clazz
- -Class
implemented by the Tuple- Returns:
- -
FastTuple
case to typeTupleSchema
- Throws:
java.lang.Exception
- - Throws an exception if unable to allocate tuple or cast to the specified type
-
createTupleArray
public abstract FastTuple[] createTupleArray(int size) throws java.lang.Exception
Allocates an array of tuples. This method will try to ensure that tuples get allocated in adjacent memory, however with the heap based allocation this is not guaranteed.- Parameters:
size
- the number of tuples in the array.- Returns:
- - Array of
FastTuple
- Throws:
java.lang.Exception
- - Throws if unable to allocate tuple array
-
createTypedTupleArray
public abstract <T> T[] createTypedTupleArray(java.lang.Class<T> clazz, int size) throws java.lang.Exception
* Allocates an array of tuples. This method will try to ensure that tuples get allocated in adjacent memory, however with the heap based allocation this is not guaranteed.- Type Parameters:
T
- -TupleSchema
type parameter- Parameters:
clazz
- -Class
implemented by the Tuplesize
- - the number of tuples in the array- Returns:
- - Array of
FastTuple
cast to typeTupleSchema
- Throws:
java.lang.Exception
- - Throws is unable to allocate tuple array or cast to the specified type
-
destroyTuple
public abstract void destroyTuple(FastTuple tuple)
Deallocates memory for a tuple.- Parameters:
tuple
- -FastTuple
to deallocate
-
destroyTypedTuple
public abstract <T> void destroyTypedTuple(T tuple)
Deallocates memory for a typed tuple.- Type Parameters:
T
- -TupleSchema
underlying class implemented by tuples- Parameters:
tuple
- -FastTuple
cast to typeTupleSchema
-
destroyTupleArray
public abstract void destroyTupleArray(FastTuple[] ary)
Deallocates memory for an array of tuples. Assumes that they were allocated as an array.- Parameters:
ary
- - Array ofFastTuple
to deallocate
-
destroyTypedTupleArray
public abstract <T> void destroyTypedTupleArray(T[] ary)
Deallocates memory for an array of typed tuples. Assumes that they were allocated as an array.- Type Parameters:
T
- -TupleSchema
underlying class implemented by tuples- Parameters:
ary
- - Array of typedFastTuple
to deallocate
-
destroyArray
public void destroyArray(FastTuple[] ary)
- Specified by:
destroyArray
in interfaceDestroyer<FastTuple>
-
createArray
public FastTuple[] createArray(int size) throws java.lang.Exception
- Specified by:
createArray
in interfaceLoader<FastTuple>
- Throws:
java.lang.Exception
-
pool
public TuplePool<FastTuple> pool()
Returns the tuple pool for this schema. Each individual thread accessing this method will see a different pool.
-
getClassLoader
public java.lang.ClassLoader getClassLoader()
-
-