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