Skip to content

io microsphere spring cloud client service registry RegistrationMetaData

github-actions[bot] edited this page Apr 8, 2026 · 3 revisions

RegistrationMetaData

Type: Class | Module: microsphere-spring-cloud-commons | Package: io.microsphere.spring.cloud.client.service.registry | Since: 1.0.0

Source: microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/RegistrationMetaData.java

Overview

A Map-based metadata container for Registration instances that synchronizes metadata changes across all underlying registrations. This class wraps one or more Registration objects and ensures that any metadata modifications (put, remove, clear) are propagated to every registration in a thread-safe manner.

Example Usage:

`RegistrationMetaData metaData = new RegistrationMetaData(ofList(defaultRegistration));
metaData.put("key", "value");
String value = metaData.get("key");
metaData.remove("key");
`

Declaration

public final class RegistrationMetaData implements Map<String, String>

Author: 韩超

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.2.9-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

RegistrationMetaData metaData = new RegistrationMetaData(ofList(defaultRegistration));
metaData.put("key", "value");
String value = metaData.get("key");
metaData.remove("key");

Method Examples

size

DefaultRegistration registration = new DefaultRegistration();
registration.getMetadata().put("key1", "value1");
RegistrationMetaData metaData = new RegistrationMetaData(List.of(registration));
RegistrationMetaData metaData = new RegistrationMetaData(registrations);
int count = metaData.size(); // e.g. 3

isEmpty

RegistrationMetaData metaData = new RegistrationMetaData(registrations);
boolean empty = metaData.isEmpty(); // false if registrations have metadata

containsKey

RegistrationMetaData metaData = new RegistrationMetaData(registrations);
boolean hasKey = metaData.containsKey("key1"); // true
boolean missing = metaData.containsKey("unknown"); // false

containsValue

RegistrationMetaData metaData = new RegistrationMetaData(registrations);
boolean hasValue = metaData.containsValue("value1"); // true
boolean missing = metaData.containsValue("unknown"); // false

get

RegistrationMetaData metaData = new RegistrationMetaData(registrations);
String value = metaData.get("key1"); // "value1"
String missing = metaData.get("unknown"); // null

put

RegistrationMetaData metaData = new RegistrationMetaData(registrations);
metaData.put("key4", "value4");
String value = metaData.get("key4"); // "value4"

remove

RegistrationMetaData metaData = new RegistrationMetaData(registrations);
metaData.remove("key1");
String value = metaData.get("key1"); // null

putAll

RegistrationMetaData metaData = new RegistrationMetaData(registrations);
metaData.putAll(Map.of("key4", "value4", "key5", "value5"));

clear

RegistrationMetaData metaData = new RegistrationMetaData(registrations);
metaData.clear();
int size = metaData.size(); // 0

keySet

RegistrationMetaData metaData = new RegistrationMetaData(registrations);
Set<String> keys = metaData.keySet();
boolean hasKey = keys.contains("key1"); // true

values

RegistrationMetaData metaData = new RegistrationMetaData(registrations);
Collection<String> values = metaData.values();
boolean hasValue = values.contains("value1"); // true

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-spring-cloud-commons</artifactId>
    <version>${microsphere-spring-cloud.version}</version>
</dependency>

Tip: Use the BOM (microsphere-spring-cloud-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.spring.cloud.client.service.registry.RegistrationMetaData;

API Reference

Public Methods

Method Description
size The class name of org.springframework.cloud.zookeeper.serviceregistry.ServiceInstanceRegistration
isEmpty Returns whether this metadata map is empty.
containsKey Returns whether this metadata contains the specified key.
containsValue Returns whether this metadata contains the specified value.
get Returns the metadata value associated with the specified key.
put Puts a metadata entry and synchronizes it across all underlying Registration
remove Removes the metadata entry for the specified key and synchronizes the removal
putAll Copies all entries from the specified map into this metadata and synchronizes
clear Clears all metadata entries and synchronizes the clearing across all underlying
keySet Returns an unmodifiable Set view of the metadata keys.
values Returns an unmodifiable Collection view of the metadata values.

Method Details

size

public int size()

The class name of org.springframework.cloud.zookeeper.serviceregistry.ServiceInstanceRegistration / static final String ZOOKEEPER_REGISTRATION_CLASS_NAME = "org.springframework.cloud.zookeeper.serviceregistry.ServiceInstanceRegistration";

/** The method name of org.springframework.cloud.zookeeper.serviceregistry.ServiceInstanceRegistration#getServiceInstance() / static final String GET_SERVICE_INSTANCE_METHOD_NAME = "getServiceInstance";

/** MetaData information manually added by the application,usually specified by configuration / private final Map applicationMetaData;

private final Collection registrations;

private final Object lock = new Object();

/** Constructs a new RegistrationMetaData that aggregates metadata from the given collection of Registration instances. Metadata changes are synchronized across all registrations.

Example Usage:

`DefaultRegistration registration = new DefaultRegistration();
registration.getMetadata().put("key1", "value1");
RegistrationMetaData metaData = new RegistrationMetaData(List.of(registration));
`

isEmpty

public boolean isEmpty()

Returns whether this metadata map is empty.

Example Usage:

`RegistrationMetaData metaData = new RegistrationMetaData(registrations);
boolean empty = metaData.isEmpty(); // false if registrations have metadata
`

containsKey

public boolean containsKey(Object key)

Returns whether this metadata contains the specified key.

Example Usage:

`RegistrationMetaData metaData = new RegistrationMetaData(registrations);
boolean hasKey = metaData.containsKey("key1"); // true
boolean missing = metaData.containsKey("unknown"); // false
`

containsValue

public boolean containsValue(Object value)

Returns whether this metadata contains the specified value.

Example Usage:

`RegistrationMetaData metaData = new RegistrationMetaData(registrations);
boolean hasValue = metaData.containsValue("value1"); // true
boolean missing = metaData.containsValue("unknown"); // false
`

get

public String get(Object key)

Returns the metadata value associated with the specified key.

Example Usage:

`RegistrationMetaData metaData = new RegistrationMetaData(registrations);
String value = metaData.get("key1"); // "value1"
String missing = metaData.get("unknown"); // null
`

put

public String put(String key, String value)

Puts a metadata entry and synchronizes it across all underlying Registration instances.

Example Usage:

`RegistrationMetaData metaData = new RegistrationMetaData(registrations);
metaData.put("key4", "value4");
String value = metaData.get("key4"); // "value4"
`

remove

public String remove(Object key)

Removes the metadata entry for the specified key and synchronizes the removal across all underlying Registration instances.

Example Usage:

`RegistrationMetaData metaData = new RegistrationMetaData(registrations);
metaData.remove("key1");
String value = metaData.get("key1"); // null
`

putAll

public void putAll(Map<? extends String, ? extends String> m)

Copies all entries from the specified map into this metadata and synchronizes them across all underlying Registration instances.

Example Usage:

`RegistrationMetaData metaData = new RegistrationMetaData(registrations);
metaData.putAll(Map.of("key4", "value4", "key5", "value5"));
`

clear

public void clear()

Clears all metadata entries and synchronizes the clearing across all underlying Registration instances.

Example Usage:

`RegistrationMetaData metaData = new RegistrationMetaData(registrations);
metaData.clear();
int size = metaData.size(); // 0
`

keySet

public Set<String> keySet()

Returns an unmodifiable Set view of the metadata keys.

Example Usage:

`RegistrationMetaData metaData = new RegistrationMetaData(registrations);
Set keys = metaData.keySet();
boolean hasKey = keys.contains("key1"); // true
`

values

public Collection<String> values()

Returns an unmodifiable Collection view of the metadata values.

Example Usage:

`RegistrationMetaData metaData = new RegistrationMetaData(registrations);
Collection values = metaData.values();
boolean hasValue = values.contains("value1"); // true
`

See Also

  • Registration

This documentation was auto-generated from the source code of microsphere-spring-cloud.

Home

spring-cloud-commons

spring-cloud-openfeign

Clone this wiki locally