From 209f3d0922b168cf068a880a35730004d07afb79 Mon Sep 17 00:00:00 2001 From: Rogiel Date: Thu, 29 Dec 2011 02:44:41 -0200 Subject: [PATCH] Implements configuration for WorldEventDispatcherService --- .../distribution/services.xml | 12 +++- l2jserver2-gameserver/services-sample.xml | 12 +++- .../main/java/com/l2jserver/game/ai/AI.java | 4 +- .../service/game/AttackServiceImpl.java | 8 +-- .../service/game/ai/AIServiceImpl.java | 6 +- .../game/character/CharacterServiceImpl.java | 6 +- .../game/character/ShortcutServiceImpl.java | 6 +- .../service/game/item/ItemServiceImpl.java | 6 +- .../map/pathing/MapperPathingService.java | 6 +- .../service/game/npc/NPCServiceImpl.java | 6 +- .../service/game/spawn/SpawnServiceImpl.java | 6 +- .../service/game/world/WorldService.java | 11 +--- .../service/game/world/WorldServiceImpl.java | 19 ++----- .../service/game/world/event/WorldEvent.java | 2 +- ....java => WorldEventDispatcherService.java} | 11 +++- ...ldEventDispatcherServiceConfiguration.java | 43 ++++++++++++++ ...a => WorldEventDispatcherServiceImpl.java} | 56 +++++++++---------- .../broadcast/BroadcastServiceImpl.java | 6 +- .../world/WorldEventDispatcherImplTest.java | 10 ++-- 19 files changed, 144 insertions(+), 92 deletions(-) rename l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/event/{WorldEventDispatcher.java => WorldEventDispatcherService.java} (91%) create mode 100644 l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/event/WorldEventDispatcherServiceConfiguration.java rename l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/event/{WorldEventDispatcherImpl.java => WorldEventDispatcherServiceImpl.java} (88%) diff --git a/l2jserver2-gameserver/distribution/services.xml b/l2jserver2-gameserver/distribution/services.xml index bc16dd81d..d4a33f7e7 100644 --- a/l2jserver2-gameserver/distribution/services.xml +++ b/l2jserver2-gameserver/distribution/services.xml @@ -113,8 +113,16 @@ - + + + + + diff --git a/l2jserver2-gameserver/services-sample.xml b/l2jserver2-gameserver/services-sample.xml index 14f95c415..4897c5880 100644 --- a/l2jserver2-gameserver/services-sample.xml +++ b/l2jserver2-gameserver/services-sample.xml @@ -134,8 +134,16 @@ - + + + + + diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/game/ai/AI.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/game/ai/AI.java index bba3eea52..d44bf6382 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/game/ai/AI.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/game/ai/AI.java @@ -21,7 +21,7 @@ import com.l2jserver.game.ai.desires.Desire; import com.l2jserver.game.ai.desires.DesireQueue; import com.l2jserver.model.world.Actor; import com.l2jserver.service.game.world.WorldService; -import com.l2jserver.service.game.world.event.WorldEventDispatcher; +import com.l2jserver.service.game.world.event.WorldEventDispatcherService; /** * @author Rogiel @@ -42,7 +42,7 @@ public abstract class AI { * The {@link WorldService} event dispatcher */ @Inject - protected WorldEventDispatcher eventDispatcher; + protected WorldEventDispatcherService eventDispatcher; /** * Creates a new AI diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/AttackServiceImpl.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/AttackServiceImpl.java index 90ca5db3e..02e6e5236 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/AttackServiceImpl.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/AttackServiceImpl.java @@ -37,7 +37,7 @@ import com.l2jserver.service.core.threading.AbstractTask; import com.l2jserver.service.core.threading.AsyncFuture; import com.l2jserver.service.core.threading.ThreadService; import com.l2jserver.service.game.npc.NPCService; -import com.l2jserver.service.game.world.event.WorldEventDispatcher; +import com.l2jserver.service.game.world.event.WorldEventDispatcherService; /** * @author Rogiel @@ -64,10 +64,10 @@ public class AttackServiceImpl extends AbstractService implements AttackService private final NPCService npcService; /** - * The {@link WorldEventDispatcher} is used to dispatch attack events to the + * The {@link WorldEventDispatcherService} is used to dispatch attack events to the * world */ - private final WorldEventDispatcher eventDispatcher; + private final WorldEventDispatcherService eventDispatcher; /** * @param threadService @@ -79,7 +79,7 @@ public class AttackServiceImpl extends AbstractService implements AttackService */ @Inject public AttackServiceImpl(ThreadService threadService, - NPCService npcService, WorldEventDispatcher eventDispatcher) { + NPCService npcService, WorldEventDispatcherService eventDispatcher) { this.threadService = threadService; this.npcService = npcService; this.eventDispatcher = eventDispatcher; diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/ai/AIServiceImpl.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/ai/AIServiceImpl.java index 3a0456436..caa2b7b4f 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/ai/AIServiceImpl.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/ai/AIServiceImpl.java @@ -28,7 +28,7 @@ import com.l2jserver.service.ServiceStopException; import com.l2jserver.service.core.threading.ThreadService; import com.l2jserver.service.game.template.TemplateService; import com.l2jserver.service.game.world.WorldService; -import com.l2jserver.service.game.world.event.WorldEventDispatcher; +import com.l2jserver.service.game.world.event.WorldEventDispatcherService; import com.l2jserver.service.network.NetworkService; import com.l2jserver.util.geometry.Coordinate; @@ -55,7 +55,7 @@ public class AIServiceImpl extends AbstractService implements AIService { * The {@link WorldService} event dispatcher */ @SuppressWarnings("unused") - private final WorldEventDispatcher eventDispatcher; + private final WorldEventDispatcherService eventDispatcher; /** * The {@link ThreadService} */ @@ -79,7 +79,7 @@ public class AIServiceImpl extends AbstractService implements AIService { */ @Inject public AIServiceImpl(WorldService worldService, - WorldEventDispatcher eventDispatcher, ThreadService threadService, + WorldEventDispatcherService eventDispatcher, ThreadService threadService, NetworkService networkService) { this.worldService = worldService; this.eventDispatcher = eventDispatcher; diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/character/CharacterServiceImpl.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/character/CharacterServiceImpl.java index e5106b8a5..db0a445f4 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/character/CharacterServiceImpl.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/character/CharacterServiceImpl.java @@ -60,7 +60,7 @@ import com.l2jserver.service.game.spawn.NotSpawnedServiceException; import com.l2jserver.service.game.spawn.SpawnPointNotFoundServiceException; import com.l2jserver.service.game.spawn.SpawnService; import com.l2jserver.service.game.world.WorldService; -import com.l2jserver.service.game.world.event.WorldEventDispatcher; +import com.l2jserver.service.game.world.event.WorldEventDispatcherService; import com.l2jserver.service.network.broadcast.BroadcastService; import com.l2jserver.service.network.gameguard.GameGuardService; import com.l2jserver.util.ArrayUtils; @@ -90,7 +90,7 @@ public class CharacterServiceImpl extends /** * The {@link WorldService} event dispatcher */ - private final WorldEventDispatcher eventDispatcher; + private final WorldEventDispatcherService eventDispatcher; /** * The {@link SpawnService} */ @@ -161,7 +161,7 @@ public class CharacterServiceImpl extends */ @Inject public CharacterServiceImpl(BroadcastService broadcastService, - WorldEventDispatcher eventDispatcher, SpawnService spawnService, + WorldEventDispatcherService eventDispatcher, SpawnService spawnService, NPCService npcService, GameGuardService ggService, CharacterDAO characterDao, ItemDAO itemDao, CharacterShortcutDAO shortcutDao, diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/character/ShortcutServiceImpl.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/character/ShortcutServiceImpl.java index 57e4b05a8..330d70773 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/character/ShortcutServiceImpl.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/character/ShortcutServiceImpl.java @@ -27,7 +27,7 @@ import com.l2jserver.model.world.character.event.CharacterCreateShortcutEvent; import com.l2jserver.model.world.character.event.CharacterDeleteShortcutEvent; import com.l2jserver.service.AbstractService; import com.l2jserver.service.game.world.WorldService; -import com.l2jserver.service.game.world.event.WorldEventDispatcher; +import com.l2jserver.service.game.world.event.WorldEventDispatcherService; /** * @author Rogiel @@ -37,7 +37,7 @@ public class ShortcutServiceImpl extends AbstractService implements /** * The {@link WorldService} event dispatcher */ - private final WorldEventDispatcher eventDispatcher; + private final WorldEventDispatcherService eventDispatcher; /** * The {@link CharacterShortcut} DAO */ @@ -50,7 +50,7 @@ public class ShortcutServiceImpl extends AbstractService implements * the shortcut DAO */ @Inject - private ShortcutServiceImpl(WorldEventDispatcher eventDispatcher, + private ShortcutServiceImpl(WorldEventDispatcherService eventDispatcher, CharacterShortcutDAO shortcutDao) { this.eventDispatcher = eventDispatcher; this.shortcutDao = shortcutDao; diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/item/ItemServiceImpl.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/item/ItemServiceImpl.java index e17aeaf4d..dbecdfb17 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/item/ItemServiceImpl.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/item/ItemServiceImpl.java @@ -44,7 +44,7 @@ import com.l2jserver.service.game.spawn.NotSpawnedServiceException; import com.l2jserver.service.game.spawn.SpawnPointNotFoundServiceException; import com.l2jserver.service.game.spawn.SpawnService; import com.l2jserver.service.game.world.WorldService; -import com.l2jserver.service.game.world.event.WorldEventDispatcher; +import com.l2jserver.service.game.world.event.WorldEventDispatcherService; import com.l2jserver.util.ArrayUtils; import com.l2jserver.util.geometry.Point3D; @@ -66,7 +66,7 @@ public class ItemServiceImpl extends /** * The {@link WorldService} event dispatcher */ - private final WorldEventDispatcher eventDispatcher; + private final WorldEventDispatcherService eventDispatcher; /** * The {@link ItemID} provider */ @@ -89,7 +89,7 @@ public class ItemServiceImpl extends */ @Inject private ItemServiceImpl(ItemDAO itemDao, SpawnService spawnService, - WorldEventDispatcher eventDispatcher, ItemIDProvider itemIdProvider) { + WorldEventDispatcherService eventDispatcher, ItemIDProvider itemIdProvider) { super(ItemServiceConfiguration.class); this.itemDao = itemDao; this.spawnService = spawnService; diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/map/pathing/MapperPathingService.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/map/pathing/MapperPathingService.java index 7475db2e3..93806eca8 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/map/pathing/MapperPathingService.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/map/pathing/MapperPathingService.java @@ -38,7 +38,7 @@ import com.l2jserver.service.ServiceStopException; import com.l2jserver.service.game.character.CharacterService; import com.l2jserver.service.game.world.WorldService; import com.l2jserver.service.game.world.event.TypedWorldListener; -import com.l2jserver.service.game.world.event.WorldEventDispatcher; +import com.l2jserver.service.game.world.event.WorldEventDispatcherService; import com.l2jserver.util.geometry.Coordinate; import com.l2jserver.util.geometry.Point3D; @@ -69,7 +69,7 @@ public class MapperPathingService extends AbstractService implements /** * The {@link WorldService} event dispatcher */ - private final WorldEventDispatcher eventDispatcher; + private final WorldEventDispatcherService eventDispatcher; /** * The database channel, will remain open until service is stopped. @@ -83,7 +83,7 @@ public class MapperPathingService extends AbstractService implements * the world event dispatcher */ @Inject - public MapperPathingService(WorldEventDispatcher eventDispatcher) { + public MapperPathingService(WorldEventDispatcherService eventDispatcher) { this.eventDispatcher = eventDispatcher; } diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/npc/NPCServiceImpl.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/npc/NPCServiceImpl.java index 0c74f4618..4875e467a 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/npc/NPCServiceImpl.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/npc/NPCServiceImpl.java @@ -53,7 +53,7 @@ import com.l2jserver.service.game.spawn.AlreadySpawnedServiceException; import com.l2jserver.service.game.spawn.SpawnPointNotFoundServiceException; import com.l2jserver.service.game.spawn.SpawnService; import com.l2jserver.service.game.world.WorldService; -import com.l2jserver.service.game.world.event.WorldEventDispatcher; +import com.l2jserver.service.game.world.event.WorldEventDispatcherService; import com.l2jserver.util.exception.L2Exception; import com.l2jserver.util.factory.CollectionFactory; import com.l2jserver.util.geometry.Point3D; @@ -93,7 +93,7 @@ public class NPCServiceImpl extends AbstractService implements NPCService { /** * The {@link WorldService} event dispatcher */ - private final WorldEventDispatcher eventDispatcher; + private final WorldEventDispatcherService eventDispatcher; /** * The {@link NPCDAO} */ @@ -134,7 +134,7 @@ public class NPCServiceImpl extends AbstractService implements NPCService { @Inject public NPCServiceImpl(SpawnService spawnService, CharacterService characterService, ThreadService threadService, - AttackService attackService, WorldEventDispatcher eventDispatcher, + AttackService attackService, WorldEventDispatcherService eventDispatcher, NPCDAO npcDao, Injector injector) { this.spawnService = spawnService; this.characterService = characterService; diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/spawn/SpawnServiceImpl.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/spawn/SpawnServiceImpl.java index c77041f2c..6d4ee5ecd 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/spawn/SpawnServiceImpl.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/spawn/SpawnServiceImpl.java @@ -40,7 +40,7 @@ import com.l2jserver.service.core.threading.AbstractTask; import com.l2jserver.service.core.threading.AsyncFuture; import com.l2jserver.service.core.threading.ThreadService; import com.l2jserver.service.game.world.WorldService; -import com.l2jserver.service.game.world.event.WorldEventDispatcher; +import com.l2jserver.service.game.world.event.WorldEventDispatcherService; import com.l2jserver.util.geometry.Coordinate; import com.l2jserver.util.geometry.Point3D; @@ -63,7 +63,7 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService { /** * The {@link WorldService} event dispatcher */ - private final WorldEventDispatcher eventDispatcher; + private final WorldEventDispatcherService eventDispatcher; /** * The {@link ThreadService} */ @@ -79,7 +79,7 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService { */ @Inject public SpawnServiceImpl(WorldService worldService, - WorldEventDispatcher eventDispatcher, ThreadService threadService) { + WorldEventDispatcherService eventDispatcher, ThreadService threadService) { this.worldService = worldService; this.eventDispatcher = eventDispatcher; this.threadService = threadService; diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/WorldService.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/WorldService.java index c5ae11ac9..af276cb70 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/WorldService.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/WorldService.java @@ -25,7 +25,7 @@ import com.l2jserver.model.world.NPC; import com.l2jserver.model.world.PositionableObject; import com.l2jserver.model.world.WorldObject; import com.l2jserver.service.Service; -import com.l2jserver.service.game.world.event.WorldEventDispatcher; +import com.l2jserver.service.game.world.event.WorldEventDispatcherService; import com.l2jserver.service.game.world.filter.WorldObjectFilter; import com.l2jserver.service.network.broadcast.BroadcastService; @@ -38,7 +38,7 @@ import com.l2jserver.service.network.broadcast.BroadcastService; * this service and it can be broadcasted (using {@link BroadcastService}) to * all nearby clients (see {@link Lineage2Client}). *

Other tasks

World event dispatching is handled by - * {@link WorldEventDispatcher}. + * {@link WorldEventDispatcherService}. *

* {@link ObjectID} object management is done through {@link WorldIDService} * that can be used to cache those IDs. @@ -112,13 +112,6 @@ public interface WorldService extends Service, Iterable { void knownObject(WorldObject object); } - /** - * Get the event dispatcher - * - * @return the event dispatcher - */ - WorldEventDispatcher getEventDispatcher(); - /** * Creates a list of all objects matching filter * diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/WorldServiceImpl.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/WorldServiceImpl.java index b16b16112..b1caf350d 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/WorldServiceImpl.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/WorldServiceImpl.java @@ -36,8 +36,7 @@ import com.l2jserver.service.core.LoggingService; import com.l2jserver.service.database.DatabaseService; import com.l2jserver.service.game.scripting.ScriptingService; import com.l2jserver.service.game.template.TemplateService; -import com.l2jserver.service.game.world.event.WorldEventDispatcher; -import com.l2jserver.service.game.world.event.WorldEventDispatcherImpl; +import com.l2jserver.service.game.world.event.WorldEventDispatcherService; import com.l2jserver.service.game.world.filter.FilterIterator; import com.l2jserver.service.game.world.filter.WorldObjectFilter; import com.l2jserver.service.game.world.filter.impl.IDFilter; @@ -51,7 +50,8 @@ import com.l2jserver.util.factory.CollectionFactory; * @author Rogiel */ @Depends({ LoggingService.class, TemplateService.class, ScriptingService.class, - DatabaseService.class, WorldIDService.class }) + DatabaseService.class, WorldIDService.class, + WorldEventDispatcherService.class }) public class WorldServiceImpl extends AbstractService implements WorldService { /** * The logger @@ -66,7 +66,7 @@ public class WorldServiceImpl extends AbstractService implements WorldService { /** * The world event dispatcher */ - private final WorldEventDispatcherImpl dispatcher; + private final WorldEventDispatcherService dispatcher; /** * The {@link WorldIDService} */ @@ -79,9 +79,9 @@ public class WorldServiceImpl extends AbstractService implements WorldService { * the world id service */ @Inject - public WorldServiceImpl(WorldEventDispatcher dispatcher, + public WorldServiceImpl(WorldEventDispatcherService dispatcher, WorldIDService idService) { - this.dispatcher = (WorldEventDispatcherImpl) dispatcher; + this.dispatcher = dispatcher; this.idService = idService; } @@ -89,7 +89,6 @@ public class WorldServiceImpl extends AbstractService implements WorldService { protected void doStart() throws ServiceStartException { objects.clear(); idService.load(); - dispatcher.start(); } @Override @@ -139,11 +138,6 @@ public class WorldServiceImpl extends AbstractService implements WorldService { } } - @Override - public WorldEventDispatcher getEventDispatcher() { - return dispatcher; - } - @Override public List list(WorldObjectFilter filter) { Preconditions.checkNotNull(filter, "filter"); @@ -190,6 +184,5 @@ public class WorldServiceImpl extends AbstractService implements WorldService { protected void doStop() throws ServiceStopException { objects.clear(); idService.unload(); - dispatcher.stop(); } } diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/event/WorldEvent.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/event/WorldEvent.java index fab8c2f92..0ede9eec3 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/event/WorldEvent.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/event/WorldEvent.java @@ -21,7 +21,7 @@ import com.l2jserver.model.world.WorldObject; /** * Base event class. Every event must implement this interface in order to be - * dispatched by {@link WorldEventDispatcher} + * dispatched by {@link WorldEventDispatcherService} * * @author Rogiel */ diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/event/WorldEventDispatcher.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/event/WorldEventDispatcherService.java similarity index 91% rename from l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/event/WorldEventDispatcher.java rename to l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/event/WorldEventDispatcherService.java index 3e355ee80..c6d63a775 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/event/WorldEventDispatcher.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/event/WorldEventDispatcherService.java @@ -18,6 +18,7 @@ package com.l2jserver.service.game.world.event; import com.l2jserver.model.id.ObjectID; import com.l2jserver.model.world.WorldObject; +import com.l2jserver.service.Service; /** * This event dispatcher notify listeners that an certain event occured in their @@ -25,7 +26,7 @@ import com.l2jserver.model.world.WorldObject; * * @author Rogiel */ -public interface WorldEventDispatcher { +public interface WorldEventDispatcherService extends Service { /** * Notify listeners of the event. Note that not all implementation * need to invoke listeners immediately. Dispatching can occur @@ -95,4 +96,12 @@ public interface WorldEventDispatcher { * the listener */ void removeListener(ObjectID id, WorldListener listener); + + /** + * Removes all listeners from a given object + * + * @param id + * the object id + */ + public void clear(ObjectID id); } diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/event/WorldEventDispatcherServiceConfiguration.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/event/WorldEventDispatcherServiceConfiguration.java new file mode 100644 index 000000000..44e658335 --- /dev/null +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/event/WorldEventDispatcherServiceConfiguration.java @@ -0,0 +1,43 @@ +/* + * This file is part of l2jserver2 . + * + * l2jserver2 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. + * + * l2jserver2 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 l2jserver2. If not, see . + */ +package com.l2jserver.service.game.world.event; + +import com.l2jserver.service.ServiceConfiguration; +import com.l2jserver.service.configuration.XMLConfigurationService.ConfigurationXPath; + +/** + * Configuration interface for {@link WorldEventDispatcherService} + * + * @author Rogiel + */ +public interface WorldEventDispatcherServiceConfiguration extends + ServiceConfiguration { + /** + * @return the number of threads to use (0 for automatic detection) + */ + @ConfigurationPropertyGetter(defaultValue = "0") + @ConfigurationXPath("threading/@count") + int getDispatcherThreadCount(); + + /** + * @param dispatcherThreadCount + * the number of threads to use (0 for automatic detection) + */ + @ConfigurationPropertySetter + @ConfigurationXPath("threading/@count") + void setDispatcherThreadCount(int dispatcherThreadCount); +} diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/event/WorldEventDispatcherImpl.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/event/WorldEventDispatcherServiceImpl.java similarity index 88% rename from l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/event/WorldEventDispatcherImpl.java rename to l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/event/WorldEventDispatcherServiceImpl.java index 35fc829f7..49c2ac97e 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/event/WorldEventDispatcherImpl.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/event/WorldEventDispatcherServiceImpl.java @@ -23,30 +23,26 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.google.common.base.Preconditions; import com.google.common.util.concurrent.AbstractFuture; import com.google.inject.Inject; import com.l2jserver.model.id.ObjectID; import com.l2jserver.model.world.WorldObject; +import com.l2jserver.service.AbstractConfigurableService; +import com.l2jserver.service.AbstractService.Depends; import com.l2jserver.service.core.threading.ThreadPool; import com.l2jserver.service.core.threading.ThreadService; import com.l2jserver.util.factory.CollectionFactory; /** - * Default {@link WorldEventDispatcher} implementation + * Default {@link WorldEventDispatcherService} implementation * * @author Rogiel */ -public class WorldEventDispatcherImpl implements WorldEventDispatcher { - /** - * The logger - */ - private static final Logger log = LoggerFactory - .getLogger(WorldEventDispatcherImpl.class); - +@Depends(ThreadService.class) +public class WorldEventDispatcherServiceImpl extends + AbstractConfigurableService + implements WorldEventDispatcherService { /** * The thread service */ @@ -77,15 +73,20 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher { * the thread service */ @Inject - public WorldEventDispatcherImpl(ThreadService threadService) { + public WorldEventDispatcherServiceImpl(ThreadService threadService) { + super(WorldEventDispatcherServiceConfiguration.class); this.threadService = threadService; } /** * Stats the world event dispatcher */ - public void start() { - final int threads = Runtime.getRuntime().availableProcessors(); + @Override + public void doStart() { + int threads = config.getDispatcherThreadCount(); + if (threads <= 0) + threads = Runtime.getRuntime().availableProcessors(); + threadPool = threadService .createThreadPool("event-dispatcher", threads); for (int i = 0; i < threads; i++) { @@ -99,7 +100,8 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher { if (event.future.isCancelled()) continue; - log.debug("Dispatching event {}", event.event); + logger.debug("Dispatching event {}", + event.event); // set state event.future.running = true; @@ -111,7 +113,7 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher { event.future.set(event.event); } catch (Throwable t) { event.future.setException(t); - log.warn( + logger.warn( "Exception in WorldEventDispatcher thread", t); } @@ -125,7 +127,7 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher { @Override public WorldEventFuture dispatch(final E event) { Preconditions.checkNotNull(event, "event"); - log.debug("Queing dispatch for event {}", event); + logger.debug("Queing dispatch for event {}", event); final WorldEventFutureImpl future = new WorldEventFutureImpl(); events.add(new EventContainer(event, future)); @@ -149,7 +151,7 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher { // remove listener if return value is false globalListeners.remove(listener); } catch (Throwable t) { - log.warn("Exception in listener", t); + logger.warn("Exception in listener", t); // always remove any listener that throws an exception globalListeners.remove(listener); } @@ -161,7 +163,7 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher { // remove listener if return value is false listeners.remove(listener); } catch (Throwable t) { - log.warn("Exception in listener", t); + logger.warn("Exception in listener", t); // always remove any listener that throws an exception listeners.remove(listener); } @@ -172,7 +174,7 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher { @Override public void addListener(WorldListener listener) { Preconditions.checkNotNull(listener, "listener"); - log.debug("Adding new listener global {}", listener); + logger.debug("Adding new listener global {}", listener); globalListeners.add(listener); } @@ -187,7 +189,7 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher { public void addListener(ObjectID id, WorldListener listener) { Preconditions.checkNotNull(id, "id"); Preconditions.checkNotNull(listener, "listener"); - log.debug("Adding new listener {} to {}", listener, id); + logger.debug("Adding new listener {} to {}", listener, id); getListeners(id).add(listener); } @@ -208,16 +210,11 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher { public void removeListener(ObjectID id, WorldListener listener) { Preconditions.checkNotNull(id, "id"); Preconditions.checkNotNull(listener, "listener"); - log.debug("Removing new listener {} from {}", listener, id); + logger.debug("Removing new listener {} from {}", listener, id); getListeners(id).remove(listener); } - /** - * Removes all listeners from a given object - * - * @param id - * the object id - */ + @Override public void clear(ObjectID id) { Preconditions.checkNotNull(id, "id"); listeners.remove(id); @@ -244,7 +241,8 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher { /** * Stops the world event dispatcher */ - public void stop() { + @Override + public void doStop() { threadService.dispose(threadPool); threadPool = null; } diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/network/broadcast/BroadcastServiceImpl.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/network/broadcast/BroadcastServiceImpl.java index a54a33532..42cd681ff 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/network/broadcast/BroadcastServiceImpl.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/network/broadcast/BroadcastServiceImpl.java @@ -81,7 +81,7 @@ import com.l2jserver.service.game.chat.ChatService; import com.l2jserver.service.game.world.WorldService; import com.l2jserver.service.game.world.event.FilteredWorldListener; import com.l2jserver.service.game.world.event.WorldEvent; -import com.l2jserver.service.game.world.event.WorldEventDispatcher; +import com.l2jserver.service.game.world.event.WorldEventDispatcherService; import com.l2jserver.service.game.world.event.WorldListener; import com.l2jserver.service.game.world.filter.impl.KnownListFilter; import com.l2jserver.service.game.world.filter.impl.KnownListUpdateFilter; @@ -115,7 +115,7 @@ public class BroadcastServiceImpl extends AbstractService implements /** * The world service event dispatcher */ - private final WorldEventDispatcher eventDispatcher; + private final WorldEventDispatcherService eventDispatcher; /** * @param worldService @@ -130,7 +130,7 @@ public class BroadcastServiceImpl extends AbstractService implements @Inject public BroadcastServiceImpl(WorldService worldService, ChatService chatService, NetworkService networkService, - WorldEventDispatcher eventDispatcher) { + WorldEventDispatcherService eventDispatcher) { this.worldService = worldService; this.chatService = chatService; this.networkService = networkService; diff --git a/l2jserver2-gameserver/src/test/java/com/l2jserver/service/world/WorldEventDispatcherImplTest.java b/l2jserver2-gameserver/src/test/java/com/l2jserver/service/world/WorldEventDispatcherImplTest.java index dc75934c9..a35e3331f 100644 --- a/l2jserver2-gameserver/src/test/java/com/l2jserver/service/world/WorldEventDispatcherImplTest.java +++ b/l2jserver2-gameserver/src/test/java/com/l2jserver/service/world/WorldEventDispatcherImplTest.java @@ -40,11 +40,11 @@ import com.l2jserver.service.ServiceManager; import com.l2jserver.service.ServiceStartException; import com.l2jserver.service.game.world.WorldIDService; import com.l2jserver.service.game.world.WorldService; -import com.l2jserver.service.game.world.event.WorldEventDispatcher; -import com.l2jserver.service.game.world.event.WorldEventDispatcherImpl; +import com.l2jserver.service.game.world.event.WorldEventDispatcherService; +import com.l2jserver.service.game.world.event.WorldEventDispatcherServiceImpl; /** - * Test for {@link WorldEventDispatcherImpl} + * Test for {@link WorldEventDispatcherServiceImpl} * * @author Rogiel */ @@ -56,7 +56,7 @@ public class WorldEventDispatcherImplTest { /** * The dispatcher */ - private WorldEventDispatcher dispatcher; + private WorldEventDispatcherService dispatcher; /** * The character id provider @@ -82,7 +82,7 @@ public class WorldEventDispatcherImplTest { iidFactory = injector.getInstance(ItemIDProvider.class); world = injector.getInstance(WorldService.class); - dispatcher = injector.getInstance(WorldEventDispatcher.class); + dispatcher = injector.getInstance(WorldEventDispatcherService.class); Assert.assertNotNull(world); Assert.assertNotNull(dispatcher); world.start();