Skip to content

Commit

Permalink
Dropped support of old-qualifier (#869)
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-v authored Dec 4, 2024
1 parent a85b474 commit d704ba4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ public String qualifier() {
return qualifier;
}

public String oldQualifier() {
return Qualifier.DELIMITER + qualifier();
}

public String endpointId() {
return endpointId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ public String qualifier() {
return qualifier;
}

public String oldQualifier() {
return Qualifier.DELIMITER + qualifier();
}

public Type parameterizedReturnType() {
return parameterizedReturnType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ public interface SecuredService {
@RequestType(String.class)
Mono<String> createSession(ServiceMessage request);

@Secured
@ServiceMethod
@RequestType(String.class)
@Secured
Mono<String> requestOne(String req);

@Secured
@ServiceMethod
@RequestType(Integer.class)
@Secured
Flux<String> requestN(Integer req);
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void securedMethodAuthenticatedReqStream() {

private static ServiceMessage createSessionRequest(String username) {
return ServiceMessage.builder()
.qualifier("/" + SecuredService.NAMESPACE + "/createSession")
.qualifier(SecuredService.NAMESPACE + "/createSession")
.data(username)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,7 @@ public boolean registerService(ServiceEndpoint serviceEndpoint) {
boolean success = serviceEndpoints.putIfAbsent(serviceEndpoint.id(), serviceEndpoint) == null;
if (success) {
LOGGER.log(Level.DEBUG, "ServiceEndpoint registered: {0}", serviceEndpoint);
serviceEndpoint
.serviceReferences()
.forEach(
sr -> {
populateServiceReferences(sr.qualifier(), sr);
populateServiceReferences(sr.oldQualifier(), sr);
});
serviceEndpoint.serviceReferences().forEach(this::populateServiceReferences);
}
return success;
}
Expand All @@ -93,13 +87,9 @@ public ServiceEndpoint unregisterService(String endpointId) {
serviceReferencesByQualifier.values().stream()
.flatMap(Collection::stream)
.filter(sr -> sr.endpointId().equals(endpointId))
.collect(Collectors.toList());
.toList();

serviceReferencesOfEndpoint.forEach(
sr -> {
computeServiceReferences(sr.qualifier(), sr);
computeServiceReferences(sr.oldQualifier(), sr);
});
serviceReferencesOfEndpoint.forEach(this::cleanServiceReferences);
}
return serviceEndpoint;
}
Expand Down Expand Up @@ -158,13 +148,11 @@ public void registerService(ServiceInfo serviceInfo) {
serviceInfo.level());

methodInvokers.put(methodInfo.qualifier(), methodInvoker);
methodInvokers.put(methodInfo.oldQualifier(), methodInvoker);
}));
}

private void checkMethodInvokerDoesntExist(MethodInfo methodInfo) {
if (methodInvokers.containsKey(methodInfo.qualifier())
|| methodInvokers.containsKey(methodInfo.oldQualifier())) {
if (methodInvokers.containsKey(methodInfo.qualifier())) {
LOGGER.log(Level.ERROR, "MethodInvoker already exists, methodInfo: {0}", methodInfo);
throw new IllegalStateException("MethodInvoker already exists");
}
Expand All @@ -180,20 +168,20 @@ public List<ServiceInfo> listServices() {
return serviceInfos;
}

private void populateServiceReferences(String qualifier, ServiceReference serviceReference) {
private void populateServiceReferences(ServiceReference sr) {
serviceReferencesByQualifier
.computeIfAbsent(qualifier, key -> new CopyOnWriteArrayList<>())
.add(serviceReference);
.computeIfAbsent(sr.qualifier(), key -> new CopyOnWriteArrayList<>())
.add(sr);
}

private void computeServiceReferences(String qualifier, ServiceReference serviceReference) {
private void cleanServiceReferences(ServiceReference sr) {
serviceReferencesByQualifier.compute(
qualifier,
sr.qualifier(),
(key, list) -> {
if (list == null || list.isEmpty()) {
return null;
}
list.remove(serviceReference);
list.remove(sr);
return !list.isEmpty() ? list : null;
});
}
Expand Down

0 comments on commit d704ba4

Please sign in to comment.