From 7f663dd8737a181ddf2bf2edbc33e7db7832ff2e Mon Sep 17 00:00:00 2001 From: Obique PSWG Date: Fri, 30 Dec 2016 12:45:41 -0600 Subject: [PATCH] Changed ConcurrentHashMap to a custom SynchronizedHashMap for null value support --- src/resources/objects/SWGObject.java | 4 +- .../server_info/SynchronizedHashMap.java | 133 ++++++++++++++++++ 2 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 src/resources/server_info/SynchronizedHashMap.java diff --git a/src/resources/objects/SWGObject.java b/src/resources/objects/SWGObject.java index 71b4c0e73..88eb5f31f 100644 --- a/src/resources/objects/SWGObject.java +++ b/src/resources/objects/SWGObject.java @@ -52,6 +52,7 @@ import resources.persistable.Persistable; import resources.persistable.SWGObjectFactory; import resources.player.Player; import resources.server_info.Log; +import resources.server_info.SynchronizedHashMap; import services.CoreManager; import services.objects.ObjectCreator; import utilities.AwarenessUtilities; @@ -65,7 +66,6 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; public abstract class SWGObject extends BaselineObject implements Comparable, Persistable { @@ -74,7 +74,7 @@ public abstract class SWGObject extends BaselineObject implements Comparable containedObjects= new HashSet<>(); - private final Map slots = new ConcurrentHashMap<>(); // HashMap used for null value support + private final Map slots = new SynchronizedHashMap<>(); private final transient Map attributes = new LinkedHashMap<>(); private final transient ObjectAware awareness = new ObjectAware(this); private final transient Map dataAttributes = new HashMap<>(); diff --git a/src/resources/server_info/SynchronizedHashMap.java b/src/resources/server_info/SynchronizedHashMap.java new file mode 100644 index 000000000..9bd0ff865 --- /dev/null +++ b/src/resources/server_info/SynchronizedHashMap.java @@ -0,0 +1,133 @@ +/************************************************************************************ + * Copyright (c) 2015 /// Project SWG /// www.projectswg.com * + * * + * ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on * + * July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. * + * Our goal is to create an emulator which will provide a server for players to * + * continue playing a game similar to the one they used to play. We are basing * + * it on the final publish of the game prior to end-game events. * + * * + * This file is part of Holocore. * + * * + * -------------------------------------------------------------------------------- * + * * + * Holocore is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * Holocore is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with Holocore. If not, see . * + * * + ***********************************************************************************/ +package resources.server_info; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +public class SynchronizedHashMap implements Map { + + private final HashMap map; + + public SynchronizedHashMap() { + map = new HashMap<>(); + } + + public int hashCode() { + synchronized (map) { + return map.hashCode(); + } + } + + public String toString() { + synchronized (map) { + return map.toString(); + } + } + + public int size() { + synchronized (map) { + return map.size(); + } + } + + public boolean isEmpty() { + synchronized (map) { + return map.isEmpty(); + } + } + + public V get(Object key) { + synchronized (map) { + return map.get(key); + } + } + + public boolean containsKey(Object key) { + synchronized (map) { + return map.containsKey(key); + } + } + + public V put(K key, V value) { + synchronized (map) { + return map.put(key, value); + } + } + + public void putAll(Map m) { + synchronized (map) { + map.putAll(m); + } + } + + public V remove(Object key) { + synchronized (map) { + return map.remove(key); + } + } + + public void clear() { + synchronized (map) { + map.clear(); + } + } + + public boolean containsValue(Object value) { + synchronized (map) { + return map.containsValue(value); + } + } + + public Set keySet() { + synchronized (map) { + return map.keySet(); + } + } + + public Collection values() { + synchronized (map) { + return map.values(); + } + } + + public Set> entrySet() { + synchronized (map) { + return map.entrySet(); + } + } + + public V replace(K key, V value) { + synchronized (map) { + return map.replace(key, value); + } + } + +}