-
- All Implemented Interfaces:
-
java.lang.AutoCloseable
public final class MultiPrivacyContextManager extends PrivacyManager
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classMultiPrivacyContextManager.Metricspublic classMultiPrivacyContextManager.Companion
-
Field Summary
Fields Modifier and Type Field Description private final IntegermaxAllowedBadContextsprivate final IntegernumBadContextsprivate final MultiPrivacyContextManager.Metricsmetricsprivate final WebDriverPoolManagerdriverPoolManagerprivate final ProxyPoolManagerproxyPoolManagerprivate final CoreMetricscoreMetricsprivate final ConcurrentHashMap<PrivacyAgent, PrivacyContext>activeContextsprivate final ImmutableConfigconfprivate final BooleanisActiveprivate final BooleanisClosedprivate final PrivacyContextIdGeneratorprivacyContextIdGeneratorprivate final ConcurrentLinkedDeque<PrivacyContext>zombieContexts
-
Constructor Summary
Constructors Constructor Description MultiPrivacyContextManager(WebDriverPoolManager driverPoolManager, ImmutableConfig immutableConfig)MultiPrivacyContextManager(WebDriverPoolManager driverPoolManager, ProxyPoolManager proxyPoolManager, CoreMetrics coreMetrics, ImmutableConfig immutableConfig)
-
Method Summary
Modifier and Type Method Description final IntegergetMaxAllowedBadContexts()final IntegergetNumBadContexts()final MultiPrivacyContextManager.MetricsgetMetrics()final WebDriverPoolManagergetDriverPoolManager()final ProxyPoolManagergetProxyPoolManager()final CoreMetricsgetCoreMetrics()final ConcurrentHashMap<PrivacyAgent, PrivacyContext>getActiveContexts()final ImmutableConfiggetConf()final BooleangetIsActive()final BooleangetIsClosed()PrivacyContextIdGeneratorgetPrivacyContextIdGenerator()final ConcurrentLinkedDeque<PrivacyContext>getZombieContexts()FetchResultrun(FetchTask task, SuspendFunction2<FetchTask, WebDriver, FetchResult> fetchFun)Run a task in a privacy context. BrowserPrivacyContextcreateUnmanagedContext(PrivacyAgent id)Create a privacy context who is not added to the context list. PrivacyContextcomputeNextContext(Fingerprint fingerprint)Try to get a ready privacy context. PrivacyContextcomputeIfNecessary(Fingerprint fingerprint)Gets an under-loaded privacy context, which can be either active or inactive. PrivacyContextcomputeIfAbsent(PrivacyAgent id)Unitmaintain()Maintain all the privacy contexts, check and report inconsistency, illness, idleness, etc., close bad contexts if necessary. Unitclose()-
-
Constructor Detail
-
MultiPrivacyContextManager
MultiPrivacyContextManager(WebDriverPoolManager driverPoolManager, ImmutableConfig immutableConfig)
-
MultiPrivacyContextManager
MultiPrivacyContextManager(WebDriverPoolManager driverPoolManager, ProxyPoolManager proxyPoolManager, CoreMetrics coreMetrics, ImmutableConfig immutableConfig)
-
-
Method Detail
-
getMaxAllowedBadContexts
final Integer getMaxAllowedBadContexts()
-
getNumBadContexts
final Integer getNumBadContexts()
-
getMetrics
final MultiPrivacyContextManager.Metrics getMetrics()
-
getDriverPoolManager
final WebDriverPoolManager getDriverPoolManager()
-
getProxyPoolManager
final ProxyPoolManager getProxyPoolManager()
-
getCoreMetrics
final CoreMetrics getCoreMetrics()
-
getActiveContexts
final ConcurrentHashMap<PrivacyAgent, PrivacyContext> getActiveContexts()
-
getConf
final ImmutableConfig getConf()
-
getIsActive
final Boolean getIsActive()
-
getIsClosed
final Boolean getIsClosed()
-
getPrivacyContextIdGenerator
PrivacyContextIdGenerator getPrivacyContextIdGenerator()
-
getZombieContexts
final ConcurrentLinkedDeque<PrivacyContext> getZombieContexts()
-
run
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
-
createUnmanagedContext
BrowserPrivacyContext createUnmanagedContext(PrivacyAgent id)
Create a privacy context who is not added to the context list.
-
computeNextContext
PrivacyContext computeNextContext(Fingerprint fingerprint)
Try to get a ready privacy context.
If the total number of active contexts is less than the maximum number allowed, a new privacy context will be created.
If the privacy context is inactive, close it and create a new one immediately, and return the new one.
This method can return a non-ready privacy context, in which case the task will be canceled.
A ready privacy context is:
is active
requirement removed not idle
the associated driver pool promises to provide an available driver (but the promise can be failed)
- Parameters:
fingerprint- The fingerprint of this privacy context.
-
computeIfNecessary
PrivacyContext computeIfNecessary(Fingerprint fingerprint)
Gets an under-loaded privacy context, which can be either active or inactive.
If the total number of active contexts is less than the maximum number allowed, a new privacy context will be created.
This method can return an inactive privacy context, in which case, the task should be canceled, and the privacy context should be closed.
- Parameters:
fingerprint- The fingerprint of this privacy context.
-
computeIfAbsent
PrivacyContext computeIfAbsent(PrivacyAgent id)
-
maintain
Unit maintain()
Maintain all the privacy contexts, check and report inconsistency, illness, idleness, etc., close bad contexts if necessary.
If "takePrivacyContextSnapshot" is in file AppPaths.PATH_LOCAL_COMMAND, perform the action.
If the tmp dir is the default one, run the following command to take snapshot once: echo takePrivacyContextSnapshot /tmp/pulsar/pulsar-commands
-
-
-
-