Class CrawlerAttributes

java.lang.Object
com.norconex.crawler.core.session.CrawlerAttributes

public class CrawlerAttributes extends Object
Wrapper around an existing cluster string cache, offering generic attribute setters and getters for convenience. Whether and how the attributes are persisted is dependent on the underlying cache implementation.
  • Constructor Details

    • CrawlerAttributes

      public CrawlerAttributes(CacheMap<String> cache)
      Creates a new CrawlerAttributes instance.
      Parameters:
      cache - The underlying cache.
  • Method Details

    • setString

      public void setString(String key, String value)
      Sets an attribute as a string.
      Parameters:
      key - attribute key
      value - attribute value
    • setStringIfAbsent

      public boolean setStringIfAbsent(String key, String value)
      Atomically sets an attribute as a string if it is not already set. This is a cluster-safe operation that prevents race conditions in distributed environments.
      Parameters:
      key - attribute key
      value - attribute value to set if key is absent
      Returns:
      true if the value was set (key was absent), false if the key already existed
    • getString

      public Optional<String> getString(String key)
      Gets an attribute as a string.
      Parameters:
      key - attribute key
      Returns:
      value attribute value
    • setBoolean

      public void setBoolean(String key, boolean value)
      Sets an attribute as a boolean.
      Parameters:
      key - attribute key
      value - attribute value
    • setBooleanIfAbsent

      public boolean setBooleanIfAbsent(String key, boolean value)
      Atomically sets an attribute as a boolean if it is not already set. This is a cluster-safe operation that prevents race conditions in distributed environments.
      Parameters:
      key - attribute key
      value - attribute value to set if key is absent
      Returns:
      true if the value was set (key was absent), false if the key already existed
    • getBoolean

      public boolean getBoolean(String key)
      Gets an attribute as a boolean.
      Parameters:
      key - attribute key
      Returns:
      value attribute value
    • setInteger

      public void setInteger(String key, int value)
      Sets an attribute as an integer.
      Parameters:
      key - attribute key
      value - attribute value
    • setIntegerIfAbsent

      public boolean setIntegerIfAbsent(String key, int value)
      Atomically sets an attribute as an integer if it is not already set. This is a cluster-safe operation that prevents race conditions in distributed environments.
      Parameters:
      key - attribute key
      value - attribute value to set if key is absent
      Returns:
      true if the value was set (key was absent), false if the key already existed
    • getInteger

      public int getInteger(String key)
      Gets an attribute as an integer. If no value is set, zero is returned.
      Parameters:
      key - attribute key
      Returns:
      value attribute value, or zero
    • getCache

      public CacheMap<String> getCache()
      The underlying cache.