public StructRegistry merge(StructRegistry source) { StructRegistry result = new StructRegistry(); for(int i=0; i<structCount; i++) { maxDims(fieldDims[i]); result.addStruct(fieldNames[i], fieldTypes[i], fieldDims[i]); } for(int i=0; i<source.structCount; i++) { result.addStruct(source.fieldNames[i], source.fieldTypes[i], source.fieldDims[i]); } return result; }
@Override public CompositeRouteFinish refineText(String key, Object associatedObject, ByteSequenceValidator validator) { long fieldLookup = scs.registry.fieldLookup(key, structId); if (-1 == fieldLookup) { throw new UnsupportedOperationException("The field "+key+" was not found defined above"); } scs.registry.setAssociatedObject(fieldLookup, associatedObject); assert(fieldLookup == scs.registry.fieldLookupByIdentity(associatedObject, structId)); scs.registry.setValidator(fieldLookup, JSONRequired.REQUIRED, validator); return this; }
public <T extends Object> T getAssociatedObject(long fieldId) { assert(fieldId>=0) : "bad fieldId"; return (T) this.fieldLocals[extractStructId(fieldId)][extractFieldPosition(fieldId)]; }
@Override public CompositeRouteFinish associatedObject(String key, Object object) { long fieldLookup = scs.registry.fieldLookup(key, structId); assert(-1 != fieldLookup) : "Unable to find associated key "+key; scs.registry.setAssociatedObject(fieldLookup, object); assert(fieldLookup == scs.registry.fieldLookupByIdentity(object, structId)); return this; }
/** * Writes text to specified field in pipe * @param fieldId field to write to * @return channelWriter */ public Appendable writeText(long fieldId) { assert(Pipe.structRegistry(channelWriter.backingPipe).fieldType(fieldId) == StructType.Text); DataOutputBlobWriter.commitBackData(channelWriter, StructRegistry.extractStructId(fieldId)); DataOutputBlobWriter.setIntBackData( channelWriter, channelWriter.position(), StructRegistry.extractFieldPosition(fieldId)); return channelWriter; }
if (null!=fieldDim) { assert(fieldNames.length == fieldDim.length); maxDims(fieldDim); grow(structCount); long base = ((long)(IS_STRUCT_BIT|(STRUCT_MASK & structIdx)))<<STRUCT_OFFSET; while (--n>=0) { assert(isNotAlreadyDefined(fieldParser, fieldNames[n])); while (--j >= 0) { if (null!=fieldAssoc[j]) { setAssoc(fieldAssoc[j], structIdx, j); registerStructAssociation(resultStructId, associatedObject);
long fieldId = registry.fieldLookup(key, 0, key.length, Integer.MAX_VALUE, structId); Object validator = registry.fieldValidator(fieldId); final int fieldPos = StructRegistry.extractFieldPosition(fieldId); switch (registry.fieldType(fieldId)) { case Text: final byte[] textBytes = CharSequenceToUTF8Local.get().convert(value).asBytes();
public static void addHeader(StructRegistry schema, int structId, TrieParser headerParser, HTTPHeader header) { long fieldId = schema.growStruct(structId, StructType.Blob, //TODO: need a way to define dimensions on headers 0, //NOTE: associated object will be used to interpret header.rootBytes()); if (!schema.setAssociatedObject(fieldId, header)) { throw new UnsupportedOperationException("A header with the same identity hash is already held, can not add "+header); } assert(schema.getAssociatedObject(fieldId) == header) : "unable to get associated object"; assert(fieldId == schema.fieldLookupByIdentity(header, structId)); CharSequence template = header.readingTemplate(); addHeader(headerParser, fieldId, template); }
@Override public long lookupFieldByIdentity(int id, Object obj) { if ((id & StructRegistry.IS_STRUCT_BIT) == 0) { //this is a route so we must covert to struct id = routerConfig.getStructIdForRouteId(id); } return gm.recordTypeData.fieldLookupByIdentity(obj, id); }
public int[] addToStruct(StructRegistry struct, int structId) { int length = mappings.length; int[] jsonIndexLookup = new int[length]; int i = length; assert(i>0) : "Must not add an empty extraction"; while (--i>=0) { JSONFieldMapping mapping = mappings[i]; long fieldId = struct.growStruct(structId, mapTypes(mapping), mapping.dimensions(), mapping.getName().getBytes()); jsonIndexLookup[i] = StructRegistry.FIELD_MASK&(int)fieldId; Object assoc = mapping.getAssociatedObject(); if (null!=assoc) { if (!struct.setAssociatedObject(fieldId, assoc)) { throw new UnsupportedOperationException("An object with the same identity hash is already held, can not add "+assoc); } } struct.setValidator(fieldId, mapping.isRequired(), mapping.getValidator()); } return jsonIndexLookup; }
public int addStruct(byte[][] fieldNames, StructType[] fieldTypes //all fields are precede by array count byte ) { return addStruct(fieldNames, fieldTypes, null, null); }
@Override public CompositeRouteFinish validator(String key, JSONRequired required, DecimalValidator validator) { long fieldLookup = scs.registry.fieldLookup(key, structId); if (-1 == fieldLookup) { throw new UnsupportedOperationException("The field "+key+" was not found defined above"); } scs.registry.setValidator(fieldLookup, required, validator); return this; }
public void headersToEcho(int maxSingleHeaderSize, HTTPHeader ... headers) { if (0==minInternalInFlightPayloadSize) { minInternalInFlightPayloadSize += 4;//room to open and add index } minInternalInFlightPayloadSize += (headers.length*maxSingleHeaderSize); headersToEcho = headers; for(int h = 0; h<headers.length; h++) { long id = registry.growStruct(connectionStructId, StructType.Blob, 0, headers[h].rootBytes()); registry.setAssociatedObject(id, headers[h]); } }
public int totalSizeOfIndexes() { return schema.totalSizeOfIndexes(structureId); }
public boolean setAssociatedObject(final long id, Object localObject) { assert(null!=localObject) : "must not be null, not supported"; int structIdx = extractStructId(id); int fieldIdx = extractFieldPosition(id); return setAssoc(localObject, structIdx, fieldIdx); }
public void setValidator(final long id, JSONRequired isRequired, Object validator) { assert( (null == validator || validator instanceof LongValidator || validator instanceof ByteSequenceValidator || validator instanceof DecimalValidator )) : "unsupported validator"; int structIdx = extractStructId(id); int fieldIdx = extractFieldPosition(id); assert(structIdx < fieldLocals.length); assert(fieldIdx < fieldLocals[structIdx].length); setValidator(isRequired, validator, structIdx, fieldIdx); }
public long modifyStruct(int structId, byte[] fieldName, int fieldPos, int fieldLen, StructType fieldType, int fieldDim) { assert((IS_STRUCT_BIT&structId)!=0) : "must be valid struct"; int idx = STRUCT_MASK & structId; long fieldIdx = fieldIdLookup(this.fields[idx], fieldName, fieldPos, fieldLen, Integer.MAX_VALUE); if (-1 == fieldIdx) { //only creating copy here because we know it will be held for the run. fieldIdx = growStruct(structId, fieldType, fieldDim, Arrays.copyOfRange(fieldName,fieldPos,fieldLen)); } else { ////////// //modify an existing field, we have new data to apply ////////// //use the newest defined type this.fieldTypes[idx][ FIELD_MASK&(int)fieldIdx] = fieldType; //keep largest dim value this.fieldDims[idx][ FIELD_MASK&(int)fieldIdx] = Math.max(this.fieldDims[idx][FIELD_MASK&(int)fieldIdx], fieldDim); } return fieldIdx; }
@Override public long lookupFieldByName(int id, String name) { if ((id & StructRegistry.IS_STRUCT_BIT) == 0) { //this is a route so we must covert to struct id = routerConfig.getStructIdForRouteId(id); } return gm.recordTypeData.fieldLookup(name, id); }
private final boolean matchOneOfTypes(long fieldId, StructType... assoc) { boolean ok = false; StructType fieldType = Pipe.structRegistry(DataInputBlobReader.getBackingPipe(channelReader)).fieldType(fieldId); int i=assoc.length; while (--i>=0) { if (assoc[i]==fieldType) { ok = true; } } return ok; }
public GraphManager(String name) { Arrays.fill(ringIdToStages, -1); Arrays.fill(stageIdToInputsBeginIdx, -1); Arrays.fill(multInputIds, -1); Arrays.fill(stageIdToOutputsBeginIdx, -1); Arrays.fill(multOutputIds, -1); Arrays.fill(notaIdToStageId, -1); Arrays.fill(stageIdToNotasBeginIdx, -1); Arrays.fill(multNotaIds, -1); this.startupTimeNS = System.nanoTime(); this.stageStateData = new GraphManagerStageStateData(); this.recordTypeData = new StructRegistry(); this.name = name; }