mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-09 17:02:53 +00:00
Implemented service dependencies
Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
@@ -16,18 +16,49 @@
|
||||
*/
|
||||
package com.l2jserver.service;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* An abstract service implementing basic life-cycle methods.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class AbstractService implements Service {
|
||||
public abstract class AbstractService implements Service {
|
||||
/**
|
||||
* Running state of a service
|
||||
*/
|
||||
protected boolean running = false;
|
||||
|
||||
@Override
|
||||
public void start() throws ServiceStartException {
|
||||
public final void start() throws ServiceStartException {
|
||||
if (running)
|
||||
throw new ServiceStartException("Service is already started");
|
||||
try {
|
||||
this.doStart();
|
||||
this.running = true;
|
||||
} catch (ServiceStartException e) {
|
||||
this.running = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected void doStart() throws ServiceStartException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() throws ServiceStopException {
|
||||
public final void stop() throws ServiceStopException {
|
||||
if (!running)
|
||||
throw new ServiceStopException("Service is not started");
|
||||
try {
|
||||
this.doStop();
|
||||
} finally {
|
||||
this.running = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected void doStop() throws ServiceStopException {
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -35,4 +66,28 @@ public class AbstractService implements Service {
|
||||
this.stop();
|
||||
this.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStarted() {
|
||||
return running;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStopped() {
|
||||
return !running;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Service>[] getDependencies() {
|
||||
final Depends deps = this.getClass().getAnnotation(Depends.class);
|
||||
if (deps == null)
|
||||
return null;
|
||||
return deps.value();
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface Depends {
|
||||
Class<? extends Service>[] value();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,4 +46,19 @@ public interface Service {
|
||||
* if an error occurred
|
||||
*/
|
||||
void restart() throws ServiceException;
|
||||
|
||||
/**
|
||||
* @return true if service is running
|
||||
*/
|
||||
boolean isStarted();
|
||||
|
||||
/**
|
||||
* @return false if service is not running
|
||||
*/
|
||||
boolean isStopped();
|
||||
|
||||
/**
|
||||
* @return the other services that the service depends on
|
||||
*/
|
||||
Class<? extends Service>[] getDependencies();
|
||||
}
|
||||
|
||||
@@ -16,12 +16,16 @@
|
||||
*/
|
||||
package com.l2jserver.service;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.l2jserver.service.logging.LoggingService;
|
||||
import com.l2jserver.util.ClassUtils;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
/**
|
||||
* The {@link ServiceManager} is responsible for starting and stopping services
|
||||
@@ -38,11 +42,14 @@ public class ServiceManager {
|
||||
*/
|
||||
private final Injector injector;
|
||||
|
||||
private final Set<Service> knownServices = CollectionFactory.newSet(null);
|
||||
|
||||
@Inject
|
||||
public ServiceManager(Injector injector) {
|
||||
this.injector = injector;
|
||||
final LoggingService service = injector
|
||||
.getInstance(LoggingService.class);
|
||||
knownServices.add(service);
|
||||
try {
|
||||
service.start();
|
||||
} catch (ServiceStartException e) {
|
||||
@@ -56,7 +63,11 @@ public class ServiceManager {
|
||||
final T service = injector.getInstance(serviceClass);
|
||||
if (service == null)
|
||||
return null;
|
||||
if (service.isStarted())
|
||||
return service;
|
||||
knownServices.add(service);
|
||||
try {
|
||||
startDependencies(service.getDependencies());
|
||||
logger.info("{}: Starting service...",
|
||||
serviceClass.getCanonicalName());
|
||||
service.start();
|
||||
@@ -64,19 +75,34 @@ public class ServiceManager {
|
||||
return service;
|
||||
} catch (ServiceStartException e) {
|
||||
logger.error("{}: Error starting service: {}",
|
||||
serviceClass.getCanonicalName(), e.getCause());
|
||||
serviceClass.getCanonicalName(), e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private void startDependencies(Class<? extends Service>[] dependencies)
|
||||
throws ServiceStartException {
|
||||
if (dependencies == null)
|
||||
return;
|
||||
if (dependencies.length == 0)
|
||||
return;
|
||||
for (final Class<? extends Service> serviceClass : dependencies) {
|
||||
this.start(serviceClass);
|
||||
}
|
||||
}
|
||||
|
||||
public void stop(Class<? extends Service> serviceClass)
|
||||
throws ServiceStopException {
|
||||
final Service service = injector.getInstance(serviceClass);
|
||||
if (service == null)
|
||||
return;
|
||||
if (service.isStopped())
|
||||
return;
|
||||
knownServices.add(service);
|
||||
try {
|
||||
logger.info("{0}: Stopping service...",
|
||||
serviceClass.getCanonicalName());
|
||||
stopDependencies(service);
|
||||
service.stop();
|
||||
logger.info("{0}: Service stopped!",
|
||||
serviceClass.getCanonicalName());
|
||||
@@ -87,16 +113,46 @@ public class ServiceManager {
|
||||
}
|
||||
}
|
||||
|
||||
private void stopDependencies(Service service) throws ServiceStopException {
|
||||
final Set<Class<? extends Service>> dependencies = createStopDependencies(
|
||||
null, service);
|
||||
for (final Class<? extends Service> dependency : dependencies) {
|
||||
this.stop(dependency);
|
||||
}
|
||||
}
|
||||
|
||||
private Set<Class<? extends Service>> createStopDependencies(
|
||||
Set<Class<? extends Service>> depends, Service serviceClass) {
|
||||
if (depends == null)
|
||||
depends = CollectionFactory.newSet(null);
|
||||
for (final Service service : knownServices) {
|
||||
if (service.getDependencies() == null
|
||||
|| service.getDependencies().length == 0)
|
||||
continue;
|
||||
for (final Class<? extends Service> dependency : service
|
||||
.getDependencies()) {
|
||||
if (!ClassUtils.isSubclass(service.getClass(), dependency))
|
||||
continue;
|
||||
depends.add(dependency);
|
||||
createStopDependencies(depends,
|
||||
injector.getInstance(dependency));
|
||||
}
|
||||
}
|
||||
return depends;
|
||||
}
|
||||
|
||||
public <T extends Service> T restart(Class<T> serviceClass)
|
||||
throws ServiceStartException, ServiceStopException {
|
||||
throws ServiceException {
|
||||
final T service = injector.getInstance(serviceClass);
|
||||
if (service == null)
|
||||
return null;
|
||||
if (service.isStopped())
|
||||
throw new ServiceStopException("Service is already stopped");
|
||||
knownServices.add(service);
|
||||
try {
|
||||
logger.info("{0}: Restaring service...",
|
||||
serviceClass.getCanonicalName());
|
||||
service.stop();
|
||||
service.start();
|
||||
service.restart();
|
||||
logger.info("{0}: Service restarted!",
|
||||
serviceClass.getCanonicalName());
|
||||
return service;
|
||||
@@ -108,6 +164,10 @@ public class ServiceManager {
|
||||
logger.error("{0}: Error stopping service: {1}",
|
||||
serviceClass.getCanonicalName(), e.getCause());
|
||||
throw e;
|
||||
} catch (ServiceException e) {
|
||||
logger.error("{0}: Error restarting service: {1}",
|
||||
serviceClass.getCanonicalName(), e.getCause());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class PseudoRandomBlowfishKeygenService extends AbstractService
|
||||
private Random random;
|
||||
|
||||
@Override
|
||||
public void start() throws ServiceStartException {
|
||||
protected void doStart() throws ServiceStartException {
|
||||
random = new Random();
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class PseudoRandomBlowfishKeygenService extends AbstractService
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() throws ServiceStopException {
|
||||
protected void doStop() throws ServiceStopException {
|
||||
random = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.apache.commons.math.random.RandomData;
|
||||
import org.apache.commons.math.random.RandomDataImpl;
|
||||
|
||||
import com.l2jserver.service.AbstractService;
|
||||
import com.l2jserver.service.Service;
|
||||
import com.l2jserver.service.ServiceStartException;
|
||||
import com.l2jserver.service.ServiceStopException;
|
||||
|
||||
@@ -38,7 +39,7 @@ public class SecureBlowfishKeygenService extends AbstractService implements
|
||||
private RandomData random;
|
||||
|
||||
@Override
|
||||
public void start() throws ServiceStartException {
|
||||
protected void doStart() throws ServiceStartException {
|
||||
random = new RandomDataImpl();
|
||||
}
|
||||
|
||||
@@ -63,7 +64,7 @@ public class SecureBlowfishKeygenService extends AbstractService implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() throws ServiceStopException {
|
||||
protected void doStop() throws ServiceStopException {
|
||||
random = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class EhCacheService extends AbstractService implements CacheService {
|
||||
private Cache interfaceCache;
|
||||
|
||||
@Override
|
||||
public void start() throws ServiceStartException {
|
||||
protected void doStart() throws ServiceStartException {
|
||||
manager = new CacheManager();
|
||||
interfaceCache = createCache("interface-cache");
|
||||
}
|
||||
@@ -111,7 +111,7 @@ public class EhCacheService extends AbstractService implements CacheService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() throws ServiceStopException {
|
||||
protected void doStop() throws ServiceStopException {
|
||||
manager.removalAll();
|
||||
manager.shutdown();
|
||||
interfaceCache = null;
|
||||
|
||||
@@ -32,10 +32,13 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.l2jserver.service.AbstractService;
|
||||
import com.l2jserver.service.AbstractService.Depends;
|
||||
import com.l2jserver.service.ServiceStartException;
|
||||
import com.l2jserver.service.cache.CacheService;
|
||||
import com.l2jserver.service.configuration.Configuration.ConfigurationName;
|
||||
import com.l2jserver.service.configuration.Configuration.ConfigurationPropertyGetter;
|
||||
import com.l2jserver.service.configuration.Configuration.ConfigurationPropertySetter;
|
||||
import com.l2jserver.service.logging.LoggingService;
|
||||
import com.l2jserver.util.transformer.Transformer;
|
||||
import com.l2jserver.util.transformer.TransformerFactory;
|
||||
|
||||
@@ -45,6 +48,7 @@ import com.l2jserver.util.transformer.TransformerFactory;
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
@Depends({ LoggingService.class, CacheService.class })
|
||||
public class ProxyConfigurationService extends AbstractService implements
|
||||
ConfigurationService {
|
||||
/**
|
||||
@@ -63,7 +67,7 @@ public class ProxyConfigurationService extends AbstractService implements
|
||||
private Map<Class<?>, Object> cache = new WeakHashMap<Class<?>, Object>();
|
||||
|
||||
@Override
|
||||
public void start() throws ServiceStartException {
|
||||
protected void doStart() throws ServiceStartException {
|
||||
if (!directory.exists())
|
||||
if (!directory.mkdirs())
|
||||
throw new ServiceStartException("Failed to create directories");
|
||||
|
||||
@@ -43,10 +43,13 @@ import com.google.inject.Inject;
|
||||
import com.l2jserver.model.id.ObjectID;
|
||||
import com.l2jserver.model.world.WorldObject;
|
||||
import com.l2jserver.service.AbstractService;
|
||||
import com.l2jserver.service.AbstractService.Depends;
|
||||
import com.l2jserver.service.ServiceStartException;
|
||||
import com.l2jserver.service.ServiceStopException;
|
||||
import com.l2jserver.service.cache.CacheService;
|
||||
import com.l2jserver.service.configuration.ConfigurationService;
|
||||
import com.l2jserver.service.game.template.TemplateService;
|
||||
import com.l2jserver.service.logging.LoggingService;
|
||||
import com.l2jserver.util.ArrayIterator;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
@@ -55,6 +58,8 @@ import com.l2jserver.util.factory.CollectionFactory;
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
@Depends({ LoggingService.class, CacheService.class,
|
||||
ConfigurationService.class, TemplateService.class })
|
||||
public class MySQLDatabaseService extends AbstractService implements
|
||||
DatabaseService {
|
||||
/**
|
||||
@@ -103,7 +108,7 @@ public class MySQLDatabaseService extends AbstractService implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() throws ServiceStartException {
|
||||
protected void doStart() throws ServiceStartException {
|
||||
connectionPool = new GenericObjectPool(null);
|
||||
connectionFactory = new DriverManagerConnectionFactory(
|
||||
config.getJdbcUrl(), config.getUsername(), config.getPassword());
|
||||
@@ -170,7 +175,7 @@ public class MySQLDatabaseService extends AbstractService implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() throws ServiceStopException {
|
||||
protected void doStop() throws ServiceStopException {
|
||||
if (objectCache != null)
|
||||
objectCache.dispose();
|
||||
objectCache = null;
|
||||
|
||||
@@ -19,10 +19,10 @@ package com.l2jserver.service.game;
|
||||
import com.l2jserver.service.Service;
|
||||
|
||||
/**
|
||||
* This service handles PVP battles.
|
||||
* This service handles PvP battles.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface PVPService extends Service {
|
||||
public interface PvPService extends Service {
|
||||
|
||||
}
|
||||
@@ -31,11 +31,17 @@ import com.l2jserver.service.game.chat.channel.PublicChatChannel;
|
||||
*/
|
||||
public interface ChatService extends Service {
|
||||
/**
|
||||
* Get the Global {@link ChatChannel}. Messages sent in this chat are
|
||||
* broadcasted to everyone online.
|
||||
*
|
||||
* @return the global {@link ChatChannel}
|
||||
*/
|
||||
PublicChatChannel getGlobalChannel();
|
||||
|
||||
/**
|
||||
* Get the Region {@link ChatChannel}. Messages sent in this chat are
|
||||
* broadcasted to everyone nearby.
|
||||
*
|
||||
* @param character
|
||||
* the character in the region
|
||||
* @return the global {@link ChatChannel}
|
||||
@@ -43,7 +49,8 @@ public interface ChatService extends Service {
|
||||
PublicChatChannel getRegionChannel(L2Character character);
|
||||
|
||||
/**
|
||||
* Get an private {@link ChatChannel} to {@link CharacterID}
|
||||
* Get an private {@link ChatChannel} to {@link CharacterID}. Messages sent
|
||||
* in this channel are sent only to <tt>character</tt>.
|
||||
*
|
||||
* @param character
|
||||
* the target character
|
||||
@@ -52,6 +59,9 @@ public interface ChatService extends Service {
|
||||
PrivateChatChannel getChannel(CharacterID character);
|
||||
|
||||
/**
|
||||
* Get the Clan {@link ChatChannel}. Messages sent in this channel are
|
||||
* broadcast to all clan members online.
|
||||
*
|
||||
* @param clan
|
||||
* the clan
|
||||
* @return the public clan {@link ChatChannel}
|
||||
|
||||
@@ -24,11 +24,15 @@ import com.l2jserver.model.id.object.ClanID;
|
||||
import com.l2jserver.model.world.Clan;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.service.AbstractService;
|
||||
import com.l2jserver.service.AbstractService.Depends;
|
||||
import com.l2jserver.service.ServiceStartException;
|
||||
import com.l2jserver.service.ServiceStopException;
|
||||
import com.l2jserver.service.game.chat.channel.ChatChannel;
|
||||
import com.l2jserver.service.game.chat.channel.ChatChannelListener;
|
||||
import com.l2jserver.service.game.chat.channel.PrivateChatChannel;
|
||||
import com.l2jserver.service.game.chat.channel.PublicChatChannel;
|
||||
import com.l2jserver.service.game.region.Region;
|
||||
import com.l2jserver.service.game.region.RegionService;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
/**
|
||||
@@ -36,7 +40,10 @@ import com.l2jserver.util.factory.CollectionFactory;
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
@Depends(RegionService.class)
|
||||
public class SimpleChatService extends AbstractService implements ChatService {
|
||||
private final RegionService regionService;
|
||||
|
||||
/**
|
||||
* The global chat channel
|
||||
*/
|
||||
@@ -51,12 +58,27 @@ public class SimpleChatService extends AbstractService implements ChatService {
|
||||
* The list of clan chat channels
|
||||
*/
|
||||
private Map<ClanID, ClanChatChannelImpl> clanChannels;
|
||||
/**
|
||||
* The list of regional chat channels
|
||||
*/
|
||||
private Map<Region, RegionChatChannelImpl> regionChannels;
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
*
|
||||
* @param regionService
|
||||
* the region service
|
||||
*/
|
||||
public SimpleChatService(RegionService regionService) {
|
||||
this.regionService = regionService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() throws ServiceStartException {
|
||||
protected void doStart() throws ServiceStartException {
|
||||
this.global = new GlobalChatChannelImpl();
|
||||
this.privateChannels = CollectionFactory.newMap(null, null);
|
||||
this.clanChannels = CollectionFactory.newMap(null, null);
|
||||
this.regionChannels = CollectionFactory.newMap(null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,8 +88,13 @@ public class SimpleChatService extends AbstractService implements ChatService {
|
||||
|
||||
@Override
|
||||
public PublicChatChannel getRegionChannel(L2Character character) {
|
||||
// TODO Region chat channels
|
||||
return null;
|
||||
final Region region = regionService.getRegion(character);
|
||||
RegionChatChannelImpl channel = regionChannels.get(region);
|
||||
if (channel == null) {
|
||||
channel = new RegionChatChannelImpl(region);
|
||||
regionChannels.put(region, channel);
|
||||
}
|
||||
return channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,6 +117,14 @@ public class SimpleChatService extends AbstractService implements ChatService {
|
||||
return channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStop() throws ServiceStopException {
|
||||
this.global = null;
|
||||
this.privateChannels = null;
|
||||
this.clanChannels = null;
|
||||
this.regionChannels = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link ChatChannel} abstract implementation
|
||||
*
|
||||
@@ -170,4 +205,27 @@ public class SimpleChatService extends AbstractService implements ChatService {
|
||||
this.clanID = clanID;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link PublicChatChannel} implemenetation for {@link Region regions}
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
private class RegionChatChannelImpl extends ChatChannelImpl implements
|
||||
PublicChatChannel {
|
||||
/**
|
||||
* The clan ID
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
private final Region region;
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
*
|
||||
* @param clanID
|
||||
*/
|
||||
public RegionChatChannelImpl(Region region) {
|
||||
this.region = region;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
package com.l2jserver.service.game.region;
|
||||
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.capability.Actor;
|
||||
import com.l2jserver.service.Service;
|
||||
|
||||
/**
|
||||
@@ -25,5 +25,12 @@ import com.l2jserver.service.Service;
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface RegionService extends Service {
|
||||
Region getRegion(L2Character character);
|
||||
/**
|
||||
* Get the region in which this actor is.
|
||||
*
|
||||
* @param actor
|
||||
* the actor
|
||||
* @return the current region
|
||||
*/
|
||||
Region getRegion(Actor actor);
|
||||
}
|
||||
|
||||
@@ -32,13 +32,21 @@ import org.slf4j.LoggerFactory;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.l2jserver.service.AbstractService;
|
||||
import com.l2jserver.service.AbstractService.Depends;
|
||||
import com.l2jserver.service.ServiceStartException;
|
||||
import com.l2jserver.service.ServiceStopException;
|
||||
import com.l2jserver.service.game.scripting.impl.ScriptContextImpl;
|
||||
import com.l2jserver.service.game.scripting.scriptmanager.ScriptInfo;
|
||||
import com.l2jserver.service.game.scripting.scriptmanager.ScriptList;
|
||||
import com.l2jserver.service.logging.LoggingService;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
/**
|
||||
* Default {@link ScriptingService} implementation
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
@Depends(LoggingService.class)
|
||||
public class ScriptingServiceImpl extends AbstractService implements
|
||||
ScriptingService {
|
||||
/**
|
||||
@@ -60,7 +68,7 @@ public class ScriptingServiceImpl extends AbstractService implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() throws ServiceStartException {
|
||||
protected void doStart() throws ServiceStartException {
|
||||
for (ScriptContext context : contexts) {
|
||||
context.shutdown();
|
||||
}
|
||||
@@ -165,7 +173,7 @@ public class ScriptingServiceImpl extends AbstractService implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() throws ServiceStopException {
|
||||
protected void doStop() throws ServiceStopException {
|
||||
for (ScriptContext context : contexts) {
|
||||
context.shutdown();
|
||||
}
|
||||
|
||||
@@ -23,13 +23,17 @@ import com.google.inject.Injector;
|
||||
import com.l2jserver.model.id.TemplateID;
|
||||
import com.l2jserver.model.template.Template;
|
||||
import com.l2jserver.service.AbstractService;
|
||||
import com.l2jserver.service.AbstractService.Depends;
|
||||
import com.l2jserver.service.ServiceStartException;
|
||||
import com.l2jserver.service.ServiceStopException;
|
||||
import com.l2jserver.service.configuration.ConfigurationService;
|
||||
import com.l2jserver.service.game.scripting.ScriptContext;
|
||||
import com.l2jserver.service.game.scripting.ScriptingService;
|
||||
import com.l2jserver.service.logging.LoggingService;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
@Depends({ LoggingService.class, ConfigurationService.class,
|
||||
ScriptingService.class })
|
||||
public class ScriptTemplateService extends AbstractService implements
|
||||
TemplateService {
|
||||
private final ScriptingService scriptingService;
|
||||
@@ -52,7 +56,7 @@ public class ScriptTemplateService extends AbstractService implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() throws ServiceStartException {
|
||||
protected void doStart() throws ServiceStartException {
|
||||
if (context == null) {
|
||||
try {
|
||||
context = scriptingService.load(config.getTemplateDescriptor())
|
||||
@@ -94,7 +98,7 @@ public class ScriptTemplateService extends AbstractService implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() throws ServiceStopException {
|
||||
protected void doStop() throws ServiceStopException {
|
||||
if (context.isInitialized())
|
||||
context.shutdown();
|
||||
context = null;
|
||||
|
||||
@@ -26,12 +26,17 @@ import org.slf4j.LoggerFactory;
|
||||
import com.google.inject.Inject;
|
||||
import com.l2jserver.model.world.WorldObject;
|
||||
import com.l2jserver.service.AbstractService;
|
||||
import com.l2jserver.service.AbstractService.Depends;
|
||||
import com.l2jserver.service.ServiceStartException;
|
||||
import com.l2jserver.service.ServiceStopException;
|
||||
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.filter.FilterIterator;
|
||||
import com.l2jserver.service.game.world.filter.WorldObjectFilter;
|
||||
import com.l2jserver.service.game.world.filter.impl.InstanceFilter;
|
||||
import com.l2jserver.service.logging.LoggingService;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
/**
|
||||
@@ -39,6 +44,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 })
|
||||
public class WorldServiceImpl extends AbstractService implements WorldService {
|
||||
/**
|
||||
* The logger
|
||||
@@ -62,7 +69,7 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() throws ServiceStartException {
|
||||
protected void doStart() throws ServiceStartException {
|
||||
objects.clear();
|
||||
}
|
||||
|
||||
@@ -127,7 +134,7 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() throws ServiceStopException {
|
||||
protected void doStop() throws ServiceStopException {
|
||||
objects.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import com.l2jserver.service.ServiceStartException;
|
||||
public class Log4JLoggingService extends AbstractService implements
|
||||
LoggingService {
|
||||
@Override
|
||||
public void start() throws ServiceStartException {
|
||||
protected void doStart() throws ServiceStartException {
|
||||
BasicConfigurator.configure();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,11 @@ import com.l2jserver.game.net.Lineage2Connection;
|
||||
import com.l2jserver.game.net.Lineage2PipelineFactory;
|
||||
import com.l2jserver.model.id.object.CharacterID;
|
||||
import com.l2jserver.service.AbstractService;
|
||||
import com.l2jserver.service.AbstractService.Depends;
|
||||
import com.l2jserver.service.blowfish.BlowfishKeygenService;
|
||||
import com.l2jserver.service.configuration.ConfigurationService;
|
||||
import com.l2jserver.service.game.world.WorldService;
|
||||
import com.l2jserver.service.logging.LoggingService;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
/**
|
||||
@@ -41,6 +45,8 @@ import com.l2jserver.util.factory.CollectionFactory;
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
@Depends({ LoggingService.class, BlowfishKeygenService.class,
|
||||
WorldService.class })
|
||||
public class NettyNetworkService extends AbstractService implements
|
||||
NetworkService {
|
||||
/**
|
||||
@@ -75,7 +81,7 @@ public class NettyNetworkService extends AbstractService implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
protected void doStart() {
|
||||
server = new ServerBootstrap(new NioServerSocketChannelFactory(
|
||||
Executors.newCachedThreadPool(),
|
||||
Executors.newCachedThreadPool()));
|
||||
@@ -116,7 +122,7 @@ public class NettyNetworkService extends AbstractService implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
protected void doStop() {
|
||||
try {
|
||||
channel.close().awaitUninterruptibly();
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user