All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.javanut.pronghorn.pipe.MessageSchema Maven / Gradle / Ivy

Go to download

Ring buffer based queuing utility for applications that require high performance and/or a small footprint. Well suited for embedded and stream based processing.

There is a newer version: 1.1.27
Show newest version
package com.javanut.pronghorn.pipe;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

public abstract class MessageSchema> {

    protected final FieldReferenceOffsetManager from; //will be null for schema-less

    protected MessageSchema(FieldReferenceOffsetManager from) {
        this.from = from;
    }
    
    public static final FieldReferenceOffsetManager from(MessageSchema schema) {
        return schema.from;
    }
        
    public int getLocator(String messageName, String fieldName) {
    	return from.getLoc(messageName, fieldName);
    }

    public int getLocator(long messageId, long fieldId) {
    	return from.getLoc(messageId, fieldId);
    }
    
    public PipeConfig newPipeConfig(int minimumFragmentsOnRing, int maximumLenghOfVariableLengthFields) {
    	return new PipeConfig((T)this, minimumFragmentsOnRing, maximumLenghOfVariableLengthFields);
    };
    
    public PipeConfig newPipeConfig(int minimumFragmentsOnRing) {
    	return new PipeConfig((T)this, minimumFragmentsOnRing, 0);
    };
    
    public Pipe newPipe(int minimumFragmentsOnRing, int maximumLenghOfVariableLengthFields) {
    	return new Pipe((PipeConfig) newPipeConfig(minimumFragmentsOnRing, maximumLenghOfVariableLengthFields));
    }
    
    public Pipe newPipe(int minimumFragmentsOnRing) {
    	return new Pipe((PipeConfig) newPipeConfig(minimumFragmentsOnRing, 0));
    }

    //TODO: write a second one for assert only which confirms only 1 static instance field.
	public static > S findInstance(Class clazz) {
		
		Field[] declaredFields = clazz.getDeclaredFields();
		for(int i=0;i