From 976cfaf4e0153664239700c05d91bdde2c81eab5 Mon Sep 17 00:00:00 2001 From: Rogiel Date: Wed, 28 Dec 2011 00:35:35 -0200 Subject: [PATCH] Implements XML based service descriptor allowing to switch services --- l2jserver2-common/pom.xml | 2 +- .../service/AbstractConfigurableService.java | 64 ++++++++ .../service/ConfigurableService.java | 42 +++++ .../l2jserver/service/ServiceDescriptor.java | 108 +++++++++++++ .../l2jserver/service/ServiceException.java | 2 +- .../com/l2jserver/service/ServiceManager.java | 144 +++++++++++++++-- .../configuration/ConfigurationService.java | 16 +- .../XMLConfigurationService.java | 93 +++-------- .../core/vfs/Java7VFSConfiguration.java | 67 +++----- .../service/core/vfs/Java7VFSService.java | 27 +--- .../core/vfs/TrueZipVFSConfiguration.java | 62 +++----- .../service/core/vfs/TrueZipVFSService.java | 21 +-- .../service/core/vfs/VFSConfiguration.java | 62 ++++++++ .../service/core/vfs/VFSService.java | 42 ----- .../database/DatabaseConfiguration.java | 44 ++++++ .../service/database/DatabaseService.java | 26 --- .../AbstractOrientDatabaseService.java | 71 +-------- .../orientdb/OrientDatabaseConfiguration.java | 72 +++++++++ .../sql/AbstractSQLDatabaseService.java | 143 ++--------------- .../sql/JDBCDatabaseConfiguration.java | 132 ++++++++++++++++ .../java/com/l2jserver/util/ClassUtils.java | 34 ++++ .../XMLConfigurationServiceTest.java | 148 ------------------ l2jserver2-gameserver/.gitignore | 1 + l2jserver2-gameserver/config/.gitignore | 1 - .../config/config-dev-sample.xml | 92 ----------- l2jserver2-gameserver/config/config.xml | 92 ----------- .../distribution/{global => }/LICENSE | 0 .../distribution/{global => }/README | 0 .../distribution/global/config/config.xml | 92 ----------- .../distribution/services.xml | 114 ++++++++++++++ .../distribution/{global => }/start.bat | 0 .../distribution/{global => }/start.sh | 0 l2jserver2-gameserver/services-sample.xml | 125 +++++++++++++++ .../main/assembly/distribution-derby-bin.xml | 2 +- .../src/main/assembly/distribution-h2-bin.xml | 2 +- .../main/assembly/distribution-mysql5-bin.xml | 2 +- .../assembly/distribution-orientdb-bin.xml | 2 +- .../java/com/l2jserver/L2JGameServerMain.java | 41 ++++- .../com/l2jserver/service/ServiceModule.java | 137 ---------------- .../GameServerJDBCDatabaseService.java | 12 +- .../GameServerOrientDatabaseService.java | 13 +- .../game/template/XMLTemplateService.java | 41 +---- .../XMLTemplateServiceConfiguration.java | 43 +++++ .../service/network/NettyNetworkService.java | 17 +- .../service/network/NetworkService.java | 30 ---- .../network/NetworkServiceConfiguration.java | 49 ++++++ .../db/dao/mysql5/MySQL5CharacterDAOTest.java | 3 +- .../id/provider/CharacterIDProviderTest.java | 7 +- .../world/WorldEventDispatcherImplTest.java | 4 +- .../service/world/WorldServiceImplTest.java | 6 +- .../LoginServerSQLDatabaseService.java | 11 +- .../gameserver/GameServerNetworkService.java | 29 ---- .../gameserver/NetworkConfiguration.java | 51 ++++++ 53 files changed, 1270 insertions(+), 1171 deletions(-) create mode 100644 l2jserver2-common/src/main/java/com/l2jserver/service/AbstractConfigurableService.java create mode 100644 l2jserver2-common/src/main/java/com/l2jserver/service/ConfigurableService.java create mode 100644 l2jserver2-common/src/main/java/com/l2jserver/service/ServiceDescriptor.java rename l2jserver2-gameserver/src/main/java/com/l2jserver/L2JGameServer.java => l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/Java7VFSConfiguration.java (66%) rename l2jserver2-gameserver/src/main/java/com/l2jserver/GameServerModule.java => l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/TrueZipVFSConfiguration.java (60%) create mode 100644 l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/VFSConfiguration.java create mode 100644 l2jserver2-common/src/main/java/com/l2jserver/service/database/DatabaseConfiguration.java create mode 100644 l2jserver2-common/src/main/java/com/l2jserver/service/database/orientdb/OrientDatabaseConfiguration.java create mode 100644 l2jserver2-common/src/main/java/com/l2jserver/service/database/sql/JDBCDatabaseConfiguration.java delete mode 100644 l2jserver2-common/src/test/java/com/l2jserver/service/configuration/XMLConfigurationServiceTest.java delete mode 100644 l2jserver2-gameserver/config/.gitignore delete mode 100644 l2jserver2-gameserver/config/config-dev-sample.xml delete mode 100644 l2jserver2-gameserver/config/config.xml rename l2jserver2-gameserver/distribution/{global => }/LICENSE (100%) rename l2jserver2-gameserver/distribution/{global => }/README (100%) delete mode 100644 l2jserver2-gameserver/distribution/global/config/config.xml create mode 100644 l2jserver2-gameserver/distribution/services.xml rename l2jserver2-gameserver/distribution/{global => }/start.bat (100%) rename l2jserver2-gameserver/distribution/{global => }/start.sh (100%) create mode 100644 l2jserver2-gameserver/services-sample.xml delete mode 100644 l2jserver2-gameserver/src/main/java/com/l2jserver/service/ServiceModule.java create mode 100644 l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/template/XMLTemplateServiceConfiguration.java create mode 100644 l2jserver2-gameserver/src/main/java/com/l2jserver/service/network/NetworkServiceConfiguration.java create mode 100644 l2jserver2-loginserver/src/main/java/com/l2jserver/service/gameserver/NetworkConfiguration.java diff --git a/l2jserver2-common/pom.xml b/l2jserver2-common/pom.xml index 4040f9bdb..b2db445b5 100644 --- a/l2jserver2-common/pom.xml +++ b/l2jserver2-common/pom.xml @@ -25,7 +25,7 @@ org.slf4j slf4j-log4j12 1.6.4 - test + runtime org.slf4j diff --git a/l2jserver2-common/src/main/java/com/l2jserver/service/AbstractConfigurableService.java b/l2jserver2-common/src/main/java/com/l2jserver/service/AbstractConfigurableService.java new file mode 100644 index 000000000..a1399ffb4 --- /dev/null +++ b/l2jserver2-common/src/main/java/com/l2jserver/service/AbstractConfigurableService.java @@ -0,0 +1,64 @@ +/* + * This file is part of l2jserver2 . + * + * l2jserver2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * l2jserver2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with l2jserver2. If not, see . + */ +package com.l2jserver.service; + +import javolution.lang.Configurable; + +/** + * Implements basic management for configurable services + * + * @author Rogiel + * @param + * the service configuration type + */ +public class AbstractConfigurableService + extends AbstractService implements ConfigurableService { + /** + * The service configuration + */ + protected T config; + /** + * The service configuration class + */ + private final Class configType; + + /** + * @param configType + * the service configuration class + */ + public AbstractConfigurableService(Class configType) { + this.configType = configType; + } + + /** + * Transparently implements + * {@link ConfigurableService#getConfigurationInterface()} without + * implementing the interface + * + * @return the configuration interface set at {@link Configurable} + * annotation, if present. + */ + @Override + public Class getConfigurationInterface() { + return configType; + } + + @Override + public void setConfiguration(T configuration) { + config = configuration; + } +} diff --git a/l2jserver2-common/src/main/java/com/l2jserver/service/ConfigurableService.java b/l2jserver2-common/src/main/java/com/l2jserver/service/ConfigurableService.java new file mode 100644 index 000000000..8dda63938 --- /dev/null +++ b/l2jserver2-common/src/main/java/com/l2jserver/service/ConfigurableService.java @@ -0,0 +1,42 @@ +/* + * This file is part of l2jserver2 . + * + * l2jserver2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * l2jserver2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with l2jserver2. If not, see . + */ +package com.l2jserver.service; + +/** + * Marks whether an service can be configured or not + * + * @author Rogiel + * @param + * the configuration interface type + */ +public interface ConfigurableService extends + Service { + /** + * @return the configuration interface used by this service + */ + Class getConfigurationInterface(); + + /** + * Please note that this method will only be set at {@link Service#start()}. + * Once {@link Service#stop()} is called, the configuration will be set to + * null. + * + * @param configuration + * the service configuration instance + */ + void setConfiguration(T configuration); +} diff --git a/l2jserver2-common/src/main/java/com/l2jserver/service/ServiceDescriptor.java b/l2jserver2-common/src/main/java/com/l2jserver/service/ServiceDescriptor.java new file mode 100644 index 000000000..db1f37386 --- /dev/null +++ b/l2jserver2-common/src/main/java/com/l2jserver/service/ServiceDescriptor.java @@ -0,0 +1,108 @@ +/* + * This file is part of l2jserver2 . + * + * l2jserver2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * l2jserver2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with l2jserver2. If not, see . + */ +package com.l2jserver.service; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; + +import org.w3c.dom.DOMException; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; + +/** + * @author Rogiel + * @param + * the service type + */ +@XmlAccessorType(XmlAccessType.NONE) +@XmlRootElement(name = "services") +public class ServiceDescriptor { + /** + * The service interface class + */ + @XmlAttribute(name = "interface") + private final Class serviceInterface; + /** + * The service implementation class + */ + @XmlAttribute(name = "implementation") + private final Class serviceImplementation; + /** + * The node (will be used later for configuration purposes) + */ + private final Node node; + + /** + * @param serviceInterface + * the service interface + * @param serviceImplementation + * the service implementation + * @param node + * the XML node + */ + public ServiceDescriptor(Class serviceInterface, + Class serviceImplementation, Node node) { + this.serviceInterface = serviceInterface; + this.serviceImplementation = serviceImplementation; + this.node = node; + } + + /** + * @return the service interface class + */ + public Class getServiceInterface() { + return serviceInterface; + } + + /** + * @return the service implementation class + */ + public Class getServiceImplementation() { + return serviceImplementation; + } + + /** + * @return the xml node + */ + public Node getNode() { + return node; + } + + /** + * @param node + * the XML node + * @return a new {@link ServiceDescriptor} instance for the given service + * XML node + * @throws ClassNotFoundException + * if any of the services class could not be found + * @throws DOMException + * if any error occur while parsing the XML data + */ + @SuppressWarnings({ "unchecked", "rawtypes" }) + public static ServiceDescriptor fromNode(Node node) + throws ClassNotFoundException, DOMException { + final NamedNodeMap attrs = node.getAttributes(); + final Class serviceInterface = (Class) Class + .forName(attrs.getNamedItem("interface").getNodeValue()); + final Class serviceImplementation = (Class) Class + .forName(attrs.getNamedItem("implementation").getNodeValue()); + return new ServiceDescriptor(serviceInterface, serviceImplementation, + node); + } +} diff --git a/l2jserver2-common/src/main/java/com/l2jserver/service/ServiceException.java b/l2jserver2-common/src/main/java/com/l2jserver/service/ServiceException.java index 7dc8f3aa7..e92c703dd 100644 --- a/l2jserver2-common/src/main/java/com/l2jserver/service/ServiceException.java +++ b/l2jserver2-common/src/main/java/com/l2jserver/service/ServiceException.java @@ -23,7 +23,7 @@ import com.l2jserver.util.exception.L2Exception; * * @author Rogiel */ -public abstract class ServiceException extends L2Exception { +public class ServiceException extends L2Exception { /** * The Java Serialization API serial */ diff --git a/l2jserver2-common/src/main/java/com/l2jserver/service/ServiceManager.java b/l2jserver2-common/src/main/java/com/l2jserver/service/ServiceManager.java index 08d5796f8..582a4008b 100644 --- a/l2jserver2-common/src/main/java/com/l2jserver/service/ServiceManager.java +++ b/l2jserver2-common/src/main/java/com/l2jserver/service/ServiceManager.java @@ -16,14 +16,29 @@ */ package com.l2jserver.service; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Map; import java.util.Set; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.w3c.dom.DOMException; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; +import com.google.inject.AbstractModule; import com.google.inject.Guice; -import com.google.inject.Inject; import com.google.inject.Injector; +import com.google.inject.Module; +import com.google.inject.Scopes; +import com.l2jserver.service.configuration.ConfigurationService; import com.l2jserver.service.core.LoggingService; import com.l2jserver.util.ClassUtils; import com.l2jserver.util.factory.CollectionFactory; @@ -37,31 +52,89 @@ public class ServiceManager { /** * The logger */ - private final Logger logger; + private Logger logger; /** * The Guice Injector */ - private final Injector injector; + private Injector injector; + /** + * The configuration service + */ + private ConfigurationService configurationService; + /** + * The DAO module + */ + private Class daoModule; + /** * List of all known services by this manager */ private final Set knownServices = CollectionFactory.newSet(); + /** + * The service descriptors + */ + private final Map, ServiceDescriptor> descriptors = CollectionFactory + .newMap(); /** - * @param injector - * the {@link Guice} {@link Injector} + * @param file + * the XML file + * @throws SAXException + * if any XML parsing error occur + * @throws IOException + * if any error occur while reading the file + * @throws ParserConfigurationException + * if any XML parsing error occur + * @throws ClassNotFoundException + * if the service class could not be found + * @throws DOMException + * if any XML parsing error occur + * @throws ServiceException + * if any service error occur */ - @Inject - public ServiceManager(Injector injector) { + @SuppressWarnings("unchecked") + public void load(Path file) throws SAXException, IOException, + ParserConfigurationException, ClassNotFoundException, DOMException, + ServiceException { + Document document = DocumentBuilderFactory.newInstance() + .newDocumentBuilder().parse(Files.newInputStream(file)); + + final Map, ServiceDescriptor> descriptors = CollectionFactory + .newMap(); + final NodeList nodeList = document.getElementsByTagName("service"); + for (int i = 0; i < nodeList.getLength(); i++) { + final Node node = nodeList.item(i); + final ServiceDescriptor descriptor = ServiceDescriptor + .fromNode(node); + descriptors.put(descriptor.getServiceInterface(), descriptor); + } + final Node node = document.getElementsByTagName("dao").item(0); + if (node == null) + throw new ServiceException("DAO module declaration not found"); + daoModule = (Class) Class.forName(node + .getAttributes().getNamedItem("module").getNodeValue()); + + this.descriptors.putAll(descriptors); + } + + /** + * Initializes the service manager + * + * @param injector + * the injector instance + * @throws ServiceStartException + * if any error occur while starting logging or configuration + * service + */ + public void init(Injector injector) throws ServiceStartException { this.injector = injector; final LoggingService service = injector .getInstance(LoggingService.class); knownServices.add(service); - try { - service.start(); - } catch (ServiceStartException e) { - throw new RuntimeException(e); - } + service.start(); + configurationService = injector.getInstance(ConfigurationService.class); + knownServices.add(configurationService); + configurationService.start(); logger = LoggerFactory.getLogger(ServiceManager.class); } @@ -76,6 +149,17 @@ public class ServiceManager { return injector.getInstance(serviceClass); } + /** + * @param serviceClass + * the service class + * @return the {@link ServiceDescriptor} for the requested service + */ + @SuppressWarnings("unchecked") + public ServiceDescriptor getServiceDescriptor( + Class serviceClass) { + return (ServiceDescriptor) descriptors.get(serviceClass); + } + /** * Starts the given service implementation * @@ -87,6 +171,7 @@ public class ServiceManager { * @throws ServiceStartException * if any error occur while starting service */ + @SuppressWarnings({ "unchecked", "rawtypes" }) public T start(Class serviceClass) throws ServiceStartException { final T service = injector.getInstance(serviceClass); @@ -99,6 +184,13 @@ public class ServiceManager { startDependencies(service.getDependencies()); logger.debug("{}: Starting service...", serviceClass.getSimpleName()); + if (service instanceof ConfigurableService) { + final ServiceConfiguration config = configurationService + .getServiceConfiguration( + (ConfigurableService) service, + (Class) serviceClass); + ((ConfigurableService) service).setConfiguration(config); + } service.start(); logger.info("{} started", serviceClass.getSimpleName()); return service; @@ -152,6 +244,9 @@ public class ServiceManager { logger.debug("{0}: Stopping service...", serviceClass.getSimpleName()); stopDependencies(service); + if (service instanceof ConfigurableService) { + ((ConfigurableService) service).setConfiguration(null); + } service.stop(); logger.info("{0}: Service stopped!", serviceClass.getSimpleName()); } catch (ServiceStopException e) { @@ -245,4 +340,29 @@ public class ServiceManager { throw e; } } + + /** + * @return a newly created {@link Guice} {@link Module} with all loaded + * services + */ + public Module newGuiceModule() { + return new AbstractModule() { + @Override + @SuppressWarnings("unchecked") + protected void configure() { + bind(ServiceManager.class).toInstance(ServiceManager.this); + try { + install(daoModule.newInstance()); + } catch (Exception e) { + throw new RuntimeException(e); + } + for (@SuppressWarnings("rawtypes") + final ServiceDescriptor descriptor : descriptors.values()) { + bind(descriptor.getServiceInterface()).to( + descriptor.getServiceImplementation()).in( + Scopes.SINGLETON); + } + } + }; + } } diff --git a/l2jserver2-common/src/main/java/com/l2jserver/service/configuration/ConfigurationService.java b/l2jserver2-common/src/main/java/com/l2jserver/service/configuration/ConfigurationService.java index a6836eb27..5e1427e99 100644 --- a/l2jserver2-common/src/main/java/com/l2jserver/service/configuration/ConfigurationService.java +++ b/l2jserver2-common/src/main/java/com/l2jserver/service/configuration/ConfigurationService.java @@ -16,7 +16,9 @@ */ package com.l2jserver.service.configuration; +import com.l2jserver.service.ConfigurableService; import com.l2jserver.service.Service; +import com.l2jserver.service.ServiceConfiguration; /** * The configuration service is responsible for reading and writing in @@ -27,13 +29,15 @@ import com.l2jserver.service.Service; */ public interface ConfigurationService extends Service { /** - * Get the configuration object for config + * Get the configuration for the given service * - * @param - * the configuration type - * @param config - * the configuration interface class + * @param service + * the service + * @param serviceInterface + * the service interface * @return the configuration object */ - C get(Class config); + C getServiceConfiguration( + ConfigurableService service, + Class serviceInterface); } diff --git a/l2jserver2-common/src/main/java/com/l2jserver/service/configuration/XMLConfigurationService.java b/l2jserver2-common/src/main/java/com/l2jserver/service/configuration/XMLConfigurationService.java index ea757a6ab..3db56bb67 100644 --- a/l2jserver2-common/src/main/java/com/l2jserver/service/configuration/XMLConfigurationService.java +++ b/l2jserver2-common/src/main/java/com/l2jserver/service/configuration/XMLConfigurationService.java @@ -16,8 +16,6 @@ */ package com.l2jserver.service.configuration; -import java.io.File; -import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -26,23 +24,23 @@ import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.Map; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.w3c.dom.Document; import org.w3c.dom.Node; -import org.xml.sax.SAXException; import com.google.common.base.Preconditions; import com.google.inject.Inject; import com.l2jserver.service.AbstractService; import com.l2jserver.service.AbstractService.Depends; +import com.l2jserver.service.ConfigurableService; +import com.l2jserver.service.Service; +import com.l2jserver.service.ServiceConfiguration; +import com.l2jserver.service.ServiceDescriptor; +import com.l2jserver.service.ServiceManager; import com.l2jserver.service.ServiceStartException; import com.l2jserver.service.cache.CacheService; import com.l2jserver.service.configuration.Configuration.ConfigurationPropertyGetter; @@ -60,33 +58,16 @@ import com.l2jserver.util.transformer.TransformerFactory; @Depends({ LoggingService.class, CacheService.class }) public class XMLConfigurationService extends AbstractService implements ConfigurationService { - /** - * The directory in which configuration files are stored - */ - private File file = new File("./config/config.xml"); /** * The logger */ private final Logger log = LoggerFactory.getLogger(this.getClass()); /** - * The DOM {@link DocumentBuilderFactory} + * The service manager. Will provide XML nodes for service configuration + * interfaces */ - private DocumentBuilderFactory factory; - /** - * The DOM {@link DocumentBuilder} - */ - private DocumentBuilder builder; - - /** - * The XML {@link Document} containing configuration data - */ - private Document properties; - - /** - * The cache of configuration objects - */ - private Map, Object> cache = CollectionFactory.newWeakMap(); + private final ServiceManager serviceManager; /** * Defines the XPath for the configuration parameter @@ -103,50 +84,29 @@ public class XMLConfigurationService extends AbstractService implements /** * Creates a new empty instance + * + * @param serviceManager + * the service manager */ @Inject - protected XMLConfigurationService() { - } - - /** - * Creates a new service instance. This is used for tests - * - * @param file - * the configuration file - */ - protected XMLConfigurationService(File file) { - this.file = file; + protected XMLConfigurationService(ServiceManager serviceManager) { + this.serviceManager = serviceManager; } @Override protected void doStart() throws ServiceStartException { - factory = DocumentBuilderFactory.newInstance(); - try { - builder = factory.newDocumentBuilder(); - properties = builder.parse(file); - } catch (ParserConfigurationException e) { - throw new ServiceStartException(e); - } catch (SAXException e) { - throw new ServiceStartException(e); - } catch (IOException e) { - throw new ServiceStartException(e); - } } @Override @SuppressWarnings("unchecked") - public C get(Class config) { - Preconditions.checkNotNull(config, "config"); - - if (cache.containsKey(config)) - return (C) cache.get(config); - log.debug("Trying to create {} proxy", config); - - C proxy = (C) Proxy.newProxyInstance(this.getClass().getClassLoader(), - new Class[] { config }, new ConfigInvocationHandler( - properties)); - cache.put(config, proxy); - return proxy; + public C getServiceConfiguration( + ConfigurableService service, + Class serviceInterface) { + final ServiceDescriptor serviceDescriptor = serviceManager + .getServiceDescriptor(serviceInterface); + return (C) Proxy.newProxyInstance(this.getClass().getClassLoader(), + new Class[] { service.getConfigurationInterface() }, + new ConfigInvocationHandler(serviceDescriptor.getNode())); } /** @@ -158,7 +118,7 @@ public class XMLConfigurationService extends AbstractService implements /** * The invocation handler properties */ - private final Document properties; + private final Node properties; /** * The invocation cache */ @@ -168,7 +128,7 @@ public class XMLConfigurationService extends AbstractService implements * @param properties * the properties */ - public ConfigInvocationHandler(Document properties) { + public ConfigInvocationHandler(Node properties) { this.properties = properties; } @@ -345,11 +305,4 @@ public class XMLConfigurationService extends AbstractService implements } return null; } - - /** - * @return the configuration store directory - */ - public File getFile() { - return file; - } } diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/L2JGameServer.java b/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/Java7VFSConfiguration.java similarity index 66% rename from l2jserver2-gameserver/src/main/java/com/l2jserver/L2JGameServer.java rename to l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/Java7VFSConfiguration.java index 8f196902b..bc670a813 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/L2JGameServer.java +++ b/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/Java7VFSConfiguration.java @@ -1,42 +1,25 @@ -/* - * This file is part of l2jserver2 . - * - * l2jserver2 is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * l2jserver2 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with l2jserver2. If not, see . - */ -package com.l2jserver; - -import com.google.inject.Guice; -import com.google.inject.Injector; - -/** - * The L2JGameServer class - * - * @author Rogiel - */ -public class L2JGameServer { - /** - * The server injector - */ - private final Injector injector = Guice - .createInjector(new GameServerModule()); - - /** - * Get the injector - * - * @return the injector - */ - public Injector getInjector() { - return injector; - } -} +/* + * This file is part of l2jserver2 . + * + * l2jserver2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * l2jserver2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with l2jserver2. If not, see . + */ +package com.l2jserver.service.core.vfs; + +/** + * Configuration interface for {@link Java7VFSService}. + * + * @author Rogiel + */ +public interface Java7VFSConfiguration extends VFSConfiguration { +} \ No newline at end of file diff --git a/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/Java7VFSService.java b/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/Java7VFSService.java index caa1a88aa..2fef9baf2 100644 --- a/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/Java7VFSService.java +++ b/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/Java7VFSService.java @@ -22,27 +22,23 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.inject.Inject; -import com.l2jserver.service.AbstractService; +import com.l2jserver.service.AbstractConfigurableService; import com.l2jserver.service.ServiceStartException; import com.l2jserver.service.ServiceStopException; -import com.l2jserver.service.configuration.ConfigurationService; /** * Implementation of {@link VFSService} using default Java7 APIs. * * @author Rogiel */ -public class Java7VFSService extends AbstractService implements VFSService { +public class Java7VFSService extends + AbstractConfigurableService implements + VFSService { /** * The logger */ private final Logger log = LoggerFactory.getLogger(this.getClass()); - /** - * The Java 7 vfs configuration - */ - private final Java7VFSConfiguration config; - /** * The root {@link Path} of the server data */ @@ -53,20 +49,11 @@ public class Java7VFSService extends AbstractService implements VFSService { private Path dataRoot; /** - * Configuration interface for {@link Java7VFSService}. - * - * @author Rogiel - */ - public interface Java7VFSConfiguration extends VFSConfiguration { - } - - /** - * @param configService - * the configuration service + * Creates a new instance */ @Inject - protected Java7VFSService(final ConfigurationService configService) { - this.config = configService.get(Java7VFSConfiguration.class); + public Java7VFSService() { + super(Java7VFSConfiguration.class); } @Override diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/GameServerModule.java b/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/TrueZipVFSConfiguration.java similarity index 60% rename from l2jserver2-gameserver/src/main/java/com/l2jserver/GameServerModule.java rename to l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/TrueZipVFSConfiguration.java index a156b61ca..168355080 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/GameServerModule.java +++ b/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/TrueZipVFSConfiguration.java @@ -1,37 +1,25 @@ -/* - * This file is part of l2jserver2 . - * - * l2jserver2 is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * l2jserver2 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with l2jserver2. If not, see . - */ -package com.l2jserver; - -import com.google.inject.AbstractModule; -import com.google.inject.Module; -import com.l2jserver.model.id.provider.IDProviderModule; -import com.l2jserver.service.ServiceModule; -import com.l2jserver.service.database.OrientDBDAOModule; - -/** - * The game server Google Guice {@link Module}. - * - * @author Rogiel - */ -public class GameServerModule extends AbstractModule { - @Override - protected void configure() { - install(new ServiceModule()); - install(new IDProviderModule()); - install(new OrientDBDAOModule()); - } -} +/* + * This file is part of l2jserver2 . + * + * l2jserver2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * l2jserver2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with l2jserver2. If not, see . + */ +package com.l2jserver.service.core.vfs; + +/** + * Configuration interface for {@link TrueZipVFSService}. + * + * @author Rogiel + */ +public interface TrueZipVFSConfiguration extends VFSConfiguration { +} \ No newline at end of file diff --git a/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/TrueZipVFSService.java b/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/TrueZipVFSService.java index 2d1e7b3cb..ce92d0804 100644 --- a/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/TrueZipVFSService.java +++ b/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/TrueZipVFSService.java @@ -22,7 +22,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.inject.Inject; -import com.l2jserver.service.AbstractService; +import com.l2jserver.service.AbstractConfigurableService; import com.l2jserver.service.ServiceStartException; import com.l2jserver.service.ServiceStopException; import com.l2jserver.service.configuration.ConfigurationService; @@ -35,17 +35,14 @@ import de.schlichtherle.truezip.nio.file.TPath; * * @author Rogiel */ -public class TrueZipVFSService extends AbstractService implements VFSService { +public class TrueZipVFSService extends + AbstractConfigurableService implements + VFSService { /** * The logger */ private final Logger log = LoggerFactory.getLogger(this.getClass()); - /** - * The Java 7 vfs configuration - */ - private final TrueZipVFSConfiguration config; - /** * The root {@link Path} of the server data */ @@ -55,21 +52,13 @@ public class TrueZipVFSService extends AbstractService implements VFSService { */ private TPath dataRoot; - /** - * Configuration interface for {@link TrueZipVFSService}. - * - * @author Rogiel - */ - public interface TrueZipVFSConfiguration extends VFSConfiguration { - } - /** * @param configService * the configuration service */ @Inject protected TrueZipVFSService(final ConfigurationService configService) { - this.config = configService.get(TrueZipVFSConfiguration.class); + super(TrueZipVFSConfiguration.class); } @Override diff --git a/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/VFSConfiguration.java b/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/VFSConfiguration.java new file mode 100644 index 000000000..a71ec8de7 --- /dev/null +++ b/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/VFSConfiguration.java @@ -0,0 +1,62 @@ +/* + * This file is part of l2jserver2 . + * + * l2jserver2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * l2jserver2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with l2jserver2. If not, see . + */ +package com.l2jserver.service.core.vfs; + +import java.net.URI; +import java.nio.file.Path; + +import com.l2jserver.service.ServiceConfiguration; +import com.l2jserver.service.configuration.Configuration; +import com.l2jserver.service.configuration.XMLConfigurationService.ConfigurationXPath; + +/** + * VFS service configuration + * + * @author Rogiel + * @see Configuration + */ +public interface VFSConfiguration extends ServiceConfiguration { + /** + * @return the VFS root {@link URI} + */ + @ConfigurationPropertyGetter(defaultValue = "") + @ConfigurationXPath("fileSystem/@root") + Path getRoot(); + + /** + * @param root + * the new VFS root {@link URI} + */ + @ConfigurationPropertySetter + @ConfigurationXPath("fileSystem/@root") + void setRoot(Path root); + + /** + * @return the VFS root {@link URI} + */ + @ConfigurationPropertyGetter(defaultValue = "") + @ConfigurationXPath("fileSystem/data/@root") + String getDataPath(); + + /** + * @param data + * the new data root {@link URI} + */ + @ConfigurationPropertySetter + @ConfigurationXPath("fileSystem/data/@root") + void setDataPath(String data); +} \ No newline at end of file diff --git a/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/VFSService.java b/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/VFSService.java index bfb5bcca6..d0853d100 100644 --- a/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/VFSService.java +++ b/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/VFSService.java @@ -16,13 +16,9 @@ */ package com.l2jserver.service.core.vfs; -import java.net.URI; import java.nio.file.Path; import com.l2jserver.service.Service; -import com.l2jserver.service.ServiceConfiguration; -import com.l2jserver.service.configuration.Configuration; -import com.l2jserver.service.configuration.XMLConfigurationService.ConfigurationXPath; /** * The VFS service is responsible for creating a Virtual File System that is @@ -31,44 +27,6 @@ import com.l2jserver.service.configuration.XMLConfigurationService.Configuration * @author Rogiel */ public interface VFSService extends Service { - /** - * VFS service configuration - * - * @author Rogiel - * @see Configuration - */ - public interface VFSConfiguration extends ServiceConfiguration { - /** - * @return the VFS root {@link URI} - */ - @ConfigurationPropertyGetter(defaultValue = "") - @ConfigurationXPath("/configuration/services/vfs/root") - Path getRoot(); - - /** - * @param root - * the new VFS root {@link URI} - */ - @ConfigurationPropertySetter - @ConfigurationXPath("/configuration/services/vfs/root") - void setRoot(Path root); - - /** - * @return the VFS root {@link URI} - */ - @ConfigurationPropertyGetter(defaultValue = "") - @ConfigurationXPath("/configuration/services/vfs/data") - String getDataPath(); - - /** - * @param data - * the new data root {@link URI} - */ - @ConfigurationPropertySetter - @ConfigurationXPath("/configuration/services/vfs/data") - void setDataPath(String data); - } - /** * Resolves an file. If the file cannot be resolved, null will be returned. *

diff --git a/l2jserver2-common/src/main/java/com/l2jserver/service/database/DatabaseConfiguration.java b/l2jserver2-common/src/main/java/com/l2jserver/service/database/DatabaseConfiguration.java new file mode 100644 index 000000000..085bebbd1 --- /dev/null +++ b/l2jserver2-common/src/main/java/com/l2jserver/service/database/DatabaseConfiguration.java @@ -0,0 +1,44 @@ +/* + * This file is part of l2jserver2 . + * + * l2jserver2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * l2jserver2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with l2jserver2. If not, see . + */ +package com.l2jserver.service.database; + +import com.l2jserver.service.ServiceConfiguration; +import com.l2jserver.service.configuration.Configuration; +import com.l2jserver.service.configuration.XMLConfigurationService.ConfigurationXPath; + +/** + * Database service configuration + * + * @author Rogiel + * @see Configuration + */ +public interface DatabaseConfiguration extends ServiceConfiguration { + /** + * @return the update schema state + */ + @ConfigurationPropertyGetter(defaultValue = "true") + @ConfigurationXPath("schema/@automaticUpdate") + boolean isAutomaticSchemaUpdateEnabled(); + + /** + * @param updateSchema + * the new uodate schema state + */ + @ConfigurationPropertySetter + @ConfigurationXPath("schema/@automaticUpdate") + void setUpdateSchema(boolean updateSchema); +} \ No newline at end of file diff --git a/l2jserver2-common/src/main/java/com/l2jserver/service/database/DatabaseService.java b/l2jserver2-common/src/main/java/com/l2jserver/service/database/DatabaseService.java index 75d4d1563..a6677e3e0 100644 --- a/l2jserver2-common/src/main/java/com/l2jserver/service/database/DatabaseService.java +++ b/l2jserver2-common/src/main/java/com/l2jserver/service/database/DatabaseService.java @@ -22,9 +22,6 @@ import java.nio.file.Path; import com.l2jserver.model.Model; import com.l2jserver.model.id.ID; import com.l2jserver.service.Service; -import com.l2jserver.service.ServiceConfiguration; -import com.l2jserver.service.configuration.Configuration; -import com.l2jserver.service.configuration.XMLConfigurationService.ConfigurationXPath; import com.l2jserver.service.core.threading.AsyncFuture; import com.mysema.query.sql.RelationalPath; import com.mysema.query.sql.RelationalPathBase; @@ -45,29 +42,6 @@ import com.mysema.query.sql.RelationalPathBase; * @author Rogiel */ public interface DatabaseService extends Service { - /** - * Database service configuration - * - * @author Rogiel - * @see Configuration - */ - public interface DatabaseConfiguration extends ServiceConfiguration { - /** - * @return the update schema state - */ - @ConfigurationPropertyGetter(defaultValue = "true") - @ConfigurationXPath("/configuration/services/database/automaticSchemaUpdate") - boolean isAutomaticSchemaUpdateEnabled(); - - /** - * @param updateSchema - * the new uodate schema state - */ - @ConfigurationPropertySetter - @ConfigurationXPath("/configuration/services/database/automaticSchemaUpdate") - void setUpdateSchema(boolean updateSchema); - } - /** * Executes several operations inside a single database transaction. *

diff --git a/l2jserver2-common/src/main/java/com/l2jserver/service/database/orientdb/AbstractOrientDatabaseService.java b/l2jserver2-common/src/main/java/com/l2jserver/service/database/orientdb/AbstractOrientDatabaseService.java index 53e5c9711..9d68967fa 100644 --- a/l2jserver2-common/src/main/java/com/l2jserver/service/database/orientdb/AbstractOrientDatabaseService.java +++ b/l2jserver2-common/src/main/java/com/l2jserver/service/database/orientdb/AbstractOrientDatabaseService.java @@ -35,13 +35,11 @@ import com.l2jserver.model.Model; import com.l2jserver.model.Model.ObjectDesire; import com.l2jserver.model.id.ID; import com.l2jserver.model.id.object.allocator.IDAllocator; -import com.l2jserver.service.AbstractService; +import com.l2jserver.service.AbstractConfigurableService; import com.l2jserver.service.ServiceStartException; import com.l2jserver.service.ServiceStopException; import com.l2jserver.service.cache.Cache; import com.l2jserver.service.cache.CacheService; -import com.l2jserver.service.configuration.ConfigurationService; -import com.l2jserver.service.configuration.XMLConfigurationService.ConfigurationXPath; import com.l2jserver.service.core.threading.AbstractTask; import com.l2jserver.service.core.threading.AsyncFuture; import com.l2jserver.service.core.threading.ScheduledAsyncFuture; @@ -96,12 +94,9 @@ import com.orientechnologies.orient.core.tx.OTransaction; * * @author Rogiel */ -public abstract class AbstractOrientDatabaseService extends AbstractService - implements DatabaseService { - /** - * The configuration object - */ - private final OrientDatabaseConfiguration config; +public abstract class AbstractOrientDatabaseService extends + AbstractConfigurableService implements + DatabaseService { /** * The logger */ @@ -136,60 +131,6 @@ public abstract class AbstractOrientDatabaseService extends AbstractService private final ThreadLocal transaction = new ThreadLocal(); /** - * Configuration interface for {@link AbstractOrientDatabaseService}. - * - * @author Rogiel - */ - public interface OrientDatabaseConfiguration extends DatabaseConfiguration { - /** - * @return the orientdb url - */ - @ConfigurationPropertyGetter(defaultValue = "local:data/database") - @ConfigurationXPath("/configuration/services/database/orientdb/url") - String getUrl(); - - /** - * @param url - * the new orientdb url - */ - @ConfigurationPropertySetter - @ConfigurationXPath("/configuration/services/database/orientdb/url") - void setUrl(String url); - - /** - * @return the orientdb database username - */ - @ConfigurationPropertyGetter(defaultValue = "admin") - @ConfigurationXPath("/configuration/services/database/orientdb/username") - String getUsername(); - - /** - * @param username - * the orientdb database username - */ - @ConfigurationPropertySetter - @ConfigurationXPath("/configuration/services/database/orientdb/username") - void setUsername(String username); - - /** - * @return the orientdb database password - */ - @ConfigurationPropertyGetter(defaultValue = "admin") - @ConfigurationXPath("/configuration/services/database/orientdb/password") - String getPassword(); - - /** - * @param password - * the jdbc database password - */ - @ConfigurationPropertySetter - @ConfigurationXPath("/configuration/services/database/jdbc/password") - void setPassword(String password); - } - - /** - * @param configService - * the configuration service * @param cacheService * the cache service * @param threadService @@ -198,10 +139,10 @@ public abstract class AbstractOrientDatabaseService extends AbstractService * the {@link DataAccessObject DAO} resolver */ @Inject - public AbstractOrientDatabaseService(ConfigurationService configService, + public AbstractOrientDatabaseService( CacheService cacheService, ThreadService threadService, DAOResolver daoResolver) { - config = configService.get(OrientDatabaseConfiguration.class); + super(OrientDatabaseConfiguration.class); this.cacheService = cacheService; this.threadService = threadService; this.daoResolver = daoResolver; diff --git a/l2jserver2-common/src/main/java/com/l2jserver/service/database/orientdb/OrientDatabaseConfiguration.java b/l2jserver2-common/src/main/java/com/l2jserver/service/database/orientdb/OrientDatabaseConfiguration.java new file mode 100644 index 000000000..945409809 --- /dev/null +++ b/l2jserver2-common/src/main/java/com/l2jserver/service/database/orientdb/OrientDatabaseConfiguration.java @@ -0,0 +1,72 @@ +/* + * This file is part of l2jserver2 . + * + * l2jserver2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * l2jserver2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with l2jserver2. If not, see . + */ +package com.l2jserver.service.database.orientdb; + +import com.l2jserver.service.configuration.XMLConfigurationService.ConfigurationXPath; +import com.l2jserver.service.database.DatabaseConfiguration; + +/** + * Configuration interface for {@link AbstractOrientDatabaseService}. + * + * @author Rogiel + */ +public interface OrientDatabaseConfiguration extends DatabaseConfiguration { + /** + * @return the orientdb url + */ + @ConfigurationPropertyGetter(defaultValue = "local:data/database") + @ConfigurationXPath("connection/@url") + String getUrl(); + + /** + * @param url + * the new orientdb url + */ + @ConfigurationPropertySetter + @ConfigurationXPath("connection/@url") + void setUrl(String url); + + /** + * @return the orientdb database username + */ + @ConfigurationPropertyGetter(defaultValue = "admin") + @ConfigurationXPath("connection/authentication/@username") + String getUsername(); + + /** + * @param username + * the orientdb database username + */ + @ConfigurationPropertySetter + @ConfigurationXPath("connection/authentication/@username") + void setUsername(String username); + + /** + * @return the orientdb database password + */ + @ConfigurationPropertyGetter(defaultValue = "admin") + @ConfigurationXPath("connection/authentication/@password") + String getPassword(); + + /** + * @param password + * the jdbc database password + */ + @ConfigurationPropertySetter + @ConfigurationXPath("connection/authentication/@password") + void setPassword(String password); +} \ No newline at end of file diff --git a/l2jserver2-common/src/main/java/com/l2jserver/service/database/sql/AbstractSQLDatabaseService.java b/l2jserver2-common/src/main/java/com/l2jserver/service/database/sql/AbstractSQLDatabaseService.java index 171af5ebc..00460ff9a 100644 --- a/l2jserver2-common/src/main/java/com/l2jserver/service/database/sql/AbstractSQLDatabaseService.java +++ b/l2jserver2-common/src/main/java/com/l2jserver/service/database/sql/AbstractSQLDatabaseService.java @@ -43,13 +43,11 @@ import com.l2jserver.model.Model; import com.l2jserver.model.Model.ObjectDesire; import com.l2jserver.model.id.ID; import com.l2jserver.model.id.object.allocator.IDAllocator; -import com.l2jserver.service.AbstractService; +import com.l2jserver.service.AbstractConfigurableService; import com.l2jserver.service.ServiceStartException; import com.l2jserver.service.ServiceStopException; import com.l2jserver.service.cache.Cache; import com.l2jserver.service.cache.CacheService; -import com.l2jserver.service.configuration.ConfigurationService; -import com.l2jserver.service.configuration.XMLConfigurationService.ConfigurationXPath; import com.l2jserver.service.core.threading.AbstractTask; import com.l2jserver.service.core.threading.AsyncFuture; import com.l2jserver.service.core.threading.ScheduledAsyncFuture; @@ -101,12 +99,9 @@ import com.mysema.query.types.Path; * * @author Rogiel */ -public abstract class AbstractSQLDatabaseService extends AbstractService - implements DatabaseService { - /** - * The configuration object - */ - private final JDBCDatabaseConfiguration config; +public abstract class AbstractSQLDatabaseService extends + AbstractConfigurableService implements + DatabaseService { /** * The logger */ @@ -173,120 +168,6 @@ public abstract class AbstractSQLDatabaseService extends AbstractService private final Type[] sqlTypes; /** - * Configuration interface for {@link AbstractSQLDatabaseService}. - * - * @author Rogiel - */ - public interface JDBCDatabaseConfiguration extends DatabaseConfiguration { - /** - * @return the jdbc url - */ - @ConfigurationPropertyGetter(defaultValue = "jdbc:mysql://localhost/l2jserver2") - @ConfigurationXPath("/configuration/services/database/jdbc/url") - String getJdbcUrl(); - - /** - * @param jdbcUrl - * the new jdbc url - */ - @ConfigurationPropertySetter - @ConfigurationXPath("/configuration/services/database/jdbc/url") - void setJdbcUrl(String jdbcUrl); - - /** - * @return the database engine class - */ - @ConfigurationPropertyGetter(defaultValue = "com.l2jserver.service.database.sql.MySQLDatabaseEngine") - @ConfigurationXPath("/configuration/services/database/jdbc/engine") - Class getDatabaseEngineClass(); - - /** - * @param driver - * the new database engine class - */ - @ConfigurationPropertySetter - @ConfigurationXPath("/configuration/services/database/jdbc/engine") - void setDatabaseEngineClass(Class driver); - - /** - * @return the jdbc database username - */ - @ConfigurationPropertyGetter(defaultValue = "l2j") - @ConfigurationXPath("/configuration/services/database/jdbc/username") - String getUsername(); - - /** - * @param username - * the jdbc database username - */ - @ConfigurationPropertySetter - @ConfigurationXPath("/configuration/services/database/jdbc/username") - void setUsername(String username); - - /** - * @return the jdbc database password - */ - @ConfigurationPropertyGetter(defaultValue = "changeme") - @ConfigurationXPath("/configuration/services/database/jdbc/password") - String getPassword(); - - /** - * @param password - * the jdbc database password - */ - @ConfigurationPropertySetter - @ConfigurationXPath("/configuration/services/database/jdbc/password") - void setPassword(String password); - - /** - * @return the maximum number of active connections - */ - @ConfigurationPropertyGetter(defaultValue = "20") - @ConfigurationXPath("/configuration/services/database/connections/active-maximum") - int getMaxActiveConnections(); - - /** - * @param password - * the maximum number of active connections - */ - @ConfigurationPropertySetter - @ConfigurationXPath("/configuration/services/database/connections/active-maximum") - void setMaxActiveConnections(int password); - - /** - * @return the maximum number of idle connections - */ - @ConfigurationPropertyGetter(defaultValue = "20") - @ConfigurationXPath("/configuration/services/database/connections/idle-maximum") - int getMaxIdleConnections(); - - /** - * @param password - * the maximum number of idle connections - */ - @ConfigurationPropertySetter - @ConfigurationXPath("/configuration/services/database/connections/idle-maximum") - void setMaxIdleConnections(int password); - - /** - * @return the minimum number of idle connections - */ - @ConfigurationPropertyGetter(defaultValue = "5") - @ConfigurationXPath("/configuration/services/database/connections/idle-minimum") - int getMinIdleConnections(); - - /** - * @param password - * the minimum number of idle connections - */ - @ConfigurationPropertySetter - @ConfigurationXPath("/configuration/services/database/connections/idle-minimum") - void setMinIdleConnections(int password); - } - - /** - * @param configService - * the configuration service * @param cacheService * the cache service * @param threadService @@ -299,10 +180,10 @@ public abstract class AbstractSQLDatabaseService extends AbstractService * the SQL mapping types */ @Inject - public AbstractSQLDatabaseService(ConfigurationService configService, - CacheService cacheService, ThreadService threadService, - VFSService vfsService, DAOResolver daoResolver, Type... types) { - config = configService.get(JDBCDatabaseConfiguration.class); + public AbstractSQLDatabaseService(CacheService cacheService, + ThreadService threadService, VFSService vfsService, + DAOResolver daoResolver, Type... types) { + super(JDBCDatabaseConfiguration.class); this.cacheService = cacheService; this.threadService = threadService; this.vfsService = vfsService; @@ -409,6 +290,7 @@ public abstract class AbstractSQLDatabaseService extends AbstractService } log.info("Importing {} to {}", path, entity); try { + conn.setAutoCommit(false); CSVUtils.parseCSV(path, new CSVMapProcessor() { @Override public Long process(final Map map) { @@ -433,8 +315,15 @@ public abstract class AbstractSQLDatabaseService extends AbstractService return insert.execute(); } }); + conn.commit(); + } catch (SQLException e) { + try { + conn.rollback(); + } catch (SQLException e1) { + } } finally { try { + conn.setAutoCommit(true); conn.close(); } catch (SQLException e) { } diff --git a/l2jserver2-common/src/main/java/com/l2jserver/service/database/sql/JDBCDatabaseConfiguration.java b/l2jserver2-common/src/main/java/com/l2jserver/service/database/sql/JDBCDatabaseConfiguration.java new file mode 100644 index 000000000..9d3c7d952 --- /dev/null +++ b/l2jserver2-common/src/main/java/com/l2jserver/service/database/sql/JDBCDatabaseConfiguration.java @@ -0,0 +1,132 @@ +/* + * This file is part of l2jserver2 . + * + * l2jserver2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * l2jserver2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with l2jserver2. If not, see . + */ +package com.l2jserver.service.database.sql; + +import com.l2jserver.service.configuration.XMLConfigurationService.ConfigurationXPath; +import com.l2jserver.service.database.DatabaseConfiguration; + +/** + * Configuration interface for {@link AbstractSQLDatabaseService}. + * + * @author Rogiel + */ +public interface JDBCDatabaseConfiguration extends DatabaseConfiguration { + /** + * @return the jdbc url + */ + @ConfigurationPropertyGetter(defaultValue = "jdbc:mysql://localhost/l2jserver2") + @ConfigurationXPath("connection/@url") + String getJdbcUrl(); + + /** + * @param jdbcUrl + * the new jdbc url + */ + @ConfigurationPropertySetter + @ConfigurationXPath("connection/@url") + void setJdbcUrl(String jdbcUrl); + + /** + * @return the database engine class + */ + @ConfigurationPropertyGetter(defaultValue = "com.l2jserver.service.database.sql.MySQLDatabaseEngine") + @ConfigurationXPath("connection/engine/@class") + Class getDatabaseEngineClass(); + + /** + * @param driver + * the new database engine class + */ + @ConfigurationPropertySetter + @ConfigurationXPath("connection/engine/@class") + void setDatabaseEngineClass(Class driver); + + /** + * @return the jdbc database username + */ + @ConfigurationPropertyGetter(defaultValue = "l2j") + @ConfigurationXPath("connection/authentication/@username") + String getUsername(); + + /** + * @param username + * the jdbc database username + */ + @ConfigurationPropertySetter + @ConfigurationXPath("connection/authentication/@username") + void setUsername(String username); + + /** + * @return the jdbc database password + */ + @ConfigurationPropertyGetter(defaultValue = "changeme") + @ConfigurationXPath("connection/authentication/@password") + String getPassword(); + + /** + * @param password + * the jdbc database password + */ + @ConfigurationPropertySetter + @ConfigurationXPath("connection/authentication/@password") + void setPassword(String password); + + /** + * @return the maximum number of active connections + */ + @ConfigurationPropertyGetter(defaultValue = "20") + @ConfigurationXPath("connection/pool/@max-active") + int getMaxActiveConnections(); + + /** + * @param maxActive + * the maximum number of active connections + */ + @ConfigurationPropertySetter + @ConfigurationXPath("connection/pool/@max-active") + void setMaxActiveConnections(int maxActive); + + /** + * @return the maximum number of idle connections + */ + @ConfigurationPropertyGetter(defaultValue = "20") + @ConfigurationXPath("connection/pool/@max-idle") + int getMaxIdleConnections(); + + /** + * @param maxIdle + * the maximum number of idle connections + */ + @ConfigurationPropertySetter + @ConfigurationXPath("connection/pool/@max-idle") + void setMaxIdleConnections(int maxIdle); + + /** + * @return the minimum number of idle connections + */ + @ConfigurationPropertyGetter(defaultValue = "5") + @ConfigurationXPath("connection/pool/@min-idle") + int getMinIdleConnections(); + + /** + * @param minIdle + * the minimum number of idle connections + */ + @ConfigurationPropertySetter + @ConfigurationXPath("connection/pool/@min-idle") + void setMinIdleConnections(int minIdle); +} \ No newline at end of file diff --git a/l2jserver2-common/src/main/java/com/l2jserver/util/ClassUtils.java b/l2jserver2-common/src/main/java/com/l2jserver/util/ClassUtils.java index 45d0623ae..f1e495cc4 100644 --- a/l2jserver2-common/src/main/java/com/l2jserver/util/ClassUtils.java +++ b/l2jserver2-common/src/main/java/com/l2jserver/util/ClassUtils.java @@ -16,6 +16,7 @@ */ package com.l2jserver.util; +import java.lang.annotation.Annotation; import java.lang.reflect.Field; /** @@ -61,6 +62,39 @@ public class ClassUtils { return false; } + /** + * Recursively searches for an annotation

Search order

+ *

+ *

    + *
  1. cls class
  2. + *
  3. cls implementing interfaces
  4. + *
  5. cls super class
  6. + *
+ * If after all those steps, no annotation is found, null is + * returned. + * + * @param annotationClass + * the annotation class + * @param cls + * the class to start searching + * @return the annotation, if found. + */ + public static T getAnnotation( + Class annotationClass, Class cls) { + T annotation = cls.getAnnotation(annotationClass); + if (annotation == null) { + for (final Class interfaceCls : cls.getInterfaces()) { + annotation = getAnnotation(annotationClass, interfaceCls); + if (annotation != null) + break; + } + } + if (annotation == null && cls.getSuperclass() != null + && cls.getSuperclass() != Object.class) + annotation = getAnnotation(annotationClass, cls.getSuperclass()); + return annotation; + } + /** * Checks if class in member of the package * diff --git a/l2jserver2-common/src/test/java/com/l2jserver/service/configuration/XMLConfigurationServiceTest.java b/l2jserver2-common/src/test/java/com/l2jserver/service/configuration/XMLConfigurationServiceTest.java deleted file mode 100644 index 840659984..000000000 --- a/l2jserver2-common/src/test/java/com/l2jserver/service/configuration/XMLConfigurationServiceTest.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * This file is part of l2jserver2 . - * - * l2jserver2 is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * l2jserver2 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with l2jserver2. If not, see . - */ -package com.l2jserver.service.configuration; - -import java.io.File; - -import junit.framework.Assert; - -import org.junit.Before; -import org.junit.Test; - -import com.l2jserver.service.ServiceStartException; -import com.l2jserver.service.configuration.XMLConfigurationService.ConfigurationXPath; - -/** - * Tests for {@link XMLConfigurationService} - * - * @author Rogiel - */ -public class XMLConfigurationServiceTest { - /** - * The {@link TestConfig} proxy - */ - private TestConfig config; - - /** - * Preparation for tests - * - * @throws ServiceStartException - */ - @Before - public void tearUp() throws ServiceStartException { - final XMLConfigurationService service = new XMLConfigurationService( - new File("src/test/resources/test-config.xml")); - service.start(); - config = service.get(TestConfig.class); - } - - /** - * Test config string - * - * @throws ServiceStartException - */ - @Test - public void testString() throws ServiceStartException { - Assert.assertEquals("test", config.getTestString()); - } - - /** - * Test default value - * - * @throws ServiceStartException - */ - @Test - public void testDefaultValue() throws ServiceStartException { - Assert.assertEquals("default", config.getDefaultTestString()); - } - - /** - * Test integer - * - * @throws ServiceStartException - */ - @Test - public void testInteger() throws ServiceStartException { - Assert.assertEquals(256, config.getTestInteger()); - } - - /** - * Test setter - * - * @throws ServiceStartException - */ - @Test - public void testSetter() throws ServiceStartException { - config.setTestString("new-value"); - Assert.assertEquals("new-value", config.getTestString()); - } - - /** - * Test null setter - * - * @throws ServiceStartException - */ - @Test - public void testNullSetter() throws ServiceStartException { - config.setTestString(null); - Assert.assertEquals("test-default", config.getTestString()); - } - - /** - * The TestConfig interface - * - * @author Rogiel - */ - public interface TestConfig extends Configuration { - /** - * @return an configuration string - */ - @ConfigurationPropertyGetter(defaultValue = "test-default") - @ConfigurationXPath("/configuration/test/testvalue") - String getTestString(); - - /** - * @param value - * any string - */ - @ConfigurationPropertySetter - @ConfigurationXPath("/configuration/test/testvalue") - void setTestString(String value); - - /** - * @return an configuration string - */ - @ConfigurationPropertyGetter(defaultValue = "default") - @ConfigurationXPath("/configuration/test/nonexistentkey") - String getDefaultTestString(); - - /** - * @return an configuration integer - */ - @ConfigurationPropertyGetter(defaultValue = "0") - @ConfigurationXPath("/configuration/test/integer") - int getTestInteger(); - - /** - * @param n - * any integer - */ - @ConfigurationPropertySetter - @ConfigurationXPath("/configuration/test/integer") - void setTestInteger(Integer n); - } -} diff --git a/l2jserver2-gameserver/.gitignore b/l2jserver2-gameserver/.gitignore index b2ea08db6..4c6512dac 100644 --- a/l2jserver2-gameserver/.gitignore +++ b/l2jserver2-gameserver/.gitignore @@ -1,2 +1,3 @@ /log /derby.log +/services.xml diff --git a/l2jserver2-gameserver/config/.gitignore b/l2jserver2-gameserver/config/.gitignore deleted file mode 100644 index 81e4b0b61..000000000 --- a/l2jserver2-gameserver/config/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/config.xml diff --git a/l2jserver2-gameserver/config/config-dev-sample.xml b/l2jserver2-gameserver/config/config-dev-sample.xml deleted file mode 100644 index 67b2188c2..000000000 --- a/l2jserver2-gameserver/config/config-dev-sample.xml +++ /dev/null @@ -1,92 +0,0 @@ - - - - - - - - 1.0 - - 1.0 - - - - - - - - - true - - - - - local:data/database - - admin - - admin - - - - - - jdbc:mysql://localhost/l2jserver2 - - - com.l2jserver.service.database.sql.MySQLDatabaseEngine - - - - l2j - - - changeme - - - - - 20 - - 20 - - 5 - - - - - - - 0.0.0.0:7777 - - - - - - - - - data/ - - - - - - - \ No newline at end of file diff --git a/l2jserver2-gameserver/config/config.xml b/l2jserver2-gameserver/config/config.xml deleted file mode 100644 index 67b2188c2..000000000 --- a/l2jserver2-gameserver/config/config.xml +++ /dev/null @@ -1,92 +0,0 @@ - - - - - - - - 1.0 - - 1.0 - - - - - - - - - true - - - - - local:data/database - - admin - - admin - - - - - - jdbc:mysql://localhost/l2jserver2 - - - com.l2jserver.service.database.sql.MySQLDatabaseEngine - - - - l2j - - - changeme - - - - - 20 - - 20 - - 5 - - - - - - - 0.0.0.0:7777 - - - - - - - - - data/ - - - - - - - \ No newline at end of file diff --git a/l2jserver2-gameserver/distribution/global/LICENSE b/l2jserver2-gameserver/distribution/LICENSE similarity index 100% rename from l2jserver2-gameserver/distribution/global/LICENSE rename to l2jserver2-gameserver/distribution/LICENSE diff --git a/l2jserver2-gameserver/distribution/global/README b/l2jserver2-gameserver/distribution/README similarity index 100% rename from l2jserver2-gameserver/distribution/global/README rename to l2jserver2-gameserver/distribution/README diff --git a/l2jserver2-gameserver/distribution/global/config/config.xml b/l2jserver2-gameserver/distribution/global/config/config.xml deleted file mode 100644 index 04b2721d8..000000000 --- a/l2jserver2-gameserver/distribution/global/config/config.xml +++ /dev/null @@ -1,92 +0,0 @@ - - - - - - - - 1.0 - - 1.0 - - - - - - - - - true - - - - - local:data/database - - admin - - admin - - - - - - jdbc:mysql://localhost/l2jserver2 - - - com.l2jserver.service.database.sql.MySQLDatabaseEngine - - - - l2j - - - changeme - - - - - 20 - - 20 - - 5 - - - - - - - 0.0.0.0:7777 - - - - - - - - - data.zip - - - - - - - \ No newline at end of file diff --git a/l2jserver2-gameserver/distribution/services.xml b/l2jserver2-gameserver/distribution/services.xml new file mode 100644 index 000000000..db8f71a41 --- /dev/null +++ b/l2jserver2-gameserver/distribution/services.xml @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/l2jserver2-gameserver/distribution/global/start.bat b/l2jserver2-gameserver/distribution/start.bat similarity index 100% rename from l2jserver2-gameserver/distribution/global/start.bat rename to l2jserver2-gameserver/distribution/start.bat diff --git a/l2jserver2-gameserver/distribution/global/start.sh b/l2jserver2-gameserver/distribution/start.sh similarity index 100% rename from l2jserver2-gameserver/distribution/global/start.sh rename to l2jserver2-gameserver/distribution/start.sh diff --git a/l2jserver2-gameserver/services-sample.xml b/l2jserver2-gameserver/services-sample.xml new file mode 100644 index 000000000..1da3822fd --- /dev/null +++ b/l2jserver2-gameserver/services-sample.xml @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/l2jserver2-gameserver/src/main/assembly/distribution-derby-bin.xml b/l2jserver2-gameserver/src/main/assembly/distribution-derby-bin.xml index a8f8d6a99..4cab32e7e 100644 --- a/l2jserver2-gameserver/src/main/assembly/distribution-derby-bin.xml +++ b/l2jserver2-gameserver/src/main/assembly/distribution-derby-bin.xml @@ -9,7 +9,7 @@ - ${project.basedir}/distribution/global + ${project.basedir}/distribution / diff --git a/l2jserver2-gameserver/src/main/assembly/distribution-h2-bin.xml b/l2jserver2-gameserver/src/main/assembly/distribution-h2-bin.xml index 0eb55b64f..a288a7f21 100644 --- a/l2jserver2-gameserver/src/main/assembly/distribution-h2-bin.xml +++ b/l2jserver2-gameserver/src/main/assembly/distribution-h2-bin.xml @@ -9,7 +9,7 @@ - ${project.basedir}/distribution/global + ${project.basedir}/distribution / diff --git a/l2jserver2-gameserver/src/main/assembly/distribution-mysql5-bin.xml b/l2jserver2-gameserver/src/main/assembly/distribution-mysql5-bin.xml index 6cd363a96..eb845facf 100644 --- a/l2jserver2-gameserver/src/main/assembly/distribution-mysql5-bin.xml +++ b/l2jserver2-gameserver/src/main/assembly/distribution-mysql5-bin.xml @@ -9,7 +9,7 @@ - ${project.basedir}/distribution/global + ${project.basedir}/distribution / diff --git a/l2jserver2-gameserver/src/main/assembly/distribution-orientdb-bin.xml b/l2jserver2-gameserver/src/main/assembly/distribution-orientdb-bin.xml index 264ab5263..cfec84f04 100644 --- a/l2jserver2-gameserver/src/main/assembly/distribution-orientdb-bin.xml +++ b/l2jserver2-gameserver/src/main/assembly/distribution-orientdb-bin.xml @@ -9,7 +9,7 @@ - ${project.basedir}/distribution/global + ${project.basedir}/distribution / diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/L2JGameServerMain.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/L2JGameServerMain.java index 74bffb275..98b212862 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/L2JGameServerMain.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/L2JGameServerMain.java @@ -16,8 +16,20 @@ */ package com.l2jserver; +import java.io.IOException; +import java.nio.file.Paths; + +import javax.xml.parsers.ParserConfigurationException; + +import org.w3c.dom.DOMException; +import org.xml.sax.SAXException; + +import com.google.inject.Guice; +import com.l2jserver.model.id.provider.IDProviderModule; import com.l2jserver.service.Service; +import com.l2jserver.service.ServiceException; import com.l2jserver.service.ServiceManager; +import com.l2jserver.service.ServiceStartException; import com.l2jserver.service.ServiceStopException; import com.l2jserver.service.cache.CacheService; import com.l2jserver.service.configuration.ConfigurationService; @@ -65,17 +77,38 @@ public class L2JGameServerMain { */ @SuppressWarnings("unchecked") public static void main(String[] args) { - final L2JGameServer server = new L2JGameServer(); + final ServiceManager serviceManager = new ServiceManager(); try { - final ServiceManager serviceManager = server.getInjector() - .getInstance(ServiceManager.class); + serviceManager.load(Paths.get("services.xml")); + } catch (ClassNotFoundException e) { + System.out.println("Service class not found: " + e.getMessage()); + e.printStackTrace(); + return; + } catch (SAXException | DOMException | IOException + | ParserConfigurationException e) { + System.out.println("Error parsing XML service descriptor"); + e.printStackTrace(); + return; + } catch (ServiceException e) { + System.out.println("Error loading XML service descriptor"); + e.printStackTrace(); + return; + } + try { + serviceManager.init(Guice.createInjector(new IDProviderModule(), + serviceManager.newGuiceModule())); + } catch (ServiceStartException e) { + System.out.println("Error stating basic services"); + e.printStackTrace(); + return; + } + try { for (final Class[] category : SERVICES) { for (final Class service : category) { serviceManager.start((Class) service); } } - Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/ServiceModule.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/ServiceModule.java deleted file mode 100644 index 7107d1428..000000000 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/ServiceModule.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * This file is part of l2jserver2 . - * - * l2jserver2 is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * l2jserver2 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with l2jserver2. If not, see . - */ -package com.l2jserver.service; - -import com.google.inject.AbstractModule; -import com.google.inject.Module; -import com.google.inject.Scopes; -import com.l2jserver.service.cache.CacheService; -import com.l2jserver.service.cache.SoftCacheService; -import com.l2jserver.service.configuration.ConfigurationService; -import com.l2jserver.service.configuration.XMLConfigurationService; -import com.l2jserver.service.core.Log4JLoggingService; -import com.l2jserver.service.core.LoggingService; -import com.l2jserver.service.core.threading.ThreadService; -import com.l2jserver.service.core.threading.ThreadServiceImpl; -import com.l2jserver.service.core.vfs.TrueZipVFSService; -import com.l2jserver.service.core.vfs.VFSService; -import com.l2jserver.service.database.DatabaseService; -import com.l2jserver.service.database.GameServerOrientDatabaseService; -import com.l2jserver.service.game.AttackService; -import com.l2jserver.service.game.AttackServiceImpl; -import com.l2jserver.service.game.admin.AdministratorService; -import com.l2jserver.service.game.admin.AdministratorServiceImpl; -import com.l2jserver.service.game.character.CharacterService; -import com.l2jserver.service.game.character.CharacterServiceImpl; -import com.l2jserver.service.game.character.ShortcutService; -import com.l2jserver.service.game.character.ShortcutServiceImpl; -import com.l2jserver.service.game.chat.ChatLoggingService; -import com.l2jserver.service.game.chat.ChatService; -import com.l2jserver.service.game.chat.DatabaseChatLoggingService; -import com.l2jserver.service.game.chat.SimpleChatService; -import com.l2jserver.service.game.item.ItemService; -import com.l2jserver.service.game.item.ItemServiceImpl; -import com.l2jserver.service.game.map.pathing.MapperPathingService; -import com.l2jserver.service.game.map.pathing.PathingService; -import com.l2jserver.service.game.npc.NPCService; -import com.l2jserver.service.game.npc.NPCServiceImpl; -import com.l2jserver.service.game.scripting.ScriptingService; -import com.l2jserver.service.game.scripting.ScriptingServiceImpl; -import com.l2jserver.service.game.spawn.SpawnService; -import com.l2jserver.service.game.spawn.SpawnServiceImpl; -import com.l2jserver.service.game.template.TemplateService; -import com.l2jserver.service.game.template.XMLTemplateService; -import com.l2jserver.service.game.world.CachedWorldIDService; -import com.l2jserver.service.game.world.WorldIDService; -import com.l2jserver.service.game.world.WorldService; -import com.l2jserver.service.game.world.WorldServiceImpl; -import com.l2jserver.service.game.world.event.WorldEventDispatcher; -import com.l2jserver.service.game.world.event.WorldEventDispatcherImpl; -import com.l2jserver.service.network.NettyNetworkService; -import com.l2jserver.service.network.NetworkService; -import com.l2jserver.service.network.broadcast.BroadcastService; -import com.l2jserver.service.network.broadcast.BroadcastServiceImpl; -import com.l2jserver.service.network.gameguard.GameGuardService; -import com.l2jserver.service.network.gameguard.GameGuardServiceImpl; -import com.l2jserver.service.network.keygen.BlowfishKeygenService; -import com.l2jserver.service.network.keygen.SecureBlowfishKeygenService; - -/** - * Google Guice {@link Module} for services - * - * @author Rogiel - */ -public class ServiceModule extends AbstractModule { - @Override - protected void configure() { - bind(ServiceManager.class).in(Scopes.SINGLETON); - bind(LoggingService.class).to(Log4JLoggingService.class).in( - Scopes.SINGLETON); - bind(VFSService.class).to(TrueZipVFSService.class).in(Scopes.SINGLETON); - bind(ThreadService.class).to(ThreadServiceImpl.class).in( - Scopes.SINGLETON); - bind(ConfigurationService.class).to(XMLConfigurationService.class).in( - Scopes.SINGLETON); - bind(CacheService.class).to(SoftCacheService.class) - .in(Scopes.SINGLETON); - - bind(DatabaseService.class).to(GameServerOrientDatabaseService.class) - .in(Scopes.SINGLETON); - bind(WorldIDService.class).to(CachedWorldIDService.class).in( - Scopes.SINGLETON); - - bind(PathingService.class).to(MapperPathingService.class).in( - Scopes.SINGLETON); - - bind(BlowfishKeygenService.class).to(SecureBlowfishKeygenService.class) - .in(Scopes.SINGLETON); - bind(NetworkService.class).to(NettyNetworkService.class).in( - Scopes.SINGLETON); - bind(GameGuardService.class).to(GameGuardServiceImpl.class).in( - Scopes.SINGLETON); - bind(ScriptingService.class).to(ScriptingServiceImpl.class).in( - Scopes.SINGLETON); - bind(TemplateService.class).to(XMLTemplateService.class).in( - Scopes.SINGLETON); - - bind(ChatService.class).to(SimpleChatService.class) - .in(Scopes.SINGLETON); - bind(ChatLoggingService.class).to(DatabaseChatLoggingService.class).in( - Scopes.SINGLETON); - bind(AdministratorService.class).to(AdministratorServiceImpl.class).in( - Scopes.SINGLETON); - bind(SpawnService.class).to(SpawnServiceImpl.class) - .in(Scopes.SINGLETON); - bind(BroadcastService.class).to(BroadcastServiceImpl.class).in( - Scopes.SINGLETON); - - bind(CharacterService.class).to(CharacterServiceImpl.class).in( - Scopes.SINGLETON); - bind(ShortcutService.class).to(ShortcutServiceImpl.class).in( - Scopes.SINGLETON); - - bind(AttackService.class).to(AttackServiceImpl.class).in( - Scopes.SINGLETON); - bind(NPCService.class).to(NPCServiceImpl.class).in(Scopes.SINGLETON); - bind(ItemService.class).to(ItemServiceImpl.class).in(Scopes.SINGLETON); - - bind(WorldService.class).to(WorldServiceImpl.class) - .in(Scopes.SINGLETON); - bind(WorldEventDispatcher.class).to(WorldEventDispatcherImpl.class).in( - Scopes.SINGLETON); - } -} diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/database/GameServerJDBCDatabaseService.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/database/GameServerJDBCDatabaseService.java index 27427c96f..a08308b84 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/database/GameServerJDBCDatabaseService.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/database/GameServerJDBCDatabaseService.java @@ -76,8 +76,6 @@ import com.mysema.query.sql.types.EnumByNameType; public class GameServerJDBCDatabaseService extends AbstractSQLDatabaseService implements DatabaseService { /** - * @param configService - * the config service * @param cacheService * the cache service * @param threadService @@ -88,11 +86,10 @@ public class GameServerJDBCDatabaseService extends AbstractSQLDatabaseService * the {@link DataAccessObject DAO} resolver */ @Inject - public GameServerJDBCDatabaseService(ConfigurationService configService, - CacheService cacheService, ThreadService threadService, - VFSService vfsService, DAOResolver daoResolver) { + public GameServerJDBCDatabaseService(CacheService cacheService, + ThreadService threadService, VFSService vfsService, + DAOResolver daoResolver) { super( - configService, cacheService, threadService, vfsService, @@ -120,7 +117,8 @@ public class GameServerJDBCDatabaseService extends AbstractSQLDatabaseService updateSchema(QLogChat.logChat); if (updateSchema(QNPC.npc)) { try { - importData(vfsService.resolveDataFile("static/npc.csv"), QNPC.npc); + importData(vfsService.resolveDataFile("static/npc.csv"), + QNPC.npc); } catch (IOException e) { throw new DatabaseException(e); } diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/database/GameServerOrientDatabaseService.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/database/GameServerOrientDatabaseService.java index 32f14222a..244ad7038 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/database/GameServerOrientDatabaseService.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/database/GameServerOrientDatabaseService.java @@ -70,8 +70,6 @@ public class GameServerOrientDatabaseService extends private final VFSService vfsService; /** - * @param configService - * the config service * @param cacheService * the cache service * @param threadService @@ -82,10 +80,10 @@ public class GameServerOrientDatabaseService extends * the {@link DataAccessObject DAO} resolver */ @Inject - public GameServerOrientDatabaseService(ConfigurationService configService, - CacheService cacheService, ThreadService threadService, - final VFSService vfsService, DAOResolver daoResolver) { - super(configService, cacheService, threadService, daoResolver); + public GameServerOrientDatabaseService(CacheService cacheService, + ThreadService threadService, final VFSService vfsService, + DAOResolver daoResolver) { + super(cacheService, threadService, daoResolver); this.vfsService = vfsService; } @@ -100,7 +98,8 @@ public class GameServerOrientDatabaseService extends updateSchema(QLogChat.logChat); if (updateSchema(QNPC.npc)) { try { - importData(vfsService.resolveDataFile("static/npc.csv"), QNPC.npc); + importData(vfsService.resolveDataFile("static/npc.csv"), + QNPC.npc); } catch (IOException e) { throw new DatabaseException(e); } diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/template/XMLTemplateService.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/template/XMLTemplateService.java index d6f8ce41e..192925e74 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/template/XMLTemplateService.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/template/XMLTemplateService.java @@ -47,14 +47,13 @@ import com.l2jserver.model.template.character.CharacterTemplate; import com.l2jserver.model.template.item.ItemTemplate; import com.l2jserver.model.template.npc.NPCTemplate; import com.l2jserver.model.template.npc.TeleportationTemplate; -import com.l2jserver.service.AbstractService; +import com.l2jserver.service.AbstractConfigurableService; import com.l2jserver.service.AbstractService.Depends; import com.l2jserver.service.ServiceStartException; import com.l2jserver.service.ServiceStopException; import com.l2jserver.service.cache.Cache; import com.l2jserver.service.cache.CacheService; import com.l2jserver.service.configuration.ConfigurationService; -import com.l2jserver.service.configuration.XMLConfigurationService.ConfigurationXPath; import com.l2jserver.service.core.LoggingService; import com.l2jserver.service.core.vfs.VFSService; import com.l2jserver.util.jaxb.CharacterTemplateIDAdapter; @@ -72,7 +71,8 @@ import com.l2jserver.util.jaxb.TeleportationTemplateIDAdapter; */ @Depends({ LoggingService.class, VFSService.class, CacheService.class, ConfigurationService.class }) -public class XMLTemplateService extends AbstractService implements +public class XMLTemplateService extends + AbstractConfigurableService implements TemplateService { /** * The logger @@ -88,10 +88,6 @@ public class XMLTemplateService extends AbstractService implements */ private final CacheService cacheService; - /** - * The XML template service configuration - */ - private final XMLTemplateServiceConfiguration config; /** * The npc template id adapter */ @@ -132,36 +128,11 @@ public class XMLTemplateService extends AbstractService implements @SuppressWarnings("rawtypes") private Cache templates; - /** - * XML {@link TemplateService} configuration interface - * - * @author Rogiel - */ - public interface XMLTemplateServiceConfiguration extends - TemplateServiceConfiguration { - /** - * @return the directory in which templates are stored - */ - @ConfigurationPropertyGetter(defaultValue = "template/") - @ConfigurationXPath("/configuration/services/template/directory") - String getTemplateDirectory(); - - /** - * @param file - * the directory in which templates are stored - */ - @ConfigurationPropertySetter - @ConfigurationXPath("/configuration/services/template/directory") - void setTemplateDirectory(String file); - } - /** * @param vfsService * the vfs service * @param cacheService - * the cache service - * @param configService - * the configuration service + * the cache servicef * @param npcTemplateIdAdapter * the npc template id adapter * @param itemTemplateIdAdapter @@ -177,16 +148,16 @@ public class XMLTemplateService extends AbstractService implements */ @Inject public XMLTemplateService(final VFSService vfsService, - CacheService cacheService, ConfigurationService configService, + CacheService cacheService, NPCTemplateIDAdapter npcTemplateIdAdapter, ItemTemplateIDAdapter itemTemplateIdAdapter, SkillTemplateIDAdapter skillTemplateIdAdapter, CharacterTemplateIDAdapter charIdTemplateAdapter, EffectTemplateIDAdapter effectIdTemplateAdapter, TeleportationTemplateIDAdapter teleportationIdTemplateAdapter) { + super(XMLTemplateServiceConfiguration.class); this.vfsService = vfsService; this.cacheService = cacheService; - this.config = configService.get(XMLTemplateServiceConfiguration.class); this.npcTemplateIdAdapter = npcTemplateIdAdapter; this.itemTemplateIdAdapter = itemTemplateIdAdapter; this.skillTemplateIdAdapter = skillTemplateIdAdapter; diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/template/XMLTemplateServiceConfiguration.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/template/XMLTemplateServiceConfiguration.java new file mode 100644 index 000000000..0a9c82d11 --- /dev/null +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/template/XMLTemplateServiceConfiguration.java @@ -0,0 +1,43 @@ +/* + * This file is part of l2jserver2 . + * + * l2jserver2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * l2jserver2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with l2jserver2. If not, see . + */ +package com.l2jserver.service.game.template; + +import com.l2jserver.service.configuration.XMLConfigurationService.ConfigurationXPath; +import com.l2jserver.service.game.template.TemplateService.TemplateServiceConfiguration; + +/** + * XML {@link TemplateService} configuration interface + * + * @author Rogiel + */ +public interface XMLTemplateServiceConfiguration extends + TemplateServiceConfiguration { + /** + * @return the directory in which templates are stored + */ + @ConfigurationPropertyGetter(defaultValue = "template/") + @ConfigurationXPath("templates/@root") + String getTemplateDirectory(); + + /** + * @param file + * the directory in which templates are stored + */ + @ConfigurationPropertySetter + @ConfigurationXPath("templates/@root") + void setTemplateDirectory(String file); +} \ No newline at end of file diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/network/NettyNetworkService.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/network/NettyNetworkService.java index 140443f55..d0198e2de 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/network/NettyNetworkService.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/network/NettyNetworkService.java @@ -39,9 +39,8 @@ import com.l2jserver.game.net.Lineage2Client; import com.l2jserver.game.net.Lineage2PipelineFactory; import com.l2jserver.game.net.packet.ServerPacket; import com.l2jserver.model.id.object.CharacterID; -import com.l2jserver.service.AbstractService; +import com.l2jserver.service.AbstractConfigurableService; import com.l2jserver.service.AbstractService.Depends; -import com.l2jserver.service.configuration.ConfigurationService; import com.l2jserver.service.core.LoggingService; import com.l2jserver.service.core.threading.ThreadPool; import com.l2jserver.service.core.threading.ThreadPoolPriority; @@ -58,7 +57,8 @@ import com.l2jserver.util.factory.CollectionFactory; */ @Depends({ LoggingService.class, ThreadService.class, BlowfishKeygenService.class, WorldService.class }) -public class NettyNetworkService extends AbstractService implements +public class NettyNetworkService extends + AbstractConfigurableService implements NetworkService { /** * The logger @@ -70,10 +70,6 @@ public class NettyNetworkService extends AbstractService implements */ private final ThreadService threadService; - /** - * The network configuration object - */ - private final NetworkConfiguration config; /** * The Google Guice {@link Injector} */ @@ -101,18 +97,15 @@ public class NettyNetworkService extends AbstractService implements private Set clients = CollectionFactory.newSet(); /** - * @param configService - * the configuration service * @param injector * the {@link Guice} {@link Injector} * @param threadService * the {@link ThreadService} */ @Inject - public NettyNetworkService(ConfigurationService configService, - Injector injector, ThreadService threadService) { + public NettyNetworkService(Injector injector, ThreadService threadService) { + super(NetworkServiceConfiguration.class); this.threadService = threadService; - this.config = configService.get(NetworkConfiguration.class); this.injector = injector; InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory()); } diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/network/NetworkService.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/network/NetworkService.java index d2db0ecc2..a50f4f113 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/network/NetworkService.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/network/NetworkService.java @@ -16,7 +16,6 @@ */ package com.l2jserver.service.network; -import java.net.InetSocketAddress; import com.l2jserver.game.net.Lineage2Client; import com.l2jserver.game.net.Lineage2Session; @@ -25,9 +24,6 @@ import com.l2jserver.game.net.packet.ServerPacket; import com.l2jserver.model.id.object.CharacterID; import com.l2jserver.model.world.L2Character; import com.l2jserver.service.Service; -import com.l2jserver.service.ServiceConfiguration; -import com.l2jserver.service.configuration.Configuration; -import com.l2jserver.service.configuration.XMLConfigurationService.ConfigurationXPath; /** * The network service is responsible for communicating the server with the game @@ -66,32 +62,6 @@ import com.l2jserver.service.configuration.XMLConfigurationService.Configuration * @author Rogiel */ public interface NetworkService extends Service { - /** - * The network {@link Configuration} - * - * @author Rogiel - */ - public interface NetworkConfiguration extends ServiceConfiguration { - /** - * Get the server listen address - * - * @return the listen address - */ - @ConfigurationPropertyGetter(defaultValue = "0.0.0.0:7777") - @ConfigurationXPath("/configuration/services/network/listen") - InetSocketAddress getListenAddress(); - - /** - * Set the server listen address - * - * @param addr - * the listen address - */ - @ConfigurationPropertySetter - @ConfigurationXPath("/configuration/services/network/listen") - void setListenAddress(InetSocketAddress addr); - } - /** * Registers a new client * diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/network/NetworkServiceConfiguration.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/network/NetworkServiceConfiguration.java new file mode 100644 index 000000000..b7ebbc715 --- /dev/null +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/network/NetworkServiceConfiguration.java @@ -0,0 +1,49 @@ +/* + * This file is part of l2jserver2 . + * + * l2jserver2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * l2jserver2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with l2jserver2. If not, see . + */ +package com.l2jserver.service.network; + +import java.net.InetSocketAddress; + +import com.l2jserver.service.ServiceConfiguration; +import com.l2jserver.service.configuration.Configuration; +import com.l2jserver.service.configuration.XMLConfigurationService.ConfigurationXPath; + +/** + * The network {@link Configuration} + * + * @author Rogiel + */ +public interface NetworkServiceConfiguration extends ServiceConfiguration { + /** + * Get the server listen address + * + * @return the listen address + */ + @ConfigurationPropertyGetter(defaultValue = "0.0.0.0:7777") + @ConfigurationXPath("server/@listen") + InetSocketAddress getListenAddress(); + + /** + * Set the server listen address + * + * @param addr + * the listen address + */ + @ConfigurationPropertySetter + @ConfigurationXPath("server/@listen") + void setListenAddress(InetSocketAddress addr); +} \ No newline at end of file diff --git a/l2jserver2-gameserver/src/test/java/com/l2jserver/db/dao/mysql5/MySQL5CharacterDAOTest.java b/l2jserver2-gameserver/src/test/java/com/l2jserver/db/dao/mysql5/MySQL5CharacterDAOTest.java index a7cfcbd30..e3e658a4f 100644 --- a/l2jserver2-gameserver/src/test/java/com/l2jserver/db/dao/mysql5/MySQL5CharacterDAOTest.java +++ b/l2jserver2-gameserver/src/test/java/com/l2jserver/db/dao/mysql5/MySQL5CharacterDAOTest.java @@ -23,7 +23,6 @@ import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.Stage; -import com.l2jserver.GameServerModule; import com.l2jserver.model.dao.CharacterDAO; import com.l2jserver.model.id.object.provider.CharacterIDProvider; import com.l2jserver.model.world.L2Character; @@ -47,7 +46,7 @@ public class MySQL5CharacterDAOTest { * The {@link Guice} {@link Injector} */ private final Injector injector = Guice.createInjector(Stage.PRODUCTION, - new GameServerModule(), new AbstractModule() { + new AbstractModule() { @Override protected void configure() { bind(CharacterMapper.class); diff --git a/l2jserver2-gameserver/src/test/java/com/l2jserver/model/id/provider/CharacterIDProviderTest.java b/l2jserver2-gameserver/src/test/java/com/l2jserver/model/id/provider/CharacterIDProviderTest.java index 061dd6433..2bddba19a 100644 --- a/l2jserver2-gameserver/src/test/java/com/l2jserver/model/id/provider/CharacterIDProviderTest.java +++ b/l2jserver2-gameserver/src/test/java/com/l2jserver/model/id/provider/CharacterIDProviderTest.java @@ -28,7 +28,6 @@ import com.l2jserver.model.id.object.CharacterID; import com.l2jserver.model.id.object.provider.CharacterIDProvider; import com.l2jserver.model.world.L2Character; import com.l2jserver.service.ServiceManager; -import com.l2jserver.service.ServiceModule; import com.l2jserver.service.ServiceStartException; import com.l2jserver.service.database.DatabaseService; import com.l2jserver.service.database.JDBCDAOModule; @@ -44,8 +43,8 @@ public class CharacterIDProviderTest { /** * The {@link Guice} {@link Injector} */ - private final Injector injector = Guice.createInjector(new ServiceModule(), - new JDBCDAOModule(), new IDProviderModule()); + private final Injector injector = Guice.createInjector(new JDBCDAOModule(), + new IDProviderModule()); /** * The character id provider */ @@ -53,6 +52,7 @@ public class CharacterIDProviderTest { /** * Prepares the test + * * @throws ServiceStartException */ @Before @@ -86,6 +86,7 @@ public class CharacterIDProviderTest { /** * Tests DAO aware ids + * * @throws ServiceStartException */ @Test diff --git a/l2jserver2-gameserver/src/test/java/com/l2jserver/service/world/WorldEventDispatcherImplTest.java b/l2jserver2-gameserver/src/test/java/com/l2jserver/service/world/WorldEventDispatcherImplTest.java index 95967a61c..dc75934c9 100644 --- a/l2jserver2-gameserver/src/test/java/com/l2jserver/service/world/WorldEventDispatcherImplTest.java +++ b/l2jserver2-gameserver/src/test/java/com/l2jserver/service/world/WorldEventDispatcherImplTest.java @@ -25,9 +25,9 @@ import org.junit.Test; import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.Stage; -import com.l2jserver.GameServerModule; import com.l2jserver.model.id.object.provider.CharacterIDProvider; import com.l2jserver.model.id.object.provider.ItemIDProvider; +import com.l2jserver.model.id.provider.IDProviderModule; import com.l2jserver.model.world.Item; import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.item.ItemDropEvent; @@ -74,7 +74,7 @@ public class WorldEventDispatcherImplTest { @Before public void tearUp() throws ServiceStartException { Injector injector = Guice.createInjector(Stage.PRODUCTION, - new GameServerModule()); + new IDProviderModule()); injector.getInstance(ServiceManager.class).start(WorldIDService.class); diff --git a/l2jserver2-gameserver/src/test/java/com/l2jserver/service/world/WorldServiceImplTest.java b/l2jserver2-gameserver/src/test/java/com/l2jserver/service/world/WorldServiceImplTest.java index d7251318c..6a87bf876 100644 --- a/l2jserver2-gameserver/src/test/java/com/l2jserver/service/world/WorldServiceImplTest.java +++ b/l2jserver2-gameserver/src/test/java/com/l2jserver/service/world/WorldServiceImplTest.java @@ -23,8 +23,8 @@ import org.junit.Test; import com.google.inject.Guice; import com.google.inject.Injector; -import com.l2jserver.GameServerModule; import com.l2jserver.model.id.object.provider.CharacterIDProvider; +import com.l2jserver.model.id.provider.IDProviderModule; import com.l2jserver.model.world.Item; import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.WorldObject; @@ -36,6 +36,7 @@ import com.l2jserver.service.game.world.filter.impl.InstanceFilter; /** * Tests for {@link WorldServiceImpl} + * * @author Rogiel */ public class WorldServiceImplTest { @@ -50,11 +51,12 @@ public class WorldServiceImplTest { /** * Preparation for tests + * * @throws ServiceStartException */ @Before public void tearUp() throws ServiceStartException { - Injector injector = Guice.createInjector(new GameServerModule()); + Injector injector = Guice.createInjector(new IDProviderModule()); world = injector.getInstance(ServiceManager.class).start( WorldService.class); diff --git a/l2jserver2-loginserver/src/main/java/com/l2jserver/service/database/LoginServerSQLDatabaseService.java b/l2jserver2-loginserver/src/main/java/com/l2jserver/service/database/LoginServerSQLDatabaseService.java index c33862427..18703078f 100644 --- a/l2jserver2-loginserver/src/main/java/com/l2jserver/service/database/LoginServerSQLDatabaseService.java +++ b/l2jserver2-loginserver/src/main/java/com/l2jserver/service/database/LoginServerSQLDatabaseService.java @@ -53,8 +53,6 @@ import com.l2jserver.service.database.sql.AbstractSQLDatabaseService; public class LoginServerSQLDatabaseService extends AbstractSQLDatabaseService implements DatabaseService { /** - * @param configService - * the config service * @param cacheService * the cache service * @param threadService @@ -64,11 +62,10 @@ public class LoginServerSQLDatabaseService extends AbstractSQLDatabaseService * @param daoResolver * the {@link DataAccessObject DAO} resolver */ - public LoginServerSQLDatabaseService(ConfigurationService configService, - CacheService cacheService, ThreadService threadService, - VFSService vfsService, DAOResolver daoResolver) { - super(configService, cacheService, threadService, vfsService, - daoResolver); + public LoginServerSQLDatabaseService(CacheService cacheService, + ThreadService threadService, VFSService vfsService, + DAOResolver daoResolver) { + super(cacheService, threadService, vfsService, daoResolver); } @Override diff --git a/l2jserver2-loginserver/src/main/java/com/l2jserver/service/gameserver/GameServerNetworkService.java b/l2jserver2-loginserver/src/main/java/com/l2jserver/service/gameserver/GameServerNetworkService.java index 1c0c044a8..e5014eae4 100644 --- a/l2jserver2-loginserver/src/main/java/com/l2jserver/service/gameserver/GameServerNetworkService.java +++ b/l2jserver2-loginserver/src/main/java/com/l2jserver/service/gameserver/GameServerNetworkService.java @@ -16,12 +16,8 @@ */ package com.l2jserver.service.gameserver; -import java.net.InetSocketAddress; import com.l2jserver.service.Service; -import com.l2jserver.service.ServiceConfiguration; -import com.l2jserver.service.configuration.Configuration; -import com.l2jserver.service.configuration.XMLConfigurationService.ConfigurationXPath; /** * TODO @@ -29,29 +25,4 @@ import com.l2jserver.service.configuration.XMLConfigurationService.Configuration * @author Rogiel */ public interface GameServerNetworkService extends Service { - /** - * The network {@link Configuration} - * - * @author Rogiel - */ - public interface NetworkConfiguration extends ServiceConfiguration { - /** - * Get the server listen address - * - * @return the listen address - */ - @ConfigurationPropertyGetter(defaultValue = "0.0.0.0:2104") - @ConfigurationXPath("/configuration/services/network/listen") - InetSocketAddress getListenAddress(); - - /** - * Set the server listen address - * - * @param addr - * the listen address - */ - @ConfigurationPropertySetter - @ConfigurationXPath("/configuration/services/network/listen") - void setListenAddress(InetSocketAddress addr); - } } diff --git a/l2jserver2-loginserver/src/main/java/com/l2jserver/service/gameserver/NetworkConfiguration.java b/l2jserver2-loginserver/src/main/java/com/l2jserver/service/gameserver/NetworkConfiguration.java new file mode 100644 index 000000000..17df945d0 --- /dev/null +++ b/l2jserver2-loginserver/src/main/java/com/l2jserver/service/gameserver/NetworkConfiguration.java @@ -0,0 +1,51 @@ +/* + * This file is part of l2jserver2 . + * + * l2jserver2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * l2jserver2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with l2jserver2. If not, see . + */ +package com.l2jserver.service.gameserver; + +import java.net.InetSocketAddress; + +import com.l2jserver.service.ServiceConfiguration; +import com.l2jserver.service.configuration.Configuration; +import com.l2jserver.service.configuration.Configuration.ConfigurationPropertyGetter; +import com.l2jserver.service.configuration.Configuration.ConfigurationPropertySetter; +import com.l2jserver.service.configuration.XMLConfigurationService.ConfigurationXPath; + +/** + * The network {@link Configuration} + * + * @author Rogiel + */ +public interface NetworkConfiguration extends ServiceConfiguration { + /** + * Get the server listen address + * + * @return the listen address + */ + @ConfigurationPropertyGetter(defaultValue = "0.0.0.0:2104") + @ConfigurationXPath("/configuration/services/network/listen") + InetSocketAddress getListenAddress(); + + /** + * Set the server listen address + * + * @param addr + * the listen address + */ + @ConfigurationPropertySetter + @ConfigurationXPath("/configuration/services/network/listen") + void setListenAddress(InetSocketAddress addr); +} \ No newline at end of file