Class AbstractPulsarContext
-
- All Implemented Interfaces:
-
ai.platon.pulsar.context.PulsarContext,java.lang.AutoCloseable
public abstract class AbstractPulsarContext implements PulsarContext, AutoCloseable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classAbstractPulsarContext.Companion
-
Field Summary
Fields Modifier and Type Field Description private final BooleanisActiveprivate final Integeridprivate final ImmutableConfigunmodifiedConfigprivate final ChainedUrlNormalizerurlNormalizersprivate final ChainedUrlNormalizerurlNormalizerprivate final ChainedUrlNormalizerurlNormalizerOrNullprivate final WebDbwebDbprivate final GlobalCacheFactoryglobalCacheFactoryprivate final InjectComponentinjectComponentprivate final BatchFetchComponentfetchComponentprivate final ParseComponentparseComponentprivate final UpdateComponentupdateComponentprivate final LoadComponentloadComponentprivate final GlobalCacheglobalCacheprivate final UrlPoolcrawlPoolprivate final CrawlLoopscrawlLoopsprivate final LongstartTimeprivate final ConcurrentSkipListMap<Integer, PulsarSession>sessionsprivate final AbstractApplicationContextapplicationContextprivate final PulsarEnvironmentpulsarEnvironmentpublic final static AbstractPulsarContext.CompanionCompanion
-
Constructor Summary
Constructors Constructor Description AbstractPulsarContext(AbstractApplicationContext applicationContext, PulsarEnvironment pulsarEnvironment)
-
Method Summary
Modifier and Type Method Description BooleanisActive()The context id IntegergetId()The context id ImmutableConfiggetUnmodifiedConfig()An immutable config loaded from the config file at startup, and never changes ChainedUrlNormalizergetUrlNormalizers()ChainedUrlNormalizergetUrlNormalizer()ChainedUrlNormalizergetUrlNormalizerOrNull()WebDbgetWebDb()GlobalCacheFactorygetGlobalCacheFactory()InjectComponentgetInjectComponent()BatchFetchComponentgetFetchComponent()ParseComponentgetParseComponent()UpdateComponentgetUpdateComponent()LoadComponentgetLoadComponent()GlobalCachegetGlobalCache()The global cache UrlPoolgetCrawlPool()The url pool to fetch CrawlLoopsgetCrawlLoops()The main loops final LonggetStartTime()The start time final ConcurrentSkipListMap<Integer, PulsarSession>getSessions()All open sessions final AbstractApplicationContextgetApplicationContext()final PulsarEnvironmentgetPulsarEnvironment()<T extends Any> TgetBean(KClass<T> requiredType)Get a bean with the specified class, throws BeansException if the bean doesn't exist final <T extends Any> TgetBean()Get a bean with the specified class, throws BeansException if the bean doesn't exist <T extends Any> TgetBeanOrNull(KClass<T> requiredType)Get a bean with the specified class, returns null if the bean doesn't exist final <T extends Any> TgetBeanOrNull()Get a bean with the specified class, returns null if the bean doesn't exist abstract AbstractPulsarSessioncreateSession()Create a session UnitcloseSession(PulsarSession session)Close the given session UnitregisterClosable(AutoCloseable closable)Register close objects, the objects will be closed when the context closes NormUrlnormalize(String url, LoadOptions options, Boolean toItemOption)Normalize an url, the url can be one of the following: a normal url
a configured url
a base64 encoded url
a base64 encoded configured url
List<NormUrl>normalize(Iterable<String> urls, LoadOptions options, Boolean toItemOption)Normalize urls, remove invalid ones NormUrlnormalize(UrlAware url, LoadOptions options, Boolean toItemOption)Normalize an url. List<NormUrl>normalize(Collection<UrlAware> urls, LoadOptions options, Boolean toItemOption)Normalize urls, remove invalid ones NormUrlnormalizeOrNull(String url, LoadOptions options, Boolean toItemOption)NormUrlnormalizeOrNull(UrlAware url, LoadOptions options, Boolean toItemOption)WebPageinject(String url)Inject an url WebPageinject(NormUrl url)Inject an url WebPageget(String url)Get a webpage from the storage WebPageget(String url, String fields)Get a page from storage. WebPagegetOrNull(String url)Get a webpage from the storage WebPagegetOrNull(String url, String fields)Get a webpage from the storage ByteBuffergetContent(String url)Get the content of the page from the storage StringgetContentAsString(String url)Get the content of the page from the storage Booleanexists(String url)Check if a page exists in the storage CheckStatefetchState(WebPage page, LoadOptions options)Check the fetch state of a page Iterator<WebPage>scan(String urlPrefix)Scan pages in the storage Iterator<WebPage>scan(String urlPrefix, Iterable<GWebPage.Field> fields)Scan pages in the storage Iterator<WebPage>scan(String urlPrefix, Array<String> fields)Scan pages in the storage WebPageload(String url, LoadOptions options)Load an page with specified options, see LoadOptions for all options WebPageload(URL url, LoadOptions options)Load a url with specified options, see LoadOptions for all options WebPageload(NormUrl url)Load a url, options can be specified following the url, see LoadOptions for all options WebPageloadDeferred(NormUrl url)Load a url, options can be specified following the url, see LoadOptions for all options List<WebPage>loadAll(Iterable<String> urls, LoadOptions options)Load a batch of urls with the specified options. List<WebPage>loadAll(Iterable<NormUrl> urls)Load a batch of urls with the specified options. CompletableFuture<WebPage>loadAsync(NormUrl url)Load a url asynchronously, the url is added to the task queue, and will be executed asynchronously List<CompletableFuture<WebPage>>loadAllAsync(Iterable<NormUrl> urls)Load a batch of urls asynchronously, the urls are added to the task queue, and will be executed asynchronously AbstractPulsarContextsubmit(UrlAware url)Submit a url, the url will be added to the task queue, and will be executed asynchronously. AbstractPulsarContextsubmitAll(Iterable<UrlAware> urls)Submit a batch of urls, the urls are added to the task queue, and will be executed asynchronously. FeaturedDocumentparse(WebPage page)Parse the WebPage content using parseComponent Unitpersist(WebPage page)Persist the page into the storage Unitdelete(String url)Delete the page from the storage Unitdelete(WebPage page)Delete the page from the storage Unitflush()Flush the storage Unitawait()Wait until there is no tasks in the main loop UnitregisterShutdownHook()Register a shutdown hook with the JVM runtime, closing this context on JVM shutdown unless it has already been closed at that time. Unitclose()Close this pulsar contextDelegates to doClose()for the actual closing procedure.-
-
Constructor Detail
-
AbstractPulsarContext
AbstractPulsarContext(AbstractApplicationContext applicationContext, PulsarEnvironment pulsarEnvironment)
-
-
Method Detail
-
getUnmodifiedConfig
ImmutableConfig getUnmodifiedConfig()
An immutable config loaded from the config file at startup, and never changes
-
getUrlNormalizers
ChainedUrlNormalizer getUrlNormalizers()
-
getUrlNormalizer
ChainedUrlNormalizer getUrlNormalizer()
-
getUrlNormalizerOrNull
ChainedUrlNormalizer getUrlNormalizerOrNull()
-
getWebDb
WebDb getWebDb()
-
getGlobalCacheFactory
GlobalCacheFactory getGlobalCacheFactory()
-
getInjectComponent
InjectComponent getInjectComponent()
-
getFetchComponent
BatchFetchComponent getFetchComponent()
-
getParseComponent
ParseComponent getParseComponent()
-
getUpdateComponent
UpdateComponent getUpdateComponent()
-
getLoadComponent
LoadComponent getLoadComponent()
-
getGlobalCache
GlobalCache getGlobalCache()
The global cache
-
getCrawlPool
UrlPool getCrawlPool()
The url pool to fetch
-
getCrawlLoops
CrawlLoops getCrawlLoops()
The main loops
-
getStartTime
final Long getStartTime()
The start time
-
getSessions
final ConcurrentSkipListMap<Integer, PulsarSession> getSessions()
All open sessions
-
getApplicationContext
final AbstractApplicationContext getApplicationContext()
-
getPulsarEnvironment
final PulsarEnvironment getPulsarEnvironment()
-
getBean
<T extends Any> T getBean(KClass<T> requiredType)
Get a bean with the specified class, throws BeansException if the bean doesn't exist
-
getBean
final <T extends Any> T getBean()
Get a bean with the specified class, throws BeansException if the bean doesn't exist
-
getBeanOrNull
<T extends Any> T getBeanOrNull(KClass<T> requiredType)
Get a bean with the specified class, returns null if the bean doesn't exist
-
getBeanOrNull
final <T extends Any> T getBeanOrNull()
Get a bean with the specified class, returns null if the bean doesn't exist
-
createSession
abstract AbstractPulsarSession createSession()
Create a session
-
closeSession
Unit closeSession(PulsarSession session)
Close the given session
-
registerClosable
Unit registerClosable(AutoCloseable closable)
Register close objects, the objects will be closed when the context closes
-
normalize
NormUrl normalize(String url, LoadOptions options, Boolean toItemOption)
Normalize an url, the url can be one of the following:
a normal url
a configured url
a base64 encoded url
a base64 encoded configured url
An url can be configured by appending arguments to the url, and it also can be used with load options, If both tailing arguments and load options are present, the tailing arguments override the load options.
-
normalize
List<NormUrl> normalize(Iterable<String> urls, LoadOptions options, Boolean toItemOption)
Normalize urls, remove invalid ones
- Parameters:
urls- The urls to normalizeoptions- The load options applied to each urltoItemOption- If true, options will be converted to item load options
-
normalize
NormUrl normalize(UrlAware url, LoadOptions options, Boolean toItemOption)
Normalize an url.
If both tailing arguments and load options are present, the tailing arguments override the load options.
-
normalize
List<NormUrl> normalize(Collection<UrlAware> urls, LoadOptions options, Boolean toItemOption)
Normalize urls, remove invalid ones
- Parameters:
urls- The urls to normalizeoptions- The LoadOptions applied to each urltoItemOption- If the LoadOptions is converted to item load options
-
normalizeOrNull
NormUrl normalizeOrNull(String url, LoadOptions options, Boolean toItemOption)
-
normalizeOrNull
NormUrl normalizeOrNull(UrlAware url, LoadOptions options, Boolean toItemOption)
-
inject
WebPage inject(String url)
Inject an url
- Parameters:
url- The url which can be followed by arguments
-
inject
WebPage inject(NormUrl url)
Inject an url
- Parameters:
url- The url which can be followed by arguments
-
get
WebPage get(String url)
Get a webpage from the storage
- Parameters:
url- The url of the page to retrieve
-
get
WebPage get(String url, String fields)
Get a page from storage.
- Parameters:
url- The urlfields- The fields to load from local storage
-
getOrNull
WebPage getOrNull(String url)
Get a webpage from the storage
- Parameters:
url- The url of the page to retrieve
-
getOrNull
WebPage getOrNull(String url, String fields)
Get a webpage from the storage
- Parameters:
url- The urlfields- The fields to load from local storage
-
getContent
ByteBuffer getContent(String url)
Get the content of the page from the storage
- Parameters:
url- The url of the page to retrieve
-
getContentAsString
String getContentAsString(String url)
Get the content of the page from the storage
- Parameters:
url- The url of the page to retrieve
-
exists
Boolean exists(String url)
Check if a page exists in the storage
- Parameters:
url- The url of the page to check
-
fetchState
CheckState fetchState(WebPage page, LoadOptions options)
Check the fetch state of a page
- Parameters:
page- The webpage to check
-
scan
Iterator<WebPage> scan(String urlPrefix)
Scan pages in the storage
- Parameters:
urlPrefix- The url prefix
-
scan
Iterator<WebPage> scan(String urlPrefix, Iterable<GWebPage.Field> fields)
Scan pages in the storage
-
load
WebPage load(String url, LoadOptions options)
Load an page with specified options, see LoadOptions for all options
- Parameters:
url- The url which can be followed by argumentsoptions- The load options
-
load
WebPage load(URL url, LoadOptions options)
Load a url with specified options, see LoadOptions for all options
- Parameters:
url- The url which can be followed by argumentsoptions- The load options
-
load
WebPage load(NormUrl url)
Load a url, options can be specified following the url, see LoadOptions for all options
- Parameters:
url- The url which can be followed by arguments
-
loadDeferred
WebPage loadDeferred(NormUrl url)
Load a url, options can be specified following the url, see LoadOptions for all options
- Parameters:
url- The url followed by options
-
loadAll
List<WebPage> loadAll(Iterable<String> urls, LoadOptions options)
Load a batch of urls with the specified options.
If the option indicates prefer parallel, urls are fetched in a parallel manner whenever applicable. If the batch is too large, only a random part of the urls is fetched immediately, all the rest urls are put into a pending fetch list and will be fetched in background later.
If a page exists neither in local storage nor at the given remote location, WebPage.NIL is returned
- Parameters:
urls- The urls to loadoptions- The load options
-
loadAll
List<WebPage> loadAll(Iterable<NormUrl> urls)
Load a batch of urls with the specified options.
If the option indicates prefer parallel, urls are fetched in a parallel manner whenever applicable. If the batch is too large, only a random part of the urls is fetched immediately, all the rest urls are put into a pending fetch list and will be fetched in background later.
If a page exists neither in local storage nor at the given remote location, WebPage.NIL is returned
- Parameters:
urls- The urls to load
-
loadAsync
CompletableFuture<WebPage> loadAsync(NormUrl url)
Load a url asynchronously, the url is added to the task queue, and will be executed asynchronously
-
loadAllAsync
List<CompletableFuture<WebPage>> loadAllAsync(Iterable<NormUrl> urls)
Load a batch of urls asynchronously, the urls are added to the task queue, and will be executed asynchronously
-
submit
AbstractPulsarContext submit(UrlAware url)
Submit a url, the url will be added to the task queue, and will be executed asynchronously.
The url should be standard or degenerate, otherwise it will be discarded.
- Parameters:
url- The url to submit, which will be added to the task queue
-
submitAll
AbstractPulsarContext submitAll(Iterable<UrlAware> urls)
Submit a batch of urls, the urls are added to the task queue, and will be executed asynchronously.
The urls should be standard or degenerate, otherwise they will be discarded.
- Parameters:
urls- The urls to submit, which will be added to the task queue
-
parse
FeaturedDocument parse(WebPage page)
Parse the WebPage content using parseComponent
-
registerShutdownHook
Unit registerShutdownHook()
Register a shutdown hook with the JVM runtime, closing this context on JVM shutdown unless it has already been closed at that time.
Delegates to
doClose()for the actual closing procedure.
-
-
-