-
- All Implemented Interfaces:
-
java.lang.AutoCloseable
public abstract class PrivacyManager implements AutoCloseable
-
-
Field Summary
Fields Modifier and Type Field Description private final ConcurrentLinkedDeque<PrivacyContext>zombieContextsprivate final ConcurrentHashMap<PrivacyAgent, PrivacyContext>activeContextsprivate final PrivacyContextIdGeneratorprivacyContextIdGeneratorprivate final BooleanisClosedprivate final BooleanisActiveprivate final ImmutableConfigconf
-
Constructor Summary
Constructors Constructor Description PrivacyManager(ImmutableConfig conf)
-
Method Summary
Modifier and Type Method Description final ConcurrentLinkedDeque<PrivacyContext>getZombieContexts()final ConcurrentHashMap<PrivacyAgent, PrivacyContext>getActiveContexts()NOTE: we can use a priority queue and every time we need a context, take the top one PrivacyContextIdGeneratorgetPrivacyContextIdGenerator()final BooleangetIsClosed()final BooleangetIsActive()final ImmutableConfiggetConf()abstract FetchResultrun(FetchTask task, SuspendFunction2<FetchTask, WebDriver, FetchResult> fetchFun)Run a task in a privacy context. abstract PrivacyContextcomputeNextContext(Fingerprint fingerprint)Create a new context or return an existing one. abstract PrivacyContextcomputeIfNecessary(Fingerprint fingerprint)Create a new context or return an existing one abstract PrivacyContextcomputeIfAbsent(PrivacyAgent id)Create a context with id and add it to active context list if not absent abstract PrivacyContextcreateUnmanagedContext(PrivacyAgent id)Create a context and do not add to active context list StringtakeSnapshot()Unitclose(PrivacyContext privacyContext)Close a given privacy context, remove it from the active list and add it to the zombie list. Unitclose()Closing call stack:PrivacyManager.close -> PrivacyContext.close -> WebDriverContext.close -> WebDriverPoolManager.close -> BrowserManager.close -> Browser.close -> WebDriver.close |-> LoadingWebDriverPool. Unitmaintain()-
-
Method Detail
-
getZombieContexts
final ConcurrentLinkedDeque<PrivacyContext> getZombieContexts()
-
getActiveContexts
final ConcurrentHashMap<PrivacyAgent, PrivacyContext> getActiveContexts()
NOTE: we can use a priority queue and every time we need a context, take the top one
-
getPrivacyContextIdGenerator
PrivacyContextIdGenerator getPrivacyContextIdGenerator()
-
getIsClosed
final Boolean getIsClosed()
-
getIsActive
final Boolean getIsActive()
-
getConf
final ImmutableConfig getConf()
-
run
abstract FetchResult run(FetchTask task, SuspendFunction2<FetchTask, WebDriver, FetchResult> fetchFun)
Run a task in a privacy context.
The privacy context is selected from the active privacy context pool, and it is supposed to have at least one ready web driver to run the task.
If the privacy context chosen is not ready to serve, especially, it has no any ready web driver, the task will be canceled.
- Parameters:
task- the fetch taskfetchFun- the fetch function
-
computeNextContext
abstract PrivacyContext computeNextContext(Fingerprint fingerprint)
Create a new context or return an existing one.
-
computeIfNecessary
abstract PrivacyContext computeIfNecessary(Fingerprint fingerprint)
Create a new context or return an existing one
-
computeIfAbsent
abstract PrivacyContext computeIfAbsent(PrivacyAgent id)
Create a context with id and add it to active context list if not absent
-
createUnmanagedContext
abstract PrivacyContext createUnmanagedContext(PrivacyAgent id)
Create a context and do not add to active context list
-
takeSnapshot
String takeSnapshot()
-
close
Unit close(PrivacyContext privacyContext)
Close a given privacy context, remove it from the active list and add it to the zombie list. No exception.
-
close
Unit close()
Closing call stack:
PrivacyManager.close -> PrivacyContext.close -> WebDriverContext.close -> WebDriverPoolManager.close -> BrowserManager.close -> Browser.close -> WebDriver.close |-> LoadingWebDriverPool.close
-
-
-
-