1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-05 23:22:47 +00:00

Implements configuration for WorldEventDispatcherService

This commit is contained in:
2011-12-29 02:44:41 -02:00
parent f2cf139d34
commit 209f3d0922
19 changed files with 144 additions and 92 deletions

View File

@@ -113,8 +113,16 @@
</service> </service>
<service interface="com.l2jserver.service.game.world.WorldService" <service interface="com.l2jserver.service.game.world.WorldService"
implementation="com.l2jserver.service.game.world.WorldServiceImpl" /> implementation="com.l2jserver.service.game.world.WorldServiceImpl" />
<service interface="com.l2jserver.service.game.world.event.WorldEventDispatcher" <service
implementation="com.l2jserver.service.game.world.event.WorldEventDispatcherImpl" /> interface="com.l2jserver.service.game.world.event.WorldEventDispatcherService"
implementation="com.l2jserver.service.game.world.event.WorldEventDispatcherServiceImpl">
<!-- The amount of dispatching threads to use. You should not set it to
a value higher than the number of processor cores on your system. Doing so,
might result in performance loss instead of increase. -->
<!-- If you wish the system to automatically determine the number of cores
in the system and configure the system accordingly, set it to 0 -->
<threading count="0" />
</service>
<!-- ####################################################################### --> <!-- ####################################################################### -->

View File

@@ -134,8 +134,16 @@
</service> </service>
<service interface="com.l2jserver.service.game.world.WorldService" <service interface="com.l2jserver.service.game.world.WorldService"
implementation="com.l2jserver.service.game.world.WorldServiceImpl" /> implementation="com.l2jserver.service.game.world.WorldServiceImpl" />
<service interface="com.l2jserver.service.game.world.event.WorldEventDispatcher" <service
implementation="com.l2jserver.service.game.world.event.WorldEventDispatcherImpl" /> interface="com.l2jserver.service.game.world.event.WorldEventDispatcherService"
implementation="com.l2jserver.service.game.world.event.WorldEventDispatcherServiceImpl">
<!-- The amount of dispatching threads to use. You should not set it to
a value higher than the number of processor cores on your system. Doing so,
might result in performance loss instead of increase. -->
<!-- If you wish the system to automatically determine the number of cores
in the system and configure the system accordingly, set it to 0 -->
<threading count="0" />
</service>
<!-- ####################################################################### --> <!-- ####################################################################### -->

View File

@@ -21,7 +21,7 @@ import com.l2jserver.game.ai.desires.Desire;
import com.l2jserver.game.ai.desires.DesireQueue; import com.l2jserver.game.ai.desires.DesireQueue;
import com.l2jserver.model.world.Actor; import com.l2jserver.model.world.Actor;
import com.l2jserver.service.game.world.WorldService; import com.l2jserver.service.game.world.WorldService;
import com.l2jserver.service.game.world.event.WorldEventDispatcher; import com.l2jserver.service.game.world.event.WorldEventDispatcherService;
/** /**
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
@@ -42,7 +42,7 @@ public abstract class AI<T extends Actor> {
* The {@link WorldService} event dispatcher * The {@link WorldService} event dispatcher
*/ */
@Inject @Inject
protected WorldEventDispatcher eventDispatcher; protected WorldEventDispatcherService eventDispatcher;
/** /**
* Creates a new AI * Creates a new AI

View File

@@ -37,7 +37,7 @@ import com.l2jserver.service.core.threading.AbstractTask;
import com.l2jserver.service.core.threading.AsyncFuture; import com.l2jserver.service.core.threading.AsyncFuture;
import com.l2jserver.service.core.threading.ThreadService; import com.l2jserver.service.core.threading.ThreadService;
import com.l2jserver.service.game.npc.NPCService; import com.l2jserver.service.game.npc.NPCService;
import com.l2jserver.service.game.world.event.WorldEventDispatcher; import com.l2jserver.service.game.world.event.WorldEventDispatcherService;
/** /**
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
@@ -64,10 +64,10 @@ public class AttackServiceImpl extends AbstractService implements AttackService
private final NPCService npcService; 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 * world
*/ */
private final WorldEventDispatcher eventDispatcher; private final WorldEventDispatcherService eventDispatcher;
/** /**
* @param threadService * @param threadService
@@ -79,7 +79,7 @@ public class AttackServiceImpl extends AbstractService implements AttackService
*/ */
@Inject @Inject
public AttackServiceImpl(ThreadService threadService, public AttackServiceImpl(ThreadService threadService,
NPCService npcService, WorldEventDispatcher eventDispatcher) { NPCService npcService, WorldEventDispatcherService eventDispatcher) {
this.threadService = threadService; this.threadService = threadService;
this.npcService = npcService; this.npcService = npcService;
this.eventDispatcher = eventDispatcher; this.eventDispatcher = eventDispatcher;

View File

@@ -28,7 +28,7 @@ import com.l2jserver.service.ServiceStopException;
import com.l2jserver.service.core.threading.ThreadService; import com.l2jserver.service.core.threading.ThreadService;
import com.l2jserver.service.game.template.TemplateService; import com.l2jserver.service.game.template.TemplateService;
import com.l2jserver.service.game.world.WorldService; 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.service.network.NetworkService;
import com.l2jserver.util.geometry.Coordinate; import com.l2jserver.util.geometry.Coordinate;
@@ -55,7 +55,7 @@ public class AIServiceImpl extends AbstractService implements AIService {
* The {@link WorldService} event dispatcher * The {@link WorldService} event dispatcher
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final WorldEventDispatcher eventDispatcher; private final WorldEventDispatcherService eventDispatcher;
/** /**
* The {@link ThreadService} * The {@link ThreadService}
*/ */
@@ -79,7 +79,7 @@ public class AIServiceImpl extends AbstractService implements AIService {
*/ */
@Inject @Inject
public AIServiceImpl(WorldService worldService, public AIServiceImpl(WorldService worldService,
WorldEventDispatcher eventDispatcher, ThreadService threadService, WorldEventDispatcherService eventDispatcher, ThreadService threadService,
NetworkService networkService) { NetworkService networkService) {
this.worldService = worldService; this.worldService = worldService;
this.eventDispatcher = eventDispatcher; this.eventDispatcher = eventDispatcher;

View File

@@ -60,7 +60,7 @@ import com.l2jserver.service.game.spawn.NotSpawnedServiceException;
import com.l2jserver.service.game.spawn.SpawnPointNotFoundServiceException; import com.l2jserver.service.game.spawn.SpawnPointNotFoundServiceException;
import com.l2jserver.service.game.spawn.SpawnService; import com.l2jserver.service.game.spawn.SpawnService;
import com.l2jserver.service.game.world.WorldService; 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.broadcast.BroadcastService;
import com.l2jserver.service.network.gameguard.GameGuardService; import com.l2jserver.service.network.gameguard.GameGuardService;
import com.l2jserver.util.ArrayUtils; import com.l2jserver.util.ArrayUtils;
@@ -90,7 +90,7 @@ public class CharacterServiceImpl extends
/** /**
* The {@link WorldService} event dispatcher * The {@link WorldService} event dispatcher
*/ */
private final WorldEventDispatcher eventDispatcher; private final WorldEventDispatcherService eventDispatcher;
/** /**
* The {@link SpawnService} * The {@link SpawnService}
*/ */
@@ -161,7 +161,7 @@ public class CharacterServiceImpl extends
*/ */
@Inject @Inject
public CharacterServiceImpl(BroadcastService broadcastService, public CharacterServiceImpl(BroadcastService broadcastService,
WorldEventDispatcher eventDispatcher, SpawnService spawnService, WorldEventDispatcherService eventDispatcher, SpawnService spawnService,
NPCService npcService, GameGuardService ggService, NPCService npcService, GameGuardService ggService,
CharacterDAO characterDao, ItemDAO itemDao, CharacterDAO characterDao, ItemDAO itemDao,
CharacterShortcutDAO shortcutDao, CharacterShortcutDAO shortcutDao,

View File

@@ -27,7 +27,7 @@ import com.l2jserver.model.world.character.event.CharacterCreateShortcutEvent;
import com.l2jserver.model.world.character.event.CharacterDeleteShortcutEvent; import com.l2jserver.model.world.character.event.CharacterDeleteShortcutEvent;
import com.l2jserver.service.AbstractService; import com.l2jserver.service.AbstractService;
import com.l2jserver.service.game.world.WorldService; import com.l2jserver.service.game.world.WorldService;
import com.l2jserver.service.game.world.event.WorldEventDispatcher; import com.l2jserver.service.game.world.event.WorldEventDispatcherService;
/** /**
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
@@ -37,7 +37,7 @@ public class ShortcutServiceImpl extends AbstractService implements
/** /**
* The {@link WorldService} event dispatcher * The {@link WorldService} event dispatcher
*/ */
private final WorldEventDispatcher eventDispatcher; private final WorldEventDispatcherService eventDispatcher;
/** /**
* The {@link CharacterShortcut} DAO * The {@link CharacterShortcut} DAO
*/ */
@@ -50,7 +50,7 @@ public class ShortcutServiceImpl extends AbstractService implements
* the shortcut DAO * the shortcut DAO
*/ */
@Inject @Inject
private ShortcutServiceImpl(WorldEventDispatcher eventDispatcher, private ShortcutServiceImpl(WorldEventDispatcherService eventDispatcher,
CharacterShortcutDAO shortcutDao) { CharacterShortcutDAO shortcutDao) {
this.eventDispatcher = eventDispatcher; this.eventDispatcher = eventDispatcher;
this.shortcutDao = shortcutDao; this.shortcutDao = shortcutDao;

View File

@@ -44,7 +44,7 @@ import com.l2jserver.service.game.spawn.NotSpawnedServiceException;
import com.l2jserver.service.game.spawn.SpawnPointNotFoundServiceException; import com.l2jserver.service.game.spawn.SpawnPointNotFoundServiceException;
import com.l2jserver.service.game.spawn.SpawnService; import com.l2jserver.service.game.spawn.SpawnService;
import com.l2jserver.service.game.world.WorldService; 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.ArrayUtils;
import com.l2jserver.util.geometry.Point3D; import com.l2jserver.util.geometry.Point3D;
@@ -66,7 +66,7 @@ public class ItemServiceImpl extends
/** /**
* The {@link WorldService} event dispatcher * The {@link WorldService} event dispatcher
*/ */
private final WorldEventDispatcher eventDispatcher; private final WorldEventDispatcherService eventDispatcher;
/** /**
* The {@link ItemID} provider * The {@link ItemID} provider
*/ */
@@ -89,7 +89,7 @@ public class ItemServiceImpl extends
*/ */
@Inject @Inject
private ItemServiceImpl(ItemDAO itemDao, SpawnService spawnService, private ItemServiceImpl(ItemDAO itemDao, SpawnService spawnService,
WorldEventDispatcher eventDispatcher, ItemIDProvider itemIdProvider) { WorldEventDispatcherService eventDispatcher, ItemIDProvider itemIdProvider) {
super(ItemServiceConfiguration.class); super(ItemServiceConfiguration.class);
this.itemDao = itemDao; this.itemDao = itemDao;
this.spawnService = spawnService; this.spawnService = spawnService;

View File

@@ -38,7 +38,7 @@ import com.l2jserver.service.ServiceStopException;
import com.l2jserver.service.game.character.CharacterService; import com.l2jserver.service.game.character.CharacterService;
import com.l2jserver.service.game.world.WorldService; import com.l2jserver.service.game.world.WorldService;
import com.l2jserver.service.game.world.event.TypedWorldListener; 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.Coordinate;
import com.l2jserver.util.geometry.Point3D; import com.l2jserver.util.geometry.Point3D;
@@ -69,7 +69,7 @@ public class MapperPathingService extends AbstractService implements
/** /**
* The {@link WorldService} event dispatcher * The {@link WorldService} event dispatcher
*/ */
private final WorldEventDispatcher eventDispatcher; private final WorldEventDispatcherService eventDispatcher;
/** /**
* The database channel, will remain open until service is stopped. * The database channel, will remain open until service is stopped.
@@ -83,7 +83,7 @@ public class MapperPathingService extends AbstractService implements
* the world event dispatcher * the world event dispatcher
*/ */
@Inject @Inject
public MapperPathingService(WorldEventDispatcher eventDispatcher) { public MapperPathingService(WorldEventDispatcherService eventDispatcher) {
this.eventDispatcher = eventDispatcher; this.eventDispatcher = eventDispatcher;
} }

View File

@@ -53,7 +53,7 @@ import com.l2jserver.service.game.spawn.AlreadySpawnedServiceException;
import com.l2jserver.service.game.spawn.SpawnPointNotFoundServiceException; import com.l2jserver.service.game.spawn.SpawnPointNotFoundServiceException;
import com.l2jserver.service.game.spawn.SpawnService; import com.l2jserver.service.game.spawn.SpawnService;
import com.l2jserver.service.game.world.WorldService; 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.exception.L2Exception;
import com.l2jserver.util.factory.CollectionFactory; import com.l2jserver.util.factory.CollectionFactory;
import com.l2jserver.util.geometry.Point3D; import com.l2jserver.util.geometry.Point3D;
@@ -93,7 +93,7 @@ public class NPCServiceImpl extends AbstractService implements NPCService {
/** /**
* The {@link WorldService} event dispatcher * The {@link WorldService} event dispatcher
*/ */
private final WorldEventDispatcher eventDispatcher; private final WorldEventDispatcherService eventDispatcher;
/** /**
* The {@link NPCDAO} * The {@link NPCDAO}
*/ */
@@ -134,7 +134,7 @@ public class NPCServiceImpl extends AbstractService implements NPCService {
@Inject @Inject
public NPCServiceImpl(SpawnService spawnService, public NPCServiceImpl(SpawnService spawnService,
CharacterService characterService, ThreadService threadService, CharacterService characterService, ThreadService threadService,
AttackService attackService, WorldEventDispatcher eventDispatcher, AttackService attackService, WorldEventDispatcherService eventDispatcher,
NPCDAO npcDao, Injector injector) { NPCDAO npcDao, Injector injector) {
this.spawnService = spawnService; this.spawnService = spawnService;
this.characterService = characterService; this.characterService = characterService;

View File

@@ -40,7 +40,7 @@ import com.l2jserver.service.core.threading.AbstractTask;
import com.l2jserver.service.core.threading.AsyncFuture; import com.l2jserver.service.core.threading.AsyncFuture;
import com.l2jserver.service.core.threading.ThreadService; import com.l2jserver.service.core.threading.ThreadService;
import com.l2jserver.service.game.world.WorldService; 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.Coordinate;
import com.l2jserver.util.geometry.Point3D; import com.l2jserver.util.geometry.Point3D;
@@ -63,7 +63,7 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService {
/** /**
* The {@link WorldService} event dispatcher * The {@link WorldService} event dispatcher
*/ */
private final WorldEventDispatcher eventDispatcher; private final WorldEventDispatcherService eventDispatcher;
/** /**
* The {@link ThreadService} * The {@link ThreadService}
*/ */
@@ -79,7 +79,7 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService {
*/ */
@Inject @Inject
public SpawnServiceImpl(WorldService worldService, public SpawnServiceImpl(WorldService worldService,
WorldEventDispatcher eventDispatcher, ThreadService threadService) { WorldEventDispatcherService eventDispatcher, ThreadService threadService) {
this.worldService = worldService; this.worldService = worldService;
this.eventDispatcher = eventDispatcher; this.eventDispatcher = eventDispatcher;
this.threadService = threadService; this.threadService = threadService;

View File

@@ -25,7 +25,7 @@ import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.PositionableObject; import com.l2jserver.model.world.PositionableObject;
import com.l2jserver.model.world.WorldObject; import com.l2jserver.model.world.WorldObject;
import com.l2jserver.service.Service; 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.game.world.filter.WorldObjectFilter;
import com.l2jserver.service.network.broadcast.BroadcastService; 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 * this service and it can be broadcasted (using {@link BroadcastService}) to
* all nearby clients (see {@link Lineage2Client}). * all nearby clients (see {@link Lineage2Client}).
* <h1>Other tasks</h1> World event dispatching is handled by * <h1>Other tasks</h1> World event dispatching is handled by
* {@link WorldEventDispatcher}. * {@link WorldEventDispatcherService}.
* <p> * <p>
* {@link ObjectID} object management is done through {@link WorldIDService} * {@link ObjectID} object management is done through {@link WorldIDService}
* that can be used to cache those IDs. * that can be used to cache those IDs.
@@ -112,13 +112,6 @@ public interface WorldService extends Service, Iterable<WorldObject> {
void knownObject(WorldObject object); void knownObject(WorldObject object);
} }
/**
* Get the event dispatcher
*
* @return the event dispatcher
*/
WorldEventDispatcher getEventDispatcher();
/** /**
* Creates a list of all objects matching <tt>filter</tt> * Creates a list of all objects matching <tt>filter</tt>
* *

View File

@@ -36,8 +36,7 @@ import com.l2jserver.service.core.LoggingService;
import com.l2jserver.service.database.DatabaseService; import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.game.scripting.ScriptingService; import com.l2jserver.service.game.scripting.ScriptingService;
import com.l2jserver.service.game.template.TemplateService; import com.l2jserver.service.game.template.TemplateService;
import com.l2jserver.service.game.world.event.WorldEventDispatcher; import com.l2jserver.service.game.world.event.WorldEventDispatcherService;
import com.l2jserver.service.game.world.event.WorldEventDispatcherImpl;
import com.l2jserver.service.game.world.filter.FilterIterator; import com.l2jserver.service.game.world.filter.FilterIterator;
import com.l2jserver.service.game.world.filter.WorldObjectFilter; import com.l2jserver.service.game.world.filter.WorldObjectFilter;
import com.l2jserver.service.game.world.filter.impl.IDFilter; import com.l2jserver.service.game.world.filter.impl.IDFilter;
@@ -51,7 +50,8 @@ import com.l2jserver.util.factory.CollectionFactory;
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
@Depends({ LoggingService.class, TemplateService.class, ScriptingService.class, @Depends({ LoggingService.class, TemplateService.class, ScriptingService.class,
DatabaseService.class, WorldIDService.class }) DatabaseService.class, WorldIDService.class,
WorldEventDispatcherService.class })
public class WorldServiceImpl extends AbstractService implements WorldService { public class WorldServiceImpl extends AbstractService implements WorldService {
/** /**
* The logger * The logger
@@ -66,7 +66,7 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
/** /**
* The world event dispatcher * The world event dispatcher
*/ */
private final WorldEventDispatcherImpl dispatcher; private final WorldEventDispatcherService dispatcher;
/** /**
* The {@link WorldIDService} * The {@link WorldIDService}
*/ */
@@ -79,9 +79,9 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
* the world id service * the world id service
*/ */
@Inject @Inject
public WorldServiceImpl(WorldEventDispatcher dispatcher, public WorldServiceImpl(WorldEventDispatcherService dispatcher,
WorldIDService idService) { WorldIDService idService) {
this.dispatcher = (WorldEventDispatcherImpl) dispatcher; this.dispatcher = dispatcher;
this.idService = idService; this.idService = idService;
} }
@@ -89,7 +89,6 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
protected void doStart() throws ServiceStartException { protected void doStart() throws ServiceStartException {
objects.clear(); objects.clear();
idService.load(); idService.load();
dispatcher.start();
} }
@Override @Override
@@ -139,11 +138,6 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
} }
} }
@Override
public WorldEventDispatcher getEventDispatcher() {
return dispatcher;
}
@Override @Override
public <T extends WorldObject> List<T> list(WorldObjectFilter<T> filter) { public <T extends WorldObject> List<T> list(WorldObjectFilter<T> filter) {
Preconditions.checkNotNull(filter, "filter"); Preconditions.checkNotNull(filter, "filter");
@@ -190,6 +184,5 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
protected void doStop() throws ServiceStopException { protected void doStop() throws ServiceStopException {
objects.clear(); objects.clear();
idService.unload(); idService.unload();
dispatcher.stop();
} }
} }

View File

@@ -21,7 +21,7 @@ import com.l2jserver.model.world.WorldObject;
/** /**
* Base event class. Every event must implement this interface in order to be * Base event class. Every event must implement this interface in order to be
* dispatched by {@link WorldEventDispatcher} * dispatched by {@link WorldEventDispatcherService}
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */

View File

@@ -18,6 +18,7 @@ package com.l2jserver.service.game.world.event;
import com.l2jserver.model.id.ObjectID; import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.world.WorldObject; import com.l2jserver.model.world.WorldObject;
import com.l2jserver.service.Service;
/** /**
* This event dispatcher notify listeners that an certain event occured in their * This event dispatcher notify listeners that an certain event occured in their
@@ -25,7 +26,7 @@ import com.l2jserver.model.world.WorldObject;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public interface WorldEventDispatcher { public interface WorldEventDispatcherService extends Service {
/** /**
* Notify listeners of the <tt>event</tt>. Note that not all implementation * Notify listeners of the <tt>event</tt>. Note that not all implementation
* need to invoke listeners immediately. Dispatching <b>can</b> occur * need to invoke listeners immediately. Dispatching <b>can</b> occur
@@ -95,4 +96,12 @@ public interface WorldEventDispatcher {
* the listener * the listener
*/ */
void removeListener(ObjectID<?> id, WorldListener listener); void removeListener(ObjectID<?> id, WorldListener listener);
/**
* Removes all listeners from a given object
*
* @param id
* the object id
*/
public void clear(ObjectID<?> id);
} }

View File

@@ -0,0 +1,43 @@
/*
* This file is part of l2jserver2 <l2jserver2.com>.
*
* 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 <http://www.gnu.org/licenses/>.
*/
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 <a href="http://www.rogiel.com">Rogiel</a>
*/
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);
}

View File

@@ -23,30 +23,26 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.AbstractFuture; import com.google.common.util.concurrent.AbstractFuture;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.l2jserver.model.id.ObjectID; import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.world.WorldObject; 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.ThreadPool;
import com.l2jserver.service.core.threading.ThreadService; import com.l2jserver.service.core.threading.ThreadService;
import com.l2jserver.util.factory.CollectionFactory; import com.l2jserver.util.factory.CollectionFactory;
/** /**
* Default {@link WorldEventDispatcher} implementation * Default {@link WorldEventDispatcherService} implementation
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class WorldEventDispatcherImpl implements WorldEventDispatcher { @Depends(ThreadService.class)
/** public class WorldEventDispatcherServiceImpl extends
* The logger AbstractConfigurableService<WorldEventDispatcherServiceConfiguration>
*/ implements WorldEventDispatcherService {
private static final Logger log = LoggerFactory
.getLogger(WorldEventDispatcherImpl.class);
/** /**
* The thread service * The thread service
*/ */
@@ -77,15 +73,20 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
* the thread service * the thread service
*/ */
@Inject @Inject
public WorldEventDispatcherImpl(ThreadService threadService) { public WorldEventDispatcherServiceImpl(ThreadService threadService) {
super(WorldEventDispatcherServiceConfiguration.class);
this.threadService = threadService; this.threadService = threadService;
} }
/** /**
* Stats the world event dispatcher * Stats the world event dispatcher
*/ */
public void start() { @Override
final int threads = Runtime.getRuntime().availableProcessors(); public void doStart() {
int threads = config.getDispatcherThreadCount();
if (threads <= 0)
threads = Runtime.getRuntime().availableProcessors();
threadPool = threadService threadPool = threadService
.createThreadPool("event-dispatcher", threads); .createThreadPool("event-dispatcher", threads);
for (int i = 0; i < threads; i++) { for (int i = 0; i < threads; i++) {
@@ -99,7 +100,8 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
if (event.future.isCancelled()) if (event.future.isCancelled())
continue; continue;
log.debug("Dispatching event {}", event.event); logger.debug("Dispatching event {}",
event.event);
// set state // set state
event.future.running = true; event.future.running = true;
@@ -111,7 +113,7 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
event.future.set(event.event); event.future.set(event.event);
} catch (Throwable t) { } catch (Throwable t) {
event.future.setException(t); event.future.setException(t);
log.warn( logger.warn(
"Exception in WorldEventDispatcher thread", "Exception in WorldEventDispatcher thread",
t); t);
} }
@@ -125,7 +127,7 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
@Override @Override
public <E extends WorldEvent> WorldEventFuture<E> dispatch(final E event) { public <E extends WorldEvent> WorldEventFuture<E> dispatch(final E event) {
Preconditions.checkNotNull(event, "event"); Preconditions.checkNotNull(event, "event");
log.debug("Queing dispatch for event {}", event); logger.debug("Queing dispatch for event {}", event);
final WorldEventFutureImpl<E> future = new WorldEventFutureImpl<E>(); final WorldEventFutureImpl<E> future = new WorldEventFutureImpl<E>();
events.add(new EventContainer(event, future)); events.add(new EventContainer(event, future));
@@ -149,7 +151,7 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
// remove listener if return value is false // remove listener if return value is false
globalListeners.remove(listener); globalListeners.remove(listener);
} catch (Throwable t) { } catch (Throwable t) {
log.warn("Exception in listener", t); logger.warn("Exception in listener", t);
// always remove any listener that throws an exception // always remove any listener that throws an exception
globalListeners.remove(listener); globalListeners.remove(listener);
} }
@@ -161,7 +163,7 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
// remove listener if return value is false // remove listener if return value is false
listeners.remove(listener); listeners.remove(listener);
} catch (Throwable t) { } catch (Throwable t) {
log.warn("Exception in listener", t); logger.warn("Exception in listener", t);
// always remove any listener that throws an exception // always remove any listener that throws an exception
listeners.remove(listener); listeners.remove(listener);
} }
@@ -172,7 +174,7 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
@Override @Override
public void addListener(WorldListener listener) { public void addListener(WorldListener listener) {
Preconditions.checkNotNull(listener, "listener"); Preconditions.checkNotNull(listener, "listener");
log.debug("Adding new listener global {}", listener); logger.debug("Adding new listener global {}", listener);
globalListeners.add(listener); globalListeners.add(listener);
} }
@@ -187,7 +189,7 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
public void addListener(ObjectID<?> id, WorldListener listener) { public void addListener(ObjectID<?> id, WorldListener listener) {
Preconditions.checkNotNull(id, "id"); Preconditions.checkNotNull(id, "id");
Preconditions.checkNotNull(listener, "listener"); Preconditions.checkNotNull(listener, "listener");
log.debug("Adding new listener {} to {}", listener, id); logger.debug("Adding new listener {} to {}", listener, id);
getListeners(id).add(listener); getListeners(id).add(listener);
} }
@@ -208,16 +210,11 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
public void removeListener(ObjectID<?> id, WorldListener listener) { public void removeListener(ObjectID<?> id, WorldListener listener) {
Preconditions.checkNotNull(id, "id"); Preconditions.checkNotNull(id, "id");
Preconditions.checkNotNull(listener, "listener"); Preconditions.checkNotNull(listener, "listener");
log.debug("Removing new listener {} from {}", listener, id); logger.debug("Removing new listener {} from {}", listener, id);
getListeners(id).remove(listener); getListeners(id).remove(listener);
} }
/** @Override
* Removes all listeners from a given object
*
* @param id
* the object id
*/
public void clear(ObjectID<?> id) { public void clear(ObjectID<?> id) {
Preconditions.checkNotNull(id, "id"); Preconditions.checkNotNull(id, "id");
listeners.remove(id); listeners.remove(id);
@@ -244,7 +241,8 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
/** /**
* Stops the world event dispatcher * Stops the world event dispatcher
*/ */
public void stop() { @Override
public void doStop() {
threadService.dispose(threadPool); threadService.dispose(threadPool);
threadPool = null; threadPool = null;
} }

View File

@@ -81,7 +81,7 @@ import com.l2jserver.service.game.chat.ChatService;
import com.l2jserver.service.game.world.WorldService; import com.l2jserver.service.game.world.WorldService;
import com.l2jserver.service.game.world.event.FilteredWorldListener; import com.l2jserver.service.game.world.event.FilteredWorldListener;
import com.l2jserver.service.game.world.event.WorldEvent; 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.event.WorldListener;
import com.l2jserver.service.game.world.filter.impl.KnownListFilter; import com.l2jserver.service.game.world.filter.impl.KnownListFilter;
import com.l2jserver.service.game.world.filter.impl.KnownListUpdateFilter; import com.l2jserver.service.game.world.filter.impl.KnownListUpdateFilter;
@@ -115,7 +115,7 @@ public class BroadcastServiceImpl extends AbstractService implements
/** /**
* The world service event dispatcher * The world service event dispatcher
*/ */
private final WorldEventDispatcher eventDispatcher; private final WorldEventDispatcherService eventDispatcher;
/** /**
* @param worldService * @param worldService
@@ -130,7 +130,7 @@ public class BroadcastServiceImpl extends AbstractService implements
@Inject @Inject
public BroadcastServiceImpl(WorldService worldService, public BroadcastServiceImpl(WorldService worldService,
ChatService chatService, NetworkService networkService, ChatService chatService, NetworkService networkService,
WorldEventDispatcher eventDispatcher) { WorldEventDispatcherService eventDispatcher) {
this.worldService = worldService; this.worldService = worldService;
this.chatService = chatService; this.chatService = chatService;
this.networkService = networkService; this.networkService = networkService;

View File

@@ -40,11 +40,11 @@ import com.l2jserver.service.ServiceManager;
import com.l2jserver.service.ServiceStartException; import com.l2jserver.service.ServiceStartException;
import com.l2jserver.service.game.world.WorldIDService; import com.l2jserver.service.game.world.WorldIDService;
import com.l2jserver.service.game.world.WorldService; 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.game.world.event.WorldEventDispatcherImpl; import com.l2jserver.service.game.world.event.WorldEventDispatcherServiceImpl;
/** /**
* Test for {@link WorldEventDispatcherImpl} * Test for {@link WorldEventDispatcherServiceImpl}
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
@@ -56,7 +56,7 @@ public class WorldEventDispatcherImplTest {
/** /**
* The dispatcher * The dispatcher
*/ */
private WorldEventDispatcher dispatcher; private WorldEventDispatcherService dispatcher;
/** /**
* The character id provider * The character id provider
@@ -82,7 +82,7 @@ public class WorldEventDispatcherImplTest {
iidFactory = injector.getInstance(ItemIDProvider.class); iidFactory = injector.getInstance(ItemIDProvider.class);
world = injector.getInstance(WorldService.class); world = injector.getInstance(WorldService.class);
dispatcher = injector.getInstance(WorldEventDispatcher.class); dispatcher = injector.getInstance(WorldEventDispatcherService.class);
Assert.assertNotNull(world); Assert.assertNotNull(world);
Assert.assertNotNull(dispatcher); Assert.assertNotNull(dispatcher);
world.start(); world.start();