Class PrivacyManager
-
- All Implemented Interfaces:
-
java.lang.AutoCloseable
public abstract class PrivacyManager implements AutoCloseable
Manage the privacy contexts.
-
-
Field Summary
Fields Modifier and Type Field Description private final ConcurrentHashMap<PrivacyAgent, PrivacyContext>permanentContextsprivate final ConcurrentHashMap<PrivacyAgent, PrivacyContext>temporaryContextsprivate final Map<PrivacyAgent, PrivacyContext>activeContextsprivate final ConcurrentLinkedDeque<PrivacyContext>zombieContextsprivate final ObjectcontextLifeCycleMonitorprivate final PrivacyContextIdGeneratorprivacyContextIdGeneratorprivate final BooleanisClosedprivate final BooleanisActiveprivate final ImmutableConfigconf
-
Constructor Summary
Constructors Constructor Description PrivacyManager(ImmutableConfig conf)
-
Method Summary
Modifier and Type Method Description final ConcurrentHashMap<PrivacyAgent, PrivacyContext>getPermanentContexts()life cycle of the permanent context is relatively long. final ConcurrentHashMap<PrivacyAgent, PrivacyContext>getTemporaryContexts()The life cycle of the temporary context is very short. final Map<PrivacyAgent, PrivacyContext>getActiveContexts()final ConcurrentLinkedDeque<PrivacyContext>getZombieContexts()final ObjectgetContextLifeCycleMonitor()PrivacyContextIdGeneratorgetPrivacyContextIdGenerator()final BooleanisClosed()final BooleanisActive()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 PrivacyContextcomputeNextContext(WebPage page, Fingerprint fingerprint, FetchTask task)Create a new context or return an existing one. abstract PrivacyContextcomputeIfNecessary(Fingerprint fingerprint)Create a new context or return an existing one abstract PrivacyContextcomputeIfNecessary(WebPage page, Fingerprint fingerprint, FetchTask task)Create a new context or return an existing one abstract PrivacyContextcomputeIfAbsent(PrivacyAgent privacyAgent)Create a context with privacyAgent and add it to active context list if not absent abstract PrivacyContextcreateUnmanagedContext(PrivacyAgent privacyAgent)Create a context and do not add to active context list StringtakeSnapshot()Unitmaintain()Unitclose(PrivacyContext privacyContext)Close a given privacy context, remove it from the active list and add it to the zombie list. Unitclose()Close the privacy manager. Unitreset()Reset the privacy environment, close all privacy contexts, so all fetch tasks are handled by new browser contexts. -
-
Method Detail
-
getPermanentContexts
final ConcurrentHashMap<PrivacyAgent, PrivacyContext> getPermanentContexts()
life cycle of the permanent context is relatively long. The system will never delete the permanent contexts.
The predefined privacy agents for permanent contexts are:
PrivacyAgent.USER_DEFAULT
PrivacyAgent.PROTOTYPE
PrivacyAgent.DEFAULT
-
getTemporaryContexts
final ConcurrentHashMap<PrivacyAgent, PrivacyContext> getTemporaryContexts()
The life cycle of the temporary context is very short. Whenever the system detects that the privacy context is leaked, the system discards the leaked context and creates a new one.
NOTE: we can use a priority queue and every time we need a context, take the top one
-
getActiveContexts
final Map<PrivacyAgent, PrivacyContext> getActiveContexts()
-
getZombieContexts
final ConcurrentLinkedDeque<PrivacyContext> getZombieContexts()
-
getContextLifeCycleMonitor
final Object getContextLifeCycleMonitor()
-
getPrivacyContextIdGenerator
PrivacyContextIdGenerator getPrivacyContextIdGenerator()
-
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
@Deprecated(message = "Use computeNextContext(task, fingerprint)", replaceWith = @ReplaceWith(imports = {}, expression = "computeNextContext(FetchTask, Fingerprint)")) abstract PrivacyContext computeNextContext(Fingerprint fingerprint)
Create a new context or return an existing one.
-
computeNextContext
abstract PrivacyContext computeNextContext(WebPage page, Fingerprint fingerprint, FetchTask task)
Create a new context or return an existing one.
-
computeIfNecessary
@Deprecated(message = "Use computeIfNecessary(task, fingerprint)", replaceWith = @ReplaceWith(imports = {}, expression = "computeIfNecessary(FetchTask, Fingerprint)")) abstract PrivacyContext computeIfNecessary(Fingerprint fingerprint)
Create a new context or return an existing one
-
computeIfNecessary
abstract PrivacyContext computeIfNecessary(WebPage page, Fingerprint fingerprint, FetchTask task)
Create a new context or return an existing one
-
computeIfAbsent
abstract PrivacyContext computeIfAbsent(PrivacyAgent privacyAgent)
Create a context with privacyAgent and add it to active context list if not absent
-
createUnmanagedContext
abstract PrivacyContext createUnmanagedContext(PrivacyAgent privacyAgent)
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()
Close the privacy manager. All active contexts are also be closed.
Closing call stack:
PrivacyManager.close -> PrivacyContext.close -> WebDriverContext.close -> WebDriverPoolManager.close -> BrowserManager.close -> Browser.close -> WebDriver.close |-> LoadingWebDriverPool.close
-
-
-
-