/** * Factory method to build a new root object pool. * * @return The new object pool. */ public static ObjectPool newInstance() { return newInstance(SHARED_POOL); }
/** * Factory method to build a new local object pool. * * @param nextPool The next pool in the chain. Normally the shared pool * @return The new object pool. */ public static ObjectPool newInstance(ObjectPool nextPool) { ObjectPool op; if (nextPool != null) { synchronized (nextPool) { op = (ObjectPool) nextPool.get(TYPE_OBJECTPOOL); } } else { op = null; } if (op != null) { op.init(nextPool); } else { op = new ObjectPool(nextPool); } return op; }
/** * METHOD TO DO * * @param type PARAMETER TO DO * @param key PARAMETER TO DO * @param o PARAMETER TO DO */ public void put(int type, int key, Object o) { assert refCount > 0; if ( (type == TYPE_S_BLOCK) && (key == 8192)) { put(TYPE_BLOCK_8192, o); return; } Key k = newKeyInstance(type, key); ObjectStack os = (ObjectStack) sizedObjectStacks.get(k); if (os == null) { os = newObjectStackInstance(); sizedObjectStacks.put(k, os); } else { put(TYPE_KEY, k); } os.push(o); }
public void close() throws TuplesException { if (lowAVLNode != null) { if (avlNode != null) { avlNode.release(); avlNode = null; } lowAVLNode.release(); lowAVLNode = null; token.release(); token = null; objectPool.release(); objectPool = null; } }
ObjectPool objectPool = ObjectPool.newInstance(); AVLNode node = avlFilePhase.getRootNode(objectPool); if (node == null) { objectPool.release(); return 0; objectPool.release();
/** * Removes a reference to this object pool. * Clears the pool if it is no longer in use. */ public void release() { assert refCount > 0; if (--refCount == 0) { flush(true); } }
/** * Gets a pooled object of a given type and size from this pool. * * @param type The ID of the type of object to find. * @param key The size of the object to find. * @return A pooled object, or <code>null</code> if no objects are available. */ public Object get(int type, int key) { assert refCount > 0; if ( (type == TYPE_S_BLOCK) && (key == 8192)) { return get(TYPE_BLOCK_8192); } Key k = newKeyInstance(type, key); ObjectStack os = (ObjectStack) sizedObjectStacks.get(k); put(TYPE_KEY, k); if ( (os != null) && !os.isEmpty()) { return os.pop(); } if (nextPool != null) { synchronized (nextPool) { return nextPool.get(type, key); } } return null; }
public Object clone() { try { GNodeTuplesImpl t = (GNodeTuplesImpl)super.clone(); t.variables = (Variable[])variables.clone(); if (t.lowAVLNode != null) { t.lowAVLNode.incRefCount(); t.objectPool.incRefCount(); t.token = use(); // Allocate a new token. if (t.avlNode != null) { t.avlNode.incRefCount(); } } return t; } catch (CloneNotSupportedException e) { throw new Error( getClass() + " doesn't support clone, which it must", e ); } }
/** * Gets a pooled object of a given type from this pool. * * @param type The ID of the type of object to find. * @return A pooled object, or <code>null</code> if no objects are available. */ public Object get(int type) { assert refCount > 0; int count = objectStackCounts[type]; if (count > 0) { Object[] os = objectStacks[type]; Object o = os[--count]; os[count] = null; objectStackCounts[type] = count; return o; } if (nextPool != null) { synchronized (nextPool) { return nextPool.get(type); } } return null; }
/** * Constructs an object pool. * * @param nextPool The next pool in the chain. Normally the shared pool. */ private ObjectPool(ObjectPool nextPool) { init(nextPool); }
/** * Closes the file. * * @throws IOException if an I/O error occurs. */ public synchronized void close() throws IOException { try { unmap(); if (objectPool != null) { objectPool.release(); objectPool = null; } } finally { try { if (itemToPhaseSeqMap != null) { itemToPhaseSeqMap.delete(); } } finally { itemToPhaseSeqMap = null; blockFile.close(); } } }
/** * Push all objects out of this pool and into the next (root) pool. */ public void flush() { flush(false); }
nrGNodesValid = true; } else { objectPool.incRefCount(); token = use();
/** * Creates a new ObjectStack. * * @return A fresh {@link ObjectStack}. */ private ObjectStack newObjectStackInstance() { ObjectStack os = (ObjectStack) get(TYPE_OBJECTSTACK); if (os == null) { os = new ObjectStack(OBJECT_STACK_SIZE_LIMIT); } return os; }
/** * Closes and deletes the file. * * @throws IOException if an I/O error occurs. */ public synchronized void delete() throws IOException { try { unmap(); if (objectPool != null) { objectPool.release(); objectPool = null; } } finally { try { if (itemToPhaseSeqMap != null) { itemToPhaseSeqMap.delete(); } } finally { itemToPhaseSeqMap = null; blockFile.delete(); } } }
public synchronized void refresh() { if (readerObjectPool == null) { readerObjectPool = ObjectPool.newInstance(); } synchronized (committedPhaseLock) { Phase committedPhase = committedPhaseToken.getPhase(); if (phase != committedPhase) { if (token != null) { token.release(); } phase = committedPhase; token = phase.use(); } } }
/** * Constructs a FreeList which uses the specified file (if it exists) or * creates a new file (if it doesn't already exist). * * @param objectPool the ObjectPool to use when allocating Blocks. * @param file the file. * @param ioType the IOType to use for the BlockFile. * @throws IOException if an I/O error occurs. */ private FreeList( ObjectPool objectPool, File file, BlockFile.IOType ioType ) throws IOException { this.objectPool = objectPool; objectPool.incRefCount(); this.file = file; blockFile = AbstractBlockFile.openBlockFile(file, BLOCK_SIZE_B, ioType); itemToPhaseSeqMap = IntFile.open(file + INTFILE_EXT); itemToPhaseSeqMap.clear(); }
/** * Factory method to create a new block, allocating a new data buffer. Uses the objectPool * if possible, or else creates a new block that will be returned to the object pool. * * @param objectPool The pool of blocks to get the block from. * @param blockFile The file to get the block from. * @param blockSize The size of the data in the block. * @param blockId The ID of the block from the file. * @param byteOrder Represents little endian or big endian byte ordering. * @return The block from the pool, or a new block which will be returned to the pool. */ public static Block newInstance( ObjectPool objectPool, BlockFile blockFile, int blockSize, long blockId, ByteOrder byteOrder ) { Block block = (Block) objectPool.get(ObjectPool.TYPE_S_BLOCK, blockSize); if (block != null) { block.init(objectPool, blockFile, blockId); } else { block = Block.newInstance( objectPool, blockFile, blockSize, blockId, 0, ByteBuffer.allocateDirect(blockSize).order(byteOrder), null, null, null ); block.ownsBuffer = true; } return block; }