Module bus.vortex

Class AbstractRegistry<T>

java.lang.Object
org.miaixz.bus.vortex.registry.AbstractRegistry<T>
Type Parameters:
T - 注册表中存储的值的类型
All Implemented Interfaces:
Registry<T>, org.springframework.beans.factory.InitializingBean
Direct Known Subclasses:
AssetsRegistry, LimiterRegistry

public abstract class AbstractRegistry<T> extends Object implements Registry<T>, org.springframework.beans.factory.InitializingBean
抽象注册类,提供通用的注册表功能,用于管理和存储键值对数据
Since:
Java 17+
Author:
Justubborn
  • Field Details

  • Constructor Details

    • AbstractRegistry

      public AbstractRegistry()
  • Method Details

    • setKeyGenerator

      protected void setKeyGenerator(AbstractRegistry.RegistryKey<T> registryKey)
      设置键生成策略
      Parameters:
      registryKey - 键生成策略
    • init

      public abstract void init()
      初始化注册表,子类需实现具体初始化逻辑
      Specified by:
      init in interface Registry<T>
    • add

      public boolean add(String key, T reg)
      添加键值对到注册表
      Specified by:
      add in interface Registry<T>
      Parameters:
      key - 键
      reg - 值
      Returns:
      如果键不存在且添加成功返回 true,否则返回 false
    • add

      public boolean add(T item)
      添加对象到注册表,使用键生成策略生成键
      Parameters:
      item - 要添加的对象
      Returns:
      如果添加成功返回 true,否则返回 false
    • remove

      public boolean remove(String id)
      从注册表中移除指定键的记录
      Specified by:
      remove in interface Registry<T>
      Parameters:
      id - 键
      Returns:
      如果移除成功返回 true,否则返回 false
    • amend

      public boolean amend(String key, T reg)
      更新注册表中的键值对,先移除后添加
      Specified by:
      amend in interface Registry<T>
      Parameters:
      key - 键
      reg - 新值
      Returns:
      如果更新成功返回 true,否则返回 false
    • amend

      public boolean amend(T item)
      更新注册表中的对象,使用键生成策略生成键
      Parameters:
      item - 要更新的对象
      Returns:
      如果更新成功返回 true,否则返回 false
    • refresh

      public void refresh()
      刷新注册表,清空缓存并重新初始化
      Specified by:
      refresh in interface Registry<T>
    • get

      public T get(String key)
      获取指定键对应的值
      Specified by:
      get in interface Registry<T>
      Parameters:
      key - 键
      Returns:
      对应的值,若不存在返回 null
    • afterPropertiesSet

      public void afterPropertiesSet()
      Spring 初始化回调,在 bean 属性设置后调用,触发注册表刷新
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean