mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-05 23:22:47 +00:00
Implements TrueZipVFSService
This commit is contained in:
@@ -147,5 +147,20 @@
|
||||
<version>10.8.2.2</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.schlichtherle.truezip</groupId>
|
||||
<artifactId>truezip-kernel</artifactId>
|
||||
<version>7.4.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.schlichtherle.truezip</groupId>
|
||||
<artifactId>truezip-driver-zip</artifactId>
|
||||
<version>7.4.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.schlichtherle.truezip</groupId>
|
||||
<artifactId>truezip-path</artifactId>
|
||||
<version>7.4.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -32,6 +32,9 @@ import com.l2jserver.model.id.ID;
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public abstract class AbstractModel<T extends ID<?>> implements Model<T> {
|
||||
/**
|
||||
* The logger instance
|
||||
*/
|
||||
private final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
/**
|
||||
@@ -73,7 +76,6 @@ public abstract class AbstractModel<T extends ID<?>> implements Model<T> {
|
||||
* {@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<T extends ID<?>> implements Model<T> {
|
||||
* 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);
|
||||
|
||||
@@ -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<Class<?>, 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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* This file is part of l2jserver2 <l2jserver2.com>.
|
||||
*
|
||||
* l2jserver2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* l2jserver2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.service.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 <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
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 <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* Please note that, differently from {@link #resolve(String)}, if the file
|
||||
* does not exists, <code>null</code> 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);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,11 @@
|
||||
sure on the usage of any parameter, read the "Configuration" section in wiki
|
||||
article about VFSService. -->
|
||||
<vfs>
|
||||
<!-- The root of the filesystem -->
|
||||
<root></root>
|
||||
|
||||
<!-- The data folder. Relative to the root. Can be a ZIP file. -->
|
||||
<data>./data</data>
|
||||
</vfs>
|
||||
|
||||
<!-- Parameters in this section are used by VFSService. If you are not
|
||||
|
||||
@@ -27,7 +27,7 @@ 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.Java7VFSService;
|
||||
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;
|
||||
@@ -81,7 +81,7 @@ public class ServiceModule extends AbstractModule {
|
||||
bind(ServiceManager.class).in(Scopes.SINGLETON);
|
||||
bind(LoggingService.class).to(Log4JLoggingService.class).in(
|
||||
Scopes.SINGLETON);
|
||||
bind(VFSService.class).to(Java7VFSService.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(
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.l2jserver.service.database;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.l2jserver.service.AbstractService.Depends;
|
||||
@@ -25,6 +24,7 @@ import com.l2jserver.service.cache.CacheService;
|
||||
import com.l2jserver.service.configuration.ConfigurationService;
|
||||
import com.l2jserver.service.core.LoggingService;
|
||||
import com.l2jserver.service.core.threading.ThreadService;
|
||||
import com.l2jserver.service.core.vfs.VFSService;
|
||||
import com.l2jserver.service.database.model.QActorSkill;
|
||||
import com.l2jserver.service.database.model.QCharacter;
|
||||
import com.l2jserver.service.database.model.QCharacterFriend;
|
||||
@@ -64,6 +64,8 @@ import com.l2jserver.service.game.template.TemplateService;
|
||||
ConfigurationService.class, TemplateService.class, ThreadService.class })
|
||||
public class GameServerOrientDatabaseService extends
|
||||
AbstractOrientDatabaseService implements DatabaseService {
|
||||
private final VFSService vfsService;
|
||||
|
||||
/**
|
||||
* @param configService
|
||||
* the config service
|
||||
@@ -77,8 +79,9 @@ public class GameServerOrientDatabaseService extends
|
||||
@Inject
|
||||
public GameServerOrientDatabaseService(ConfigurationService configService,
|
||||
CacheService cacheService, ThreadService threadService,
|
||||
DAOResolver daoResolver) {
|
||||
final VFSService vfsService, DAOResolver daoResolver) {
|
||||
super(configService, cacheService, threadService, daoResolver);
|
||||
this.vfsService = vfsService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -92,7 +95,7 @@ public class GameServerOrientDatabaseService extends
|
||||
updateSchema(QLogChat.logChat);
|
||||
if (updateSchema(QNPC.npc)) {
|
||||
try {
|
||||
importData(Paths.get("data/static/npc.csv"), QNPC.npc);
|
||||
importData(vfsService.resolve("data/static/npc.csv"), QNPC.npc);
|
||||
} catch (IOException e) {
|
||||
throw new DatabaseException(e);
|
||||
}
|
||||
|
||||
@@ -25,9 +25,21 @@ package com.l2jserver.util.calculator;
|
||||
*/
|
||||
public abstract class AbstractDoubleFunction<T extends CalculatorContext, V extends Enum<V>>
|
||||
implements Function<T, V> {
|
||||
/**
|
||||
* The execution order
|
||||
*/
|
||||
private final int order;
|
||||
/**
|
||||
* The parameter type
|
||||
*/
|
||||
private final V type;
|
||||
|
||||
/**
|
||||
* @param order
|
||||
* the execution order
|
||||
* @param type
|
||||
* the parameter type
|
||||
*/
|
||||
public AbstractDoubleFunction(int order, V type) {
|
||||
this.order = order;
|
||||
this.type = type;
|
||||
|
||||
Reference in New Issue
Block a user