mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-09 17:02:53 +00:00
Change-Id: I0000000000000000000000000000000000000000
Change-Id: I8636776eaf000fcdfb528cc403710f6d6ee9e73e Change-Id: Iebc523681d07ecd6d7b7e89343b29a8034558f94
This commit is contained in:
@@ -2,6 +2,10 @@ package com.l2jserver.service;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Scopes;
|
||||
import com.l2jserver.service.game.scripting.ScriptingService;
|
||||
import com.l2jserver.service.game.scripting.ScriptingServiceImpl;
|
||||
import com.l2jserver.service.game.template.StaticTemplateService;
|
||||
import com.l2jserver.service.game.template.TemplateService;
|
||||
import com.l2jserver.service.game.world.WorldEventDispatcher;
|
||||
import com.l2jserver.service.game.world.WorldEventDispatcherImpl;
|
||||
import com.l2jserver.service.game.world.WorldService;
|
||||
@@ -14,6 +18,10 @@ public class ServiceModule extends AbstractModule {
|
||||
protected void configure() {
|
||||
bind(NetworkService.class).to(NettyNetworkService.class).in(
|
||||
Scopes.SINGLETON);
|
||||
bind(ScriptingService.class).to(ScriptingServiceImpl.class).in(
|
||||
Scopes.SINGLETON);
|
||||
bind(TemplateService.class).to(StaticTemplateService.class).in(
|
||||
Scopes.SINGLETON);
|
||||
|
||||
bind(WorldService.class).to(WorldServiceImpl.class)
|
||||
.in(Scopes.SINGLETON);
|
||||
|
||||
@@ -212,7 +212,7 @@ public class ScriptContextImpl implements ScriptContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ScriptContext> getChildScriptContexts() {
|
||||
public synchronized Collection<ScriptContext> getChildScriptContexts() {
|
||||
return childScriptContexts;
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ public class ScriptContextImpl implements ScriptContext {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void addChildScriptContext(ScriptContext context) {
|
||||
public synchronized void addChildScriptContext(ScriptContext context) {
|
||||
synchronized (this) {
|
||||
if (childScriptContexts == null) {
|
||||
childScriptContexts = new HashSet<ScriptContext>();
|
||||
|
||||
@@ -19,6 +19,8 @@ package com.l2jserver.service.game.scripting.impl.javacc;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -109,11 +111,20 @@ public class ClassFileManager extends
|
||||
@Override
|
||||
public synchronized ScriptClassLoaderImpl getClassLoader(Location location) {
|
||||
if (loader == null) {
|
||||
if (parentClassLoader != null) {
|
||||
loader = new ScriptClassLoaderImpl(this, parentClassLoader);
|
||||
} else {
|
||||
loader = new ScriptClassLoaderImpl(this);
|
||||
}
|
||||
return AccessController
|
||||
.doPrivileged(new PrivilegedAction<ScriptClassLoaderImpl>() {
|
||||
@Override
|
||||
public ScriptClassLoaderImpl run() {
|
||||
if (parentClassLoader != null) {
|
||||
return new ScriptClassLoaderImpl(
|
||||
ClassFileManager.this,
|
||||
ClassFileManager.this.parentClassLoader);
|
||||
} else {
|
||||
return new ScriptClassLoaderImpl(
|
||||
ClassFileManager.this);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return loader;
|
||||
}
|
||||
|
||||
@@ -25,8 +25,7 @@ import java.net.URLConnection;
|
||||
|
||||
/**
|
||||
* This class represents URL Connection that is used to "connect" to scripts
|
||||
* binary data that was loaded by specified
|
||||
* {@link ScriptCompilerImpl}.<br>
|
||||
* binary data that was loaded by specified {@link ScriptCompilerImpl}.<br>
|
||||
* <br>
|
||||
* TODO: Implement all methods of {@link URLConnection} to ensure valid
|
||||
* behaviour
|
||||
|
||||
@@ -22,6 +22,7 @@ public class StaticTemplateService extends AbstractService implements
|
||||
|
||||
private ScriptContext context;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private Map<TemplateID, Template> templates = CollectionFactory.newMap(
|
||||
TemplateID.class, Template.class);
|
||||
|
||||
@@ -52,18 +53,18 @@ public class StaticTemplateService extends AbstractService implements
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Template> T getTemplate(TemplateID<T> id) {
|
||||
public <T extends Template<?>> T getTemplate(TemplateID<T> id) {
|
||||
return (T) templates.get(id);
|
||||
}
|
||||
|
||||
public void addTemplate(Class<? extends Template> t) {
|
||||
final Template template = injector.getInstance(t);
|
||||
public void addTemplate(Class<? extends Template<?>> t) {
|
||||
final Template<?> template = injector.getInstance(t);
|
||||
System.out.println(template.getID() + " -> " + template);
|
||||
if (template.getID() != null)
|
||||
templates.put(template.getID(), template);
|
||||
}
|
||||
|
||||
public void removeTemplate(Template t) {
|
||||
public void removeTemplate(Template<?> t) {
|
||||
// TODO templates.remove(t);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.l2jserver.service.configuration.Configuration.ConfigurationName;
|
||||
public interface StaticTemplateServiceConfiguration extends Configuration {
|
||||
@ConfigurationPropertyGetter(name = "template.descriptor", defaultValue = "data/script/template/template.xml")
|
||||
File getTemplateDescriptor();
|
||||
|
||||
@ConfigurationPropertySetter(name = "template.descriptor")
|
||||
void setTemplateDescriptor(File file);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public interface TemplateService extends Service {
|
||||
* the template id
|
||||
* @return the template
|
||||
*/
|
||||
<T extends Template> T getTemplate(TemplateID<T> id);
|
||||
<T extends Template<?>> T getTemplate(TemplateID<T> id);
|
||||
|
||||
/**
|
||||
* Reload the template list.
|
||||
|
||||
@@ -4,6 +4,9 @@ import java.util.Queue;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.l2jserver.model.id.ObjectID;
|
||||
import com.l2jserver.model.world.capability.Listenable;
|
||||
import com.l2jserver.model.world.event.WorldEvent;
|
||||
@@ -16,6 +19,9 @@ import com.l2jserver.util.factory.CollectionFactory;
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class WorldEventDispatcherImpl implements WorldEventDispatcher {
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(WorldEventDispatcherImpl.class);
|
||||
|
||||
private final Timer timer = new Timer();
|
||||
|
||||
private Queue<ListenerIDPair> listeners = CollectionFactory
|
||||
@@ -39,10 +45,12 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
|
||||
}
|
||||
|
||||
public void dispatch(WorldEvent event) {
|
||||
log.debug("Queing dispatch for event {}", event);
|
||||
events.add(event);
|
||||
}
|
||||
|
||||
public void doDispatch(WorldEvent event) {
|
||||
log.debug("Dispatching event {}", event);
|
||||
final Listenable<?, ?>[] objects = event.getDispatchableObjects();
|
||||
for (final ListenerIDPair pair : listeners) {
|
||||
for (Listenable<?, ?> obj : objects) {
|
||||
@@ -54,6 +62,9 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
|
||||
if (pair.dispatch(event))
|
||||
continue;
|
||||
} catch (ClassCastException e) {
|
||||
log.debug(
|
||||
"Exception in Listener. This might indicate an implementation issue in {}",
|
||||
pair.listener.getClass());
|
||||
}
|
||||
listeners.remove(pair);
|
||||
}
|
||||
@@ -64,6 +75,7 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
|
||||
@SuppressWarnings("unchecked")
|
||||
public <E extends WorldEvent, L extends WorldListener<E>> void addListener(
|
||||
Listenable<L, E> object, WorldListener<E> listener) {
|
||||
log.debug("Adding new listener {} to {}", listener, object.getID());
|
||||
listeners.add(new ListenerIDPair(object.getID(),
|
||||
(WorldListener<WorldEvent>) listener));
|
||||
}
|
||||
@@ -72,6 +84,7 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
|
||||
@SuppressWarnings("unchecked")
|
||||
public <E extends WorldEvent, L extends WorldListener<E>> void addListener(
|
||||
ObjectID<? extends Listenable<L, E>> id, WorldListener<E> listener) {
|
||||
log.debug("Adding new listener {} to {}", listener, id);
|
||||
listeners.add(new ListenerIDPair(id,
|
||||
(WorldListener<WorldEvent>) listener));
|
||||
}
|
||||
@@ -80,6 +93,7 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
|
||||
@SuppressWarnings("unchecked")
|
||||
public <E extends WorldEvent, L extends WorldListener<E>> void removeListener(
|
||||
Listenable<L, E> object, WorldListener<E> listener) {
|
||||
log.debug("Removing new listener {} from {}", listener, object.getID());
|
||||
listeners.remove(new ListenerIDPair(object.getID(),
|
||||
(WorldListener<WorldEvent>) listener));
|
||||
}
|
||||
@@ -88,6 +102,7 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
|
||||
@SuppressWarnings("unchecked")
|
||||
public <E extends WorldEvent, L extends WorldListener<E>> void removeListener(
|
||||
ObjectID<? extends Listenable<L, E>> id, WorldListener<E> listener) {
|
||||
log.debug("Removing new listener {} from {}", listener, id);
|
||||
listeners.remove(new ListenerIDPair(id,
|
||||
(WorldListener<WorldEvent>) listener));
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.l2jserver.model.world.WorldObject;
|
||||
import com.l2jserver.model.world.filter.WorldObjectFilter;
|
||||
@@ -15,6 +18,9 @@ import com.l2jserver.service.ServiceStopException;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
public class WorldServiceImpl extends AbstractService implements WorldService {
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(WorldServiceImpl.class);
|
||||
|
||||
private final Set<WorldObject> objects = CollectionFactory
|
||||
.newSet(WorldObject.class);
|
||||
private final WorldEventDispatcher dispatcher;
|
||||
@@ -31,11 +37,13 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
|
||||
|
||||
@Override
|
||||
public void add(WorldObject object) {
|
||||
log.debug("Adding object {} to world", object);
|
||||
objects.add(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(WorldObject object) {
|
||||
log.debug("Removing object {} from world", object);
|
||||
objects.remove(object);
|
||||
}
|
||||
|
||||
@@ -51,6 +59,7 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
|
||||
|
||||
@Override
|
||||
public <T extends WorldObject> List<T> list(WorldObjectFilter<T> filter) {
|
||||
log.debug("Listing objects with filter {}", filter);
|
||||
final List<T> list = CollectionFactory.newList(null);
|
||||
for (final T object : this.iterable(filter)) {
|
||||
list.add(object);
|
||||
@@ -60,6 +69,7 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
|
||||
|
||||
@Override
|
||||
public <T extends WorldObject> List<T> list(Class<T> type) {
|
||||
log.debug("Listing of type {}", type);
|
||||
return list(new InstanceFilter<T>(type));
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@ import com.l2jserver.game.net.Lineage2PipelineFactory;
|
||||
import com.l2jserver.service.AbstractService;
|
||||
import com.l2jserver.service.configuration.ConfigurationService;
|
||||
|
||||
public class NettyNetworkService extends AbstractService implements NetworkService {
|
||||
public class NettyNetworkService extends AbstractService implements
|
||||
NetworkService {
|
||||
private final NetworkConfiguration config;
|
||||
private final Injector injector;
|
||||
private ServerBootstrap server;
|
||||
|
||||
Reference in New Issue
Block a user