docs: update service locator (#2963)

This commit is contained in:
Ilkka Seppälä
2024-05-20 15:42:46 +03:00
committed by GitHub
parent d656295d3c
commit 1c421b27ad
4 changed files with 120 additions and 28 deletions
@@ -36,7 +36,7 @@ import lombok.extern.slf4j.Slf4j;
public class InitContext {
/**
* Perform the lookup based on the service name. The returned object will need to be casted into a
* Perform the lookup based on the service name. The returned object will need to be cast into a
* {@link Service}
*
* @param serviceName a string
@@ -34,7 +34,7 @@ package com.iluwatar.servicelocator;
public interface Service {
/*
* The human readable name of the service
* The human-readable name of the service
*/
String getName();
@@ -47,9 +47,7 @@ public final class ServiceLocator {
*/
public static Service getService(String serviceJndiName) {
var serviceObj = serviceCache.getService(serviceJndiName);
if (serviceObj != null) {
return serviceObj;
} else {
if (serviceObj == null) {
/*
* If we are unable to retrieve anything from cache, then lookup the service and add it in the
* cache map
@@ -59,7 +57,7 @@ public final class ServiceLocator {
if (serviceObj != null) { // Only cache a service if it actually exists
serviceCache.addService(serviceObj);
}
return serviceObj;
}
return serviceObj;
}
}