mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-06 07:32:46 +00:00
Implements configuration for WorldEventDispatcherService
This commit is contained in:
@@ -113,8 +113,16 @@
|
||||
</service>
|
||||
<service interface="com.l2jserver.service.game.world.WorldService"
|
||||
implementation="com.l2jserver.service.game.world.WorldServiceImpl" />
|
||||
<service interface="com.l2jserver.service.game.world.event.WorldEventDispatcher"
|
||||
implementation="com.l2jserver.service.game.world.event.WorldEventDispatcherImpl" />
|
||||
<service
|
||||
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>
|
||||
|
||||
|
||||
<!-- ####################################################################### -->
|
||||
|
||||
@@ -134,8 +134,16 @@
|
||||
</service>
|
||||
<service interface="com.l2jserver.service.game.world.WorldService"
|
||||
implementation="com.l2jserver.service.game.world.WorldServiceImpl" />
|
||||
<service interface="com.l2jserver.service.game.world.event.WorldEventDispatcher"
|
||||
implementation="com.l2jserver.service.game.world.event.WorldEventDispatcherImpl" />
|
||||
<service
|
||||
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>
|
||||
|
||||
|
||||
<!-- ####################################################################### -->
|
||||
|
||||
@@ -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 <a href="http://www.rogiel.com">Rogiel</a>
|
||||
@@ -42,7 +42,7 @@ public abstract class AI<T extends Actor> {
|
||||
* The {@link WorldService} event dispatcher
|
||||
*/
|
||||
@Inject
|
||||
protected WorldEventDispatcher eventDispatcher;
|
||||
protected WorldEventDispatcherService eventDispatcher;
|
||||
|
||||
/**
|
||||
* Creates a new AI
|
||||
|
||||
@@ -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 <a href="http://www.rogiel.com">Rogiel</a>
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 <a href="http://www.rogiel.com">Rogiel</a>
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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}).
|
||||
* <h1>Other tasks</h1> World event dispatching is handled by
|
||||
* {@link WorldEventDispatcher}.
|
||||
* {@link WorldEventDispatcherService}.
|
||||
* <p>
|
||||
* {@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<WorldObject> {
|
||||
void knownObject(WorldObject object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the event dispatcher
|
||||
*
|
||||
* @return the event dispatcher
|
||||
*/
|
||||
WorldEventDispatcher getEventDispatcher();
|
||||
|
||||
/**
|
||||
* Creates a list of all objects matching <tt>filter</tt>
|
||||
*
|
||||
|
||||
@@ -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 <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
@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 <T extends WorldObject> List<T> list(WorldObjectFilter<T> 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
|
||||
@@ -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 <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
|
||||
* need to invoke listeners immediately. Dispatching <b>can</b> 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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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 <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class WorldEventDispatcherImpl implements WorldEventDispatcher {
|
||||
/**
|
||||
* The logger
|
||||
*/
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(WorldEventDispatcherImpl.class);
|
||||
|
||||
@Depends(ThreadService.class)
|
||||
public class WorldEventDispatcherServiceImpl extends
|
||||
AbstractConfigurableService<WorldEventDispatcherServiceConfiguration>
|
||||
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 <E extends WorldEvent> WorldEventFuture<E> dispatch(final E 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>();
|
||||
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;
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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 <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user