public class OCachedDatabasePoolFactoryImpl extends Object implements OCachedDatabasePoolFactory
OCachedDatabasePoolFactory
Used in OrientDBEmbedded
by default
Works like LRU cache
How it works: 1. Pool cache capacity is 100 2. We have 100 pools in cache 3. We want get 101 pool 4. First we will remove pool which used long time ago from pool cache 5. Then we add new pool from point 3 to pool cache
Constructor and Description |
---|
OCachedDatabasePoolFactoryImpl(OrientDBInternal orientDB,
int capacity,
long timeout) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Close all open pools and clear pool storage.
|
ODatabasePoolInternal |
get(String database,
String username,
String password,
OrientDBConfig parentConfig)
Get or create database pool instance for given user
|
int |
getMaxPoolSize() |
boolean |
isClosed()
Check if factory is closed
|
OCachedDatabasePoolFactory |
reset()
Close all open pools and clear pool storage
|
protected void |
scheduleCleanUpCache(TimerTask task) |
OCachedDatabasePoolFactory |
setMaxPoolSize(int maxPoolSize)
Set max pool connections size which will be used for create new
ODatabasePool |
public OCachedDatabasePoolFactoryImpl(OrientDBInternal orientDB, int capacity, long timeout)
orientDB
- instance of OrientDB
which will be used for create new database pools
ODatabasePoolInternal
capacity
- capacity of pool cache, by default is 100timeout
- timeout in milliseconds which means that every timeout will be executed task for
clean up cache from closed poolsprotected void scheduleCleanUpCache(TimerTask task)
public ODatabasePoolInternal get(String database, String username, String password, OrientDBConfig parentConfig)
Get or create database pool: 1. Create string database + username + password 2. Create key by hashing this string using SHA-256 3. Try to get pool from cache 4. If pool is in cache and pool is not closed, so return this pool 5. If pool is not in cache or pool is closed, so create new pool and put it in cache
get
in interface OCachedDatabasePoolFactory
database
- name of databaseusername
- name of user which need access to databasepassword
- user passwordODatabasePoolInternal
which is new instance of pool or instance from pool
storagepublic OCachedDatabasePoolFactory reset()
reset
in interface OCachedDatabasePoolFactory
public void close()
OCachedDatabasePoolFactory
after close one of
factories.close
in interface OCachedDatabasePoolFactory
public boolean isClosed()
OCachedDatabasePoolFactory
isClosed
in interface OCachedDatabasePoolFactory
public int getMaxPoolSize()
public OCachedDatabasePoolFactory setMaxPoolSize(int maxPoolSize)
ODatabasePool
maxPoolSize
- max pool connections sizeCopyright © 2009–2020 OrientDB. All rights reserved.