Record Class ServiceEntry<S>

java.lang.Object
java.lang.Record
cloud.opencode.base.classloader.service.ServiceEntry<S>
Type Parameters:
S - the service type | 服务类型
Record Components:
service - the service instance | 服务实例
classLoaderName - the name of the ClassLoader that loaded this service | 加载此服务的类加载器名称
priority - priority value (lower = higher priority) | 优先级值(值越小优先级越高)
All Implemented Interfaces:
Comparable<ServiceEntry<S>>

public record ServiceEntry<S>(S service, String classLoaderName, int priority) extends Record implements Comparable<ServiceEntry<S>>
Service Entry - Wrapper for a service discovered via cross-ClassLoader lookup 服务条目 - 跨类加载器查找发现的服务包装器

Holds the service instance, the name of its originating ClassLoader, and a priority value used for ordering.

持有服务实例、来源类加载器名称以及用于排序的优先级值。

Features | 主要功能:

  • Immutable record wrapping a service instance - 不可变记录,包装服务实例
  • Comparable by priority (lower = higher priority) - 按优先级比较(值越小优先级越高)
  • Stores ClassLoader name, not a strong reference - 存储类加载器名称,非强引用

Usage Examples | 使用示例:

ServiceEntry<MyService> entry = new ServiceEntry<>(impl, "AppClassLoader", 100);
int p = entry.priority();
MyService svc = entry.service();

Security | 安全性:

  • Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
Since:
JDK 25, opencode-base-classloader V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • ServiceEntry

      public ServiceEntry(S service, String classLoaderName, int priority)
      Canonical constructor with null checks. 规范构造器,包含空值检查。
      Parameters:
      service - the service instance | 服务实例
      classLoaderName - the ClassLoader name | 类加载器名称
      priority - the priority value | 优先级值
  • Method Details

    • compareTo

      public int compareTo(ServiceEntry<S> other)
      Compare by priority ascending (lower value = higher priority). 按优先级升序比较(值越小优先级越高)。
      Specified by:
      compareTo in interface Comparable<S>
      Parameters:
      other - the other entry to compare | 要比较的另一个条目
      Returns:
      comparison result | 比较结果
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • service

      public S service()
      Returns the value of the service record component.
      Returns:
      the value of the service record component
    • classLoaderName

      public String classLoaderName()
      Returns the value of the classLoaderName record component.
      Returns:
      the value of the classLoaderName record component
    • priority

      public int priority()
      Returns the value of the priority record component.
      Returns:
      the value of the priority record component