1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-09 17:02:53 +00:00

Change-Id: If18611eb0a6296da808aead8f1da54be094db2a9

This commit is contained in:
rogiel
2011-04-29 20:17:45 -03:00
parent 43403d9a1e
commit 0662150229
48 changed files with 612 additions and 513 deletions

View File

@@ -1,19 +0,0 @@
package com.l2jserver.service;
public interface Service {
/**
* Start this service
*
* @throws ServiceStartException
* if an error occurred
*/
void start() throws ServiceStartException;
/**
* Stop this service
*
* @throws ServiceStartException
* if an error occurred
*/
void stop() throws ServiceStopException;
}

View File

@@ -1,21 +0,0 @@
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);
}
}

View File

@@ -1,10 +0,0 @@
package com.l2jserver.service;
import com.google.inject.AbstractModule;
public class ServiceModule extends AbstractModule {
@Override
protected void configure() {
install(new BasicServiceModule());
}
}

View File

@@ -1,21 +0,0 @@
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);
}
}

View File

@@ -1,21 +0,0 @@
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);
}
}

View File

@@ -0,0 +1,15 @@
package com.l2jserver.service.game.world;
import com.l2jserver.model.world.event.WorldEvent;
/**
* {@link WorldEventDispatcher} implementation
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class WorldEventDispatcherImpl implements WorldEventDispatcher {
public void dispatch(WorldEvent event) {
// TODO implement threaded model
event.dispatch();
}
}

View File

@@ -1,22 +1,95 @@
package com.l2jserver.service.game.world;
import java.util.Iterator;
import java.util.List;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.model.world.filter.WorldObjectFilter;
import com.l2jserver.service.Service;
/**
* Service responsible for managing {@link WorldObject} and dispatch events.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface WorldService extends Service, Iterable<WorldObject> {
/**
* Register a new {@link WorldObject} to the service.
* Adds an object into the world.
*
* @param object
* the object
*/
void register(WorldObject object);
public void add(WorldObject object);
/**
* Removes an registered {@link WorldObject} from the service.
* Removes an object of the world
*
* @param object
* the object
*/
void unregister(WorldObject object);
public void remove(WorldObject object);
/**
* Check if this object is in the world.
*
* @param object
* the object
* @return true if object exists
*/
public boolean contains(WorldObject object);
/**
* Get the event dispatcher
*
* @return the event dispatcher
*/
public WorldEventDispatcher getEventDispatcher();
/**
* Creates a list of all objects matching <tt>filter</tt>
*
* @param <T>
* the object type
* @param filter
* the filter
* @return the list of objects
*/
public <T extends WorldObject> List<T> list(WorldObjectFilter<T> filter);
/**
* Creates a list of all objects of type <tt>type</tt>
*
* @param <T>
* the type
* @param type
* the type class
* @return the list of objects
*/
<T extends WorldObject> List<T> list(Class<T> type);
/**
* Get the iterator for this <tt>filter</tt>
*
* @param <T>
* the object type
* @param filter
* the filter
* @return the iterator instance
*/
<T extends WorldObject> Iterator<T> iterator(
final WorldObjectFilter<T> filter);
/**
* Shortcut method for {@link Iterable#iterable()} with filters. The
* iterable instance returns the same {@link Iterator} as
* {@link #iterator(WorldObjectFilter)}.
*
* @param <T>
* the object type
* @param filter
* the filter
* @return the iterable instance
*/
<T extends WorldObject> Iterable<T> iterable(
final WorldObjectFilter<T> filter);
}

View File

@@ -1,45 +1,91 @@
package com.l2jserver.service.game.world;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import com.google.inject.Inject;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.model.world.filter.WorldObjectFilter;
import com.l2jserver.model.world.filter.impl.InstanceFilter;
import com.l2jserver.model.world.iterator.FilterIterator;
import com.l2jserver.service.ServiceStartException;
import com.l2jserver.service.ServiceStopException;
import com.l2jserver.util.factory.CollectionFactory;
public class WorldServiceImpl implements WorldService {
private final Set<WorldObject> objects = CollectionFactory
.newSet(WorldObject.class);
private final WorldEventDispatcher dispatcher;
@Inject
public WorldServiceImpl(WorldEventDispatcher dispatcher) {
this.dispatcher = dispatcher;
}
@Override
public void start() throws ServiceStartException {
// TODO Auto-generated method stub
objects.clear();
}
@Override
public void register(WorldObject object) {
// TODO Auto-generated method stub
public void add(WorldObject object) {
objects.add(object);
}
@Override
public void unregister(WorldObject object) {
// TODO Auto-generated method stub
public void remove(WorldObject object) {
objects.remove(object);
}
@Override
public boolean contains(WorldObject object) {
return objects.contains(object);
}
@Override
public WorldEventDispatcher getEventDispatcher() {
return dispatcher;
}
@Override
public <T extends WorldObject> List<T> list(WorldObjectFilter<T> filter) {
final List<T> list = CollectionFactory.newList(null);
for (final T object : this.iterable(filter)) {
list.add(object);
}
return list;
}
@Override
public <T extends WorldObject> List<T> list(Class<T> type) {
return list(new InstanceFilter<T>(type));
}
@Override
public Iterator<WorldObject> iterator() {
// return objects.iterator();
return null;
return objects.iterator();
}
public <T extends WorldObject> Iterator<T> iterator(WorldObjectFilter<T> filter) {
// return objects.iterator();
return null;
@Override
public <T extends WorldObject> Iterator<T> iterator(
final WorldObjectFilter<T> filter) {
return new FilterIterator<T>(filter, objects.iterator());
}
@Override
public <T extends WorldObject> Iterable<T> iterable(
final WorldObjectFilter<T> filter) {
return new Iterable<T>() {
@Override
public Iterator<T> iterator() {
return new FilterIterator<T>(filter, objects.iterator());
}
};
}
@Override
public void stop() throws ServiceStopException {
// TODO Auto-generated method stub
objects.clear();
}
}

View File

@@ -7,16 +7,22 @@ import org.jboss.netty.channel.ServerChannel;
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.Lineage2PipelineFactory;
import com.l2jserver.service.configuration.ConfigurationService;
public class NettyNetworkService implements NetworkService {
private final NetworkConfiguration config;
private final Injector injector;
private ServerBootstrap server;
private ServerChannel channel;
@Inject
public NettyNetworkService(ConfigurationService configService) {
public NettyNetworkService(ConfigurationService configService,
Injector injector) {
this.config = configService.get(NetworkConfiguration.class);
this.injector = injector;
}
@Override
@@ -24,6 +30,7 @@ public class NettyNetworkService implements NetworkService {
server = new ServerBootstrap(new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
server.setPipelineFactory(new Lineage2PipelineFactory(injector));
channel = (ServerChannel) server.bind(config.getListenAddress());
}

View File

@@ -13,7 +13,7 @@ public interface NetworkConfiguration extends Configuration {
*
* @return the listen address
*/
@ConfigurationPropertyGetter(name = "listen", defaultValue = "0.0.0.0:54")
@ConfigurationPropertyGetter(name = "listen", defaultValue = "0.0.0.0:7777")
InetSocketAddress getListenAddress();
/**

View File

@@ -1,7 +1,7 @@
package com.l2jserver.service.network;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.service.Service;
public interface NetworkService extends Service {
}