Class OCachedDatabasePoolFactoryImpl
java.lang.Object
com.orientechnologies.orient.core.db.OCachedDatabasePoolFactoryImpl
- All Implemented Interfaces:
OCachedDatabasePoolFactory
Default implementation of
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
- Author:
- Vitalii Honchar (weaxme@gmail.com)
-
Constructor Summary
ConstructorsConstructorDescriptionOCachedDatabasePoolFactoryImpl(OrientDBInternal orientDB, int capacity, long timeout) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close all open pools and clear pool storage.get(String database, String username, String password, OrientDBConfig parentConfig) Get or create database pool instance for given userintbooleanisClosed()Check if factory is closedreset()Close all open pools and clear pool storageprotected voidsetMaxPoolSize(int maxPoolSize) Set max pool connections size which will be used for create newODatabasePool
-
Constructor Details
-
OCachedDatabasePoolFactoryImpl
- Parameters:
orientDB- instance ofOrientDBwhich will be used for create new database poolsODatabasePoolInternalcapacity- 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 pools
-
-
Method Details
-
scheduleCleanUpCache
-
get
public ODatabasePoolInternal get(String database, String username, String password, OrientDBConfig parentConfig) Get or create database pool instance for given userGet 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
- Specified by:
getin interfaceOCachedDatabasePoolFactory- Parameters:
database- name of databaseusername- name of user which need access to databasepassword- user password- Returns:
ODatabasePoolInternalwhich is new instance of pool or instance from pool storage
-
reset
Close all open pools and clear pool storage- Specified by:
resetin interfaceOCachedDatabasePoolFactory- Returns:
- this instance
-
close
public void close()Close all open pools and clear pool storage. Set flag closed to true, so this instance can't be used again. Need create new instance ofOCachedDatabasePoolFactoryafter close one of factories.- Specified by:
closein interfaceOCachedDatabasePoolFactory
-
isClosed
public boolean isClosed()Description copied from interface:OCachedDatabasePoolFactoryCheck if factory is closed- Specified by:
isClosedin interfaceOCachedDatabasePoolFactory- Returns:
- true if factory is closed
-
getMaxPoolSize
public int getMaxPoolSize()- Returns:
- max pool size. Default is 64
-
setMaxPoolSize
Set max pool connections size which will be used for create newODatabasePool- Parameters:
maxPoolSize- max pool connections size- Returns:
- this instance
-