Removal of Warehouse Cache.
This commit is contained in:
@@ -503,8 +503,6 @@ public class Config
|
||||
public static boolean ENABLE_WORLD_CHAT;
|
||||
public static int MINIMUM_CHAT_LEVEL;
|
||||
public static boolean ALLOW_WAREHOUSE;
|
||||
public static boolean WAREHOUSE_CACHE;
|
||||
public static int WAREHOUSE_CACHE_TIME;
|
||||
public static boolean ALLOW_REFUND;
|
||||
public static boolean ALLOW_MAIL;
|
||||
public static boolean ALLOW_ATTACHMENTS;
|
||||
@@ -2181,8 +2179,6 @@ public class Config
|
||||
ENABLE_WORLD_CHAT = generalConfig.getBoolean("WorldChatEnabled", true);
|
||||
MINIMUM_CHAT_LEVEL = generalConfig.getInt("MinimumChatLevel", 20);
|
||||
ALLOW_WAREHOUSE = generalConfig.getBoolean("AllowWarehouse", true);
|
||||
WAREHOUSE_CACHE = generalConfig.getBoolean("WarehouseCache", false);
|
||||
WAREHOUSE_CACHE_TIME = generalConfig.getInt("WarehouseCacheTime", 15);
|
||||
ALLOW_REFUND = generalConfig.getBoolean("AllowRefund", true);
|
||||
ALLOW_MAIL = generalConfig.getBoolean("AllowMail", true);
|
||||
ALLOW_ATTACHMENTS = generalConfig.getBoolean("AllowAttachments", true);
|
||||
|
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.cache;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.threads.ThreadPool;
|
||||
import org.l2jmobius.gameserver.model.actor.Player;
|
||||
|
||||
/**
|
||||
* @author -Nemesiss-
|
||||
*/
|
||||
public class WarehouseCacheManager
|
||||
{
|
||||
protected static final Map<Player, Long> CACHED_WH = new ConcurrentHashMap<>();
|
||||
protected static final long CACHE_TIME = Config.WAREHOUSE_CACHE_TIME * 60000;
|
||||
|
||||
protected WarehouseCacheManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(new CacheScheduler(), 120000, 60000);
|
||||
}
|
||||
|
||||
public void addCacheTask(Player pc)
|
||||
{
|
||||
CACHED_WH.put(pc, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public void remCacheTask(Player pc)
|
||||
{
|
||||
CACHED_WH.remove(pc);
|
||||
}
|
||||
|
||||
private class CacheScheduler implements Runnable
|
||||
{
|
||||
public CacheScheduler()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
final long cTime = System.currentTimeMillis();
|
||||
for (Entry<Player, Long> entry : CACHED_WH.entrySet())
|
||||
{
|
||||
if ((cTime - entry.getValue().longValue()) > CACHE_TIME)
|
||||
{
|
||||
final Player player = entry.getKey();
|
||||
player.clearWarehouse();
|
||||
CACHED_WH.remove(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static WarehouseCacheManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final WarehouseCacheManager INSTANCE = new WarehouseCacheManager();
|
||||
}
|
||||
}
|
@@ -55,7 +55,6 @@ import org.l2jmobius.gameserver.ai.CtrlIntention;
|
||||
import org.l2jmobius.gameserver.ai.PlayerAI;
|
||||
import org.l2jmobius.gameserver.ai.SummonAI;
|
||||
import org.l2jmobius.gameserver.cache.RelationCache;
|
||||
import org.l2jmobius.gameserver.cache.WarehouseCacheManager;
|
||||
import org.l2jmobius.gameserver.communitybbs.BB.Forum;
|
||||
import org.l2jmobius.gameserver.communitybbs.Manager.ForumsBBSManager;
|
||||
import org.l2jmobius.gameserver.data.ItemTable;
|
||||
@@ -613,7 +612,7 @@ public class Player extends Playable
|
||||
|
||||
private final PlayerInventory _inventory = new PlayerInventory(this);
|
||||
private final PlayerFreight _freight = new PlayerFreight(this);
|
||||
private PlayerWarehouse _warehouse;
|
||||
private final PlayerWarehouse _warehouse = new PlayerWarehouse(this);
|
||||
private PlayerRefund _refund;
|
||||
private PrivateStoreType _privateStoreType = PrivateStoreType.NONE;
|
||||
private TradeList _activeTradeList;
|
||||
@@ -3046,36 +3045,15 @@ public class Player extends Playable
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the PcWarehouse object of the Player.
|
||||
* @return the PlayerWarehouse object of the Player.
|
||||
*/
|
||||
public PlayerWarehouse getWarehouse()
|
||||
{
|
||||
if (_warehouse == null)
|
||||
{
|
||||
_warehouse = new PlayerWarehouse(this);
|
||||
_warehouse.restore();
|
||||
}
|
||||
if (Config.WAREHOUSE_CACHE)
|
||||
{
|
||||
WarehouseCacheManager.getInstance().addCacheTask(this);
|
||||
}
|
||||
return _warehouse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Free memory used by Warehouse
|
||||
*/
|
||||
public void clearWarehouse()
|
||||
{
|
||||
if (_warehouse != null)
|
||||
{
|
||||
_warehouse.deleteMe();
|
||||
}
|
||||
_warehouse = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the PcFreight object of the Player.
|
||||
* @return the PlayerFreight object of the Player.
|
||||
*/
|
||||
public PlayerFreight getFreight()
|
||||
{
|
||||
@@ -6931,11 +6909,8 @@ public class Player extends Playable
|
||||
|
||||
// Retrieve from the database all items of this Player and add them to _inventory
|
||||
player.getInventory().restore();
|
||||
player.getWarehouse().restore();
|
||||
player.getFreight().restore();
|
||||
if (!Config.WAREHOUSE_CACHE)
|
||||
{
|
||||
player.getWarehouse();
|
||||
}
|
||||
|
||||
player.restoreItemReuse();
|
||||
|
||||
@@ -11581,16 +11556,12 @@ public class Player extends Playable
|
||||
// Update database with items in its warehouse and remove them from the world
|
||||
try
|
||||
{
|
||||
clearWarehouse();
|
||||
getWarehouse().deleteMe();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, "deleteMe()", e);
|
||||
}
|
||||
if (Config.WAREHOUSE_CACHE)
|
||||
{
|
||||
WarehouseCacheManager.getInstance().remCacheTask(this);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
Reference in New Issue
Block a user