Closes #1283: Add custom Callable to prevent memory leaks
This commit is contained in:
@@ -25,7 +25,6 @@ import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
@@ -48,6 +47,7 @@ import appeng.crafting.CraftingJob;
|
||||
import appeng.me.Grid;
|
||||
import appeng.me.NetworkList;
|
||||
import appeng.tile.AEBaseTile;
|
||||
import appeng.util.IWorldCallable;
|
||||
import appeng.util.Platform;
|
||||
|
||||
import com.google.common.base.Stopwatch;
|
||||
@@ -59,9 +59,9 @@ public class TickHandler
|
||||
{
|
||||
|
||||
public static final TickHandler INSTANCE = new TickHandler();
|
||||
final Queue<Callable> serverQueue = new LinkedList<Callable>();
|
||||
final Queue<IWorldCallable<?>> serverQueue = new LinkedList<IWorldCallable<?>>();
|
||||
final Multimap<World, CraftingJob> craftingJobs = LinkedListMultimap.create();
|
||||
private final WeakHashMap<World, Queue<Callable>> callQueue = new WeakHashMap<World, Queue<Callable>>();
|
||||
private final WeakHashMap<World, Queue<IWorldCallable<?>>> callQueue = new WeakHashMap<World, Queue<IWorldCallable<?>>>();
|
||||
private final HandlerRep server = new HandlerRep();
|
||||
private final HandlerRep client = new HandlerRep();
|
||||
private final HashMap<Integer, PlayerColor> cliPlayerColors = new HashMap<Integer, PlayerColor>();
|
||||
@@ -77,7 +77,7 @@ public class TickHandler
|
||||
return this.cliPlayerColors;
|
||||
}
|
||||
|
||||
public void addCallable( World w, Callable c )
|
||||
public void addCallable( World w, IWorldCallable<?> c )
|
||||
{
|
||||
if( w == null )
|
||||
{
|
||||
@@ -85,11 +85,12 @@ public class TickHandler
|
||||
}
|
||||
else
|
||||
{
|
||||
Queue<Callable> queue = this.callQueue.get( w );
|
||||
Queue<IWorldCallable<?>> queue = this.callQueue.get( w );
|
||||
|
||||
if( queue == null )
|
||||
{
|
||||
this.callQueue.put( w, queue = new LinkedList<Callable>() );
|
||||
queue = new LinkedList<IWorldCallable<?>>();
|
||||
this.callQueue.put( w, queue );
|
||||
}
|
||||
|
||||
queue.add( c );
|
||||
@@ -235,13 +236,15 @@ public class TickHandler
|
||||
}
|
||||
|
||||
// cross world queue.
|
||||
this.processQueue( this.serverQueue );
|
||||
this.processQueue( this.serverQueue, null );
|
||||
}
|
||||
|
||||
// world synced queue(s)
|
||||
if( ev.type == Type.WORLD && ev.phase == Phase.START )
|
||||
{
|
||||
this.processQueue( this.callQueue.get( ( (WorldTickEvent) ev ).world ) );
|
||||
final World world = ( (WorldTickEvent) ev ).world;
|
||||
final Queue<IWorldCallable<?>> queue = this.callQueue.get( world );
|
||||
this.processQueue( queue, world );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,7 +262,7 @@ public class TickHandler
|
||||
}
|
||||
}
|
||||
|
||||
private void processQueue( Queue<Callable> queue )
|
||||
private void processQueue( Queue<IWorldCallable<?>> queue, World world )
|
||||
{
|
||||
if( queue == null )
|
||||
{
|
||||
@@ -268,12 +271,12 @@ public class TickHandler
|
||||
|
||||
Stopwatch sw = Stopwatch.createStarted();
|
||||
|
||||
Callable c = null;
|
||||
IWorldCallable<?> c = null;
|
||||
while( ( c = queue.poll() ) != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
c.call();
|
||||
c.call( world );
|
||||
|
||||
if( sw.elapsed( TimeUnit.MILLISECONDS ) > 50 )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user