public class TemporaryAccountPool
extends java.lang.Object
TemporaryAccount
structure.
When an item is requested from pool the item is removed form pool and the associated
account is enabled before returned to caller.
If the pool is empty the current thread will wait for an specified amount of time to
get an item returned to pool by other threads.
When an item is returned to pool first the associated account is disabled than the item
is enqueued at the tail of the pool and other threads waiting for an item are notified.
In order to manipulate user accounts special permissions are mandatory.
A dedicated worker thread is spawned on start-up and is used to manage user accounts at
runtime. This daemon thread is running on server security context having admin permissions.Modifier and Type | Class and Description |
---|---|
private static class |
TemporaryAccountPool.ManagerHolder
Helper clasee for the lazt initialization of the TemporaryAccountPool instance
|
Modifier and Type | Field and Description |
---|---|
static int |
GEN_DIGITS
Random generator digits
|
static int |
GEN_LENGTH
Random generator length
|
static int |
GEN_SYMBOLS
Random generator symbols
|
private static java.util.logging.Logger |
LOG
Logger.
|
private static java.util.concurrent.BlockingQueue<TemporaryAccount> |
pool
FIFO Pool
|
private static TemporaryAccountPool |
poolManager
Pool Manager instance
|
private static int |
poolSize
Pool size
|
private static TemporaryAccountWorker |
poolTask
Task used to change the user account status
|
private static java.lang.Object |
taskLock
poolTask guard
|
private static java.lang.String |
TEMP_GROUP
Temporary accounts group name
|
private static long |
timeout
Timeout
|
private static AssociatedThread |
worker
A daemon worker thread having a security context which allow to change user account.
|
Constructor and Description |
---|
TemporaryAccountPool() |
Modifier and Type | Method and Description |
---|---|
private static void |
createGroupIfNotExists()
Check if temporary group exists.
|
private static void |
createTemporaryAccounts()
Create new temporary accounts
|
(package private) static TemporaryAccount |
createUser(boolean enabled)
Create a temporary user.
|
private static void |
deleteTemporaryAccounts()
Delete all temporary accounts.
|
private void |
enableAccount(TemporaryAccount item,
boolean enabled)
Enable / disable temporary account.
|
static TemporaryAccountPool |
getInstance()
Create and return the pool manager instance.
|
TemporaryAccount |
poll()
Get and remove an item from pool.
|
static void |
shutDown()
Shut down worker thread.
|
private static void |
startUp()
Startup worker thread.
|
void |
tail(TemporaryAccount item)
Disable temporary account and return the item to pool.
|
private static final java.util.logging.Logger LOG
private static final java.lang.String TEMP_GROUP
public static final int GEN_LENGTH
public static final int GEN_DIGITS
public static final int GEN_SYMBOLS
private static final java.util.concurrent.BlockingQueue<TemporaryAccount> pool
private static volatile TemporaryAccountPool poolManager
private static TemporaryAccountWorker poolTask
private static final java.lang.Object taskLock
private static AssociatedThread worker
private static long timeout
private static int poolSize
private static void createTemporaryAccounts()
private static void deleteTemporaryAccounts()
private static void createGroupIfNotExists()
static TemporaryAccount createUser(boolean enabled)
enabled
- Initial account status.public static TemporaryAccountPool getInstance()
private static void startUp()
public static void shutDown()
public TemporaryAccount poll()
public void tail(TemporaryAccount item)
item
- A TemporaryAccount item returned to pool.private void enableAccount(TemporaryAccount item, boolean enabled)
item
- Account pool item.enabled
- true
enable account.
false
disable account.