public int lookupAlias(int sessionId) { return IntHashTable.getItem(aliasStructIdTable, sessionId); }
public int lookupAlias(int sessionId) { return IntHashTable.getItem(aliasStructIdTable, sessionId); }
public static <T> int lookupIndexOffset(StructRegistry that, T attachedObject, int structId) { assert ((IS_STRUCT_BIT&structId) !=0 && (structId>0) ) : "Struct Id must be passed in, got "+structId; int hash = attachedObject.hashCode(); int idx = IntHashTable.getItem(that.fieldAttachedIndex[STRUCT_MASK&structId], hash); if (0==idx) { if (!IntHashTable.hasItem(that.fieldAttachedIndex[STRUCT_MASK&structId], hash)) { throw new UnsupportedOperationException("Object not found: "+attachedObject+" in structure "+structId+" obj hash "+hash); } } return idx; }
public int structLookupByIdentity(Object assoc) { final int hash = assoc.hashCode(); final int idx = IntHashTable.getItem(structTable, hash); if (0==idx) { if (!IntHashTable.hasItem(structTable, hash)) { throw new UnsupportedOperationException("Object not found: "+assoc); } } return idx; }
public static HTTPContentType lookupContentTypeByFullPathExtension(HTTPSpecification httpSpec, String resourceName) { int idxOfDot = resourceName.lastIndexOf('.'); int typeIdx = 0; if (idxOfDot>=0) { int extHash = HTTPSpecification.extHash(resourceName.substring(idxOfDot+1, resourceName.length())); //value will be zero if not found typeIdx = IntHashTable.getItem(httpSpec.fileExtHashTable, extHash); } return (HTTPContentType)httpSpec.contentTypes[typeIdx]; }
public int structLookupByIdentity(Object assoc) { final int hash = assoc.hashCode(); final int idx = IntHashTable.getItem(structTable, hash); if (0==idx) { if (!IntHashTable.hasItem(structTable, hash)) { throw new UnsupportedOperationException("Object not found: "+assoc); } } return idx; }
public static <T> int lookupIndexOffset(StructRegistry that, T attachedObject, int structId) { assert ((IS_STRUCT_BIT&structId) !=0 && (structId>0) ) : "Struct Id must be passed in, got "+structId; int hash = attachedObject.hashCode(); int idx = IntHashTable.getItem(that.fieldAttachedIndex[STRUCT_MASK&structId], hash); if (0==idx) { if (!IntHashTable.hasItem(that.fieldAttachedIndex[STRUCT_MASK&structId], hash)) { throw new UnsupportedOperationException("Object not found: "+attachedObject+" in structure "+structId+" obj hash "+hash); } } return idx; }
public static <T> int lookupIndexOffset(StructRegistry that, T attachedObject, int structId, int hash) { assert ((IS_STRUCT_BIT&structId) !=0 && (structId>0) ) : "Struct Id must be passed in, got "+structId; int idx = IntHashTable.getItem(that.fieldAttachedIndex[STRUCT_MASK&structId], hash); if (0==idx) { if (!IntHashTable.hasItem(that.fieldAttachedIndex[STRUCT_MASK&structId], hash)) { throw new UnsupportedOperationException("Object not found: "+attachedObject); } } return idx; }
public int structLookupByIdentity(Object assoc) { final int hash = assoc.hashCode(); final int idx = IntHashTable.getItem(structTable, hash); if (0==idx) { if (!IntHashTable.hasItem(structTable, hash)) { throw new UnsupportedOperationException("Object not found: "+assoc); } } return idx; }
public int lookupRouteIdByIdentity(Object associatedObject) { final int hash = associatedObject.hashCode(); final int idx = IntHashTable.getItem(routeIdTable, hash); if (0==idx) { if (!IntHashTable.hasItem(routeIdTable, hash)) { throw new UnsupportedOperationException("Object not found: "+associatedObject); } } return idx; }
public static HTTPContentType lookupContentTypeByExtension(HTTPSpecification httpSpec, String ext) { //value will be zero if not found return (HTTPContentType)httpSpec.contentTypes[IntHashTable.getItem(httpSpec.fileExtHashTable, HTTPSpecification.extHash(ext))]; }
private int rootId(int id, IntHashTable hashTable) { int item = 0; int orig = id; do { if (id<lastKnownRoot.length && lastKnownRoot[id]!=0) { id = lastKnownRoot[id]; } //this code must only read the hash table item = IntHashTable.getItem(hashTable, id); if (item!=0) { cacheLastKnown(orig, item); id = item; } } while (item!=0); return id; }
private static int rootId(int id, IntHashTable hashTable, IntArrayHolder lastKnownRoot) { //skip any non stages, this happens in unit tests. if (id<0) { return -1; } int item = 0; int orig = id; do { if (id<lastKnownRoot.data.length && lastKnownRoot.data[id]!=0) { id = lastKnownRoot.data[id]; } //this code must only read the hash table item = IntHashTable.getItem(hashTable, id); if (item!=0) { lastKnownRoot.growIfNeeded(orig); lastKnownRoot.data[orig]=item; id = item; } } while (item!=0); return id; }
/** * * @param child Object arg used for System.identityHashCode * @param topParent Object arg used for System.identityHashCode * @param usageChecker IntHashTable arg compared against parentHash * @return if IntHashTable.hasItem and parentHash!=IntHashTable return false else true */ public static boolean notPreviouslyHeld(Object child, Object topParent, IntHashTable usageChecker) { int hash = System.identityHashCode(child); int parentHash = System.identityHashCode(topParent); if (IntHashTable.hasItem(usageChecker, hash)) { if (parentHash!=IntHashTable.getItem(usageChecker, hash)) { return false; } } //keep so this is detected later if use IntHashTable.setItem(usageChecker, hash, parentHash); return true; } ///////////
private static < T extends Enum<T> & HTTPContentType> IntHashTable buildFileExtHashTable(Class<T> supportedHTTPContentTypes) { int hashBits = 13; //8K IntHashTable localExtTable = new IntHashTable(hashBits); T[] conentTypes = supportedHTTPContentTypes.getEnumConstants(); int c = conentTypes.length; while (--c >= 0) { if (!conentTypes[c].isAlias()) {//never use an alias for the file Ext lookup. int hash = HTTPSpecification.extHash(conentTypes[c].fileExtension()); if ( IntHashTable.hasItem(localExtTable, hash) ) { final int ord = IntHashTable.getItem(localExtTable, hash); throw new UnsupportedOperationException("Hash error, check for new values and algo. "+conentTypes[c].fileExtension()+" colides with existing "+conentTypes[ord].fileExtension()); } else { IntHashTable.setItem(localExtTable, hash, conentTypes[c].ordinal()); } } } return localExtTable; }
private boolean addAssocHashToTable(Object localObject, int structIdx, int fieldIdx) { if (null==this.fieldAttachedIndex[structIdx]) { this.fieldAttachedIndex[structIdx] = new IntHashTable( IntHashTable.computeBits(this.fieldLocals[structIdx].length*2) ); } int hashCode = localObject.hashCode(); assert(0!=hashCode) : "can not insert null"; assert(!IntHashTable.hasItem(this.fieldAttachedIndex[structIdx], hashCode)) : "These objects are too similar or was attached twice, Hash must be unique. Choose different objects"; if (IntHashTable.hasItem(this.fieldAttachedIndex[structIdx], hashCode)) { logger.warn("Unable to add object {} as an association, Another object with an identical Hash is already held. Try a different object.", localObject); return false; } else { if (!IntHashTable.setItem(this.fieldAttachedIndex[structIdx], hashCode, fieldIdx)) { //we are out of space this.fieldAttachedIndex[structIdx] = IntHashTable.doubleSize(this.fieldAttachedIndex[structIdx]); if (!IntHashTable.setItem(this.fieldAttachedIndex[structIdx], hashCode, fieldIdx)) { throw new RuntimeException("internal error"); } } else { //logger.info("{} set object {} to index {}",structIdx, localObject, fieldIdx); } assert(fieldIdx == IntHashTable.getItem(this.fieldAttachedIndex[structIdx], hashCode)); return true; } }
void unsubscribe(Pipe<MessagePubSub> pipe) { int hash = PipeReader.readInt(pipe, MessagePubSub.MSG_UNSUBSCRIBE_101_FIELD_SUBSCRIBERIDENTITYHASH_4); final short pipeIdx = (short)IntHashTable.getItem(subscriptionPipeLookup, hash); assert(pipeIdx>=0) : "Must have valid pipe index"; final byte[] backing = PipeReader.readBytesBackingArray(pipe, MessagePubSub.MSG_UNSUBSCRIBE_101_FIELD_TOPIC_1); final int pos = PipeReader.readBytesPosition(pipe, MessagePubSub.MSG_UNSUBSCRIBE_101_FIELD_TOPIC_1); final int len = PipeReader.readBytesLength(pipe, MessagePubSub.MSG_UNSUBSCRIBE_101_FIELD_TOPIC_1); final int mask = PipeReader.readBytesMask(pipe, MessagePubSub.MSG_UNSUBSCRIBE_101_FIELD_TOPIC_1); unsubscribe(pipeIdx, backing, pos, len, mask); }
void addSubscription(Pipe<MessagePubSub> pipe) { //hash of the subscribing object int hash = PipeReader.readInt(pipe, MessagePubSub.MSG_SUBSCRIBE_100_FIELD_SUBSCRIBERIDENTITYHASH_4); //convert the hash into the specific outgoing pipe where this will go final short pipeIdx = (short)IntHashTable.getItem(subscriptionPipeLookup, hash); assert(pipeIdx>=0) : "Must have valid pipe index"; final byte[] backing = PipeReader.readBytesBackingArray(pipe, MessagePubSub.MSG_SUBSCRIBE_100_FIELD_TOPIC_1); final int pos = PipeReader.readBytesPosition(pipe, MessagePubSub.MSG_SUBSCRIBE_100_FIELD_TOPIC_1); final int len = PipeReader.readBytesLength(pipe, MessagePubSub.MSG_SUBSCRIBE_100_FIELD_TOPIC_1); final int mask = PipeReader.readBytesMask(pipe, MessagePubSub.MSG_SUBSCRIBE_100_FIELD_TOPIC_1); addSubscription(pipeIdx, backing, pos, len, mask); }
protected void consumeStoreWriteAck(int index, Object target, Pipe<PersistedBlobLoadProducerSchema> p) { final int store = IntHashTable.getItem(serialStoreProdAckPipeMap, NON_ZERO_BASE+p.id)-NON_ZERO_BASE; while (Pipe.hasContentToRead(p)) { Pipe.markTail(p); int msgIdx = Pipe.takeMsgIdx(p); if (msgIdx == PersistedBlobLoadProducerSchema.MSG_ACKWRITE_11) { long value = Pipe.takeLong(p); if (!((SerialStoreProducerAckListener)target).producerAck(store, value)) { Pipe.resetTail(p); return;//continue later and repeat this same value. } } else { logger.error("unrecognized message on {} ",p); throw new UnsupportedOperationException("unexpected message "+msgIdx); } Pipe.confirmLowLevelRead(p, Pipe.sizeOf(p,msgIdx)); Pipe.releaseReadLock(p); } }
protected void consumeStoreReleaseAck(int index, Object target, Pipe<PersistedBlobLoadReleaseSchema> p) { final int store = IntHashTable.getItem(serialStoreRelAckPipeMap, NON_ZERO_BASE+p.id)-NON_ZERO_BASE; while (Pipe.hasContentToRead(p)) { Pipe.markTail(p); int msgIdx = Pipe.takeMsgIdx(p); if (msgIdx == PersistedBlobLoadReleaseSchema.MSG_ACKRELEASE_10) { long value = Pipe.takeLong(p); if (!((SerialStoreReleaseAckListener)target).releaseAck(store, value)) { Pipe.resetTail(p); return;//continue later and repeat this same value. } } else { logger.error("unrecognized message on {} ",p); throw new UnsupportedOperationException("unexpected message "+msgIdx); } Pipe.confirmLowLevelRead(p, Pipe.sizeOf(p,msgIdx)); Pipe.releaseReadLock(p); } }