Record Class ServiceInstanceKey
java.lang.Object
java.lang.Record
io.axoniq.framework.springcloud.discovery.ServiceInstanceKey
- Record Components:
serviceId- theservice idof the instancehost- thehostof the instanceport- theportof the instance
An identity for a
ServiceInstance that can safely be used as a map key.
ServiceInstance is an interface, and several Spring Cloud Discovery implementations return instances that do
not override Object.equals(Object). Two lookups of the same running service therefore routinely produce
objects that are unequal, which quietly breaks any bookkeeping keyed on the instance itself. This record pins the
identity down to the three fields every implementation populates: the service id, host and port.
- Since:
- 5.4.0
- Author:
- Allard Buijze
-
Constructor Summary
ConstructorsConstructorDescriptionServiceInstanceKey(String serviceId, String host, int port) Creates an instance of aServiceInstanceKeyrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.host()Returns the value of thehostrecord component.static ServiceInstanceKeyof(org.springframework.cloud.client.ServiceInstance instance) Derives theServiceInstanceKeyof the giveninstance.intport()Returns the value of theportrecord component.Returns the value of theserviceIdrecord component.toString()Returns a string representation of this record class.
-
Constructor Details
-
Method Details
-
of
Derives theServiceInstanceKeyof the giveninstance.- Parameters:
instance- the instance to derive a key for- Returns:
- the key identifying the given
instance
-
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. -
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. -
equals
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 withObjects::equals(Object,Object); primitive components are compared with '=='. -
serviceId
Returns the value of theserviceIdrecord component.- Returns:
- the value of the
serviceIdrecord component
-
host
Returns the value of thehostrecord component.- Returns:
- the value of the
hostrecord component
-
port
public int port()Returns the value of theportrecord component.- Returns:
- the value of the
portrecord component
-