diff --git a/.classpath b/.classpath index c87a51abc..0dd58a7ee 100644 --- a/.classpath +++ b/.classpath @@ -7,7 +7,7 @@ - + diff --git a/.settings/org.hibernate.eclipse.console.prefs b/.settings/org.hibernate.eclipse.console.prefs new file mode 100644 index 000000000..befbed85b --- /dev/null +++ b/.settings/org.hibernate.eclipse.console.prefs @@ -0,0 +1,4 @@ +#Fri May 13 16:44:30 BRT 2011 +default.configuration= +eclipse.preferences.version=1 +hibernate3.enabled=false diff --git a/ data/plugin/plugin/DisabledPlugin.java b/data/plugin/plugin/DisabledPlugin.java similarity index 100% rename from data/plugin/plugin/DisabledPlugin.java rename to data/plugin/plugin/DisabledPlugin.java diff --git a/ data/plugin/plugin/PluginLoader.java b/data/plugin/plugin/PluginLoader.java similarity index 74% rename from data/plugin/plugin/PluginLoader.java rename to data/plugin/plugin/PluginLoader.java index 11a62dd5d..389d54da6 100644 --- a/ data/plugin/plugin/PluginLoader.java +++ b/data/plugin/plugin/PluginLoader.java @@ -10,6 +10,8 @@ import com.google.inject.Inject; import com.l2jserver.model.template.Template; import com.l2jserver.service.game.scripting.classlistener.Loader; import com.l2jserver.service.game.scripting.classlistener.Unloader; +import com.l2jserver.service.game.template.StaticTemplateService; +import com.l2jserver.service.game.template.TemplateService; import com.l2jserver.util.ClassUtils; import com.l2jserver.util.factory.CollectionFactory; @@ -24,25 +26,27 @@ public class PluginLoader implements Loader, Unloader { private static final Logger log = LoggerFactory .getLogger(PluginLoader.class); + private final StaticTemplateService templateService; + @Inject - public PluginLoader() { - + public PluginLoader(TemplateService templateService) { + this.templateService = (StaticTemplateService) templateService; } @Override public void load(Class[] classes) { - log.debug("Loading plugins from {} classes", classes.length); + log.debug("Loading templates from {} classes", classes.length); for (final Class> template : getSuitableClasses(classes)) { - log.debug("Found loadable plugin class: {}", template); - //templateService.addTemplate(template); + log.debug("Found loadable template class: {}", template); + templateService.addTemplate(template); } } @Override public void unload(Class[] classes) { - log.debug("Unloading plugins from {} classes", classes.length); + log.debug("Unloading templates from {} classes", classes.length); for (final Class> template : getSuitableClasses(classes)) { - log.debug("Found unloadable plugin class: {}", template); + log.debug("Found unloadable template class: {}", template); // TODO unloading } } diff --git a/pom.xml b/pom.xml index 94db3bdd4..5b9ca3766 100644 --- a/pom.xml +++ b/pom.xml @@ -4,18 +4,151 @@ com.l2jserver l2jserver2-gameserver 2.0.0-DEVEL - L2JServer - Game Server Module + L2JServer - Game Server Lineage II server emulator + 2011 - com.l2jserver - l2jserver2-core - 2.0.0-DEVEL + junit + junit + 4.8.2 + jar + compile + + + org.jboss.netty + netty + 3.2.4.Final + compile + + + com.google.inject + guice + 3.0 + jar + compile + + + com.google.inject.extensions + guice-assistedinject + 3.0 + jar + compile + + + org.slf4j + slf4j-log4j12 + 1.6.1 + jar + compile + + + mysql + mysql-connector-java + 5.1.16 + jar + compile + + + javacc + javacc + 4.1 + jar + compile + + + org.apache.commons + commons-io + 1.3.2 + jar + compile + + + com.kenai.nbpwr + org-apache-commons-dbcp + 1.2.2-201002241055 + nbm compile + + GitHub + https://github.com/Rogiel/l2jserver2-gs/issues + + + GitHub + https://github.com/Rogiel/l2jserver2-gs/wiki + + + + rogiel + Rogiel + rogiel@rogiel.com + http://www.rogiel.com + GMT - 3 + + Creator + API Designer + + + + + + + git://github.com/Rogiel/l2jserver2-gs.git + ssh://git@github.com:Rogiel/l2jserver2-gs.git + master + https://github.com/Rogiel/l2jserver2-gs + + + package + + + org.apache.maven.plugins + maven-jar-plugin + 2.3.1 + + + jar + package + + jar + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.1.2 + + + default + package + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.7 + + + default + package + + jar + + + + + + repository.jboss.org diff --git a/src/main/java/com/l2jserver/GameServerModule.java b/src/main/java/com/l2jserver/GameServerModule.java index 7bfbb0f6f..6325c44b7 100644 --- a/src/main/java/com/l2jserver/GameServerModule.java +++ b/src/main/java/com/l2jserver/GameServerModule.java @@ -4,13 +4,11 @@ import com.google.inject.AbstractModule; import com.l2jserver.db.dao.DAOModuleMySQL5; import com.l2jserver.model.id.factory.IDFactoryModule; import com.l2jserver.routines.GameServerInitializationRoutine; -import com.l2jserver.service.BasicServiceModule; import com.l2jserver.service.ServiceModule; public class GameServerModule extends AbstractModule { @Override protected void configure() { - install(new BasicServiceModule()); install(new ServiceModule()); install(new IDFactoryModule()); install(new DAOModuleMySQL5()); diff --git a/src/main/java/com/l2jserver/routines/Routine.java b/src/main/java/com/l2jserver/routines/Routine.java new file mode 100644 index 000000000..ee66b9b80 --- /dev/null +++ b/src/main/java/com/l2jserver/routines/Routine.java @@ -0,0 +1,6 @@ +package com.l2jserver.routines; + +import java.util.concurrent.Callable; + +public interface Routine extends Callable { +} diff --git a/src/main/java/com/l2jserver/service/AbstractService.java b/src/main/java/com/l2jserver/service/AbstractService.java new file mode 100644 index 000000000..f47ac1752 --- /dev/null +++ b/src/main/java/com/l2jserver/service/AbstractService.java @@ -0,0 +1,17 @@ +package com.l2jserver.service; + +public class AbstractService implements Service { + @Override + public void start() throws ServiceStartException { + } + + @Override + public void stop() throws ServiceStopException { + } + + @Override + public void restart() throws ServiceException { + this.stop(); + this.start(); + } +} diff --git a/src/main/java/com/l2jserver/service/Service.java b/src/main/java/com/l2jserver/service/Service.java new file mode 100644 index 000000000..115bcd4b8 --- /dev/null +++ b/src/main/java/com/l2jserver/service/Service.java @@ -0,0 +1,27 @@ +package com.l2jserver.service; + +public interface Service { + /** + * Start this service + * + * @throws ServiceStartException + * if an error occurred + */ + void start() throws ServiceStartException; + + /** + * Stop this service + * + * @throws ServiceStopException + * if an error occurred + */ + void stop() throws ServiceStopException; + + /** + * Stop this service + * + * @throws ServiceException + * if an error occurred + */ + void restart() throws ServiceException; +} diff --git a/src/main/java/com/l2jserver/service/ServiceException.java b/src/main/java/com/l2jserver/service/ServiceException.java new file mode 100644 index 000000000..cd4ca7c39 --- /dev/null +++ b/src/main/java/com/l2jserver/service/ServiceException.java @@ -0,0 +1,21 @@ +package com.l2jserver.service; + +public class ServiceException extends Exception { + private static final long serialVersionUID = 1L; + + public ServiceException() { + super(); + } + + public ServiceException(String message, Throwable cause) { + super(message, cause); + } + + public ServiceException(String message) { + super(message); + } + + public ServiceException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/com/l2jserver/service/ServiceManager.java b/src/main/java/com/l2jserver/service/ServiceManager.java new file mode 100644 index 000000000..fac8dcb96 --- /dev/null +++ b/src/main/java/com/l2jserver/service/ServiceManager.java @@ -0,0 +1,93 @@ +package com.l2jserver.service; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.inject.Inject; +import com.google.inject.Injector; +import com.l2jserver.service.logging.LoggingService; + +public class ServiceManager { + /** + * The logger + */ + private final Logger logger; + /** + * The Guice Injector + */ + private final Injector injector; + + @Inject + public ServiceManager(Injector injector) { + this.injector = injector; + final LoggingService service = injector + .getInstance(LoggingService.class); + try { + service.start(); + } catch (ServiceStartException e) { + throw new RuntimeException(e); + } + logger = LoggerFactory.getLogger(ServiceManager.class); + } + + public T start(Class serviceClass) + throws ServiceStartException { + final T service = injector.getInstance(serviceClass); + if (service == null) + return null; + try { + logger.info("{}: Starting service...", + serviceClass.getCanonicalName()); + service.start(); + logger.info("{}: Service started!", + serviceClass.getCanonicalName()); + return service; + } catch (ServiceStartException e) { + logger.error("{}: Error starting service: {}", + serviceClass.getCanonicalName(), e.getCause()); + throw e; + } + } + + public void stop(Class serviceClass) + throws ServiceStopException { + final Service service = injector.getInstance(serviceClass); + if (service == null) + return; + try { + logger.info("{0}: Stopping service...", + serviceClass.getCanonicalName()); + service.stop(); + logger.info("{0}: Service stopped!", + serviceClass.getCanonicalName()); + } catch (ServiceStopException e) { + logger.error("{0}: Error stopping service: {1}", + serviceClass.getCanonicalName(), e.getCause()); + throw e; + } + } + + public T restart(Class serviceClass) + throws ServiceStartException, ServiceStopException { + final T service = injector.getInstance(serviceClass); + if (service == null) + return null; + try { + logger.info("{0}: Restaring service...", + serviceClass.getCanonicalName()); + service.stop(); + service.start(); + logger.info("{0}: Service restarted!", + serviceClass.getCanonicalName()); + return service; + } catch (ServiceStartException e) { + logger.error("{0}: Error starting service: {1}", + serviceClass.getCanonicalName(), e.getCause()); + throw e; + } catch (ServiceStopException e) { + logger.error("{0}: Error stopping service: {1}", + serviceClass.getCanonicalName(), e.getCause()); + throw e; + } + } +} diff --git a/src/main/java/com/l2jserver/service/ServiceModule.java b/src/main/java/com/l2jserver/service/ServiceModule.java index 988c85dc1..bde84b50b 100644 --- a/src/main/java/com/l2jserver/service/ServiceModule.java +++ b/src/main/java/com/l2jserver/service/ServiceModule.java @@ -2,6 +2,10 @@ package com.l2jserver.service; import com.google.inject.AbstractModule; import com.google.inject.Scopes; +import com.l2jserver.service.configuration.ConfigurationService; +import com.l2jserver.service.configuration.ProxyConfigurationService; +import com.l2jserver.service.database.DatabaseService; +import com.l2jserver.service.database.MySQLDatabaseService; import com.l2jserver.service.game.scripting.ScriptingService; import com.l2jserver.service.game.scripting.ScriptingServiceImpl; import com.l2jserver.service.game.template.StaticTemplateService; @@ -10,12 +14,22 @@ 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.logging.Log4JLoggingService; +import com.l2jserver.service.logging.LoggingService; import com.l2jserver.service.network.NettyNetworkService; import com.l2jserver.service.network.NetworkService; 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(ConfigurationService.class).to(ProxyConfigurationService.class) + .in(Scopes.SINGLETON); + bind(DatabaseService.class).to(MySQLDatabaseService.class).in( + Scopes.SINGLETON); + bind(NetworkService.class).to(NettyNetworkService.class).in( Scopes.SINGLETON); bind(ScriptingService.class).to(ScriptingServiceImpl.class).in( diff --git a/src/main/java/com/l2jserver/service/ServiceRestartException.java b/src/main/java/com/l2jserver/service/ServiceRestartException.java new file mode 100644 index 000000000..68d0bf8c1 --- /dev/null +++ b/src/main/java/com/l2jserver/service/ServiceRestartException.java @@ -0,0 +1,21 @@ +package com.l2jserver.service; + +public class ServiceRestartException extends ServiceException { + private static final long serialVersionUID = 1L; + + public ServiceRestartException() { + super(); + } + + public ServiceRestartException(String message, Throwable cause) { + super(message, cause); + } + + public ServiceRestartException(String message) { + super(message); + } + + public ServiceRestartException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/com/l2jserver/service/ServiceStartException.java b/src/main/java/com/l2jserver/service/ServiceStartException.java new file mode 100644 index 000000000..9ff9cd53a --- /dev/null +++ b/src/main/java/com/l2jserver/service/ServiceStartException.java @@ -0,0 +1,21 @@ +package com.l2jserver.service; + +public class ServiceStartException extends ServiceException { + private static final long serialVersionUID = 1L; + + public ServiceStartException() { + super(); + } + + public ServiceStartException(String message, Throwable cause) { + super(message, cause); + } + + public ServiceStartException(String message) { + super(message); + } + + public ServiceStartException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/com/l2jserver/service/ServiceStopException.java b/src/main/java/com/l2jserver/service/ServiceStopException.java new file mode 100644 index 000000000..df856da15 --- /dev/null +++ b/src/main/java/com/l2jserver/service/ServiceStopException.java @@ -0,0 +1,21 @@ +package com.l2jserver.service; + +public class ServiceStopException extends ServiceException { + private static final long serialVersionUID = 1L; + + public ServiceStopException() { + super(); + } + + public ServiceStopException(String message, Throwable cause) { + super(message, cause); + } + + public ServiceStopException(String message) { + super(message); + } + + public ServiceStopException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/com/l2jserver/service/configuration/Configuration.java b/src/main/java/com/l2jserver/service/configuration/Configuration.java new file mode 100644 index 000000000..7b0213d20 --- /dev/null +++ b/src/main/java/com/l2jserver/service/configuration/Configuration.java @@ -0,0 +1,29 @@ +package com.l2jserver.service.configuration; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +public interface Configuration { + @Retention(RetentionPolicy.RUNTIME) + @Documented + @Target(value = ElementType.TYPE) + public @interface ConfigurationName { + String value(); + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(value = ElementType.METHOD) + public @interface ConfigurationPropertyGetter { + String name(); + String defaultValue() default ""; + } + + @Retention(RetentionPolicy.RUNTIME) + @Target(value = ElementType.METHOD) + public @interface ConfigurationPropertySetter { + String name(); + } +} diff --git a/src/main/java/com/l2jserver/service/configuration/ConfigurationService.java b/src/main/java/com/l2jserver/service/configuration/ConfigurationService.java new file mode 100644 index 000000000..be9e9241d --- /dev/null +++ b/src/main/java/com/l2jserver/service/configuration/ConfigurationService.java @@ -0,0 +1,7 @@ +package com.l2jserver.service.configuration; + +import com.l2jserver.service.Service; + +public interface ConfigurationService extends Service { + C get(Class config); +} diff --git a/src/main/java/com/l2jserver/service/configuration/ProxyConfigurationService.java b/src/main/java/com/l2jserver/service/configuration/ProxyConfigurationService.java new file mode 100644 index 000000000..4baa6bb4e --- /dev/null +++ b/src/main/java/com/l2jserver/service/configuration/ProxyConfigurationService.java @@ -0,0 +1,185 @@ +package com.l2jserver.service.configuration; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.Map; +import java.util.Properties; +import java.util.WeakHashMap; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.l2jserver.service.AbstractService; +import com.l2jserver.service.ServiceStartException; +import com.l2jserver.service.configuration.Configuration.ConfigurationName; +import com.l2jserver.service.configuration.Configuration.ConfigurationPropertyGetter; +import com.l2jserver.service.configuration.Configuration.ConfigurationPropertySetter; +import com.l2jserver.util.transformer.Transformer; +import com.l2jserver.util.transformer.TransformerFactory; + +public class ProxyConfigurationService extends AbstractService implements + ConfigurationService { + private File directory = new File("./config"); + private final Logger logger = LoggerFactory + .getLogger(ProxyConfigurationService.class); + + private Map, Object> cache = new WeakHashMap, Object>(); + + @Override + public void start() throws ServiceStartException { + if (!directory.exists()) + directory.mkdirs(); + } + + @Override + @SuppressWarnings("unchecked") + public C get(Class config) { + if (cache.containsKey(config)) + return (C) cache.get(config); + logger.info("Trying to create {} proxy", config); + Properties properties; + try { + properties = findProperties(config); + } catch (IOException e) { + properties = new Properties(); + logger.info( + "Configuration file for {} not found, falling back to default values", + config); + } + C proxy = (C) Proxy.newProxyInstance(this.getClass().getClassLoader(), + new Class[] { config }, new ConfigInvocationHandler( + properties)); + cache.put(config, proxy); + return proxy; + } + + private class ConfigInvocationHandler implements InvocationHandler { + private final Properties properties; + private Map cache = new WeakHashMap(); + + public ConfigInvocationHandler(Properties properties) { + this.properties = properties; + } + + @Override + public Object invoke(Object proxy, Method method, Object[] args) + throws Throwable { + logger.debug("Configuration service, method invoked: {}", method.getName()); + if (args == null || args.length == 0) { + final ConfigurationPropertyGetter getter = method + .getAnnotation(ConfigurationPropertyGetter.class); + if (getter == null) + return null; + return get(getter, method.getReturnType()); + } else if (args.length == 1) { + final ConfigurationPropertySetter setter = method + .getAnnotation(ConfigurationPropertySetter.class); + if (setter == null) + return null; + set(setter, args[0], method.getParameterTypes()[0]); + } + return null; + } + + private Object get(ConfigurationPropertyGetter getter, Class type) { + if (cache.containsKey(getter.name())) + return cache.get(getter.name()); + Object o = untransform( + getRaw(getter.name(), getter.defaultValue()), type); + cache.put(getter.name(), o); + return o; + } + + private void set(ConfigurationPropertySetter setter, Object value, + Class type) { + if (value != null) { + properties.setProperty(setter.name(), + transform(value.toString(), type)); + cache.remove(setter.name()); + } else { + properties.remove(setter.name()); + cache.remove(setter.name()); + } + } + + private Object untransform(String value, Class type) { + if (value == null) + return null; + if (type == String.class) + return value; + final Transformer transformer = TransformerFactory + .getTransfromer(type); + if (transformer == null) + return null; + return transformer.untransform(value); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + private String transform(Object value, Class type) { + if (value == null) + return null; + if (value instanceof String) + return (String) value; + final Transformer transformer = TransformerFactory + .getTransfromer(type); + if (transformer == null) + return null; + return transformer.transform(value); + } + + private String getRaw(String key, String defaultValue) { + if (properties == null) + return defaultValue; + if (properties.containsKey(key)) { + return (String) properties.get(key); + } + return defaultValue; + } + } + + private Properties findProperties(Class clazz) throws IOException { + ConfigurationName config = findAnnotation(ConfigurationName.class, + clazz); + if (config == null) + return null; + final Properties prop = new Properties(); + final File file = new File(directory, config.value() + ".properties"); + final InputStream in = new FileInputStream(file); + try { + prop.load(in); + } finally { + in.close(); + } + return prop; + } + + private T findAnnotation(Class annotationClass, + Class clazz) { + T ann = clazz.getAnnotation(annotationClass); + if (ann != null) + return ann; + + for (Class clazz2 : annotationClass.getInterfaces()) { + if (clazz2 == clazz) + continue; + ann = findAnnotation(annotationClass, clazz2); + if (ann != null) + return ann; + } + return null; + } + + public File getDirectory() { + return directory; + } + + public void setDirectory(File directory) { + this.directory = directory; + } +} diff --git a/src/main/java/com/l2jserver/service/database/AbstractDAO.java b/src/main/java/com/l2jserver/service/database/AbstractDAO.java new file mode 100644 index 000000000..8ea589c3e --- /dev/null +++ b/src/main/java/com/l2jserver/service/database/AbstractDAO.java @@ -0,0 +1,16 @@ +package com.l2jserver.service.database; + +import com.google.inject.Inject; + +public abstract class AbstractDAO implements DataAccessObject { + protected final DatabaseService database; + + @Inject + protected AbstractDAO(DatabaseService database) { + this.database = database; + } + + public DatabaseService getDatabase() { + return database; + } +} diff --git a/src/main/java/com/l2jserver/service/database/DB4ODatabaseConfiguration.java b/src/main/java/com/l2jserver/service/database/DB4ODatabaseConfiguration.java new file mode 100644 index 000000000..d5dc918a2 --- /dev/null +++ b/src/main/java/com/l2jserver/service/database/DB4ODatabaseConfiguration.java @@ -0,0 +1,21 @@ +package com.l2jserver.service.database; + +import java.io.File; + +import com.l2jserver.service.configuration.Configuration.ConfigurationName; + +@ConfigurationName("db4o") +public interface DB4ODatabaseConfiguration extends DatabaseConfiguration { + /** + * @return the database file + */ + @ConfigurationPropertyGetter(name = "db4o.file", defaultValue = "database.bin") + File getDatabaseFile(); + + /** + * @param jdbcUrl + * the new database file + */ + @ConfigurationPropertySetter(name = "db4o.file") + void setDatabaseFile(File file); +} diff --git a/src/main/java/com/l2jserver/service/database/DB4ODatabaseService.java b/src/main/java/com/l2jserver/service/database/DB4ODatabaseService.java new file mode 100644 index 000000000..6193580b3 --- /dev/null +++ b/src/main/java/com/l2jserver/service/database/DB4ODatabaseService.java @@ -0,0 +1,7 @@ +package com.l2jserver.service.database; + +import com.l2jserver.service.AbstractService; + +public class DB4ODatabaseService extends AbstractService implements + DatabaseService { +} diff --git a/src/main/java/com/l2jserver/service/database/DataAccessObject.java b/src/main/java/com/l2jserver/service/database/DataAccessObject.java new file mode 100644 index 000000000..c908c3255 --- /dev/null +++ b/src/main/java/com/l2jserver/service/database/DataAccessObject.java @@ -0,0 +1,17 @@ +package com.l2jserver.service.database; + +/** + * The DAO interface + *

+ * TODO make DAO an {@link Iterable}. So if we want to select all objects we can + * do like this:

+ * for(final Object o : daoInstance) {
+ * 	...
+ * }
+ * 
+ * + * @author Rogiel + */ +public interface DataAccessObject { + +} diff --git a/src/main/java/com/l2jserver/service/database/DatabaseConfiguration.java b/src/main/java/com/l2jserver/service/database/DatabaseConfiguration.java new file mode 100644 index 000000000..fc941b327 --- /dev/null +++ b/src/main/java/com/l2jserver/service/database/DatabaseConfiguration.java @@ -0,0 +1,9 @@ +package com.l2jserver.service.database; + +import com.l2jserver.service.configuration.Configuration; +import com.l2jserver.service.configuration.Configuration.ConfigurationName; + +@ConfigurationName("database") +public interface DatabaseConfiguration extends Configuration { + +} diff --git a/src/main/java/com/l2jserver/service/database/DatabaseService.java b/src/main/java/com/l2jserver/service/database/DatabaseService.java new file mode 100644 index 000000000..b38f85a4c --- /dev/null +++ b/src/main/java/com/l2jserver/service/database/DatabaseService.java @@ -0,0 +1,7 @@ +package com.l2jserver.service.database; + +import com.l2jserver.service.Service; + +public interface DatabaseService extends Service { + +} diff --git a/src/main/java/com/l2jserver/service/database/MySQLDatabaseConfiguration.java b/src/main/java/com/l2jserver/service/database/MySQLDatabaseConfiguration.java new file mode 100644 index 000000000..2db0539ab --- /dev/null +++ b/src/main/java/com/l2jserver/service/database/MySQLDatabaseConfiguration.java @@ -0,0 +1,55 @@ +package com.l2jserver.service.database; + +public interface MySQLDatabaseConfiguration extends DatabaseConfiguration { + /** + * @return the jdbc url + */ + @ConfigurationPropertyGetter(name = "jdbc.mysql.url", defaultValue = "jdbc:mysql://localhost/l2jserver2") + String getJdbcUrl(); + + /** + * @param jdbcUrl + * the new jdbc url + */ + @ConfigurationPropertySetter(name = "jdbc.mysql.url") + void setJdbcUrl(String jdbcUrl); + + /** + * @return the jdbc driver class + */ + @ConfigurationPropertyGetter(name = "jdbc.mysql.driver", defaultValue = "com.mysql.jdbc.Driver") + String getDriver(); + + /** + * @param driver + * the new jdbc driver + */ + @ConfigurationPropertySetter(name = "jdbc.mysql.driver") + void setDriver(Class driver); + + /** + * @return the mysql database username + */ + @ConfigurationPropertyGetter(name = "jdbc.mysql.username", defaultValue = "l2j") + String getUsername(); + + /** + * @param username + * the mysql database username + */ + @ConfigurationPropertySetter(name = "jdbc.mysql.username") + void setUsername(String username); + + /** + * @return the mysql database password + */ + @ConfigurationPropertyGetter(name = "jdbc.mysql.password", defaultValue = "changeme") + String getPassword(); + + /** + * @param password + * the mysql database password + */ + @ConfigurationPropertySetter(name = "jdbc.mysql.password") + void setPassword(String password); +} diff --git a/src/main/java/com/l2jserver/service/database/MySQLDatabaseService.java b/src/main/java/com/l2jserver/service/database/MySQLDatabaseService.java new file mode 100644 index 000000000..82997b84c --- /dev/null +++ b/src/main/java/com/l2jserver/service/database/MySQLDatabaseService.java @@ -0,0 +1,177 @@ +package com.l2jserver.service.database; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Iterator; +import java.util.List; + +import org.apache.commons.dbcp.ConnectionFactory; +import org.apache.commons.dbcp.DriverManagerConnectionFactory; +import org.apache.commons.dbcp.PoolableConnectionFactory; +import org.apache.commons.dbcp.PoolingDataSource; +import org.apache.commons.pool.ObjectPool; +import org.apache.commons.pool.impl.GenericObjectPool; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.inject.Inject; +import com.l2jserver.service.AbstractService; +import com.l2jserver.service.ServiceStartException; +import com.l2jserver.service.ServiceStopException; +import com.l2jserver.service.configuration.ConfigurationService; +import com.l2jserver.util.ArrayIterator; +import com.l2jserver.util.factory.CollectionFactory; + +public class MySQLDatabaseService extends AbstractService implements + DatabaseService { + private final MySQLDatabaseConfiguration config; + private final Logger logger = LoggerFactory + .getLogger(MySQLDatabaseService.class); + + private ObjectPool connectionPool; + private ConnectionFactory connectionFactory; + @SuppressWarnings("unused") + private PoolableConnectionFactory poolableConnectionFactory; + private PoolingDataSource dataSource; + + @Inject + public MySQLDatabaseService(ConfigurationService configService) { + config = configService.get(MySQLDatabaseConfiguration.class); + } + + @Override + public void start() throws ServiceStartException { + connectionPool = new GenericObjectPool(null); + connectionFactory = new DriverManagerConnectionFactory( + config.getJdbcUrl(), config.getUsername(), config.getPassword()); + poolableConnectionFactory = new PoolableConnectionFactory( + connectionFactory, connectionPool, null, null, false, true); + dataSource = new PoolingDataSource(connectionPool); + } + + public T query(Query query) { + try { + final Connection conn = dataSource.getConnection(); + try { + return query.query(conn); + } catch (SQLException e) { + logger.error("Error executing query", e); + return null; + } finally { + conn.close(); + } + } catch (SQLException e) { + logger.error("Could not open database connection", e); + return null; + } + } + + @Override + public void stop() throws ServiceStopException { + try { + if (connectionPool != null) + connectionPool.close(); + } catch (Exception e) { + logger.error("Error stopping database service", e); + throw new ServiceStopException(e); + } finally { + connectionPool = null; + connectionFactory = null; + poolableConnectionFactory = null; + dataSource = null; + } + } + + public interface Query { + R query(Connection conn) throws SQLException; + } + + public static abstract class InsertUpdateQuery implements Query { + private final Iterator iterator; + + public InsertUpdateQuery(T... objects) { + this(new ArrayIterator(objects)); + } + + public InsertUpdateQuery(Iterator iterator) { + this.iterator = iterator; + } + + @Override + public Integer query(Connection conn) throws SQLException { + int rows = 0; + while (iterator.hasNext()) { + final T object = iterator.next(); + final PreparedStatement st = conn.prepareStatement(query()); + this.parametize(st, object); + rows += st.executeUpdate(); + final Mapper mapper = keyMapper(object); + if (mapper == null) + continue; + final ResultSet rs = st.getGeneratedKeys(); + while (rs.next()) { + mapper.map(rs); + } + } + return rows; + } + + protected abstract String query(); + + protected abstract void parametize(PreparedStatement st, T object) + throws SQLException; + + protected Mapper keyMapper(T object) { + return null; + } + } + + public static abstract class SelectListQuery implements Query> { + @Override + public List query(Connection conn) throws SQLException { + final PreparedStatement st = conn.prepareStatement(query()); + parametize(st); + st.execute(); + final List list = CollectionFactory.newList(null); + final ResultSet rs = st.getResultSet(); + while (rs.next()) { + list.add(mapper().map(rs)); + } + return list; + } + + protected abstract String query(); + + protected void parametize(PreparedStatement st) throws SQLException { + } + + protected abstract Mapper mapper(); + } + + public static abstract class SelectSingleQuery implements Query { + @Override + public T query(Connection conn) throws SQLException { + final PreparedStatement st = conn.prepareStatement(query()); + parametize(st); + st.execute(); + final ResultSet rs = st.getResultSet(); + while (rs.next()) { + return mapper().map(rs); + } + return null; + } + + protected abstract String query(); + + protected abstract void parametize(PreparedStatement st) + throws SQLException; + + protected abstract Mapper mapper(); + } + + public interface Mapper { + T map(ResultSet rs) throws SQLException; + } +} diff --git a/src/main/java/com/l2jserver/service/logging/Log4JLoggingService.java b/src/main/java/com/l2jserver/service/logging/Log4JLoggingService.java new file mode 100644 index 000000000..79ecb2be6 --- /dev/null +++ b/src/main/java/com/l2jserver/service/logging/Log4JLoggingService.java @@ -0,0 +1,14 @@ +package com.l2jserver.service.logging; + +import org.apache.log4j.BasicConfigurator; + +import com.l2jserver.service.AbstractService; +import com.l2jserver.service.ServiceStopException; + +public class Log4JLoggingService extends AbstractService implements + LoggingService { + @Override + public void stop() throws ServiceStopException { + BasicConfigurator.configure(); + } +} diff --git a/src/main/java/com/l2jserver/service/logging/LoggingService.java b/src/main/java/com/l2jserver/service/logging/LoggingService.java new file mode 100644 index 000000000..1cdf2ed7d --- /dev/null +++ b/src/main/java/com/l2jserver/service/logging/LoggingService.java @@ -0,0 +1,13 @@ +package com.l2jserver.service.logging; + +import org.slf4j.Logger; + +import com.l2jserver.service.Service; + +/** + * The logging service is used to get instances of the {@link Logger} class. + * + * @author Rogiel + */ +public interface LoggingService extends Service { +} diff --git a/src/main/java/com/l2jserver/util/ArrayIterator.java b/src/main/java/com/l2jserver/util/ArrayIterator.java new file mode 100644 index 000000000..6d1a36df6 --- /dev/null +++ b/src/main/java/com/l2jserver/util/ArrayIterator.java @@ -0,0 +1,31 @@ +package com.l2jserver.util; + +import java.util.Iterator; +import java.util.NoSuchElementException; + +public class ArrayIterator implements Iterator { + private final T[] objects; + private int i = 0; + + public ArrayIterator(T... objects) { + this.objects = objects; + } + + @Override + public boolean hasNext() { + return i < objects.length; + } + + @Override + public T next() { + try { + return objects[i++]; + } catch (ArrayIndexOutOfBoundsException e) { + throw new NoSuchElementException(); + } + } + + @Override + public void remove() { + } +} diff --git a/src/main/java/com/l2jserver/util/factory/CollectionFactory.java b/src/main/java/com/l2jserver/util/factory/CollectionFactory.java new file mode 100644 index 000000000..8978a563a --- /dev/null +++ b/src/main/java/com/l2jserver/util/factory/CollectionFactory.java @@ -0,0 +1,92 @@ +package com.l2jserver.util.factory; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Queue; +import java.util.Set; +import java.util.WeakHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; + +/** + * Factory class to create {@link Collection} instances. + * + * @author Rogiel + */ +public class CollectionFactory { + /** + * Creates a new list of type T + * + * @param + * the type + * @param type + * the type + * @return the created list + */ + public static final List newList(Class type) { + return new ArrayList(); + } + + /** + * Creates a new set of type T + * + * @param + * the type + * @param type + * the type + * @return the created set + */ + public static final Set newSet(Class type) { + return new HashSet(); + } + + /** + * Creates a new concurrent queue of type T + * + * @param + * the type + * @param type + * the type + * @return the created queue + */ + public static final Queue newConcurrentQueue(Class type) { + return new ConcurrentLinkedQueue(); + } + + /** + * Creates a new map. + * + * @param + * the key type + * @param + * the value type + * @param key + * the key type class + * @param value + * the value type class + * @return the new map + */ + public static final Map newMap(Class key, Class value) { + return new HashMap(); + } + + /** + * Creates a new weak map. + * + * @param + * the key type + * @param + * the value type + * @param key + * the key type class + * @param value + * the value type class + * @return the new map + */ + public static final Map newWeakMap(Class key, Class value) { + return new WeakHashMap(); + } +} diff --git a/src/main/java/com/l2jserver/util/transformer/Transformer.java b/src/main/java/com/l2jserver/util/transformer/Transformer.java new file mode 100644 index 000000000..a6172447d --- /dev/null +++ b/src/main/java/com/l2jserver/util/transformer/Transformer.java @@ -0,0 +1,27 @@ +package com.l2jserver.util.transformer; + +/** + * An transformer can transform an {@link Object} into an {@link String} and the + * {@link String} back to an equivalent object. + * + * @author Rogiel + */ +public interface Transformer { + /** + * Transform the object in a string + * + * @param value + * the object + * @return the string of the object + */ + String transform(T value); + + /** + * Untransforms the string back to an object + * + * @param value + * the string + * @return the object + */ + T untransform(String value); +} diff --git a/src/main/java/com/l2jserver/util/transformer/TransformerFactory.java b/src/main/java/com/l2jserver/util/transformer/TransformerFactory.java new file mode 100644 index 000000000..4660e625e --- /dev/null +++ b/src/main/java/com/l2jserver/util/transformer/TransformerFactory.java @@ -0,0 +1,42 @@ +package com.l2jserver.util.transformer; + +import java.io.File; +import java.net.InetSocketAddress; + +import com.l2jserver.util.transformer.impl.BooleanTransformer; +import com.l2jserver.util.transformer.impl.ByteTransformer; +import com.l2jserver.util.transformer.impl.ClassTransformer; +import com.l2jserver.util.transformer.impl.DoubleTransformer; +import com.l2jserver.util.transformer.impl.FileTransformer; +import com.l2jserver.util.transformer.impl.FloatTransformer; +import com.l2jserver.util.transformer.impl.InetSocketAddressTransformer; +import com.l2jserver.util.transformer.impl.IntegerTransformer; +import com.l2jserver.util.transformer.impl.LongTransformer; +import com.l2jserver.util.transformer.impl.ShortTransformer; + +public class TransformerFactory { + public static final Transformer getTransfromer(Class type) { + if (type == Byte.class || type == Byte.TYPE) { + return ByteTransformer.SHARED_INSTANCE; + } else if (type == Short.class || type == Short.TYPE) { + return ShortTransformer.SHARED_INSTANCE; + } else if (type == Integer.class || type == Integer.TYPE) { + return IntegerTransformer.SHARED_INSTANCE; + } else if (type == Long.class || type == Long.TYPE) { + return LongTransformer.SHARED_INSTANCE; + } else if (type == Float.class || type == Float.TYPE) { + return FloatTransformer.SHARED_INSTANCE; + } else if (type == Double.class || type == Double.TYPE) { + return DoubleTransformer.SHARED_INSTANCE; + } else if (type == Boolean.class || type == Boolean.TYPE) { + return BooleanTransformer.SHARED_INSTANCE; + } else if(type == InetSocketAddress.class) { + return InetSocketAddressTransformer.SHARED_INSTANCE; + } else if(type == File.class) { + return FileTransformer.SHARED_INSTANCE; + }else if(type == Class.class) { + return ClassTransformer.SHARED_INSTANCE; + } + return null; + } +} diff --git a/src/main/java/com/l2jserver/util/transformer/impl/BooleanTransformer.java b/src/main/java/com/l2jserver/util/transformer/impl/BooleanTransformer.java new file mode 100644 index 000000000..8c0658345 --- /dev/null +++ b/src/main/java/com/l2jserver/util/transformer/impl/BooleanTransformer.java @@ -0,0 +1,23 @@ +package com.l2jserver.util.transformer.impl; + +import com.l2jserver.util.transformer.Transformer; + +/** + * Transform an {@link Boolean} into an string. + * + * @author Rogiel + */ +public class BooleanTransformer implements Transformer { + public static final BooleanTransformer SHARED_INSTANCE = new BooleanTransformer(); + + @Override + public String transform(Boolean value) { + return (value ? "true" : "false"); + } + + @Override + public Boolean untransform(String value) { + return Boolean.parseBoolean(value); + } + +} diff --git a/src/main/java/com/l2jserver/util/transformer/impl/ByteTransformer.java b/src/main/java/com/l2jserver/util/transformer/impl/ByteTransformer.java new file mode 100644 index 000000000..d6d35085e --- /dev/null +++ b/src/main/java/com/l2jserver/util/transformer/impl/ByteTransformer.java @@ -0,0 +1,23 @@ +package com.l2jserver.util.transformer.impl; + +import com.l2jserver.util.transformer.Transformer; + +/** + * Transform an {@link Integer} into an string. + * + * @author Rogiel + */ +public class ByteTransformer implements Transformer { + public static final ByteTransformer SHARED_INSTANCE = new ByteTransformer(); + + @Override + public String transform(Byte value) { + return Double.toString(value); + } + + @Override + public Byte untransform(String value) { + return Byte.decode(value); + } + +} diff --git a/src/main/java/com/l2jserver/util/transformer/impl/ClassTransformer.java b/src/main/java/com/l2jserver/util/transformer/impl/ClassTransformer.java new file mode 100644 index 000000000..9bd87315b --- /dev/null +++ b/src/main/java/com/l2jserver/util/transformer/impl/ClassTransformer.java @@ -0,0 +1,27 @@ +package com.l2jserver.util.transformer.impl; + +import com.l2jserver.util.transformer.Transformer; + +/** + * Transform an {@link Class} into an string. + * + * @author Rogiel + */ +public class ClassTransformer implements Transformer> { + public static final ClassTransformer SHARED_INSTANCE = new ClassTransformer(); + + @Override + public String transform(Class value) { + return value.getName(); + } + + @Override + public Class untransform(String value) { + try { + return Class.forName(value); + } catch (ClassNotFoundException e) { + return null; + } + } + +} diff --git a/src/main/java/com/l2jserver/util/transformer/impl/DoubleTransformer.java b/src/main/java/com/l2jserver/util/transformer/impl/DoubleTransformer.java new file mode 100644 index 000000000..3bdf2ccc3 --- /dev/null +++ b/src/main/java/com/l2jserver/util/transformer/impl/DoubleTransformer.java @@ -0,0 +1,23 @@ +package com.l2jserver.util.transformer.impl; + +import com.l2jserver.util.transformer.Transformer; + +/** + * Transform an {@link Integer} into an string. + * + * @author Rogiel + */ +public class DoubleTransformer implements Transformer { + public static final DoubleTransformer SHARED_INSTANCE = new DoubleTransformer(); + + @Override + public String transform(Double value) { + return Double.toString(value); + } + + @Override + public Double untransform(String value) { + return Double.parseDouble(value); + } + +} diff --git a/src/main/java/com/l2jserver/util/transformer/impl/FileTransformer.java b/src/main/java/com/l2jserver/util/transformer/impl/FileTransformer.java new file mode 100644 index 000000000..3f5c37fa1 --- /dev/null +++ b/src/main/java/com/l2jserver/util/transformer/impl/FileTransformer.java @@ -0,0 +1,27 @@ +package com.l2jserver.util.transformer.impl; + +import java.io.File; + +import com.l2jserver.util.transformer.Transformer; + +/** + * Transform an {@link Integer} into an string. + * + * @author Rogiel + */ +public class FileTransformer implements Transformer { + public static final FileTransformer SHARED_INSTANCE = new FileTransformer(); + + private final File root = new File("./"); + + @Override + public String transform(File value) { + return value.getAbsolutePath(); + } + + @Override + public File untransform(String value) { + return new File(root, value); + } + +} diff --git a/src/main/java/com/l2jserver/util/transformer/impl/FloatTransformer.java b/src/main/java/com/l2jserver/util/transformer/impl/FloatTransformer.java new file mode 100644 index 000000000..2505f9066 --- /dev/null +++ b/src/main/java/com/l2jserver/util/transformer/impl/FloatTransformer.java @@ -0,0 +1,23 @@ +package com.l2jserver.util.transformer.impl; + +import com.l2jserver.util.transformer.Transformer; + +/** + * Transform an {@link Integer} into an string. + * + * @author Rogiel + */ +public class FloatTransformer implements Transformer { + public static final FloatTransformer SHARED_INSTANCE = new FloatTransformer(); + + @Override + public String transform(Float value) { + return Double.toString(value); + } + + @Override + public Float untransform(String value) { + return Float.parseFloat(value); + } + +} diff --git a/src/main/java/com/l2jserver/util/transformer/impl/InetSocketAddressTransformer.java b/src/main/java/com/l2jserver/util/transformer/impl/InetSocketAddressTransformer.java new file mode 100644 index 000000000..2c25208e6 --- /dev/null +++ b/src/main/java/com/l2jserver/util/transformer/impl/InetSocketAddressTransformer.java @@ -0,0 +1,29 @@ +package com.l2jserver.util.transformer.impl; + +import java.net.InetSocketAddress; + +import com.l2jserver.util.transformer.Transformer; + +/** + * Transform an {@link Integer} into an string. + * + * @author Rogiel + */ +public class InetSocketAddressTransformer implements + Transformer { + public static final InetSocketAddressTransformer SHARED_INSTANCE = new InetSocketAddressTransformer(); + + @Override + public String transform(InetSocketAddress value) { + return value.getHostName() + ":" + value.getPort(); + } + + @Override + public InetSocketAddress untransform(String value) { + final String[] pieces = value.split(":"); + if (pieces.length != 2) + return null; + return new InetSocketAddress(pieces[0], Integer.parseInt(pieces[1])); + } + +} diff --git a/src/main/java/com/l2jserver/util/transformer/impl/IntegerTransformer.java b/src/main/java/com/l2jserver/util/transformer/impl/IntegerTransformer.java new file mode 100644 index 000000000..8a795d8f6 --- /dev/null +++ b/src/main/java/com/l2jserver/util/transformer/impl/IntegerTransformer.java @@ -0,0 +1,23 @@ +package com.l2jserver.util.transformer.impl; + +import com.l2jserver.util.transformer.Transformer; + +/** + * Transform an {@link Integer} into an string. + * + * @author Rogiel + */ +public class IntegerTransformer implements Transformer { + public static final IntegerTransformer SHARED_INSTANCE = new IntegerTransformer(); + + @Override + public String transform(Integer value) { + return Integer.toString(value); + } + + @Override + public Integer untransform(String value) { + return Integer.decode(value); + } + +} diff --git a/src/main/java/com/l2jserver/util/transformer/impl/LongTransformer.java b/src/main/java/com/l2jserver/util/transformer/impl/LongTransformer.java new file mode 100644 index 000000000..d77f58720 --- /dev/null +++ b/src/main/java/com/l2jserver/util/transformer/impl/LongTransformer.java @@ -0,0 +1,23 @@ +package com.l2jserver.util.transformer.impl; + +import com.l2jserver.util.transformer.Transformer; + +/** + * Transform an {@link Long} into an string. + * + * @author Rogiel + */ +public class LongTransformer implements Transformer { + public static final LongTransformer SHARED_INSTANCE = new LongTransformer(); + + @Override + public String transform(Long value) { + return Long.toString(value); + } + + @Override + public Long untransform(String value) { + return Long.decode(value); + } + +} diff --git a/src/main/java/com/l2jserver/util/transformer/impl/ShortTransformer.java b/src/main/java/com/l2jserver/util/transformer/impl/ShortTransformer.java new file mode 100644 index 000000000..c72dac476 --- /dev/null +++ b/src/main/java/com/l2jserver/util/transformer/impl/ShortTransformer.java @@ -0,0 +1,23 @@ +package com.l2jserver.util.transformer.impl; + +import com.l2jserver.util.transformer.Transformer; + +/** + * Transform an {@link Integer} into an string. + * + * @author Rogiel + */ +public class ShortTransformer implements Transformer { + public static final ShortTransformer SHARED_INSTANCE = new ShortTransformer(); + + @Override + public String transform(Short value) { + return Short.toString(value); + } + + @Override + public Short untransform(String value) { + return Short.decode(value); + } + +} diff --git a/src/test/java/com/l2jserver/model/id/factory/IDFactoryTest.java b/src/test/java/com/l2jserver/model/id/factory/IDFactoryTest.java index 89bc75b05..e3cf26d76 100644 --- a/src/test/java/com/l2jserver/model/id/factory/IDFactoryTest.java +++ b/src/test/java/com/l2jserver/model/id/factory/IDFactoryTest.java @@ -12,7 +12,6 @@ import com.l2jserver.model.id.ID; import com.l2jserver.model.id.object.CharacterID; import com.l2jserver.model.id.object.factory.CharacterIDFactory; import com.l2jserver.model.world.L2Character; -import com.l2jserver.service.BasicServiceModule; import com.l2jserver.service.ServiceModule; import com.l2jserver.service.ServiceStartException; import com.l2jserver.service.database.DatabaseService; @@ -21,8 +20,7 @@ import com.l2jserver.service.game.template.TemplateService; public class IDFactoryTest { private final Injector injector = Guice.createInjector(new ServiceModule(), - new BasicServiceModule(), new DAOModuleMySQL5(), - new IDFactoryModule()); + new DAOModuleMySQL5(), new IDFactoryModule()); private final CharacterIDFactory charIdFactory = injector .getInstance(CharacterIDFactory.class); diff --git a/src/test/java/com/l2jserver/model/world/character/CharacterFriendListTest.java b/src/test/java/com/l2jserver/model/world/character/CharacterFriendListTest.java index 31dd63b31..68f8e21b4 100644 --- a/src/test/java/com/l2jserver/model/world/character/CharacterFriendListTest.java +++ b/src/test/java/com/l2jserver/model/world/character/CharacterFriendListTest.java @@ -13,7 +13,6 @@ import com.l2jserver.model.id.factory.IDFactoryModule; import com.l2jserver.model.id.object.CharacterID; import com.l2jserver.model.id.object.factory.CharacterIDFactory; import com.l2jserver.model.world.L2Character; -import com.l2jserver.service.BasicServiceModule; import com.l2jserver.service.ServiceModule; import com.l2jserver.service.ServiceStartException; import com.l2jserver.service.database.DatabaseService; @@ -22,8 +21,7 @@ import com.l2jserver.service.game.template.TemplateService; public class CharacterFriendListTest { private final Injector injector = Guice.createInjector(new ServiceModule(), - new BasicServiceModule(), new DAOModuleMySQL5(), - new IDFactoryModule()); + new DAOModuleMySQL5(), new IDFactoryModule()); private final CharacterIDFactory charIdFactory = injector .getInstance(CharacterIDFactory.class); diff --git a/src/test/java/com/l2jserver/service/game/template/StaticTemplateServiceTest.java b/src/test/java/com/l2jserver/service/game/template/StaticTemplateServiceTest.java index b40cc555c..4a5963ce8 100644 --- a/src/test/java/com/l2jserver/service/game/template/StaticTemplateServiceTest.java +++ b/src/test/java/com/l2jserver/service/game/template/StaticTemplateServiceTest.java @@ -11,15 +11,13 @@ import com.google.inject.Scopes; import com.l2jserver.db.dao.DAOModuleMySQL5; import com.l2jserver.model.id.factory.IDFactoryModule; import com.l2jserver.model.id.template.factory.ItemTemplateIDFactory; -import com.l2jserver.service.BasicServiceModule; import com.l2jserver.service.ServiceStartException; import com.l2jserver.service.game.scripting.ScriptingService; import com.l2jserver.service.game.scripting.ScriptingServiceImpl; public class StaticTemplateServiceTest { private final Injector injector = Guice.createInjector( - new BasicServiceModule(), new IDFactoryModule(), - new DAOModuleMySQL5(), new AbstractModule() { + new IDFactoryModule(), new DAOModuleMySQL5(), new AbstractModule() { @Override protected void configure() { bind(ScriptingService.class).to(ScriptingServiceImpl.class) diff --git a/src/test/java/com/l2jserver/service/world/WorldEventDispatcherImplTest.java b/src/test/java/com/l2jserver/service/world/WorldEventDispatcherImplTest.java index 78ffe0df8..dd14d2ae2 100644 --- a/src/test/java/com/l2jserver/service/world/WorldEventDispatcherImplTest.java +++ b/src/test/java/com/l2jserver/service/world/WorldEventDispatcherImplTest.java @@ -23,7 +23,6 @@ import com.l2jserver.model.world.item.ItemListener; import com.l2jserver.model.world.player.PlayerEvent; import com.l2jserver.model.world.player.PlayerListener; import com.l2jserver.model.world.player.PlayerSpawnEvent; -import com.l2jserver.service.BasicServiceModule; import com.l2jserver.service.ServiceModule; import com.l2jserver.service.ServiceStartException; import com.l2jserver.service.game.world.WorldService; @@ -40,9 +39,9 @@ public class WorldEventDispatcherImplTest { @Before public void tearUp() throws ServiceStartException { - Injector injector = Guice.createInjector(new BasicServiceModule(), - new ServiceModule(), new DAOModuleMySQL5(), - new IDFactoryModule(), new AbstractModule() { + Injector injector = Guice.createInjector(new ServiceModule(), + new DAOModuleMySQL5(), new IDFactoryModule(), + new AbstractModule() { @Override protected void configure() { bind(WorldService.class).to(WorldServiceImpl.class).in( diff --git a/src/test/java/com/l2jserver/service/world/WorldServiceImplTest.java b/src/test/java/com/l2jserver/service/world/WorldServiceImplTest.java index f206765c5..e742733f3 100644 --- a/src/test/java/com/l2jserver/service/world/WorldServiceImplTest.java +++ b/src/test/java/com/l2jserver/service/world/WorldServiceImplTest.java @@ -13,7 +13,6 @@ import com.l2jserver.model.world.Item; import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.WorldObject; import com.l2jserver.model.world.filter.impl.InstanceFilter; -import com.l2jserver.service.BasicServiceModule; import com.l2jserver.service.ServiceStartException; import com.l2jserver.service.game.world.WorldService; import com.l2jserver.service.game.world.WorldServiceImpl; @@ -25,17 +24,15 @@ public class WorldServiceImplTest { @Before public void tearUp() throws ServiceStartException { - Injector injector = Guice.createInjector(new BasicServiceModule(), - new AbstractModule() { - @Override - protected void configure() { - bind(WorldService.class).to(WorldServiceImpl.class).in( - Scopes.SINGLETON); - bind(WorldEventDispatcher.class).to( - WorldEventDispatcherImpl.class).in( - Scopes.SINGLETON); - } - }); + Injector injector = Guice.createInjector(new AbstractModule() { + @Override + protected void configure() { + bind(WorldService.class).to(WorldServiceImpl.class).in( + Scopes.SINGLETON); + bind(WorldEventDispatcher.class).to( + WorldEventDispatcherImpl.class).in(Scopes.SINGLETON); + } + }); world = injector.getInstance(WorldService.class); Assert.assertNotNull(world);