Class AbstractPrivacyContext
-
- All Implemented Interfaces:
-
ai.platon.pulsar.skeleton.crawl.fetch.privacy.PrivacyContext,java.lang.AutoCloseable,kotlin.Comparable
public abstract class AbstractPrivacyContext implements PrivacyContext, Comparable<PrivacyContext>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classAbstractPrivacyContext.Companion
-
Field Summary
-
Constructor Summary
Constructors Constructor Description AbstractPrivacyContext(PrivacyAgent privacyAgent, ImmutableConfig conf)
-
Method Summary
Modifier and Type Method Description final WebDriverFetchergetWebdriverFetcher()final UnitsetWebdriverFetcher(WebDriverFetcher webdriverFetcher)PrivacyAgentIdgetId()The privacy context id. final IntegergetSeq()StringgetDisplay()A readable privacy context display. final PathgetBaseDir()final FloatgetMinimumThroughput()final IntegergetMaximumWarnings()final IntegergetMinorWarningFactor()final AtomicIntegergetPrivacyLeakWarnings()final AtomicIntegergetPrivacyLeakMinorWarnings()final MetergetMeterTasks()final MetergetMeterSuccesses()final MetergetMeterFinishes()final MetergetMeterSmallPages()final DoublegetSmallPageRate()final FloatgetSuccessRate()FloatgetFailureRate()The failure rate of the privacy context. final FloatgetFailureRateThreshold()BooleanisHighFailureRate()Check whether the failure rate is high. final InstantgetStartTime()The start time of the privacy context. final InstantgetLastActiveTime()The last active time of the privacy context. DurationgetElapsedTime()The elapsed time of the privacy context. DurationgetIdleTime()The idle time of the privacy context. BooleanisIdle()Check whether the privacy context is idle. BooleanisGood()Check whether the privacy context is good. BooleanisLeaked()Check whether the privacy context is leaked. BooleanisRetired()Check whether the privacy context is retired. BooleanisActive()Check whether the privacy context is active. BooleanisClosed()Check whether the privacy context is closed. BooleanisReady()A ready privacy context is ready to serve tasks. BooleanisFullCapacity()Check whether the privacy context is at full capacity. BooleanisUnderLoaded()Check whether the privacy context is running under loaded. StringgetReadableState()Get the readable privacy context state. PrivacyAgentgetPrivacyAgent()The associated privacy agent. final ImmutableConfiggetConf()abstract IntegerpromisedWebDriverCount()The promised workers (free web drivers) count. BooleanhasWebDriverPromise()Check if the privacy context promises at least one worker to provide. abstract WebDriversubscribeWebDriver()final UnitmarkSuccess()Marks a task as successful and updates relevant metrics. final UnitmarkWarning()Mark a warning. final UnitmarkWarning(Integer n)Mark n warnings. final UnitmarkMinorWarning()Mark a minor warnings. final UnitmarkLeaked()Mark the privacy context as leaked. abstract FetchResultopen(String url)Open an url in the privacy context. abstract FetchResultopen(String url, LoadOptions options)Open an url in the privacy context, with the specified options. FetchResultopen(String url, SuspendFunction2<FetchTask, WebDriver, FetchResult> fetchFun)Open an url in the privacy context, with the specified fetch function. FetchResultrun(FetchTask task, SuspendFunction2<FetchTask, WebDriver, FetchResult> fetchFun)Run a task in the privacy context, with the specified fetch function. abstract FetchResultdoRun(FetchTask task, SuspendFunction2<FetchTask, WebDriver, FetchResult> fetchFun)Run a task in the privacy context. StringbuildStatusString()Build the privacy context status string. Unitdismiss()Dismisses the privacy context and marks it as retired, indicating that it should be closed later. abstract Unitmaintain()Do the maintaining jobs. IntegercompareTo(PrivacyContext other)Booleanequals(Object other)IntegerhashCode()StringbuildReport()Build the privacy context report. Unitreport()-
-
Constructor Detail
-
AbstractPrivacyContext
AbstractPrivacyContext(PrivacyAgent privacyAgent, ImmutableConfig conf)
-
-
Method Detail
-
getWebdriverFetcher
final WebDriverFetcher getWebdriverFetcher()
-
setWebdriverFetcher
final Unit setWebdriverFetcher(WebDriverFetcher webdriverFetcher)
-
getId
PrivacyAgentId getId()
The privacy context id.
-
getDisplay
String getDisplay()
A readable privacy context display.
-
getBaseDir
final Path getBaseDir()
-
getMinimumThroughput
final Float getMinimumThroughput()
-
getMaximumWarnings
final Integer getMaximumWarnings()
-
getMinorWarningFactor
final Integer getMinorWarningFactor()
-
getPrivacyLeakWarnings
final AtomicInteger getPrivacyLeakWarnings()
-
getPrivacyLeakMinorWarnings
final AtomicInteger getPrivacyLeakMinorWarnings()
-
getMeterTasks
final Meter getMeterTasks()
-
getMeterSuccesses
final Meter getMeterSuccesses()
-
getMeterFinishes
final Meter getMeterFinishes()
-
getMeterSmallPages
final Meter getMeterSmallPages()
-
getSmallPageRate
final Double getSmallPageRate()
-
getSuccessRate
final Float getSuccessRate()
-
getFailureRate
Float getFailureRate()
The failure rate of the privacy context.
-
getFailureRateThreshold
final Float getFailureRateThreshold()
-
isHighFailureRate
Boolean isHighFailureRate()
Check whether the failure rate is high.
-
getStartTime
final Instant getStartTime()
The start time of the privacy context.
-
getLastActiveTime
final Instant getLastActiveTime()
The last active time of the privacy context.
-
getElapsedTime
Duration getElapsedTime()
The elapsed time of the privacy context.
-
getIdleTime
Duration getIdleTime()
The idle time of the privacy context.
-
isGood
Boolean isGood()
Check whether the privacy context is good.
A good privacy context has to meet the following requirements:
the fetch speed is good
-
isLeaked
Boolean isLeaked()
Check whether the privacy context is leaked.
This property indicates whether the privacy context has been marked as leaked. It returns the value of the
leakedfield, which is a boolean indicating the leakage status.- Returns:
trueif the privacy context is leaked,falseotherwise.
-
isRetired
Boolean isRetired()
Check whether the privacy context is retired.
This property indicates whether the privacy context has been marked as retired. It returns the value of the
retiredfield, which is a boolean indicating the retirement status.- Returns:
trueif the privacy context is retired,falseotherwise.
-
isActive
Boolean isActive()
Check whether the privacy context is active.
TODO: check and distinct from isReady in use cases.
An active privacy context has to meet the following requirements:
not closed
not leaked
not retired
Note: this flag does not guarantee consistency, and can change immediately after it's read
-
isReady
Boolean isReady()
A ready privacy context is ready to serve tasks.
A ready privacy context has to meet the following requirements:
not closed
not leaked
requirement removed not idle
not retired
if there is a proxy, the proxy has to be ready
the associated driver pool promises to provide an available driver, ether one of the following:
Note: this flag does not guarantee consistency, and can change immediately after it's read
-
isFullCapacity
Boolean isFullCapacity()
Check whether the privacy context is at full capacity. If the privacy context is indeed at full capacity, it should not be used for processing new tasks, and the underlying services may potentially refuse to provide service.
A privacy context is running at full capacity when the underlying webdriver pool is full capacity, so the webdriver pool can not provide a webdriver for new tasks.
Note that if a driver pool is retired or closed, it's not full capacity.
- Returns:
True if the privacy context is running at full capacity, false otherwise.
-
isUnderLoaded
Boolean isUnderLoaded()
Check whether the privacy context is running under loaded.
-
getReadableState
String getReadableState()
Get the readable privacy context state.
-
getPrivacyAgent
PrivacyAgent getPrivacyAgent()
The associated privacy agent.
-
getConf
final ImmutableConfig getConf()
-
promisedWebDriverCount
abstract Integer promisedWebDriverCount()
The promised workers (free web drivers) count.
The implementation has to tell the caller how many workers (free web drivers) it can provide.
The number of workers can change immediately after reading, so the caller only has promises but no guarantees.
- Returns:
the number of workers promised.
-
hasWebDriverPromise
Boolean hasWebDriverPromise()
Check if the privacy context promises at least one worker to provide.
-
subscribeWebDriver
@Beta() abstract WebDriver subscribeWebDriver()
-
markSuccess
final Unit markSuccess()
Marks a task as successful and updates relevant metrics.
-
markWarning
final Unit markWarning()
Mark a warning.
-
markWarning
final Unit markWarning(Integer n)
Mark n warnings.
-
markMinorWarning
final Unit markMinorWarning()
Mark a minor warnings.
-
markLeaked
final Unit markLeaked()
Mark the privacy context as leaked. A leaked privacy context should not serve anymore, and will be closed soon.
-
open
abstract FetchResult open(String url)
Open an url in the privacy context.
- Parameters:
url- The URL to open.
-
open
abstract FetchResult open(String url, LoadOptions options)
Open an url in the privacy context, with the specified options.
- Parameters:
url- The URL to open.options- The load options to use.
-
open
FetchResult open(String url, SuspendFunction2<FetchTask, WebDriver, FetchResult> fetchFun)
Open an url in the privacy context, with the specified fetch function.
- Parameters:
url- The URL to open.fetchFun- The fetch function to use.
-
run
FetchResult run(FetchTask task, SuspendFunction2<FetchTask, WebDriver, FetchResult> fetchFun)
Run a task in the privacy context, with the specified fetch function.
- Parameters:
task- the fetch taskfetchFun- the fetch function- Returns:
the fetch result
-
doRun
abstract FetchResult doRun(FetchTask task, SuspendFunction2<FetchTask, WebDriver, FetchResult> fetchFun)
Run a task in the privacy context.
- Parameters:
task- the fetch taskfetchFun- the fetch function- Returns:
the fetch result
-
buildStatusString
String buildStatusString()
Build the privacy context status string.
-
dismiss
Unit dismiss()
Dismisses the privacy context and marks it as retired, indicating that it should be closed later. This function sets the
retiredflag totrue, signaling that the privacy context is no longer active and should be handled accordingly (e.g., closed or cleaned up).This function does not take any parameters and does not return any value.
-
compareTo
Integer compareTo(PrivacyContext other)
-
buildReport
String buildReport()
Build the privacy context report.
This method is used to build the privacy context report. It should be called periodically to keep the privacy context alive.
-
-
-
-