Skip to content

Commit

Permalink
FIX: Change syncronization tool in getVersion().
Browse files Browse the repository at this point in the history
  • Loading branch information
brido4125 committed Jul 27, 2023
1 parent 6e2c63b commit 8820c50
Showing 1 changed file with 22 additions and 28 deletions.
50 changes: 22 additions & 28 deletions src/main/java/net/spy/memcached/ArcusClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
*/
public class ArcusClient extends FrontCacheMemcachedClient implements ArcusClientIF {

private static String VERSION = "INIT";
private static final AtomicReference<String> VERSION = new AtomicReference<String>("INIT");
private static final Logger arcusLogger = LoggerFactory.getLogger(ArcusClient.class);
private static final String ARCUS_CLOUD_ADDR = "127.0.0.1:2181";
private static final String DEFAULT_ARCUS_CLIENT_NAME = "ArcusClient";
Expand Down Expand Up @@ -4273,37 +4273,31 @@ private void checkDupKey(Collection<String> keyList) {
* @return version string
*/
public static String getVersion() {
if (!VERSION.equals("INIT")) {
return VERSION;
String result = VERSION.get();
if (!result.equals("INIT")) {
return result;
}
synchronized (VERSION) {
if (VERSION.equals("INIT")) {
Enumeration<URL> resEnum;
try {
resEnum = Thread.currentThread()
.getContextClassLoader().getResources(JarFile.MANIFEST_NAME);
while (resEnum.hasMoreElements()) {
URL url = resEnum.nextElement();
InputStream is = url.openStream();
if (is != null) {
Manifest manifest = new Manifest(is);
java.util.jar.Attributes mainAttribs = manifest.getMainAttributes();
String version = mainAttribs.getValue("Arcusclient-Version");
if (version != null) {
VERSION = version;
break;
}
}
}
} catch (Exception e) {
// Failed to get version.
} finally {
if (VERSION.equals("INIT")) {
VERSION = "NONE";
Enumeration<URL> resEnum;
try {
resEnum = Thread.currentThread()
.getContextClassLoader().getResources(JarFile.MANIFEST_NAME);
while (resEnum.hasMoreElements()) {
URL url = resEnum.nextElement();
InputStream is = url.openStream();
if (is != null) {
Manifest manifest = new Manifest(is);
java.util.jar.Attributes mainAttribs = manifest.getMainAttributes();
String version = mainAttribs.getValue("Arcusclient-Version");
if (version != null) {
VERSION.compareAndSet("INIT", version);
break;
}
}
}
} catch (Exception e) {
// Failed to get version.
VERSION.compareAndSet("INIT", "NONE");
}
return VERSION;
return VERSION.get();
}
}

0 comments on commit 8820c50

Please sign in to comment.