mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-09-06 18:18:50 +00:00
docs: update service locator (#2963)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user