001/* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at 010 * docs/licenses/cddl.txt 011 * or http://www.opensource.org/licenses/cddl1.php. 012 * See the License for the specific language governing permissions 013 * and limitations under the License. 014 * 015 * When distributing Covered Code, include this CDDL HEADER in each 016 * file and include the License file at 017 * docs/licenses/cddl.txt. If applicable, 018 * add the following below this CDDL HEADER, with the fields enclosed 019 * by brackets "[]" replaced with your own identifying information: 020 * Portions Copyright [yyyy] [name of copyright owner] 021 * 022 * CDDL HEADER END 023 * 024 * 025 * Portions Copyright 2014-2023 Ping Identity Corporation 026 */ 027package com.unboundid.directory.sdk.proxy.types; 028 029 030 031import java.util.Date; 032 033import com.unboundid.util.StaticUtils; 034 035 036 037/** 038 * This class provides a data structure for holding information about an 039 * affinity to a particular backend server instance. 040 */ 041public final class ServerAffinity 042{ 043 // The backend server to which the affinity is established. 044 private final BackendServer backendServer; 045 046 // The time that the affinity was established. 047 private final long affinityEstablishedTime; 048 049 050 051 /** 052 * Creates a server affinity for the provided backend server. 053 * 054 * @param backendServer The backend server with which the affinity is to be 055 * associated. 056 */ 057 public ServerAffinity(final BackendServer backendServer) 058 { 059 this.backendServer = backendServer; 060 061 affinityEstablishedTime = System.currentTimeMillis(); 062 } 063 064 065 066 /** 067 * Retrieves the backend server to which the affinity is established. 068 * 069 * @return The backend server to which the affinity is established. 070 */ 071 public BackendServer getBackendServer() 072 { 073 return backendServer; 074 } 075 076 077 078 /** 079 * Retrieves a timestamp indicating when the affinity was established. The 080 * timestamp value will be the number of milliseconds since the epoch, in the 081 * same format returned by {@code System.currentTimeMillis} or 082 * {@code Date.getTime}. 083 * 084 * @return A timestamp indicating when the affinity was established. 085 */ 086 public long getAffinityEstablishedTime() 087 { 088 return affinityEstablishedTime; 089 } 090 091 092 093 /** 094 * Retrieves a string representation of this server affinity object. 095 * 096 * @return A string representation of this server affinity object. 097 */ 098 @Override() 099 public String toString() 100 { 101 final StringBuilder buffer = new StringBuilder(); 102 toString(buffer); 103 return buffer.toString(); 104 } 105 106 107 108 /** 109 * Appends a string representation of this server affinity object to the 110 * provided buffer. 111 * 112 * @param buffer The buffer to which the information should be appended. 113 */ 114 public void toString(final StringBuilder buffer) 115 { 116 buffer.append("ServerAffinity(backendServer='"); 117 buffer.append(backendServer.getServerAddress()); 118 buffer.append(':'); 119 buffer.append(backendServer.getServerPort()); 120 buffer.append("', establishedTime='"); 121 buffer.append(StaticUtils.encodeGeneralizedTime( 122 new Date(affinityEstablishedTime))); 123 buffer.append("')"); 124 } 125}