Fixed SummonEffectTable concurrency problem.

This commit is contained in:
MobiusDevelopment
2019-11-18 02:32:55 +00:00
parent 4d04017769
commit 2d19e0b2a1
47 changed files with 281 additions and 300 deletions

View File

@ -16,9 +16,9 @@
*/
package org.l2jmobius.gameserver.data.sql.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.skills.Skill;
@ -33,16 +33,16 @@ public class SummonEffectsTable
// -> key: charObjectId, value: classIndex Map
// --> key: classIndex, value: servitors Map
// ---> key: servitorSkillId, value: Effects list
private final Map<Integer, Map<Integer, Map<Integer, List<SummonEffect>>>> _servitorEffects = new HashMap<>();
private final Map<Integer, Map<Integer, Map<Integer, Collection<SummonEffect>>>> _servitorEffects = new ConcurrentHashMap<>();
public Map<Integer, Map<Integer, Map<Integer, List<SummonEffect>>>> getServitorEffectsOwner()
public Map<Integer, Map<Integer, Map<Integer, Collection<SummonEffect>>>> getServitorEffectsOwner()
{
return _servitorEffects;
}
public Map<Integer, List<SummonEffect>> getServitorEffects(PlayerInstance owner)
public Map<Integer, Collection<SummonEffect>> getServitorEffects(PlayerInstance owner)
{
final Map<Integer, Map<Integer, List<SummonEffect>>> servitorMap = _servitorEffects.get(owner.getObjectId());
final Map<Integer, Map<Integer, Collection<SummonEffect>>> servitorMap = _servitorEffects.get(owner.getObjectId());
if (servitorMap == null)
{
return null;
@ -51,9 +51,9 @@ public class SummonEffectsTable
}
/** Pets **/
private final Map<Integer, List<SummonEffect>> _petEffects = new HashMap<>(); // key: petItemObjectId, value: Effects list
private final Map<Integer, Collection<SummonEffect>> _petEffects = new ConcurrentHashMap<>(); // key: petItemObjectId, value: Effects list
public Map<Integer, List<SummonEffect>> getPetEffects()
public Map<Integer, Collection<SummonEffect>> getPetEffects()
{
return _petEffects;
}

View File

@ -19,11 +19,12 @@ package org.l2jmobius.gameserver.model.actor.instance;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -899,7 +900,7 @@ public class PetInstance extends Summon
public void stopSkillEffects(boolean removed, int skillId)
{
super.stopSkillEffects(removed, skillId);
final List<SummonEffect> effects = SummonEffectsTable.getInstance().getPetEffects().get(getControlObjectId());
final Collection<SummonEffect> effects = SummonEffectsTable.getInstance().getPetEffects().get(getControlObjectId());
if ((effects != null) && !effects.isEmpty())
{
for (SummonEffect effect : effects)
@ -1047,7 +1048,7 @@ public class PetInstance extends Summon
ps2.setInt(6, ++buff_index);
ps2.addBatch();
SummonEffectsTable.getInstance().getPetEffects().computeIfAbsent(getControlObjectId(), k -> new CopyOnWriteArrayList<>()).add(new SummonEffect(skill, info.getTime()));
SummonEffectsTable.getInstance().getPetEffects().computeIfAbsent(getControlObjectId(), k -> ConcurrentHashMap.newKeySet()).add(new SummonEffect(skill, info.getTime()));
}
ps2.executeBatch();
}
@ -1082,7 +1083,7 @@ public class PetInstance extends Summon
if (skill.hasEffects(EffectScope.GENERAL))
{
SummonEffectsTable.getInstance().getPetEffects().computeIfAbsent(getControlObjectId(), k -> new CopyOnWriteArrayList<>()).add(new SummonEffect(skill, effectCurTime));
SummonEffectsTable.getInstance().getPetEffects().computeIfAbsent(getControlObjectId(), k -> ConcurrentHashMap.newKeySet()).add(new SummonEffect(skill, effectCurTime));
}
}
}

View File

@ -22,10 +22,8 @@ import java.sql.ResultSet;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -237,10 +235,10 @@ public class ServitorInstance extends Summon implements Runnable
public void stopSkillEffects(boolean removed, int skillId)
{
super.stopSkillEffects(removed, skillId);
final Map<Integer, List<SummonEffect>> servitorEffects = SummonEffectsTable.getInstance().getServitorEffects(getOwner());
final Map<Integer, Collection<SummonEffect>> servitorEffects = SummonEffectsTable.getInstance().getServitorEffects(getOwner());
if (servitorEffects != null)
{
final List<SummonEffect> effects = servitorEffects.get(_referenceSkill);
final Collection<SummonEffect> effects = servitorEffects.get(_referenceSkill);
if ((effects != null) && !effects.isEmpty())
{
for (SummonEffect effect : effects)
@ -373,7 +371,7 @@ public class ServitorInstance extends Summon implements Runnable
}
if (!SummonEffectsTable.getInstance().getServitorEffects(getOwner()).containsKey(getReferenceSkill()))
{
SummonEffectsTable.getInstance().getServitorEffects(getOwner()).put(getReferenceSkill(), new CopyOnWriteArrayList<>());
SummonEffectsTable.getInstance().getServitorEffects(getOwner()).put(getReferenceSkill(), ConcurrentHashMap.newKeySet());
}
SummonEffectsTable.getInstance().getServitorEffects(getOwner()).get(getReferenceSkill()).add(new SummonEffect(skill, info.getTime()));
@ -430,7 +428,7 @@ public class ServitorInstance extends Summon implements Runnable
}
if (!SummonEffectsTable.getInstance().getServitorEffects(getOwner()).containsKey(getReferenceSkill()))
{
SummonEffectsTable.getInstance().getServitorEffects(getOwner()).put(getReferenceSkill(), new CopyOnWriteArrayList<>());
SummonEffectsTable.getInstance().getServitorEffects(getOwner()).put(getReferenceSkill(), ConcurrentHashMap.newKeySet());
}
SummonEffectsTable.getInstance().getServitorEffects(getOwner()).get(getReferenceSkill()).add(new SummonEffect(skill, effectCurTime));