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

Service exceptions externalized and better logging configuration

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-21 22:41:27 -03:00
parent ab38e7d5ba
commit b3ff0795ec
44 changed files with 559 additions and 215 deletions

View File

@@ -0,0 +1,11 @@
package com.l2jserver.service.game.character;
/**
* Exception thrown when the target cannot be set
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CannotSetTargetServiceException extends
CharacterServiceException {
private static final long serialVersionUID = 1L;
}

View File

@@ -0,0 +1,11 @@
package com.l2jserver.service.game.character;
/**
* Exception thrown when the character is in jail
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CharacterInJailServiceException extends
CharacterServiceException {
private static final long serialVersionUID = 1L;
}

View File

@@ -0,0 +1,11 @@
package com.l2jserver.service.game.character;
/**
* Exception thrown when the character is <b>not</b> in jail
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CharacterNotInJailServiceException extends
CharacterServiceException {
private static final long serialVersionUID = 1L;
}

View File

@@ -14,17 +14,16 @@
* 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.service.game;
package com.l2jserver.service.game.character;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.service.Service;
import com.l2jserver.service.game.SpawnService.AlreadySpawnedServiceException;
import com.l2jserver.service.game.SpawnService.NotSpawnedServiceException;
import com.l2jserver.service.game.SpawnService.SpawnPointNotFoundServiceException;
import com.l2jserver.service.game.spawn.AlreadySpawnedServiceException;
import com.l2jserver.service.game.spawn.NotSpawnedServiceException;
import com.l2jserver.service.game.spawn.SpawnPointNotFoundServiceException;
import com.l2jserver.util.dimensional.Coordinate;
import com.l2jserver.util.dimensional.Point;
import com.l2jserver.util.exception.L2ChatServiceException;
/**
* This service manages {@link L2Character} instances
@@ -105,7 +104,8 @@ public interface CharacterService extends Service {
* @throws CharacterNotInJailServiceException
* if character is not in jail
*/
void unjail(L2Character character) throws CharacterNotInJailServiceException;
void unjail(L2Character character)
throws CharacterNotInJailServiceException;
/**
* Moves the given <tt>character</tt> to <tt>coordinate</tt>
@@ -152,32 +152,4 @@ public interface CharacterService extends Service {
* the character
*/
void run(L2Character character);
/**
* Exception thrown when the target cannot be set
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CannotSetTargetServiceException extends L2ChatServiceException {
private static final long serialVersionUID = 1L;
}
/**
* Exception thrown when the character is in jail
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CharacterInJailServiceException extends L2ChatServiceException {
private static final long serialVersionUID = 1L;
}
/**
* Exception thrown when the character is <b>not</b> in jail
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CharacterNotInJailServiceException extends
L2ChatServiceException {
private static final long serialVersionUID = 1L;
}
}

View File

@@ -0,0 +1,42 @@
/*
* 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.service.game.character;
import com.l2jserver.service.ServiceException;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CharacterServiceException extends ServiceException {
private static final long serialVersionUID = 1L;
public CharacterServiceException() {
super();
}
public CharacterServiceException(String message, Throwable cause) {
super(message, cause);
}
public CharacterServiceException(String message) {
super(message);
}
public CharacterServiceException(Throwable cause) {
super(cause);
}
}

View File

@@ -14,7 +14,7 @@
* 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.service.game;
package com.l2jserver.service.game.character;
import com.google.common.base.Preconditions;
import com.google.inject.Inject;
@@ -48,13 +48,14 @@ import com.l2jserver.model.world.character.event.CharacterTargetSelectedEvent;
import com.l2jserver.model.world.npc.event.NPCSpawnEvent;
import com.l2jserver.service.AbstractService;
import com.l2jserver.service.AbstractService.Depends;
import com.l2jserver.service.game.SpawnService.AlreadySpawnedServiceException;
import com.l2jserver.service.game.SpawnService.NotSpawnedServiceException;
import com.l2jserver.service.game.SpawnService.SpawnPointNotFoundServiceException;
import com.l2jserver.service.game.chat.ChatMessageDestination;
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.spawn.AlreadySpawnedServiceException;
import com.l2jserver.service.game.spawn.NotSpawnedServiceException;
import com.l2jserver.service.game.spawn.SpawnPointNotFoundServiceException;
import com.l2jserver.service.game.spawn.SpawnService;
import com.l2jserver.service.game.world.WorldService;
import com.l2jserver.service.game.world.event.FilteredWorldListener;
import com.l2jserver.service.game.world.event.WorldEvent;

View File

@@ -0,0 +1,12 @@
package com.l2jserver.service.game.chat;
/**
* Exception thrown if the player is trying to chat with itself.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CannotChatToSelfChatServiceException extends
ChatServiceException {
private static final long serialVersionUID = 1L;
}

View File

@@ -0,0 +1,13 @@
package com.l2jserver.service.game.chat;
/**
* Exception thrown if the player trying to send a message is currently
* banned.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class ChatBanActiveChatServiceException extends
ChatServiceException {
private static final long serialVersionUID = 1L;
}

View File

@@ -23,7 +23,6 @@ import com.l2jserver.service.Service;
import com.l2jserver.service.game.chat.channel.ChatChannel;
import com.l2jserver.service.game.chat.channel.PrivateChatChannel;
import com.l2jserver.service.game.chat.channel.PublicChatChannel;
import com.l2jserver.util.exception.L2ChatServiceException;
/**
* This service chatting in the server
@@ -107,37 +106,4 @@ public interface ChatService extends Service {
* @return the public clan {@link ChatChannel}
*/
PublicChatChannel getChannel(ClanID clan);
// TODO party chat
/**
* Exception thrown when the target of an private chat is not found
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class TargetNotFoundChatServiceException extends
L2ChatServiceException {
private static final long serialVersionUID = 1L;
}
/**
* Exception thrown if the player is trying to chat with itself.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CannotChatToSelfChatServiceException extends
L2ChatServiceException {
private static final long serialVersionUID = 1L;
}
/**
* Exception thrown if the player trying to send a message is currently
* banned.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class ChatBanActiveChatServiceException extends
L2ChatServiceException {
private static final long serialVersionUID = 1L;
}
}

View File

@@ -0,0 +1,42 @@
/*
* 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.service.game.chat;
import com.l2jserver.service.ServiceException;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class ChatServiceException extends ServiceException {
private static final long serialVersionUID = 1L;
public ChatServiceException() {
super();
}
public ChatServiceException(String message, Throwable cause) {
super(message, cause);
}
public ChatServiceException(String message) {
super(message);
}
public ChatServiceException(Throwable cause) {
super(cause);
}
}

View File

@@ -0,0 +1,12 @@
package com.l2jserver.service.game.chat;
/**
* Exception thrown when the target of an private chat is not found
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class TargetNotFoundChatServiceException extends
ChatServiceException {
private static final long serialVersionUID = 1L;
}

View File

@@ -17,7 +17,7 @@
package com.l2jserver.service.game.chat.channel;
import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.service.game.chat.ChatService.ChatBanActiveChatServiceException;
import com.l2jserver.service.game.chat.ChatBanActiveChatServiceException;
/**
* The {@link ChatChannel} object is used to send messages to a channel.

View File

@@ -0,0 +1,23 @@
package com.l2jserver.service.game.npc;
import com.l2jserver.util.exception.L2Exception;
/**
* Exception thrown when the action implementation thrown an exception. Will
* always contain an <tt>cause</tt>
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class ActionServiceException extends NPCServiceException {
private static final long serialVersionUID = 1L;
/**
* Creates a new instance
*
* @param cause
* the cause
*/
public ActionServiceException(L2Exception cause) {
super(cause);
}
}

View File

@@ -0,0 +1,57 @@
/*
* 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.service.game.npc;
import com.l2jserver.game.net.packet.client.CharacterActionPacket.CharacterAction;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.NPC;
import com.l2jserver.service.Service;
/**
* This service manages {@link NPC} instances
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface NPCService extends Service {
/**
* Executes an action for an NPC. Each {@link NPCTemplate} have it's own
* actions.
*
* @param npc
* the npc
* @param character
* the character
* @param action
* the action type
*/
void action(NPC npc, L2Character character, CharacterAction action)
throws ActionServiceException;
/**
* Attacks an given NPC, if possible.
*
* @param npc
* the npc
* @param attacker
* the character
* @throws NotAttackableNPCServiceException
* if {@link NPC} is not attackable
*/
void attack(NPC npc, L2Character attacker)
throws NotAttackableNPCServiceException;
}

View File

@@ -14,25 +14,29 @@
* 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.service.game;
package com.l2jserver.service.game.npc;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.NPC;
import com.l2jserver.service.Service;
import com.l2jserver.service.ServiceException;
/**
* This service controls {@link NPC}s
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface MonsterService extends Service {
/**
* Interacts the given <tt>player</tt> with the given <tt>npc</tt>
*
* @param npc
* the npc
* @param character
* the character
*/
void interact(NPC npc, L2Character character);
public class NPCServiceException extends ServiceException {
private static final long serialVersionUID = 1L;
public NPCServiceException() {
super();
}
public NPCServiceException(String message, Throwable cause) {
super(message, cause);
}
public NPCServiceException(String message) {
super(message);
}
public NPCServiceException(Throwable cause) {
super(cause);
}
}

View File

@@ -0,0 +1,54 @@
/*
* 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.service.game.npc;
import com.google.common.base.Preconditions;
import com.l2jserver.game.net.packet.client.CharacterActionPacket.CharacterAction;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.NPC;
import com.l2jserver.service.AbstractService;
import com.l2jserver.util.exception.L2Exception;
/**
* Default {@link NPCService} implementation
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class NPCServiceImpl extends AbstractService implements NPCService {
@Override
public void action(NPC npc, L2Character character, CharacterAction action)
throws ActionServiceException {
Preconditions.checkNotNull(npc, "npc");
Preconditions.checkNotNull(character, "character");
Preconditions.checkNotNull(action, "action");
final NPCTemplate template = npc.getTemplate();
try {
template.action(npc, character, action);
} catch (L2Exception e) {
throw new ActionServiceException(e);
}
}
@Override
public void attack(NPC npc, L2Character attacker)
throws NotAttackableNPCServiceException {
Preconditions.checkNotNull(npc, "npc");
Preconditions.checkNotNull(attacker, "attacker");
}
}

View File

@@ -0,0 +1,12 @@
package com.l2jserver.service.game.npc;
import com.l2jserver.model.world.NPC;
/**
* Exception thrown when the {@link NPC} is not attackable
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class NotAttackableNPCServiceException extends NPCServiceException {
private static final long serialVersionUID = 1L;
}

View File

@@ -33,7 +33,7 @@ import com.l2jserver.service.AbstractService;
import com.l2jserver.service.AbstractService.Depends;
import com.l2jserver.service.ServiceStartException;
import com.l2jserver.service.ServiceStopException;
import com.l2jserver.service.game.CharacterService;
import com.l2jserver.service.game.character.CharacterService;
import com.l2jserver.service.game.world.WorldService;
import com.l2jserver.service.game.world.event.TypedWorldListener;
import com.l2jserver.service.game.world.event.WorldEventDispatcher;

View File

@@ -118,8 +118,7 @@ public class ScriptingServiceImpl extends AbstractService implements
private ScriptContext createContext(ScriptInfo si, ScriptContext parent)
throws Exception {
Preconditions.checkNotNull(si, "si");
Preconditions.checkNotNull(parent, "parent");
ScriptContext context = getScriptContext(si.getRoot(), parent);
context.setLibraries(si.getLibraries());
context.setCompilerClassName(si.getCompilerClass());
@@ -159,8 +158,7 @@ public class ScriptingServiceImpl extends AbstractService implements
private ScriptContext getScriptContext(File root, ScriptContext parent)
throws InstantiationException {
Preconditions.checkNotNull(root, "root");
Preconditions.checkNotNull(parent, "parent");
ScriptContextImpl ctx;
if (parent == null) {
ctx = new ScriptContextImpl(injector, root);

View File

@@ -0,0 +1,12 @@
package com.l2jserver.service.game.spawn;
/**
* Exception thrown when the object is already spawned and registered in the
* world
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class AlreadySpawnedServiceException extends SpawnServiceException {
private static final long serialVersionUID = 1L;
}

View File

@@ -0,0 +1,11 @@
package com.l2jserver.service.game.spawn;
/**
* Exception thrown when trying to unspawn an object that is not spawned
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class NotSpawnedServiceException extends SpawnServiceException {
private static final long serialVersionUID = 1L;
}

View File

@@ -0,0 +1,12 @@
package com.l2jserver.service.game.spawn;
/**
* Exception thrown when the target spawn point is not found
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class SpawnPointNotFoundServiceException extends
SpawnServiceException {
private static final long serialVersionUID = 1L;
}

View File

@@ -14,7 +14,7 @@
* 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.service.game;
package com.l2jserver.service.game.spawn;
import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.capability.Spawnable;
@@ -23,7 +23,6 @@ import com.l2jserver.model.world.player.event.PlayerTeleportEvent;
import com.l2jserver.service.Service;
import com.l2jserver.util.dimensional.Coordinate;
import com.l2jserver.util.dimensional.Point;
import com.l2jserver.util.exception.L2SpawnServiceException;
/**
* This service is responsible for spawning monsters, npcs and players.
@@ -87,33 +86,4 @@ public interface SpawnService extends Service {
* if the object is not spawned
*/
void unspawn(Spawnable spawnable) throws NotSpawnedServiceException;
/**
* Exception thrown when the object is already spawned and registered in the
* world
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class AlreadySpawnedServiceException extends L2SpawnServiceException {
private static final long serialVersionUID = 1L;
}
/**
* Exception thrown when the target spawn point is not found
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class SpawnPointNotFoundServiceException extends
L2SpawnServiceException {
private static final long serialVersionUID = 1L;
}
/**
* Exception thrown when trying to unspawn an object that is not spawned
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class NotSpawnedServiceException extends L2SpawnServiceException {
private static final long serialVersionUID = 1L;
}
}

View File

@@ -0,0 +1,42 @@
/*
* 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.service.game.spawn;
import com.l2jserver.service.ServiceException;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class SpawnServiceException extends ServiceException {
private static final long serialVersionUID = 1L;
public SpawnServiceException() {
super();
}
public SpawnServiceException(String message, Throwable cause) {
super(message, cause);
}
public SpawnServiceException(String message) {
super(message);
}
public SpawnServiceException(Throwable cause) {
super(cause);
}
}

View File

@@ -14,7 +14,7 @@
* 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.service.game;
package com.l2jserver.service.game.spawn;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@@ -90,8 +90,7 @@ public class CachedWorldIDService extends AbstractService implements
cache = new Cache(new CacheConfiguration("id-cache",
IDAllocator.ALLOCABLE_IDS)
.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU)
.overflowToDisk(true).eternal(true).timeToLiveSeconds(60)
.timeToIdleSeconds(30).diskPersistent(false)
.overflowToDisk(true).eternal(true).diskPersistent(false)
.diskExpiryThreadIntervalSeconds(0));
cacheService.register(cache);
}