mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-06 07:32:46 +00:00
Implemented service dependencies
Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
7
pom.xml
7
pom.xml
@@ -99,6 +99,13 @@
|
|||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.inject.extensions</groupId>
|
||||||
|
<artifactId>guice-multibindings</artifactId>
|
||||||
|
<version>3.0</version>
|
||||||
|
<type>jar</type>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<issueManagement>
|
<issueManagement>
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import com.google.inject.AbstractModule;
|
|||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
import com.l2jserver.db.dao.DAOModuleMySQL5;
|
import com.l2jserver.db.dao.DAOModuleMySQL5;
|
||||||
import com.l2jserver.model.id.factory.IDFactoryModule;
|
import com.l2jserver.model.id.factory.IDFactoryModule;
|
||||||
import com.l2jserver.routines.GameServerInitializationRoutine;
|
|
||||||
import com.l2jserver.service.ServiceModule;
|
import com.l2jserver.service.ServiceModule;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,8 +33,5 @@ public class GameServerModule extends AbstractModule {
|
|||||||
install(new ServiceModule());
|
install(new ServiceModule());
|
||||||
install(new IDFactoryModule());
|
install(new IDFactoryModule());
|
||||||
install(new DAOModuleMySQL5());
|
install(new DAOModuleMySQL5());
|
||||||
|
|
||||||
// routines
|
|
||||||
bind(GameServerInitializationRoutine.class);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,14 @@
|
|||||||
*/
|
*/
|
||||||
package com.l2jserver;
|
package com.l2jserver;
|
||||||
|
|
||||||
import com.l2jserver.routines.GameServerInitializationRoutine;
|
import com.l2jserver.service.ServiceManager;
|
||||||
|
import com.l2jserver.service.blowfish.BlowfishKeygenService;
|
||||||
|
import com.l2jserver.service.cache.CacheService;
|
||||||
|
import com.l2jserver.service.configuration.ConfigurationService;
|
||||||
|
import com.l2jserver.service.database.DatabaseService;
|
||||||
|
import com.l2jserver.service.game.scripting.ScriptingService;
|
||||||
|
import com.l2jserver.service.game.template.TemplateService;
|
||||||
|
import com.l2jserver.service.network.NetworkService;
|
||||||
|
|
||||||
public class L2JGameServerMain {
|
public class L2JGameServerMain {
|
||||||
/**
|
/**
|
||||||
@@ -26,8 +33,18 @@ public class L2JGameServerMain {
|
|||||||
public static void main(String[] args) throws InterruptedException {
|
public static void main(String[] args) throws InterruptedException {
|
||||||
final L2JGameServer server = new L2JGameServer();
|
final L2JGameServer server = new L2JGameServer();
|
||||||
try {
|
try {
|
||||||
server.getInjector()
|
final ServiceManager serviceManager = server.getInjector()
|
||||||
.getInstance(GameServerInitializationRoutine.class).call();
|
.getInstance(ServiceManager.class);
|
||||||
|
|
||||||
|
serviceManager.start(CacheService.class);
|
||||||
|
serviceManager.start(ConfigurationService.class);
|
||||||
|
serviceManager.start(DatabaseService.class);
|
||||||
|
|
||||||
|
serviceManager.start(ScriptingService.class);
|
||||||
|
serviceManager.start(TemplateService.class);
|
||||||
|
|
||||||
|
serviceManager.start(BlowfishKeygenService.class);
|
||||||
|
serviceManager.start(NetworkService.class);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("GameServer could not be started!");
|
System.out.println("GameServer could not be started!");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -31,9 +31,9 @@ public enum ProtocolVersion {
|
|||||||
*/
|
*/
|
||||||
FREYA(216, RELEASE),
|
FREYA(216, RELEASE),
|
||||||
/**
|
/**
|
||||||
* High5(217)
|
* High5(268)
|
||||||
*/
|
*/
|
||||||
HIGH5(217, FREYA);
|
HIGH5(268, FREYA);
|
||||||
|
|
||||||
public final ProtocolVersion parent;
|
public final ProtocolVersion parent;
|
||||||
public final int version;
|
public final int version;
|
||||||
|
|||||||
@@ -22,6 +22,11 @@ import com.l2jserver.game.net.Lineage2Connection;
|
|||||||
import com.l2jserver.game.net.packet.AbstractClientPacket;
|
import com.l2jserver.game.net.packet.AbstractClientPacket;
|
||||||
import com.l2jserver.game.net.packet.server.GameGuardQueryPacket;
|
import com.l2jserver.game.net.packet.server.GameGuardQueryPacket;
|
||||||
import com.l2jserver.game.net.packet.server.UserInformationPacket;
|
import com.l2jserver.game.net.packet.server.UserInformationPacket;
|
||||||
|
import com.l2jserver.model.id.object.CharacterID;
|
||||||
|
import com.l2jserver.service.game.chat.ChatService;
|
||||||
|
import com.l2jserver.service.game.chat.channel.ChatChannel;
|
||||||
|
import com.l2jserver.service.game.chat.channel.ChatChannelListener;
|
||||||
|
import com.l2jserver.service.game.chat.channel.PublicChatChannel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The client is requesting a logout. Currently, when this packet is received
|
* The client is requesting a logout. Currently, when this packet is received
|
||||||
@@ -35,6 +40,21 @@ public class EnterWorld extends AbstractClientPacket {
|
|||||||
*/
|
*/
|
||||||
public static final int OPCODE = 0x11;
|
public static final int OPCODE = 0x11;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The chat service
|
||||||
|
*/
|
||||||
|
private final ChatService chatService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*
|
||||||
|
* @param chatService
|
||||||
|
* the chat service
|
||||||
|
*/
|
||||||
|
public EnterWorld(ChatService chatService) {
|
||||||
|
this.chatService = chatService;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(Lineage2Connection conn, ChannelBuffer buffer) {
|
public void read(Lineage2Connection conn, ChannelBuffer buffer) {
|
||||||
buffer.readBytes(new byte[32]); // Unknown Byte Array
|
buffer.readBytes(new byte[32]); // Unknown Byte Array
|
||||||
@@ -52,8 +72,20 @@ public class EnterWorld extends AbstractClientPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void process(final Lineage2Connection conn) {
|
public void process(final Lineage2Connection conn) {
|
||||||
|
if (conn.getCharacter().getClanID() != null) {
|
||||||
|
final PublicChatChannel clanChannel = chatService.getChannel(conn
|
||||||
|
.getCharacter().getClanID());
|
||||||
|
clanChannel.addChatChannelListener(new ChatChannelListener() {
|
||||||
|
@Override
|
||||||
|
public void onMessage(ChatChannel channel, CharacterID source,
|
||||||
|
String message) {
|
||||||
|
// TODO write message
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
conn.write(new UserInformationPacket(conn.getCharacter()));
|
conn.write(new UserInformationPacket(conn.getCharacter()));
|
||||||
conn.write(new GameGuardQueryPacket());
|
conn.write(new GameGuardQueryPacket());
|
||||||
//conn.write(new InventoryPacket(conn.getCharacter().getInventory()));
|
// conn.write(new InventoryPacket(conn.getCharacter().getInventory()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of l2jserver <l2jserver.com>.
|
|
||||||
*
|
|
||||||
* l2jserver 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.
|
|
||||||
*
|
|
||||||
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package com.l2jserver.routines;
|
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
|
||||||
import com.l2jserver.service.ServiceManager;
|
|
||||||
import com.l2jserver.service.blowfish.BlowfishKeygenService;
|
|
||||||
import com.l2jserver.service.cache.CacheService;
|
|
||||||
import com.l2jserver.service.configuration.ConfigurationService;
|
|
||||||
import com.l2jserver.service.database.DatabaseService;
|
|
||||||
import com.l2jserver.service.game.scripting.ScriptingService;
|
|
||||||
import com.l2jserver.service.game.template.TemplateService;
|
|
||||||
import com.l2jserver.service.network.NetworkService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Routine used to initialize the server. Starts all services.
|
|
||||||
*
|
|
||||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
|
||||||
*/
|
|
||||||
public class GameServerInitializationRoutine implements Routine<Boolean> {
|
|
||||||
/**
|
|
||||||
* The service manager
|
|
||||||
*/
|
|
||||||
private final ServiceManager serviceManager;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance
|
|
||||||
*
|
|
||||||
* @param serviceManager
|
|
||||||
* the service manager
|
|
||||||
*/
|
|
||||||
@Inject
|
|
||||||
public GameServerInitializationRoutine(ServiceManager serviceManager) {
|
|
||||||
this.serviceManager = serviceManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean call() throws Exception {
|
|
||||||
serviceManager.start(CacheService.class);
|
|
||||||
serviceManager.start(ConfigurationService.class);
|
|
||||||
serviceManager.start(DatabaseService.class);
|
|
||||||
|
|
||||||
serviceManager.start(ScriptingService.class);
|
|
||||||
serviceManager.start(TemplateService.class);
|
|
||||||
|
|
||||||
serviceManager.start(BlowfishKeygenService.class);
|
|
||||||
serviceManager.start(NetworkService.class);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of l2jserver <l2jserver.com>.
|
|
||||||
*
|
|
||||||
* l2jserver 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.
|
|
||||||
*
|
|
||||||
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package com.l2jserver.routines;
|
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An routine is a set of operations that can be performed on another thread.
|
|
||||||
*
|
|
||||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
|
||||||
*
|
|
||||||
* @param <T>
|
|
||||||
* the routine return type
|
|
||||||
*/
|
|
||||||
public interface Routine<T> extends Callable<T> {
|
|
||||||
}
|
|
||||||
@@ -16,18 +16,49 @@
|
|||||||
*/
|
*/
|
||||||
package com.l2jserver.service;
|
package com.l2jserver.service;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An abstract service implementing basic life-cycle methods.
|
* An abstract service implementing basic life-cycle methods.
|
||||||
*
|
*
|
||||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
*/
|
*/
|
||||||
public class AbstractService implements Service {
|
public abstract class AbstractService implements Service {
|
||||||
|
/**
|
||||||
|
* Running state of a service
|
||||||
|
*/
|
||||||
|
protected boolean running = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() throws ServiceStartException {
|
public final void start() throws ServiceStartException {
|
||||||
|
if (running)
|
||||||
|
throw new ServiceStartException("Service is already started");
|
||||||
|
try {
|
||||||
|
this.doStart();
|
||||||
|
this.running = true;
|
||||||
|
} catch (ServiceStartException e) {
|
||||||
|
this.running = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doStart() throws ServiceStartException {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() throws ServiceStopException {
|
public final void stop() throws ServiceStopException {
|
||||||
|
if (!running)
|
||||||
|
throw new ServiceStopException("Service is not started");
|
||||||
|
try {
|
||||||
|
this.doStop();
|
||||||
|
} finally {
|
||||||
|
this.running = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doStop() throws ServiceStopException {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -35,4 +66,28 @@ public class AbstractService implements Service {
|
|||||||
this.stop();
|
this.stop();
|
||||||
this.start();
|
this.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isStarted() {
|
||||||
|
return running;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isStopped() {
|
||||||
|
return !running;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends Service>[] getDependencies() {
|
||||||
|
final Depends deps = this.getClass().getAnnotation(Depends.class);
|
||||||
|
if (deps == null)
|
||||||
|
return null;
|
||||||
|
return deps.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.TYPE)
|
||||||
|
public @interface Depends {
|
||||||
|
Class<? extends Service>[] value();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,4 +46,19 @@ public interface Service {
|
|||||||
* if an error occurred
|
* if an error occurred
|
||||||
*/
|
*/
|
||||||
void restart() throws ServiceException;
|
void restart() throws ServiceException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if service is running
|
||||||
|
*/
|
||||||
|
boolean isStarted();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return false if service is not running
|
||||||
|
*/
|
||||||
|
boolean isStopped();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the other services that the service depends on
|
||||||
|
*/
|
||||||
|
Class<? extends Service>[] getDependencies();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,12 +16,16 @@
|
|||||||
*/
|
*/
|
||||||
package com.l2jserver.service;
|
package com.l2jserver.service;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.l2jserver.service.logging.LoggingService;
|
import com.l2jserver.service.logging.LoggingService;
|
||||||
|
import com.l2jserver.util.ClassUtils;
|
||||||
|
import com.l2jserver.util.factory.CollectionFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link ServiceManager} is responsible for starting and stopping services
|
* The {@link ServiceManager} is responsible for starting and stopping services
|
||||||
@@ -38,11 +42,14 @@ public class ServiceManager {
|
|||||||
*/
|
*/
|
||||||
private final Injector injector;
|
private final Injector injector;
|
||||||
|
|
||||||
|
private final Set<Service> knownServices = CollectionFactory.newSet(null);
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ServiceManager(Injector injector) {
|
public ServiceManager(Injector injector) {
|
||||||
this.injector = injector;
|
this.injector = injector;
|
||||||
final LoggingService service = injector
|
final LoggingService service = injector
|
||||||
.getInstance(LoggingService.class);
|
.getInstance(LoggingService.class);
|
||||||
|
knownServices.add(service);
|
||||||
try {
|
try {
|
||||||
service.start();
|
service.start();
|
||||||
} catch (ServiceStartException e) {
|
} catch (ServiceStartException e) {
|
||||||
@@ -56,7 +63,11 @@ public class ServiceManager {
|
|||||||
final T service = injector.getInstance(serviceClass);
|
final T service = injector.getInstance(serviceClass);
|
||||||
if (service == null)
|
if (service == null)
|
||||||
return null;
|
return null;
|
||||||
|
if (service.isStarted())
|
||||||
|
return service;
|
||||||
|
knownServices.add(service);
|
||||||
try {
|
try {
|
||||||
|
startDependencies(service.getDependencies());
|
||||||
logger.info("{}: Starting service...",
|
logger.info("{}: Starting service...",
|
||||||
serviceClass.getCanonicalName());
|
serviceClass.getCanonicalName());
|
||||||
service.start();
|
service.start();
|
||||||
@@ -64,19 +75,34 @@ public class ServiceManager {
|
|||||||
return service;
|
return service;
|
||||||
} catch (ServiceStartException e) {
|
} catch (ServiceStartException e) {
|
||||||
logger.error("{}: Error starting service: {}",
|
logger.error("{}: Error starting service: {}",
|
||||||
serviceClass.getCanonicalName(), e.getCause());
|
serviceClass.getCanonicalName(), e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void startDependencies(Class<? extends Service>[] dependencies)
|
||||||
|
throws ServiceStartException {
|
||||||
|
if (dependencies == null)
|
||||||
|
return;
|
||||||
|
if (dependencies.length == 0)
|
||||||
|
return;
|
||||||
|
for (final Class<? extends Service> serviceClass : dependencies) {
|
||||||
|
this.start(serviceClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void stop(Class<? extends Service> serviceClass)
|
public void stop(Class<? extends Service> serviceClass)
|
||||||
throws ServiceStopException {
|
throws ServiceStopException {
|
||||||
final Service service = injector.getInstance(serviceClass);
|
final Service service = injector.getInstance(serviceClass);
|
||||||
if (service == null)
|
if (service == null)
|
||||||
return;
|
return;
|
||||||
|
if (service.isStopped())
|
||||||
|
return;
|
||||||
|
knownServices.add(service);
|
||||||
try {
|
try {
|
||||||
logger.info("{0}: Stopping service...",
|
logger.info("{0}: Stopping service...",
|
||||||
serviceClass.getCanonicalName());
|
serviceClass.getCanonicalName());
|
||||||
|
stopDependencies(service);
|
||||||
service.stop();
|
service.stop();
|
||||||
logger.info("{0}: Service stopped!",
|
logger.info("{0}: Service stopped!",
|
||||||
serviceClass.getCanonicalName());
|
serviceClass.getCanonicalName());
|
||||||
@@ -87,16 +113,46 @@ public class ServiceManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void stopDependencies(Service service) throws ServiceStopException {
|
||||||
|
final Set<Class<? extends Service>> dependencies = createStopDependencies(
|
||||||
|
null, service);
|
||||||
|
for (final Class<? extends Service> dependency : dependencies) {
|
||||||
|
this.stop(dependency);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Set<Class<? extends Service>> createStopDependencies(
|
||||||
|
Set<Class<? extends Service>> depends, Service serviceClass) {
|
||||||
|
if (depends == null)
|
||||||
|
depends = CollectionFactory.newSet(null);
|
||||||
|
for (final Service service : knownServices) {
|
||||||
|
if (service.getDependencies() == null
|
||||||
|
|| service.getDependencies().length == 0)
|
||||||
|
continue;
|
||||||
|
for (final Class<? extends Service> dependency : service
|
||||||
|
.getDependencies()) {
|
||||||
|
if (!ClassUtils.isSubclass(service.getClass(), dependency))
|
||||||
|
continue;
|
||||||
|
depends.add(dependency);
|
||||||
|
createStopDependencies(depends,
|
||||||
|
injector.getInstance(dependency));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return depends;
|
||||||
|
}
|
||||||
|
|
||||||
public <T extends Service> T restart(Class<T> serviceClass)
|
public <T extends Service> T restart(Class<T> serviceClass)
|
||||||
throws ServiceStartException, ServiceStopException {
|
throws ServiceException {
|
||||||
final T service = injector.getInstance(serviceClass);
|
final T service = injector.getInstance(serviceClass);
|
||||||
if (service == null)
|
if (service == null)
|
||||||
return null;
|
return null;
|
||||||
|
if (service.isStopped())
|
||||||
|
throw new ServiceStopException("Service is already stopped");
|
||||||
|
knownServices.add(service);
|
||||||
try {
|
try {
|
||||||
logger.info("{0}: Restaring service...",
|
logger.info("{0}: Restaring service...",
|
||||||
serviceClass.getCanonicalName());
|
serviceClass.getCanonicalName());
|
||||||
service.stop();
|
service.restart();
|
||||||
service.start();
|
|
||||||
logger.info("{0}: Service restarted!",
|
logger.info("{0}: Service restarted!",
|
||||||
serviceClass.getCanonicalName());
|
serviceClass.getCanonicalName());
|
||||||
return service;
|
return service;
|
||||||
@@ -108,6 +164,10 @@ public class ServiceManager {
|
|||||||
logger.error("{0}: Error stopping service: {1}",
|
logger.error("{0}: Error stopping service: {1}",
|
||||||
serviceClass.getCanonicalName(), e.getCause());
|
serviceClass.getCanonicalName(), e.getCause());
|
||||||
throw e;
|
throw e;
|
||||||
|
} catch (ServiceException e) {
|
||||||
|
logger.error("{0}: Error restarting service: {1}",
|
||||||
|
serviceClass.getCanonicalName(), e.getCause());
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class PseudoRandomBlowfishKeygenService extends AbstractService
|
|||||||
private Random random;
|
private Random random;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() throws ServiceStartException {
|
protected void doStart() throws ServiceStartException {
|
||||||
random = new Random();
|
random = new Random();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ public class PseudoRandomBlowfishKeygenService extends AbstractService
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() throws ServiceStopException {
|
protected void doStop() throws ServiceStopException {
|
||||||
random = null;
|
random = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import org.apache.commons.math.random.RandomData;
|
|||||||
import org.apache.commons.math.random.RandomDataImpl;
|
import org.apache.commons.math.random.RandomDataImpl;
|
||||||
|
|
||||||
import com.l2jserver.service.AbstractService;
|
import com.l2jserver.service.AbstractService;
|
||||||
|
import com.l2jserver.service.Service;
|
||||||
import com.l2jserver.service.ServiceStartException;
|
import com.l2jserver.service.ServiceStartException;
|
||||||
import com.l2jserver.service.ServiceStopException;
|
import com.l2jserver.service.ServiceStopException;
|
||||||
|
|
||||||
@@ -38,7 +39,7 @@ public class SecureBlowfishKeygenService extends AbstractService implements
|
|||||||
private RandomData random;
|
private RandomData random;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() throws ServiceStartException {
|
protected void doStart() throws ServiceStartException {
|
||||||
random = new RandomDataImpl();
|
random = new RandomDataImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +64,7 @@ public class SecureBlowfishKeygenService extends AbstractService implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() throws ServiceStopException {
|
protected void doStop() throws ServiceStopException {
|
||||||
random = null;
|
random = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public class EhCacheService extends AbstractService implements CacheService {
|
|||||||
private Cache interfaceCache;
|
private Cache interfaceCache;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() throws ServiceStartException {
|
protected void doStart() throws ServiceStartException {
|
||||||
manager = new CacheManager();
|
manager = new CacheManager();
|
||||||
interfaceCache = createCache("interface-cache");
|
interfaceCache = createCache("interface-cache");
|
||||||
}
|
}
|
||||||
@@ -111,7 +111,7 @@ public class EhCacheService extends AbstractService implements CacheService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() throws ServiceStopException {
|
protected void doStop() throws ServiceStopException {
|
||||||
manager.removalAll();
|
manager.removalAll();
|
||||||
manager.shutdown();
|
manager.shutdown();
|
||||||
interfaceCache = null;
|
interfaceCache = null;
|
||||||
|
|||||||
@@ -32,10 +32,13 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.l2jserver.service.AbstractService;
|
import com.l2jserver.service.AbstractService;
|
||||||
|
import com.l2jserver.service.AbstractService.Depends;
|
||||||
import com.l2jserver.service.ServiceStartException;
|
import com.l2jserver.service.ServiceStartException;
|
||||||
|
import com.l2jserver.service.cache.CacheService;
|
||||||
import com.l2jserver.service.configuration.Configuration.ConfigurationName;
|
import com.l2jserver.service.configuration.Configuration.ConfigurationName;
|
||||||
import com.l2jserver.service.configuration.Configuration.ConfigurationPropertyGetter;
|
import com.l2jserver.service.configuration.Configuration.ConfigurationPropertyGetter;
|
||||||
import com.l2jserver.service.configuration.Configuration.ConfigurationPropertySetter;
|
import com.l2jserver.service.configuration.Configuration.ConfigurationPropertySetter;
|
||||||
|
import com.l2jserver.service.logging.LoggingService;
|
||||||
import com.l2jserver.util.transformer.Transformer;
|
import com.l2jserver.util.transformer.Transformer;
|
||||||
import com.l2jserver.util.transformer.TransformerFactory;
|
import com.l2jserver.util.transformer.TransformerFactory;
|
||||||
|
|
||||||
@@ -45,6 +48,7 @@ import com.l2jserver.util.transformer.TransformerFactory;
|
|||||||
*
|
*
|
||||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
*/
|
*/
|
||||||
|
@Depends({ LoggingService.class, CacheService.class })
|
||||||
public class ProxyConfigurationService extends AbstractService implements
|
public class ProxyConfigurationService extends AbstractService implements
|
||||||
ConfigurationService {
|
ConfigurationService {
|
||||||
/**
|
/**
|
||||||
@@ -63,7 +67,7 @@ public class ProxyConfigurationService extends AbstractService implements
|
|||||||
private Map<Class<?>, Object> cache = new WeakHashMap<Class<?>, Object>();
|
private Map<Class<?>, Object> cache = new WeakHashMap<Class<?>, Object>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() throws ServiceStartException {
|
protected void doStart() throws ServiceStartException {
|
||||||
if (!directory.exists())
|
if (!directory.exists())
|
||||||
if (!directory.mkdirs())
|
if (!directory.mkdirs())
|
||||||
throw new ServiceStartException("Failed to create directories");
|
throw new ServiceStartException("Failed to create directories");
|
||||||
|
|||||||
@@ -43,10 +43,13 @@ import com.google.inject.Inject;
|
|||||||
import com.l2jserver.model.id.ObjectID;
|
import com.l2jserver.model.id.ObjectID;
|
||||||
import com.l2jserver.model.world.WorldObject;
|
import com.l2jserver.model.world.WorldObject;
|
||||||
import com.l2jserver.service.AbstractService;
|
import com.l2jserver.service.AbstractService;
|
||||||
|
import com.l2jserver.service.AbstractService.Depends;
|
||||||
import com.l2jserver.service.ServiceStartException;
|
import com.l2jserver.service.ServiceStartException;
|
||||||
import com.l2jserver.service.ServiceStopException;
|
import com.l2jserver.service.ServiceStopException;
|
||||||
import com.l2jserver.service.cache.CacheService;
|
import com.l2jserver.service.cache.CacheService;
|
||||||
import com.l2jserver.service.configuration.ConfigurationService;
|
import com.l2jserver.service.configuration.ConfigurationService;
|
||||||
|
import com.l2jserver.service.game.template.TemplateService;
|
||||||
|
import com.l2jserver.service.logging.LoggingService;
|
||||||
import com.l2jserver.util.ArrayIterator;
|
import com.l2jserver.util.ArrayIterator;
|
||||||
import com.l2jserver.util.factory.CollectionFactory;
|
import com.l2jserver.util.factory.CollectionFactory;
|
||||||
|
|
||||||
@@ -55,6 +58,8 @@ import com.l2jserver.util.factory.CollectionFactory;
|
|||||||
*
|
*
|
||||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
*/
|
*/
|
||||||
|
@Depends({ LoggingService.class, CacheService.class,
|
||||||
|
ConfigurationService.class, TemplateService.class })
|
||||||
public class MySQLDatabaseService extends AbstractService implements
|
public class MySQLDatabaseService extends AbstractService implements
|
||||||
DatabaseService {
|
DatabaseService {
|
||||||
/**
|
/**
|
||||||
@@ -103,7 +108,7 @@ public class MySQLDatabaseService extends AbstractService implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() throws ServiceStartException {
|
protected void doStart() throws ServiceStartException {
|
||||||
connectionPool = new GenericObjectPool(null);
|
connectionPool = new GenericObjectPool(null);
|
||||||
connectionFactory = new DriverManagerConnectionFactory(
|
connectionFactory = new DriverManagerConnectionFactory(
|
||||||
config.getJdbcUrl(), config.getUsername(), config.getPassword());
|
config.getJdbcUrl(), config.getUsername(), config.getPassword());
|
||||||
@@ -170,7 +175,7 @@ public class MySQLDatabaseService extends AbstractService implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() throws ServiceStopException {
|
protected void doStop() throws ServiceStopException {
|
||||||
if (objectCache != null)
|
if (objectCache != null)
|
||||||
objectCache.dispose();
|
objectCache.dispose();
|
||||||
objectCache = null;
|
objectCache = null;
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ package com.l2jserver.service.game;
|
|||||||
import com.l2jserver.service.Service;
|
import com.l2jserver.service.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This service handles PVP battles.
|
* This service handles PvP battles.
|
||||||
*
|
*
|
||||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
*/
|
*/
|
||||||
public interface PVPService extends Service {
|
public interface PvPService extends Service {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -31,11 +31,17 @@ import com.l2jserver.service.game.chat.channel.PublicChatChannel;
|
|||||||
*/
|
*/
|
||||||
public interface ChatService extends Service {
|
public interface ChatService extends Service {
|
||||||
/**
|
/**
|
||||||
|
* Get the Global {@link ChatChannel}. Messages sent in this chat are
|
||||||
|
* broadcasted to everyone online.
|
||||||
|
*
|
||||||
* @return the global {@link ChatChannel}
|
* @return the global {@link ChatChannel}
|
||||||
*/
|
*/
|
||||||
PublicChatChannel getGlobalChannel();
|
PublicChatChannel getGlobalChannel();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get the Region {@link ChatChannel}. Messages sent in this chat are
|
||||||
|
* broadcasted to everyone nearby.
|
||||||
|
*
|
||||||
* @param character
|
* @param character
|
||||||
* the character in the region
|
* the character in the region
|
||||||
* @return the global {@link ChatChannel}
|
* @return the global {@link ChatChannel}
|
||||||
@@ -43,7 +49,8 @@ public interface ChatService extends Service {
|
|||||||
PublicChatChannel getRegionChannel(L2Character character);
|
PublicChatChannel getRegionChannel(L2Character character);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an private {@link ChatChannel} to {@link CharacterID}
|
* Get an private {@link ChatChannel} to {@link CharacterID}. Messages sent
|
||||||
|
* in this channel are sent only to <tt>character</tt>.
|
||||||
*
|
*
|
||||||
* @param character
|
* @param character
|
||||||
* the target character
|
* the target character
|
||||||
@@ -52,6 +59,9 @@ public interface ChatService extends Service {
|
|||||||
PrivateChatChannel getChannel(CharacterID character);
|
PrivateChatChannel getChannel(CharacterID character);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get the Clan {@link ChatChannel}. Messages sent in this channel are
|
||||||
|
* broadcast to all clan members online.
|
||||||
|
*
|
||||||
* @param clan
|
* @param clan
|
||||||
* the clan
|
* the clan
|
||||||
* @return the public clan {@link ChatChannel}
|
* @return the public clan {@link ChatChannel}
|
||||||
|
|||||||
@@ -24,11 +24,15 @@ import com.l2jserver.model.id.object.ClanID;
|
|||||||
import com.l2jserver.model.world.Clan;
|
import com.l2jserver.model.world.Clan;
|
||||||
import com.l2jserver.model.world.L2Character;
|
import com.l2jserver.model.world.L2Character;
|
||||||
import com.l2jserver.service.AbstractService;
|
import com.l2jserver.service.AbstractService;
|
||||||
|
import com.l2jserver.service.AbstractService.Depends;
|
||||||
import com.l2jserver.service.ServiceStartException;
|
import com.l2jserver.service.ServiceStartException;
|
||||||
|
import com.l2jserver.service.ServiceStopException;
|
||||||
import com.l2jserver.service.game.chat.channel.ChatChannel;
|
import com.l2jserver.service.game.chat.channel.ChatChannel;
|
||||||
import com.l2jserver.service.game.chat.channel.ChatChannelListener;
|
import com.l2jserver.service.game.chat.channel.ChatChannelListener;
|
||||||
import com.l2jserver.service.game.chat.channel.PrivateChatChannel;
|
import com.l2jserver.service.game.chat.channel.PrivateChatChannel;
|
||||||
import com.l2jserver.service.game.chat.channel.PublicChatChannel;
|
import com.l2jserver.service.game.chat.channel.PublicChatChannel;
|
||||||
|
import com.l2jserver.service.game.region.Region;
|
||||||
|
import com.l2jserver.service.game.region.RegionService;
|
||||||
import com.l2jserver.util.factory.CollectionFactory;
|
import com.l2jserver.util.factory.CollectionFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,7 +40,10 @@ import com.l2jserver.util.factory.CollectionFactory;
|
|||||||
*
|
*
|
||||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
*/
|
*/
|
||||||
|
@Depends(RegionService.class)
|
||||||
public class SimpleChatService extends AbstractService implements ChatService {
|
public class SimpleChatService extends AbstractService implements ChatService {
|
||||||
|
private final RegionService regionService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The global chat channel
|
* The global chat channel
|
||||||
*/
|
*/
|
||||||
@@ -51,12 +58,27 @@ public class SimpleChatService extends AbstractService implements ChatService {
|
|||||||
* The list of clan chat channels
|
* The list of clan chat channels
|
||||||
*/
|
*/
|
||||||
private Map<ClanID, ClanChatChannelImpl> clanChannels;
|
private Map<ClanID, ClanChatChannelImpl> clanChannels;
|
||||||
|
/**
|
||||||
|
* The list of regional chat channels
|
||||||
|
*/
|
||||||
|
private Map<Region, RegionChatChannelImpl> regionChannels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*
|
||||||
|
* @param regionService
|
||||||
|
* the region service
|
||||||
|
*/
|
||||||
|
public SimpleChatService(RegionService regionService) {
|
||||||
|
this.regionService = regionService;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() throws ServiceStartException {
|
protected void doStart() throws ServiceStartException {
|
||||||
this.global = new GlobalChatChannelImpl();
|
this.global = new GlobalChatChannelImpl();
|
||||||
this.privateChannels = CollectionFactory.newMap(null, null);
|
this.privateChannels = CollectionFactory.newMap(null, null);
|
||||||
this.clanChannels = CollectionFactory.newMap(null, null);
|
this.clanChannels = CollectionFactory.newMap(null, null);
|
||||||
|
this.regionChannels = CollectionFactory.newMap(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -66,8 +88,13 @@ public class SimpleChatService extends AbstractService implements ChatService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PublicChatChannel getRegionChannel(L2Character character) {
|
public PublicChatChannel getRegionChannel(L2Character character) {
|
||||||
// TODO Region chat channels
|
final Region region = regionService.getRegion(character);
|
||||||
return null;
|
RegionChatChannelImpl channel = regionChannels.get(region);
|
||||||
|
if (channel == null) {
|
||||||
|
channel = new RegionChatChannelImpl(region);
|
||||||
|
regionChannels.put(region, channel);
|
||||||
|
}
|
||||||
|
return channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -90,6 +117,14 @@ public class SimpleChatService extends AbstractService implements ChatService {
|
|||||||
return channel;
|
return channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doStop() throws ServiceStopException {
|
||||||
|
this.global = null;
|
||||||
|
this.privateChannels = null;
|
||||||
|
this.clanChannels = null;
|
||||||
|
this.regionChannels = null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link ChatChannel} abstract implementation
|
* {@link ChatChannel} abstract implementation
|
||||||
*
|
*
|
||||||
@@ -170,4 +205,27 @@ public class SimpleChatService extends AbstractService implements ChatService {
|
|||||||
this.clanID = clanID;
|
this.clanID = clanID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link PublicChatChannel} implemenetation for {@link Region regions}
|
||||||
|
*
|
||||||
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
|
*/
|
||||||
|
private class RegionChatChannelImpl extends ChatChannelImpl implements
|
||||||
|
PublicChatChannel {
|
||||||
|
/**
|
||||||
|
* The clan ID
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private final Region region;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*
|
||||||
|
* @param clanID
|
||||||
|
*/
|
||||||
|
public RegionChatChannelImpl(Region region) {
|
||||||
|
this.region = region;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.l2jserver.service.game.region;
|
package com.l2jserver.service.game.region;
|
||||||
|
|
||||||
import com.l2jserver.model.world.L2Character;
|
import com.l2jserver.model.world.capability.Actor;
|
||||||
import com.l2jserver.service.Service;
|
import com.l2jserver.service.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,5 +25,12 @@ import com.l2jserver.service.Service;
|
|||||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
*/
|
*/
|
||||||
public interface RegionService extends Service {
|
public interface RegionService extends Service {
|
||||||
Region getRegion(L2Character character);
|
/**
|
||||||
|
* Get the region in which this actor is.
|
||||||
|
*
|
||||||
|
* @param actor
|
||||||
|
* the actor
|
||||||
|
* @return the current region
|
||||||
|
*/
|
||||||
|
Region getRegion(Actor actor);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,13 +32,21 @@ import org.slf4j.LoggerFactory;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.l2jserver.service.AbstractService;
|
import com.l2jserver.service.AbstractService;
|
||||||
|
import com.l2jserver.service.AbstractService.Depends;
|
||||||
import com.l2jserver.service.ServiceStartException;
|
import com.l2jserver.service.ServiceStartException;
|
||||||
import com.l2jserver.service.ServiceStopException;
|
import com.l2jserver.service.ServiceStopException;
|
||||||
import com.l2jserver.service.game.scripting.impl.ScriptContextImpl;
|
import com.l2jserver.service.game.scripting.impl.ScriptContextImpl;
|
||||||
import com.l2jserver.service.game.scripting.scriptmanager.ScriptInfo;
|
import com.l2jserver.service.game.scripting.scriptmanager.ScriptInfo;
|
||||||
import com.l2jserver.service.game.scripting.scriptmanager.ScriptList;
|
import com.l2jserver.service.game.scripting.scriptmanager.ScriptList;
|
||||||
|
import com.l2jserver.service.logging.LoggingService;
|
||||||
import com.l2jserver.util.factory.CollectionFactory;
|
import com.l2jserver.util.factory.CollectionFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default {@link ScriptingService} implementation
|
||||||
|
*
|
||||||
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
|
*/
|
||||||
|
@Depends(LoggingService.class)
|
||||||
public class ScriptingServiceImpl extends AbstractService implements
|
public class ScriptingServiceImpl extends AbstractService implements
|
||||||
ScriptingService {
|
ScriptingService {
|
||||||
/**
|
/**
|
||||||
@@ -60,7 +68,7 @@ public class ScriptingServiceImpl extends AbstractService implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() throws ServiceStartException {
|
protected void doStart() throws ServiceStartException {
|
||||||
for (ScriptContext context : contexts) {
|
for (ScriptContext context : contexts) {
|
||||||
context.shutdown();
|
context.shutdown();
|
||||||
}
|
}
|
||||||
@@ -165,7 +173,7 @@ public class ScriptingServiceImpl extends AbstractService implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() throws ServiceStopException {
|
protected void doStop() throws ServiceStopException {
|
||||||
for (ScriptContext context : contexts) {
|
for (ScriptContext context : contexts) {
|
||||||
context.shutdown();
|
context.shutdown();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,13 +23,17 @@ import com.google.inject.Injector;
|
|||||||
import com.l2jserver.model.id.TemplateID;
|
import com.l2jserver.model.id.TemplateID;
|
||||||
import com.l2jserver.model.template.Template;
|
import com.l2jserver.model.template.Template;
|
||||||
import com.l2jserver.service.AbstractService;
|
import com.l2jserver.service.AbstractService;
|
||||||
|
import com.l2jserver.service.AbstractService.Depends;
|
||||||
import com.l2jserver.service.ServiceStartException;
|
import com.l2jserver.service.ServiceStartException;
|
||||||
import com.l2jserver.service.ServiceStopException;
|
import com.l2jserver.service.ServiceStopException;
|
||||||
import com.l2jserver.service.configuration.ConfigurationService;
|
import com.l2jserver.service.configuration.ConfigurationService;
|
||||||
import com.l2jserver.service.game.scripting.ScriptContext;
|
import com.l2jserver.service.game.scripting.ScriptContext;
|
||||||
import com.l2jserver.service.game.scripting.ScriptingService;
|
import com.l2jserver.service.game.scripting.ScriptingService;
|
||||||
|
import com.l2jserver.service.logging.LoggingService;
|
||||||
import com.l2jserver.util.factory.CollectionFactory;
|
import com.l2jserver.util.factory.CollectionFactory;
|
||||||
|
|
||||||
|
@Depends({ LoggingService.class, ConfigurationService.class,
|
||||||
|
ScriptingService.class })
|
||||||
public class ScriptTemplateService extends AbstractService implements
|
public class ScriptTemplateService extends AbstractService implements
|
||||||
TemplateService {
|
TemplateService {
|
||||||
private final ScriptingService scriptingService;
|
private final ScriptingService scriptingService;
|
||||||
@@ -52,7 +56,7 @@ public class ScriptTemplateService extends AbstractService implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() throws ServiceStartException {
|
protected void doStart() throws ServiceStartException {
|
||||||
if (context == null) {
|
if (context == null) {
|
||||||
try {
|
try {
|
||||||
context = scriptingService.load(config.getTemplateDescriptor())
|
context = scriptingService.load(config.getTemplateDescriptor())
|
||||||
@@ -94,7 +98,7 @@ public class ScriptTemplateService extends AbstractService implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() throws ServiceStopException {
|
protected void doStop() throws ServiceStopException {
|
||||||
if (context.isInitialized())
|
if (context.isInitialized())
|
||||||
context.shutdown();
|
context.shutdown();
|
||||||
context = null;
|
context = null;
|
||||||
|
|||||||
@@ -26,12 +26,17 @@ import org.slf4j.LoggerFactory;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.l2jserver.model.world.WorldObject;
|
import com.l2jserver.model.world.WorldObject;
|
||||||
import com.l2jserver.service.AbstractService;
|
import com.l2jserver.service.AbstractService;
|
||||||
|
import com.l2jserver.service.AbstractService.Depends;
|
||||||
import com.l2jserver.service.ServiceStartException;
|
import com.l2jserver.service.ServiceStartException;
|
||||||
import com.l2jserver.service.ServiceStopException;
|
import com.l2jserver.service.ServiceStopException;
|
||||||
|
import com.l2jserver.service.database.DatabaseService;
|
||||||
|
import com.l2jserver.service.game.scripting.ScriptingService;
|
||||||
|
import com.l2jserver.service.game.template.TemplateService;
|
||||||
import com.l2jserver.service.game.world.event.WorldEventDispatcher;
|
import com.l2jserver.service.game.world.event.WorldEventDispatcher;
|
||||||
import com.l2jserver.service.game.world.filter.FilterIterator;
|
import com.l2jserver.service.game.world.filter.FilterIterator;
|
||||||
import com.l2jserver.service.game.world.filter.WorldObjectFilter;
|
import com.l2jserver.service.game.world.filter.WorldObjectFilter;
|
||||||
import com.l2jserver.service.game.world.filter.impl.InstanceFilter;
|
import com.l2jserver.service.game.world.filter.impl.InstanceFilter;
|
||||||
|
import com.l2jserver.service.logging.LoggingService;
|
||||||
import com.l2jserver.util.factory.CollectionFactory;
|
import com.l2jserver.util.factory.CollectionFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,6 +44,8 @@ import com.l2jserver.util.factory.CollectionFactory;
|
|||||||
*
|
*
|
||||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
*/
|
*/
|
||||||
|
@Depends({ LoggingService.class, TemplateService.class, ScriptingService.class,
|
||||||
|
DatabaseService.class })
|
||||||
public class WorldServiceImpl extends AbstractService implements WorldService {
|
public class WorldServiceImpl extends AbstractService implements WorldService {
|
||||||
/**
|
/**
|
||||||
* The logger
|
* The logger
|
||||||
@@ -62,7 +69,7 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() throws ServiceStartException {
|
protected void doStart() throws ServiceStartException {
|
||||||
objects.clear();
|
objects.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,7 +134,7 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() throws ServiceStopException {
|
protected void doStop() throws ServiceStopException {
|
||||||
objects.clear();
|
objects.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import com.l2jserver.service.ServiceStartException;
|
|||||||
public class Log4JLoggingService extends AbstractService implements
|
public class Log4JLoggingService extends AbstractService implements
|
||||||
LoggingService {
|
LoggingService {
|
||||||
@Override
|
@Override
|
||||||
public void start() throws ServiceStartException {
|
protected void doStart() throws ServiceStartException {
|
||||||
BasicConfigurator.configure();
|
BasicConfigurator.configure();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,11 @@ import com.l2jserver.game.net.Lineage2Connection;
|
|||||||
import com.l2jserver.game.net.Lineage2PipelineFactory;
|
import com.l2jserver.game.net.Lineage2PipelineFactory;
|
||||||
import com.l2jserver.model.id.object.CharacterID;
|
import com.l2jserver.model.id.object.CharacterID;
|
||||||
import com.l2jserver.service.AbstractService;
|
import com.l2jserver.service.AbstractService;
|
||||||
|
import com.l2jserver.service.AbstractService.Depends;
|
||||||
|
import com.l2jserver.service.blowfish.BlowfishKeygenService;
|
||||||
import com.l2jserver.service.configuration.ConfigurationService;
|
import com.l2jserver.service.configuration.ConfigurationService;
|
||||||
|
import com.l2jserver.service.game.world.WorldService;
|
||||||
|
import com.l2jserver.service.logging.LoggingService;
|
||||||
import com.l2jserver.util.factory.CollectionFactory;
|
import com.l2jserver.util.factory.CollectionFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,6 +45,8 @@ import com.l2jserver.util.factory.CollectionFactory;
|
|||||||
*
|
*
|
||||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
*/
|
*/
|
||||||
|
@Depends({ LoggingService.class, BlowfishKeygenService.class,
|
||||||
|
WorldService.class })
|
||||||
public class NettyNetworkService extends AbstractService implements
|
public class NettyNetworkService extends AbstractService implements
|
||||||
NetworkService {
|
NetworkService {
|
||||||
/**
|
/**
|
||||||
@@ -75,7 +81,7 @@ public class NettyNetworkService extends AbstractService implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
protected void doStart() {
|
||||||
server = new ServerBootstrap(new NioServerSocketChannelFactory(
|
server = new ServerBootstrap(new NioServerSocketChannelFactory(
|
||||||
Executors.newCachedThreadPool(),
|
Executors.newCachedThreadPool(),
|
||||||
Executors.newCachedThreadPool()));
|
Executors.newCachedThreadPool()));
|
||||||
@@ -116,7 +122,7 @@ public class NettyNetworkService extends AbstractService implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
protected void doStop() {
|
||||||
try {
|
try {
|
||||||
channel.close().awaitUninterruptibly();
|
channel.close().awaitUninterruptibly();
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -26,12 +26,10 @@ import com.l2jserver.GameServerModule;
|
|||||||
import com.l2jserver.db.dao.CharacterDAO;
|
import com.l2jserver.db.dao.CharacterDAO;
|
||||||
import com.l2jserver.model.id.object.factory.CharacterIDFactory;
|
import com.l2jserver.model.id.object.factory.CharacterIDFactory;
|
||||||
import com.l2jserver.model.world.L2Character;
|
import com.l2jserver.model.world.L2Character;
|
||||||
|
import com.l2jserver.service.ServiceManager;
|
||||||
import com.l2jserver.service.ServiceStartException;
|
import com.l2jserver.service.ServiceStartException;
|
||||||
import com.l2jserver.service.cache.CacheService;
|
|
||||||
import com.l2jserver.service.database.DatabaseService;
|
import com.l2jserver.service.database.DatabaseService;
|
||||||
import com.l2jserver.service.game.scripting.ScriptingService;
|
|
||||||
import com.l2jserver.service.game.template.TemplateService;
|
import com.l2jserver.service.game.template.TemplateService;
|
||||||
import com.l2jserver.service.logging.LoggingService;
|
|
||||||
|
|
||||||
public class MySQL5CharacterDAOTest {
|
public class MySQL5CharacterDAOTest {
|
||||||
private final Injector injector = Guice
|
private final Injector injector = Guice
|
||||||
@@ -39,11 +37,8 @@ public class MySQL5CharacterDAOTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCachedLoad() throws ServiceStartException {
|
public void testCachedLoad() throws ServiceStartException {
|
||||||
injector.getInstance(LoggingService.class).start();
|
injector.getInstance(ServiceManager.class).start(TemplateService.class);
|
||||||
injector.getInstance(CacheService.class).start();
|
injector.getInstance(ServiceManager.class).start(DatabaseService.class);
|
||||||
injector.getInstance(DatabaseService.class).start();
|
|
||||||
injector.getInstance(ScriptingService.class).start();
|
|
||||||
injector.getInstance(TemplateService.class).start();
|
|
||||||
|
|
||||||
final CharacterDAO dao = injector.getInstance(CharacterDAO.class);
|
final CharacterDAO dao = injector.getInstance(CharacterDAO.class);
|
||||||
final L2Character char1 = dao.load(injector.getInstance(
|
final L2Character char1 = dao.load(injector.getInstance(
|
||||||
|
|||||||
Reference in New Issue
Block a user