diff --git a/l2jserver2-common/pom.xml b/l2jserver2-common/pom.xml index ae6ab77a7..749cbb415 100644 --- a/l2jserver2-common/pom.xml +++ b/l2jserver2-common/pom.xml @@ -147,5 +147,20 @@ 10.8.2.2 runtime + + de.schlichtherle.truezip + truezip-kernel + 7.4.3 + + + de.schlichtherle.truezip + truezip-driver-zip + 7.4.3 + + + de.schlichtherle.truezip + truezip-path + 7.4.3 + \ No newline at end of file diff --git a/l2jserver2-common/src/main/java/com/l2jserver/model/AbstractModel.java b/l2jserver2-common/src/main/java/com/l2jserver/model/AbstractModel.java index f4dd9379d..ba4d98ff6 100644 --- a/l2jserver2-common/src/main/java/com/l2jserver/model/AbstractModel.java +++ b/l2jserver2-common/src/main/java/com/l2jserver/model/AbstractModel.java @@ -32,6 +32,9 @@ import com.l2jserver.model.id.ID; * @author Rogiel */ public abstract class AbstractModel> implements Model { + /** + * The logger instance + */ private final Logger log = LoggerFactory.getLogger(this.getClass()); /** @@ -73,7 +76,6 @@ public abstract class AbstractModel> implements Model { * {@link ObjectDesire#INSERT} or {@link ObjectDesire#DELETE} the desire * will not be changed. */ - @SuppressWarnings("javadoc") protected void desireUpdate() { if (this.desire != ObjectDesire.INSERT && this.desire != ObjectDesire.DELETE) { @@ -86,7 +88,6 @@ public abstract class AbstractModel> implements Model { * Set this object desire to {@link ObjectDesire#INSERT}. If the desire is * {@link ObjectDesire#DELETE} the desire will not be changed. */ - @SuppressWarnings("javadoc") protected void desireInsert() { if (this.desire != ObjectDesire.DELETE) { log.debug("{} desires an insert", this); 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 612e3eaeb..ea757a6ab 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 @@ -78,6 +78,9 @@ public class XMLConfigurationService extends AbstractService implements */ private DocumentBuilder builder; + /** + * The XML {@link Document} containing configuration data + */ private Document properties; /** @@ -85,8 +88,16 @@ public class XMLConfigurationService extends AbstractService implements */ private Map, Object> cache = CollectionFactory.newWeakMap(); + /** + * Defines the XPath for the configuration parameter + * + * @author Rogiel + */ @Retention(RetentionPolicy.RUNTIME) public @interface ConfigurationXPath { + /** + * @return the xml path for the configuration + */ String value(); } diff --git a/l2jserver2-common/src/main/java/com/l2jserver/service/core/threading/ThreadPoolPriority.java b/l2jserver2-common/src/main/java/com/l2jserver/service/core/threading/ThreadPoolPriority.java index 3d4e80db9..6b534b9a3 100644 --- a/l2jserver2-common/src/main/java/com/l2jserver/service/core/threading/ThreadPoolPriority.java +++ b/l2jserver2-common/src/main/java/com/l2jserver/service/core/threading/ThreadPoolPriority.java @@ -49,6 +49,9 @@ public enum ThreadPoolPriority { */ public final int threadPriority; + /** + * @param threadPriority the {@link Thread} priority {@link Integer} index + */ ThreadPoolPriority(int threadPriority) { this.threadPriority = threadPriority; } 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 e30d6df3e..caa1a88aa 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 @@ -16,11 +16,6 @@ */ package com.l2jserver.service.core.vfs; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.nio.file.FileSystem; -import java.nio.file.FileSystems; import java.nio.file.Path; import org.slf4j.Logger; @@ -48,14 +43,14 @@ public class Java7VFSService extends AbstractService implements VFSService { */ private final Java7VFSConfiguration config; - /** - * The {@link FileSystem} implementation - */ - private FileSystem fs; /** * The root {@link Path} of the server data */ private Path root; + /** + * The root for the "data" folder + */ + private Path dataRoot; /** * Configuration interface for {@link Java7VFSService}. @@ -76,13 +71,11 @@ public class Java7VFSService extends AbstractService implements VFSService { @Override protected void doStart() throws ServiceStartException { - try { - fs = FileSystems.getFileSystem(new URI("file:///")); - } catch (URISyntaxException e) { - throw new ServiceStartException(e); - } root = config.getRoot().toAbsolutePath(); log.debug("Root path is {}", root); + + dataRoot = root.resolve(config.getDataPath()); + log.debug("Data root path is {}", root); } @Override @@ -91,14 +84,15 @@ public class Java7VFSService extends AbstractService implements VFSService { return root.resolve(path); } + @Override + public Path resolveDataFile(String path) { + log.debug("Resolving data file {}", path); + return dataRoot.resolve(path); + } + @Override protected void doStop() throws ServiceStopException { - try { - fs.close(); - } catch (IOException e) { - throw new ServiceStopException(e); - } finally { - fs = null; - } + root = null; + dataRoot = null; } } 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 new file mode 100644 index 000000000..2d1e7b3cb --- /dev/null +++ b/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/TrueZipVFSService.java @@ -0,0 +1,107 @@ +/* + * 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.nio.file.Path; + +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 de.schlichtherle.truezip.fs.FsSyncException; +import de.schlichtherle.truezip.nio.file.TPath; + +/** + * Implementation of {@link VFSService} using default Java7 APIs. + * + * @author Rogiel + */ +public class TrueZipVFSService extends AbstractService 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 + */ + private TPath root; + /** + * The root for the "data" folder + */ + 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); + } + + @Override + protected void doStart() throws ServiceStartException { + root = new TPath(config.getRoot().toAbsolutePath()); + log.debug("Root path is {}", root); + + dataRoot = root.resolve(config.getDataPath()); + log.debug("Data root path is {}", root); + } + + @Override + public Path resolve(String path) { + log.debug("Resolving file {}", path); + return root.resolve(path); + } + + @Override + public Path resolveDataFile(String path) { + log.debug("Resolving data file {}", path); + return dataRoot.resolve(path); + } + + @Override + protected void doStop() throws ServiceStopException { + try { + root.getFileSystem().close(); + } catch (FsSyncException e) { + throw new ServiceStopException(e); + } finally { + root = null; + dataRoot = null; + } + } +} 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 80c6e29fe..bfb5bcca6 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 @@ -52,12 +52,27 @@ public interface VFSService extends Service { @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. *

- * Please note that event if the file DOES NOT exists a valid object will be + * Please note that even if the file DOES NOT exists a valid object will be * returned. * * @param path @@ -65,4 +80,17 @@ public interface VFSService extends Service { * @return the resolved file. Will return null if could not resolve. */ Path resolve(String path); + + /** + * Resolves an file inside the data storage file system. If the file cannot + * be resolved, null will be returned. + *

+ * Please note that, differently from {@link #resolve(String)}, if the file + * does not exists, null is returned. + * + * @param path + * the file path as an string + * @return the resolved file. Will return null if could not resolve. + */ + Path resolveDataFile(String path); } diff --git a/l2jserver2-gameserver/config/config.xml b/l2jserver2-gameserver/config/config.xml index f2fc211c6..731d4d22b 100644 --- a/l2jserver2-gameserver/config/config.xml +++ b/l2jserver2-gameserver/config/config.xml @@ -73,7 +73,11 @@ sure on the usage of any parameter, read the "Configuration" section in wiki article about VFSService. --> + + + + ./data