Record Class ConnectionTestResult

java.lang.Object
java.lang.Record
cloud.opencode.base.email.ConnectionTestResult

public record ConnectionTestResult(boolean success, String serverGreeting, Duration latency, String errorMessage, Throwable cause) extends Record
SMTP Connection Test Result SMTP连接测试结果

Result of testing SMTP server connectivity and authentication.

测试SMTP服务器连接和认证的结果。

Features | 主要功能:

  • Connection status - 连接状态
  • Latency measurement - 延迟测量
  • Error details - 错误详情

Usage Examples | 使用示例:

ConnectionTestResult result = sender.testConnection();
if (result.success()) {
    System.out.println("Connected in " + result.latency().toMillis() + "ms");
} else {
    System.err.println("Failed: " + result.errorMessage());
}

Security | 安全性:

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

    • ConnectionTestResult

      public ConnectionTestResult(boolean success, String serverGreeting, Duration latency, String errorMessage, Throwable cause)
      Creates an instance of a ConnectionTestResult record class.
      Parameters:
      success - the value for the success record component
      serverGreeting - the value for the serverGreeting record component
      latency - the value for the latency record component
      errorMessage - the value for the errorMessage record component
      cause - the value for the cause record component
  • Method Details

    • success

      public static ConnectionTestResult success(String serverGreeting, Duration latency)
      Create a successful test result 创建成功的测试结果
      Parameters:
      serverGreeting - the SMTP server greeting | SMTP服务器问候语
      latency - the connection latency | 连接延迟
      Returns:
      the result | 结果
    • failure

      public static ConnectionTestResult failure(String errorMessage, Throwable cause, Duration latency)
      Create a failed test result 创建失败的测试结果
      Parameters:
      errorMessage - the error message | 错误消息
      cause - the exception cause | 异常原因
      latency - the time spent before failure | 失败前的耗时
      Returns:
      the 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.
    • success

      public boolean success()
      Returns the value of the success record component.
      Returns:
      the value of the success record component
    • serverGreeting

      public String serverGreeting()
      Returns the value of the serverGreeting record component.
      Returns:
      the value of the serverGreeting record component
    • latency

      public Duration latency()
      Returns the value of the latency record component.
      Returns:
      the value of the latency record component
    • errorMessage

      public String errorMessage()
      Returns the value of the errorMessage record component.
      Returns:
      the value of the errorMessage record component
    • cause

      public Throwable cause()
      Returns the value of the cause record component.
      Returns:
      the value of the cause record component