public Map<String, OReentrantResourcePool<String, DB>> getPools() { lock(); try { return Collections.unmodifiableMap(pools); } finally { unlock(); } }
/** * Removes from memory the pool associated to the closed storage. This avoids pool open against closed storages. */ public void onStorageUnregistered(final OStorage iStorage) { final String storageURL = iStorage.getURL(); lock(); try { Set<String> poolToClose = null; for (Entry<String, OReentrantResourcePool<String, DB>> e : pools.entrySet()) { final int pos = e.getKey().indexOf("@"); final String dbName = e.getKey().substring(pos + 1); if (storageURL.equals(dbName)) { if (poolToClose == null) poolToClose = new HashSet<String>(); poolToClose.add(e.getKey()); } } if (poolToClose != null) for (String pool : poolToClose) remove(pool); } finally { unlock(); } }
public int getMaxConnections(final String url, final String userName) { final String dbPooledName = OIOUtils.getUnixFileName(userName + "@" + url); final OReentrantResourcePool<String, DB> pool; lock(); try { pool = pools.get(dbPooledName); } finally { unlock(); } if (pool == null) return maxSize; return pool.getMaxResources(); }
public int getCreatedInstances(String url, String userName) { final String dbPooledName = OIOUtils.getUnixFileName(userName + "@" + url); lock(); try { final OReentrantResourcePool<String, DB> pool = pools.get(dbPooledName); if (pool == null) return 0; return pool.getCreatedInstances(); } finally { unlock(); } }
public int getAvailableConnections(final String url, final String userName) { final String dbPooledName = OIOUtils.getUnixFileName(userName + "@" + url); final OReentrantResourcePool<String, DB> pool; lock(); try { pool = pools.get(dbPooledName); } finally { unlock(); } if (pool == null) return 0; return pool.getAvailableResources(); }
public int getConnectionsInCurrentThread(final String url, final String userName) { final String dbPooledName = OIOUtils.getUnixFileName(userName + "@" + url); final OReentrantResourcePool<String, DB> pool; lock(); try { pool = pools.get(dbPooledName); } finally { unlock(); } if (pool == null) return 0; return pool.getConnectionsInCurrentThread(url); }
public DB acquire(final String iURL, final String iUserName, final String iUserPassword, final Map<String, Object> iOptionalParams) throws OLockException { final String dbPooledName = OIOUtils.getUnixFileName(iUserName + "@" + iURL); OReentrantResourcePool<String, DB> pool; lock(); try { pool = pools.get(dbPooledName); if (pool == null) // CREATE A NEW ONE pool = new OReentrantResourcePool<String, DB>(maxSize, this); // PUT IN THE POOL MAP ONLY IF AUTHENTICATION SUCCEED pools.put(dbPooledName, pool); } finally { unlock(); } final DB db = pool.getResource(iURL, timeout, iUserName, iUserPassword, iOptionalParams); return db; }
/** * Closes all the databases. */ public void close() { lock(); try { if (this.evictionTask != null) { this.evictionTask.cancel(); } for (Entry<String, OReentrantResourcePool<String, DB>> pool : pools.entrySet()) { for (DB db : pool.getValue().getResources()) { pool.getValue().close(); try { OLogManager.instance().debug(this, "Closing pooled database '%s'...", db.getName()); ((ODatabasePooled) db).forceClose(); OLogManager.instance().debug(this, "OK", db.getName()); } catch (Exception e) { OLogManager.instance().debug(this, "Error: %d", e.toString()); } } } } finally { unlock(); } }
public void release(final DB iDatabase) { // REMOVE ANY INTENT BEFORE. THIS RESTORE ANYTHING BEFORE THE CLOSE, LIKE THE USER NAME IN CASE OF MASSIVE INSERT iDatabase.declareIntent(null); final String dbPooledName = iDatabase.getUser().getName() + "@" + iDatabase.getURL(); final OReentrantResourcePool<String, DB> pool; lock(); try { pool = pools.get(dbPooledName); } finally { unlock(); } if (pool == null) throw new OLockException("Cannot release a database URL not acquired before. URL: " + iDatabase.getName()); if (pool.returnResource(iDatabase)) this.notifyEvictor(dbPooledName, iDatabase); }
public void remove(final String iPoolName) { lock(); try { final OReentrantResourcePool<String, DB> pool = pools.remove(iPoolName); if (pool != null) { for (DB db : pool.getResources()) { final OStorage stg = db.getStorage(); if (stg != null && stg.getStatus() == OStorage.STATUS.OPEN) try { OLogManager.instance().debug(this, "Closing pooled database '%s'...", db.getName()); db.activateOnCurrentThread(); ((ODatabasePooled) db).forceClose(); OLogManager.instance().debug(this, "OK", db.getName()); } catch (Exception e) { OLogManager.instance().debug(this, "Error: %d", e.toString()); } } pool.close(); } } finally { unlock(); } }