com.javanut.pronghorn.pipe.proxy.OutputPipeInvocationHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pronghorn-pipes Show documentation
Show all versions of pronghorn-pipes Show documentation
Ring buffer based queuing utility for applications that require high performance and/or a small
footprint. Well suited for embedded and stream based processing.
package com.javanut.pronghorn.pipe.proxy;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.javanut.pronghorn.pipe.FieldReferenceOffsetManager;
import com.javanut.pronghorn.pipe.Pipe;
import com.javanut.pronghorn.pipe.token.TokenBuilder;
public class OutputPipeInvocationHandler extends PipeInvokeHandler implements InvocationHandler {
//TODO: NOTE: this approach does NOT support nested structures at all.
private static final Logger log = LoggerFactory.getLogger(OutputPipeInvocationHandler.class);
//This only supports one template message
private final OutputPipeWriterMethod[] writers;
public OutputPipeInvocationHandler(Pipe pipe, int msgIdx, Class> clazz) {
super(clazz.getMethods());
FieldReferenceOffsetManager from = Pipe.from(pipe);
final Method[] methods = clazz.getMethods();
writers = new OutputPipeWriterMethod[MAX_METHODS];
int j = methods.length;
while (--j>=0) {
final Method method = methods[j];
ProngTemplateField fieldAnnonation = method.getAnnotation(ProngTemplateField.class);
if (null!=fieldAnnonation) {
int fieldLoc = FieldReferenceOffsetManager.lookupFieldLocator(fieldAnnonation.fieldId(), msgIdx, from);
int key = buildKey(this, method.getName());
if (null!=writers[key]) {
throw new UnsupportedOperationException();
}
writers[key] = OutputPipeWriterMethod.buildWriteForYourType(pipe, fieldAnnonation.decimalPlaces(), fieldLoc, (fieldLoc >> FieldReferenceOffsetManager.RW_FIELD_OFF_BITS) & TokenBuilder.MASK_TYPE, from);
}
}
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
writers[buildKey(this,method.getName())].write(args);
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy