Addition of AttackableThink and Movement task pools.
This commit is contained in:
@@ -48,7 +48,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -146,16 +145,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -146,16 +145,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -146,16 +145,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -146,16 +145,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -146,16 +145,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -146,16 +145,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -146,16 +145,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -146,16 +145,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -146,16 +145,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -146,16 +145,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -146,16 +145,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -146,16 +145,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ import org.l2jmobius.gameserver.network.serverpackets.LeaveWorld;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -296,16 +295,6 @@ public class Shutdown extends Thread
|
|||||||
// saveData sends messages to exit players, so shutdown selector after it
|
// saveData sends messages to exit players, so shutdown selector after it
|
||||||
saveData();
|
saveData();
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager thread has been shutdown.");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ import org.l2jmobius.gameserver.network.serverpackets.LeaveWorld;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -298,16 +297,6 @@ public class Shutdown extends Thread
|
|||||||
// saveData sends messages to exit players, so shutdown selector after it
|
// saveData sends messages to exit players, so shutdown selector after it
|
||||||
saveData();
|
saveData();
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager thread has been shutdown.");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -149,16 +148,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -151,16 +150,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -151,16 +150,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -147,16 +146,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -147,16 +146,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -147,16 +146,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -147,16 +146,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -147,16 +146,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -147,16 +146,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -147,16 +146,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -147,16 +146,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -147,16 +146,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -147,16 +146,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -147,16 +146,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -158,16 +157,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -158,16 +157,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
|||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
import org.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
|
||||||
import org.l2jmobius.gameserver.util.Broadcast;
|
import org.l2jmobius.gameserver.util.Broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -158,16 +157,6 @@ public class Shutdown extends Thread
|
|||||||
|
|
||||||
// ensure all services are stopped
|
// ensure all services are stopped
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MovementTaskManager.getInstance().interrupt();
|
|
||||||
LOGGER.info("Movement Task Manager: Thread interruped(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
|
||||||
}
|
|
||||||
catch (Throwable t)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameTimeTaskManager.getInstance().interrupt();
|
GameTimeTaskManager.getInstance().interrupt();
|
||||||
|
|||||||
@@ -26,60 +26,85 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager implements Runnable
|
public class AttackableThinkTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Attackable>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 1000;
|
||||||
|
|
||||||
protected AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class AttackableThink implements Runnable
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
if (_working)
|
private final Set<Attackable> _attackables;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
public AttackableThink(Set<Attackable> attackables)
|
||||||
for (Attackable attackable : ATTACKABLES)
|
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
_attackables = attackables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : _attackables)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
if (attackable.hasAI())
|
||||||
if (ai != null)
|
|
||||||
{
|
{
|
||||||
ai.onEvtThink();
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
|
{
|
||||||
|
ai.onEvtThink();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attackables.remove(attackable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
_attackables.remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(Attackable attackable)
|
||||||
|
{
|
||||||
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.contains(attackable))
|
||||||
{
|
{
|
||||||
remove(attackable);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
for (Set<Attackable> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
|
||||||
{
|
|
||||||
if (!ATTACKABLES.contains(attackable))
|
|
||||||
{
|
{
|
||||||
ATTACKABLES.add(attackable);
|
if (pool.size() < POOL_SIZE)
|
||||||
|
{
|
||||||
|
pool.add(attackable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Attackable> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(attackable);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new AttackableThink(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Attackable attackable)
|
public void remove(Attackable attackable)
|
||||||
{
|
{
|
||||||
ATTACKABLES.remove(attackable);
|
for (Set<Attackable> pool : POOLS)
|
||||||
|
{
|
||||||
|
if (pool.remove(attackable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AttackableThinkTaskManager getInstance()
|
public static AttackableThinkTaskManager getInstance()
|
||||||
|
|||||||
@@ -19,53 +19,66 @@ package org.l2jmobius.gameserver.taskmanager;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.threads.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Movement task manager class.
|
* Movement task manager class.
|
||||||
* @author Forsaiken, Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MovementTaskManager extends Thread
|
public class MovementTaskManager
|
||||||
{
|
{
|
||||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
private static final Set<Set<Creature>> POOLS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final int POOL_SIZE = 1000;
|
||||||
|
private static final int TASK_DELAY = 100;
|
||||||
|
|
||||||
protected MovementTaskManager()
|
protected MovementTaskManager()
|
||||||
{
|
{
|
||||||
super("MovementTaskManager");
|
}
|
||||||
super.setDaemon(true);
|
|
||||||
super.setPriority(MAX_PRIORITY);
|
private class Movement implements Runnable
|
||||||
super.start();
|
{
|
||||||
|
private final Set<Creature> _creatures;
|
||||||
|
|
||||||
|
public Movement(Set<Creature> creatures)
|
||||||
|
{
|
||||||
|
_creatures = creatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_creatures.removeIf(Creature::updatePosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Creature to moving objects of MovementTaskManager.
|
* Add a Creature to moving objects of MovementTaskManager.
|
||||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||||
*/
|
*/
|
||||||
public void registerMovingObject(Creature creature)
|
public synchronized void registerMovingObject(Creature creature)
|
||||||
{
|
{
|
||||||
if (creature == null)
|
for (Set<Creature> pool : POOLS)
|
||||||
{
|
{
|
||||||
return;
|
if (pool.contains(creature))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVING_OBJECTS.add(creature);
|
for (Set<Creature> pool : POOLS)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
try
|
if (pool.size() < POOL_SIZE)
|
||||||
{
|
{
|
||||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
pool.add(creature);
|
||||||
Thread.sleep(100);
|
return;
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
// Ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<Creature> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
|
||||||
|
pool.add(creature);
|
||||||
|
ThreadPool.scheduleAtFixedRate(new Movement(pool), TASK_DELAY, TASK_DELAY);
|
||||||
|
POOLS.add(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final MovementTaskManager getInstance()
|
public static final MovementTaskManager getInstance()
|
||||||
|
|||||||
Reference in New Issue
Block a user