/** * Take optional Long which may be null. Null is defined as specific long value passed in. * @param pipe Pipe source * @param absent64Value long value mapped to null * @return Long value */ public static <S extends MessageSchema<S>> Long takeOptionalLong(Pipe<S> pipe, long absent64Value) { assert(pipe.slabRingTail.workingTailPos.value<Pipe.workingHeadPosition(pipe)) : "working tail "+pipe.slabRingTail.workingTailPos.value+" but head is "+Pipe.workingHeadPosition(pipe); long result = readLong(pipe.slabRing,pipe.slabMask,pipe.slabRingTail.workingTailPos.value); pipe.slabRingTail.workingTailPos.value+=2; return absent64Value!=result ? new Long(result) : null; }
/** * Returns nano-second count of how much time should pass before producing more data * into this pipe. This is based on the rate configuration. */ public static <S extends MessageSchema<S>> long computeRateLimitProducerDelay(Pipe<S> pipe) { return PipeRegulator.computeRateLimitDelay(pipe, Pipe.workingHeadPosition(pipe), pipe.regulatorProducer); }
/** * Hold this position in case we want to abandon what is written * @param pipe pipe to be used */ public static void markHead(Pipe pipe) { pipe.markedHeadSlab = Pipe.workingHeadPosition(pipe); pipe.markedHeadBlob = Pipe.getWorkingBlobHeadPosition(pipe); }
/** * Returns nano-second count of how much time should pass before producing more data * into this pipe. This is based on the rate configuration. */ public static <S extends MessageSchema<S>> long computeRateLimitProducerDelay(Pipe<S> pipe) { return PipeRegulator.computeRateLimitDelay(pipe, Pipe.workingHeadPosition(pipe), pipe.regulatorProducer); }
/** * Hold this position in case we want to abandon what is written * @param pipe pipe to be used */ public static void markHead(Pipe pipe) { pipe.markedHeadSlab = Pipe.workingHeadPosition(pipe); pipe.markedHeadBlob = Pipe.getWorkingBlobHeadPosition(pipe); }
/** * Hold this position in case we want to abandon what is written * @param pipe pipe to be used */ public static void markHead(Pipe pipe) { pipe.markedHeadSlab = Pipe.workingHeadPosition(pipe); pipe.markedHeadBlob = Pipe.getWorkingBlobHeadPosition(pipe); }
private static void prepWriteMessageStart(Pipe pipe, final int cursorPosition, FieldReferenceOffsetManager from) { assert(isValidStart(from,cursorPosition)) : "cursorPosition must be a valid message start but it is not. Value is "+cursorPosition; //each time some bytes were written in the previous fragment this value was incremented. //now it becomes the base value for all byte writes Pipe.markBytesWriteBase(pipe); //Start new stack of fragments because this is a new message pipe.ringWalker.activeWriteFragmentStack[0] = Pipe.workingHeadPosition(pipe); Pipe.slab(pipe)[pipe.slabMask &(int)(Pipe.workingHeadPosition(pipe) + from.templateOffset)] = cursorPosition; }
@Override public void startup() { fileChannel = inputFile.getChannel(); header = ByteBuffer.allocate(8); ((Buffer)header).clear(); intHeader = header.asIntBuffer(); INT_BUFFER_WRAPPER = new IntBuferWritableByteChannel(); targetBlobPos = Pipe.getWorkingBlobHeadPosition(target); targetSlabPos = Pipe.workingHeadPosition(target); }
private static void prepWriteFragmentSpecificProcessing(Pipe pipe, final int cursorPosition, FieldReferenceOffsetManager from) { if (FieldReferenceOffsetManager.isTemplateStart(from, cursorPosition)) { prepWriteMessageStart(pipe, cursorPosition, from); } else { //this fragment does not start a new message but its start position must be recorded for usage later pipe.ringWalker.activeWriteFragmentStack[from.fragDepth[cursorPosition]]=Pipe.workingHeadPosition(pipe); } }
private static boolean copyFragment1(Pipe inputRing, Pipe outputRing, long start, int spaceNeeded, int bytesToCopy) { if ((spaceNeeded > outputRing.sizeOfSlabRing-(int)(Pipe.workingHeadPosition(outputRing) - Pipe.tailPosition(outputRing)) )) { return false; } copyFragment2(inputRing, outputRing, (int)start, spaceNeeded, bytesToCopy); return true; }
private static void prepWriteFragmentSpecificProcessing(Pipe pipe, final int cursorPosition, FieldReferenceOffsetManager from) { if (FieldReferenceOffsetManager.isTemplateStart(from, cursorPosition)) { prepWriteMessageStart(pipe, cursorPosition, from); } else { //this fragment does not start a new message but its start position must be recorded for usage later pipe.ringWalker.activeWriteFragmentStack[from.fragDepth[cursorPosition]]=Pipe.workingHeadPosition(pipe); } }
private static boolean copyFragment1(Pipe inputRing, Pipe outputRing, long start, int spaceNeeded, int bytesToCopy) { if ((spaceNeeded > outputRing.sizeOfSlabRing-(int)(Pipe.workingHeadPosition(outputRing) - Pipe.tailPosition(outputRing)) )) { return false; } copyFragment2(inputRing, outputRing, (int)start, spaceNeeded, bytesToCopy); return true; }
private static void publishWrites2(Pipe pipe) { //TODO: Not sure this assert works when we write high and read low.... //assert(Pipe.workingHeadPosition(pipe) <= pipe.ringWalker.nextWorkingHead) : "Unsupported use of high level API with low level methods."; //publish writes Pipe.setBlobHeadPosition(pipe, Pipe.getWorkingBlobHeadPosition(pipe)); Pipe.publishWorkingHeadPosition(pipe, Pipe.workingHeadPosition(pipe)); Pipe.beginNewPublishBatch(pipe); }
private static void publishWrites2(Pipe pipe) { //TODO: Not sure this assert works when we write high and read low.... //assert(Pipe.workingHeadPosition(pipe) <= pipe.ringWalker.nextWorkingHead) : "Unsupported use of high level API with low level methods."; //publish writes Pipe.setBlobHeadPosition(pipe, Pipe.getWorkingBlobHeadPosition(pipe)); Pipe.publishWorkingHeadPosition(pipe, Pipe.workingHeadPosition(pipe)); Pipe.beginNewPublishBatch(pipe); }
public static void writeNull(Pipe output) { //before write make sure the tail is moved ahead so we have room to write long lastCheckedValue = Pipe.tailPosition(output); while (null==Pipe.slab(output) || lastCheckedValue < Pipe.workingHeadPosition(output)-(output.sizeOfSlabRing-Pipe.from(output).fragDataSize[MetaMessageDefs.MSG_NULL_LOC])) { Pipe.spinWork(output); lastCheckedValue = Pipe.tailPosition(output); } Pipe.addMsgIdx(output, MetaMessageDefs.MSG_NULL_LOC); }
public static void writeUInt(TypeExtractor typeExtractor, Pipe output) { //before write make sure the tail is moved ahead so we have room to write long lastCheckedValue = Pipe.tailPosition(output); while (null==Pipe.slab(output) || lastCheckedValue < Pipe.workingHeadPosition(output)-(output.sizeOfSlabRing-Pipe.from(output).fragDataSize[MetaMessageDefs.MSG_UINT32_LOC])) { Pipe.spinWork(output); lastCheckedValue = Pipe.tailPosition(output); } Pipe.addMsgIdx(output, MetaMessageDefs.MSG_UINT32_LOC); Pipe.addIntValue((int)typeExtractor.activeFieldLong, output); }
public static void writeBytes(byte[] data, int offset, int length, Pipe output) { //before write make sure the tail is moved ahead so we have room to write long lastCheckedValue = Pipe.tailPosition(output); while (null==Pipe.slab(output) || lastCheckedValue < Pipe.workingHeadPosition(output)-(output.sizeOfSlabRing-Pipe.from(output).fragDataSize[MetaMessageDefs.MSG_BYTEARRAY_LOC])) { Pipe.spinWork(output); lastCheckedValue = Pipe.tailPosition(output); } Pipe.addMsgIdx(output, MetaMessageDefs.MSG_BYTEARRAY_LOC); Pipe.addByteArray(data, offset, length, output); }
public static void writeLong(TypeExtractor typeExtractor, Pipe output) { //before write make sure the tail is moved ahead so we have room to write long lastCheckedValue = Pipe.tailPosition(output); while (null==Pipe.slab(output) || lastCheckedValue < Pipe.workingHeadPosition(output)-(output.sizeOfSlabRing-Pipe.from(output).fragDataSize[MetaMessageDefs.MSG_INT64_LOC])) { Pipe.spinWork(output); lastCheckedValue = Pipe.tailPosition(output); } Pipe.addMsgIdx(output, MetaMessageDefs.MSG_INT64_LOC); Pipe.addLongValue(typeExtractor.activeFieldLong*(long)TypeExtractor.signMult(typeExtractor), output); }
public static void writeDecimal(TypeExtractor typeExtractor, Pipe output) { //before write make sure the tail is moved ahead so we have room to write long lastCheckedValue = Pipe.tailPosition(output); while (null==Pipe.slab(output) || lastCheckedValue < Pipe.workingHeadPosition(output)-(output.sizeOfSlabRing-Pipe.from(output).fragDataSize[MetaMessageDefs.MSG_DECIMAL_LOC])) { Pipe.spinWork(output); lastCheckedValue = Pipe.tailPosition(output); } Pipe.addMsgIdx(output, MetaMessageDefs.MSG_DECIMAL_LOC); Pipe.addDecimal(TypeExtractor.decimalPlaces(typeExtractor), typeExtractor.activeFieldLong*TypeExtractor.signMult(typeExtractor), output); }
public static void writeInt(TypeExtractor typeExtractor, Pipe output) { //before write make sure the tail is moved ahead so we have room to write long lastCheckedValue = Pipe.tailPosition(output); while (null==Pipe.slab(output) || lastCheckedValue < Pipe.workingHeadPosition(output)-(output.sizeOfSlabRing-Pipe.from(output).fragDataSize[MetaMessageDefs.MSG_INT32_LOC])) { Pipe.spinWork(output); lastCheckedValue = Pipe.tailPosition(output); } Pipe.addMsgIdx(output, MetaMessageDefs.MSG_INT32_LOC); Pipe.addIntValue((int)typeExtractor.activeFieldLong*TypeExtractor.signMult(typeExtractor), output); TypeExtractor.signMult(typeExtractor); }