diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/AbstractServer.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/AbstractServer.java
index bcb9f1e01..b6eebfa31 100644
--- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/AbstractServer.java
+++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/AbstractServer.java
@@ -9,9 +9,14 @@ public abstract class AbstractServer {
if (!_started) {
_cleaningTask.addServer(this);
_started = true;
+ doAfterStartup();
}
}
+ protected void doAfterStartup() {
+
+ }
+
public void stopServer() {
if (_started) {
_cleaningTask.removeServer(this);
diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallServer.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallServer.java
index 2bf04e496..60c8f4f6b 100644
--- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallServer.java
+++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallServer.java
@@ -66,13 +66,16 @@ public class HallServer extends AbstractServer {
_collectionsManager = collectionsManager;
_hallChat = _chatServer.createChatRoom("Game Hall", 10);
- _runningTournaments.addAll(tournamentService.getLiveTournaments());
-
_tournamentQueues.put("fotr_queue", new SingleEliminationRecurringQueue(0, "fotr_block",
new CollectionType("default", "All cards"), "fotrQueue-", "Test Fellowship Block 4-man", 4,
tournamentService));
}
+ @Override
+ protected void doAfterStartup() {
+ _runningTournaments.addAll(_tournamentService.getLiveTournaments());
+ }
+
public void setShutdown(boolean shutdown) {
_hallDataAccessLock.writeLock().lock();
try {
diff --git a/gemp-lotr/gemp-lotr-web-server/pom.xml b/gemp-lotr/gemp-lotr-web-server/pom.xml
index 042acd66f..c299638c8 100644
--- a/gemp-lotr/gemp-lotr-web-server/pom.xml
+++ b/gemp-lotr/gemp-lotr-web-server/pom.xml
@@ -33,6 +33,12 @@
jersey-server
1.8
+
+ junit
+ junit
+ 4.9
+ test
+
gemp-lotr-server
diff --git a/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/provider/DaoBuilder.java b/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/provider/DaoBuilder.java
new file mode 100644
index 000000000..805982195
--- /dev/null
+++ b/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/provider/DaoBuilder.java
@@ -0,0 +1,32 @@
+package com.gempukku.lotro.server.provider;
+
+import com.gempukku.lotro.collection.CollectionSerializer;
+import com.gempukku.lotro.db.*;
+import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
+import com.gempukku.lotro.tournament.TournamentDAO;
+import com.gempukku.lotro.tournament.TournamentMatchDAO;
+import com.gempukku.lotro.tournament.TournamentPlayerDAO;
+
+import java.lang.reflect.Type;
+import java.util.Map;
+
+public class DaoBuilder {
+ public static void fillObjectMap(Map objectMap) {
+ DbAccess dbAccess = new DbAccess();
+ CollectionSerializer collectionSerializer = new CollectionSerializer();
+
+ LotroCardBlueprintLibrary library = new LotroCardBlueprintLibrary();
+ objectMap.put(LotroCardBlueprintLibrary.class, library);
+ objectMap.put(LeagueParticipationDAO.class, new DbLeagueParticipationDAO(dbAccess));
+ objectMap.put(LeagueMatchDAO.class, new DbLeagueMatchDAO(dbAccess));
+ objectMap.put(TournamentDAO.class, new DbTournamentDAO(dbAccess));
+ objectMap.put(TournamentPlayerDAO.class, new DbTournamentPlayerDAO(dbAccess));
+ objectMap.put(TournamentMatchDAO.class, new DbTournamentMatchDAO(dbAccess));
+ objectMap.put(MerchantDAO.class, new DbMerchantDAO(dbAccess));
+ objectMap.put(LeagueDAO.class, new LeagueDAO(dbAccess));
+ objectMap.put(GameHistoryDAO.class, new GameHistoryDAO(dbAccess));
+ objectMap.put(DeckDAO.class, new DeckDAO(dbAccess, library));
+ objectMap.put(CollectionDAO.class, new CollectionDAO(dbAccess, collectionSerializer));
+ objectMap.put(PlayerDAO.class, new PlayerDAO(dbAccess));
+ }
+}
diff --git a/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/provider/DaoProvider.java b/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/provider/DaoProvider.java
deleted file mode 100644
index f52f91283..000000000
--- a/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/provider/DaoProvider.java
+++ /dev/null
@@ -1,232 +0,0 @@
-package com.gempukku.lotro.server.provider;
-
-import com.gempukku.lotro.collection.CollectionSerializer;
-import com.gempukku.lotro.db.*;
-import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
-import com.gempukku.lotro.tournament.TournamentDAO;
-import com.gempukku.lotro.tournament.TournamentMatchDAO;
-import com.gempukku.lotro.tournament.TournamentPlayerDAO;
-import com.sun.jersey.core.spi.component.ComponentContext;
-import com.sun.jersey.core.spi.component.ComponentScope;
-import com.sun.jersey.spi.inject.Injectable;
-import com.sun.jersey.spi.inject.InjectableProvider;
-
-import javax.ws.rs.core.Context;
-import javax.ws.rs.ext.Provider;
-import java.lang.reflect.Type;
-
-@Provider
-public class DaoProvider implements InjectableProvider {
- private Injectable _playerDaoInjectable;
- private Injectable _collectionDaoInjectable;
- private Injectable _merchantDaoInjectable;
- private Injectable _deckDaoInjectable;
- private Injectable _gameHistoryDAOInjectable;
-
- private Injectable _leagueDaoInjectable;
- private Injectable _leagueMatchDAOInjectable;
- private Injectable _leagueParticipationDAOInjectable;
-
- private Injectable _tournamentDAOInjectable;
- private Injectable _tournamentPlayerDAOInjectable;
- private Injectable _tournamentMatchDAOInjectable;
- private Injectable _lotroCardBlueprintLibraryInjectable;
-
- private DbAccess _dbAccess;
- private CollectionSerializer _collectionSerializer;
-
- public DaoProvider() {
- _dbAccess = new DbAccess();
- _collectionSerializer = new CollectionSerializer();
- }
-
- @Override
- public Injectable getInjectable(ComponentContext ic, Context context, Type type) {
- if (type.equals(PlayerDAO.class))
- return getPlayerDaoSafely();
- else if (type.equals(CollectionDAO.class))
- return getCollectionDaoSafely();
- else if (type.equals(DeckDAO.class))
- return getDeckDaoSafely();
- else if (type.equals(GameHistoryDAO.class))
- return getGameHistoryDaoSafely();
- else if (type.equals(LeagueDAO.class))
- return getLeagueDaoSafely();
- else if (type.equals(LeagueMatchDAO.class))
- return getLeagueMatchDaoSafely();
- else if (type.equals(LeagueParticipationDAO.class))
- return getLeagueParticipationDaoSafely();
- else if (type.equals(MerchantDAO.class))
- return getMerchantDaoSafely();
- else if (type.equals(TournamentDAO.class))
- return getTournamentDaoSafely();
- else if (type.equals(TournamentPlayerDAO.class))
- return getTournamentPlayerDaoSafely();
- else if (type.equals(TournamentMatchDAO.class))
- return getTournamentMatchDaoSafely();
- else if (type.equals(LotroCardBlueprintLibrary.class))
- return getLotroCardBlueprintLibrarySafely();
- return null;
- }
-
- private synchronized Injectable getLeagueParticipationDaoSafely() {
- if (_leagueParticipationDAOInjectable == null) {
- final LeagueParticipationDAO leagueParticipationDAO = new DbLeagueParticipationDAO(_dbAccess);
- _leagueParticipationDAOInjectable = new Injectable() {
- @Override
- public LeagueParticipationDAO getValue() {
- return leagueParticipationDAO;
- }
- };
- }
- return _leagueParticipationDAOInjectable;
- }
-
- private synchronized Injectable getLotroCardBlueprintLibrarySafely() {
- if (_lotroCardBlueprintLibraryInjectable == null) {
- final LotroCardBlueprintLibrary library = new LotroCardBlueprintLibrary();
- _lotroCardBlueprintLibraryInjectable = new Injectable() {
- @Override
- public LotroCardBlueprintLibrary getValue() {
- return library;
- }
- };
- }
- return _lotroCardBlueprintLibraryInjectable;
- }
-
- private synchronized Injectable getLeagueMatchDaoSafely() {
- if (_leagueMatchDAOInjectable == null) {
- final LeagueMatchDAO leagueMatchDao = new DbLeagueMatchDAO(_dbAccess);
- _leagueMatchDAOInjectable = new Injectable() {
- @Override
- public LeagueMatchDAO getValue() {
- return leagueMatchDao;
- }
- };
- }
- return _leagueMatchDAOInjectable;
- }
-
- private synchronized Injectable getTournamentDaoSafely() {
- if (_tournamentDAOInjectable == null) {
- final DbTournamentDAO tournamentDAO = new DbTournamentDAO(_dbAccess);
- _tournamentDAOInjectable = new Injectable() {
- @Override
- public TournamentDAO getValue() {
- return tournamentDAO;
- }
- };
- }
- return _tournamentDAOInjectable;
- }
-
- private synchronized Injectable getTournamentPlayerDaoSafely() {
- if (_tournamentPlayerDAOInjectable == null) {
- final DbTournamentPlayerDAO tournamentPlayerDAO = new DbTournamentPlayerDAO(_dbAccess);
- _tournamentPlayerDAOInjectable = new Injectable() {
- @Override
- public TournamentPlayerDAO getValue() {
- return tournamentPlayerDAO;
- }
- };
- }
- return _tournamentPlayerDAOInjectable;
- }
-
- private synchronized Injectable getTournamentMatchDaoSafely() {
- if (_tournamentMatchDAOInjectable == null) {
- final DbTournamentMatchDAO tournamentMatchDAO = new DbTournamentMatchDAO(_dbAccess);
- _tournamentMatchDAOInjectable = new Injectable() {
- @Override
- public TournamentMatchDAO getValue() {
- return tournamentMatchDAO;
- }
- };
- }
- return _tournamentMatchDAOInjectable;
- }
-
- private synchronized Injectable getMerchantDaoSafely() {
- if (_merchantDaoInjectable == null) {
- final MerchantDAO merchantDAO = new DbMerchantDAO(_dbAccess);
- _merchantDaoInjectable = new Injectable() {
- @Override
- public MerchantDAO getValue() {
- return merchantDAO;
- }
- };
- }
- return _merchantDaoInjectable;
- }
-
- private synchronized Injectable getLeagueDaoSafely() {
- if (_leagueDaoInjectable == null) {
- final LeagueDAO leagueDao = new LeagueDAO(_dbAccess);
- _leagueDaoInjectable = new Injectable() {
- @Override
- public LeagueDAO getValue() {
- return leagueDao;
- }
- };
- }
- return _leagueDaoInjectable;
- }
-
- private synchronized Injectable getGameHistoryDaoSafely() {
- if (_gameHistoryDAOInjectable == null) {
- final GameHistoryDAO gameHistoryDAO = new GameHistoryDAO(_dbAccess);
- _gameHistoryDAOInjectable = new Injectable() {
- @Override
- public GameHistoryDAO getValue() {
- return gameHistoryDAO;
- }
- };
- }
- return _gameHistoryDAOInjectable;
- }
-
- private synchronized Injectable getDeckDaoSafely() {
- if (_deckDaoInjectable == null) {
- final DeckDAO deckDao = new DeckDAO(_dbAccess, getLotroCardBlueprintLibrarySafely().getValue());
- _deckDaoInjectable = new Injectable() {
- @Override
- public DeckDAO getValue() {
- return deckDao;
- }
- };
- }
- return _deckDaoInjectable;
- }
-
- private synchronized Injectable getCollectionDaoSafely() {
- if (_collectionDaoInjectable == null) {
- final CollectionDAO collectionDao = new CollectionDAO(_dbAccess, _collectionSerializer);
- _collectionDaoInjectable = new Injectable() {
- @Override
- public CollectionDAO getValue() {
- return collectionDao;
- }
- };
- }
- return _collectionDaoInjectable;
- }
-
- private synchronized Injectable getPlayerDaoSafely() {
- if (_playerDaoInjectable == null) {
- final PlayerDAO playerDao = new PlayerDAO(_dbAccess);
- _playerDaoInjectable = new Injectable() {
- @Override
- public PlayerDAO getValue() {
- return playerDao;
- }
- };
- }
- return _playerDaoInjectable;
- }
-
- @Override
- public ComponentScope getScope() {
- return ComponentScope.Singleton;
- }
-}
diff --git a/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/provider/MapProvider.java b/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/provider/MapProvider.java
new file mode 100644
index 000000000..83d57cbf6
--- /dev/null
+++ b/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/provider/MapProvider.java
@@ -0,0 +1,55 @@
+package com.gempukku.lotro.server.provider;
+
+import com.gempukku.lotro.packs.PacksStorage;
+import com.sun.jersey.core.spi.component.ComponentContext;
+import com.sun.jersey.core.spi.component.ComponentScope;
+import com.sun.jersey.spi.inject.Injectable;
+import com.sun.jersey.spi.inject.InjectableProvider;
+import org.apache.log4j.Logger;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.ws.rs.core.Context;
+import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.Map;
+
+public class MapProvider implements InjectableProvider {
+ private static final Logger _logger = Logger.getLogger(PacksStorageBuilder.class);
+ private Map _objectMap = new HashMap();
+
+ public MapProvider() {
+ try {
+ _objectMap.put(PacksStorage.class, PacksStorageBuilder.createPacksStorage());
+ DaoBuilder.fillObjectMap(_objectMap);
+ ServerBuilder.fillObjectMap(_objectMap);
+ } catch (Exception exp) {
+ _logger.error("Unable to startup the server", exp);
+ }
+ }
+
+ @Override
+ public ComponentScope getScope() {
+ return ComponentScope.Singleton;
+ }
+
+ @PostConstruct
+ public void constructObjects() {
+ ServerBuilder.constructObjects(_objectMap);
+ }
+
+ @PreDestroy
+ public void destroyObjects() {
+ ServerBuilder.destroyObjects(_objectMap);
+ }
+
+ @Override
+ public Injectable getInjectable(ComponentContext ic, Context context, final Type type) {
+ return new Injectable() {
+ @Override
+ public Object getValue() {
+ return _objectMap.get(type);
+ }
+ };
+ }
+}
diff --git a/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/provider/PacksStorageProvider.java b/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/provider/PacksStorageBuilder.java
similarity index 85%
rename from gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/provider/PacksStorageProvider.java
rename to gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/provider/PacksStorageBuilder.java
index d1731755a..2b7aead44 100644
--- a/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/provider/PacksStorageProvider.java
+++ b/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/provider/PacksStorageBuilder.java
@@ -1,35 +1,14 @@
package com.gempukku.lotro.server.provider;
import com.gempukku.lotro.packs.*;
-import com.sun.jersey.core.spi.component.ComponentContext;
-import com.sun.jersey.core.spi.component.ComponentScope;
-import com.sun.jersey.spi.inject.Injectable;
-import com.sun.jersey.spi.inject.InjectableProvider;
import org.apache.log4j.Logger;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.ext.Provider;
import java.io.IOException;
-import java.lang.reflect.Type;
-@Provider
-public class PacksStorageProvider implements Injectable, InjectableProvider {
- private static final Logger _logger = Logger.getLogger(PacksStorageProvider.class);
- private PacksStorage _packsStorage;
+public class PacksStorageBuilder {
+ private static final Logger _logger = Logger.getLogger(PacksStorageBuilder.class);
- @Override
- public Injectable getInjectable(ComponentContext ic, Context context, Type type) {
- if (type.equals(PacksStorage.class))
- return this;
- return null;
- }
-
- @Override
- public ComponentScope getScope() {
- return ComponentScope.Singleton;
- }
-
- private PacksStorage createPacksStorage() {
+ public static PacksStorage createPacksStorage() {
try {
PacksStorage packStorage = new PacksStorage();
packStorage.addPackBox("FotR - League Starter", new LeagueStarterBox());
@@ -130,11 +109,4 @@ public class PacksStorageProvider implements Injectable, Injectabl
}
return null;
}
-
- @Override
- public synchronized PacksStorage getValue() {
- if (_packsStorage == null)
- _packsStorage = createPacksStorage();
- return _packsStorage;
- }
}
diff --git a/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/provider/ServerBuilder.java b/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/provider/ServerBuilder.java
new file mode 100644
index 000000000..39a3863aa
--- /dev/null
+++ b/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/provider/ServerBuilder.java
@@ -0,0 +1,124 @@
+package com.gempukku.lotro.server.provider;
+
+import com.gempukku.lotro.chat.ChatServer;
+import com.gempukku.lotro.collection.CollectionsManager;
+import com.gempukku.lotro.collection.DeliveryService;
+import com.gempukku.lotro.db.*;
+import com.gempukku.lotro.draft.DraftServer;
+import com.gempukku.lotro.game.GameHistoryService;
+import com.gempukku.lotro.game.GameRecorder;
+import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
+import com.gempukku.lotro.game.LotroServer;
+import com.gempukku.lotro.game.formats.LotroFormatLibrary;
+import com.gempukku.lotro.hall.HallServer;
+import com.gempukku.lotro.league.LeagueService;
+import com.gempukku.lotro.merchant.MerchantService;
+import com.gempukku.lotro.tournament.TournamentDAO;
+import com.gempukku.lotro.tournament.TournamentMatchDAO;
+import com.gempukku.lotro.tournament.TournamentPlayerDAO;
+import com.gempukku.lotro.tournament.TournamentService;
+import com.sun.jersey.spi.inject.Injectable;
+
+import java.lang.reflect.Type;
+import java.util.Map;
+
+public class ServerBuilder {
+ private Injectable _chatServerInjectable;
+ private Injectable _leagueServiceInjectable;
+ private Injectable _gameHistoryServiceInjectable;
+ private Injectable _merchantServiceInjectable;
+ private Injectable _tournamentServiceInjectable;
+ private Injectable _hallServerInjectable;
+ private Injectable _lotroServerInjectable;
+ private Injectable _draftServerInjectable;
+ private Injectable _collectionsManagerInjectable;
+ private Injectable _deliveryServiceInjectable;
+ private Injectable _lotroFormatLibraryInjectable;
+ private Injectable _gameRecorderInjectable;
+
+ public static void fillObjectMap(Map objectMap) {
+ objectMap.put(LotroFormatLibrary.class,
+ new LotroFormatLibrary(
+ extract(objectMap, LotroCardBlueprintLibrary.class)));
+
+ objectMap.put(GameHistoryService.class,
+ new GameHistoryService(
+ extract(objectMap, GameHistoryDAO.class)));
+ objectMap.put(GameRecorder.class,
+ new GameRecorder(
+ extract(objectMap, GameHistoryService.class)));
+
+ objectMap.put(DeliveryService.class,
+ new DeliveryService());
+
+ objectMap.put(CollectionsManager.class,
+ new CollectionsManager(
+ extract(objectMap, PlayerDAO.class),
+ extract(objectMap, CollectionDAO.class),
+ extract(objectMap, DeliveryService.class),
+ extract(objectMap, LotroCardBlueprintLibrary.class)));
+
+ objectMap.put(LeagueService.class,
+ new LeagueService(
+ extract(objectMap, LeagueDAO.class),
+ extract(objectMap, LeagueMatchDAO.class),
+ extract(objectMap, LeagueParticipationDAO.class),
+ extract(objectMap, CollectionsManager.class)));
+
+ objectMap.put(TournamentService.class,
+ new TournamentService(
+ extract(objectMap, TournamentDAO.class),
+ extract(objectMap, TournamentPlayerDAO.class),
+ extract(objectMap, TournamentMatchDAO.class)));
+
+ objectMap.put(MerchantService.class,
+ new MerchantService(
+ extract(objectMap, LotroCardBlueprintLibrary.class),
+ extract(objectMap, CollectionsManager.class),
+ extract(objectMap, MerchantDAO.class)));
+
+ objectMap.put(ChatServer.class, new ChatServer());
+
+ objectMap.put(LotroServer.class,
+ new LotroServer(
+ extract(objectMap, DeckDAO.class),
+ extract(objectMap, LotroCardBlueprintLibrary.class),
+ extract(objectMap, ChatServer.class),
+ extract(objectMap, GameRecorder.class)));
+
+ objectMap.put(DraftServer.class,
+ new DraftServer());
+ objectMap.put(HallServer.class,
+ new HallServer(
+ extract(objectMap, LotroServer.class),
+ extract(objectMap, DraftServer.class),
+ extract(objectMap, ChatServer.class),
+ extract(objectMap, LeagueService.class),
+ extract(objectMap, TournamentService.class),
+ extract(objectMap, LotroCardBlueprintLibrary.class),
+ extract(objectMap, LotroFormatLibrary.class),
+ extract(objectMap, CollectionsManager.class),
+ false));
+ }
+
+ private static T extract(Map objectMap, Class clazz) {
+ T result = (T) objectMap.get(clazz);
+ if (result == null)
+ throw new RuntimeException("Unable to find class " + clazz.getName());
+ return result;
+ }
+
+ public static void constructObjects(Map objectMap) {
+ extract(objectMap, HallServer.class).startServer();
+ extract(objectMap, DraftServer.class).startServer();
+ extract(objectMap, LotroServer.class).startServer();
+ extract(objectMap, ChatServer.class).startServer();
+ }
+
+ public static void destroyObjects(Map objectMap) {
+ extract(objectMap, HallServer.class).stopServer();
+ extract(objectMap, DraftServer.class).stopServer();
+ extract(objectMap, LotroServer.class).stopServer();
+ extract(objectMap, ChatServer.class).stopServer();
+ }
+}
diff --git a/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/provider/ServerProvider.java b/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/provider/ServerProvider.java
deleted file mode 100644
index 64fd127d1..000000000
--- a/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/provider/ServerProvider.java
+++ /dev/null
@@ -1,292 +0,0 @@
-package com.gempukku.lotro.server.provider;
-
-import com.gempukku.lotro.chat.ChatServer;
-import com.gempukku.lotro.collection.CollectionsManager;
-import com.gempukku.lotro.collection.DeliveryService;
-import com.gempukku.lotro.db.*;
-import com.gempukku.lotro.draft.DraftServer;
-import com.gempukku.lotro.game.GameHistoryService;
-import com.gempukku.lotro.game.GameRecorder;
-import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
-import com.gempukku.lotro.game.LotroServer;
-import com.gempukku.lotro.game.formats.LotroFormatLibrary;
-import com.gempukku.lotro.hall.HallServer;
-import com.gempukku.lotro.league.LeagueService;
-import com.gempukku.lotro.merchant.MerchantService;
-import com.gempukku.lotro.tournament.TournamentDAO;
-import com.gempukku.lotro.tournament.TournamentMatchDAO;
-import com.gempukku.lotro.tournament.TournamentPlayerDAO;
-import com.gempukku.lotro.tournament.TournamentService;
-import com.sun.jersey.core.spi.component.ComponentContext;
-import com.sun.jersey.core.spi.component.ComponentScope;
-import com.sun.jersey.spi.inject.Injectable;
-import com.sun.jersey.spi.inject.InjectableProvider;
-
-import javax.annotation.PreDestroy;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.ext.Provider;
-import java.lang.reflect.Type;
-
-@Provider
-public class ServerProvider implements InjectableProvider {
- private Injectable _chatServerInjectable;
- private Injectable _leagueServiceInjectable;
- private Injectable _gameHistoryServiceInjectable;
- private Injectable _merchantServiceInjectable;
- private Injectable _tournamentServiceInjectable;
- private Injectable _hallServerInjectable;
- private Injectable _lotroServerInjectable;
- private Injectable _draftServerInjectable;
- private Injectable _collectionsManagerInjectable;
- private Injectable _deliveryServiceInjectable;
- private Injectable _lotroFormatLibraryInjectable;
- private Injectable _gameRecorderInjectable;
-
- @Context
- private PlayerDAO _playerDao;
- @Context
- private DeckDAO _deckDao;
- @Context
- private CollectionDAO _collectionDao;
- @Context
- private MerchantDAO _merchantDao;
- @Context
- private LeagueDAO _leagueDao;
- @Context
- private LeagueMatchDAO _leagueMatchDao;
- @Context
- private LeagueParticipationDAO _leagueParticipationDao;
- @Context
- private GameHistoryDAO _gameHistoryDao;
- @Context
- private TournamentDAO _tournamentDao;
- @Context
- private TournamentPlayerDAO _tournamentPlayerDao;
- @Context
- private TournamentMatchDAO _tournamentMatchDao;
- @Context
- private LotroCardBlueprintLibrary _library;
-
- @Override
- public Injectable getInjectable(ComponentContext ic, Context context, Type type) {
- if (type.equals(ChatServer.class))
- return getChatServerInjectable();
- if (type.equals(LotroServer.class))
- return getLotroServerInjectable();
- if (type.equals(DraftServer.class))
- return getDraftServerInjectable();
- if (type.equals(HallServer.class))
- return getHallServerInjectable();
- if (type.equals(LeagueService.class))
- return getLeagueServiceInjectable();
- if (type.equals(GameHistoryService.class))
- return getGameHistoryServiceInjectable();
- if (type.equals(CollectionsManager.class))
- return getCollectionsManagerInjectable();
- if (type.equals(DeliveryService.class))
- return getDeliveryServiceInjectable();
- if (type.equals(LotroFormatLibrary.class))
- return getLotroFormatLibraryInjectable();
- if (type.equals(MerchantService.class))
- return getMerchantServiceInjectable();
- if (type.equals(TournamentService.class))
- return getTournamentServiceInjectable();
- if (type.equals(GameRecorder.class))
- return getGameRecorderInjectable();
- return null;
- }
-
- @PreDestroy
- public void destroyResources() {
- getHallServerInjectable().getValue().stopServer();
-// getTradeServerInjectable().getValue().stopServer();
- getLotroServerInjectable().getValue().stopServer();
- getChatServerInjectable().getValue().stopServer();
- }
-
- private synchronized Injectable getLotroFormatLibraryInjectable() {
- if (_lotroFormatLibraryInjectable == null) {
- final LotroFormatLibrary lotroFormatLibrary = new LotroFormatLibrary(_library);
- _lotroFormatLibraryInjectable = new Injectable() {
- @Override
- public LotroFormatLibrary getValue() {
- return lotroFormatLibrary;
- }
- };
- }
- return _lotroFormatLibraryInjectable;
- }
-
- private synchronized Injectable getLeagueServiceInjectable() {
- if (_leagueServiceInjectable == null) {
- final LeagueService leagueService = new LeagueService(_leagueDao, _leagueMatchDao, _leagueParticipationDao, getCollectionsManagerInjectable().getValue());
- _leagueServiceInjectable = new Injectable() {
- @Override
- public LeagueService getValue() {
- return leagueService;
- }
- };
- }
- return _leagueServiceInjectable;
- }
-
- private synchronized Injectable getGameHistoryServiceInjectable() {
- if (_gameHistoryServiceInjectable == null) {
- final GameHistoryService gameHistoryServiceleagueService = new GameHistoryService(_gameHistoryDao);
- _gameHistoryServiceInjectable = new Injectable() {
- @Override
- public GameHistoryService getValue() {
- return gameHistoryServiceleagueService;
- }
- };
- }
- return _gameHistoryServiceInjectable;
- }
-
- private synchronized Injectable getGameRecorderInjectable() {
- if (_gameRecorderInjectable == null) {
- final GameRecorder gameRecorder = new GameRecorder(getGameHistoryServiceInjectable().getValue());
- _gameRecorderInjectable = new Injectable() {
- @Override
- public GameRecorder getValue() {
- return gameRecorder;
- }
- };
- }
- return _gameRecorderInjectable;
- }
-
- private synchronized Injectable getMerchantServiceInjectable() {
- if (_merchantServiceInjectable == null) {
- final MerchantService merchantService = new MerchantService(_library, getCollectionsManagerInjectable().getValue(), _merchantDao);
- _merchantServiceInjectable = new Injectable() {
- @Override
- public MerchantService getValue() {
- return merchantService;
- }
- };
- }
- return _merchantServiceInjectable;
- }
-
- private synchronized Injectable getTournamentServiceInjectable() {
- if (_tournamentServiceInjectable == null) {
- final TournamentService tournamentService = new TournamentService(_tournamentDao, _tournamentPlayerDao, _tournamentMatchDao);
- _tournamentServiceInjectable = new Injectable() {
- @Override
- public TournamentService getValue() {
- return tournamentService;
- }
- };
- }
- return _tournamentServiceInjectable;
- }
-
- private synchronized Injectable getDeliveryServiceInjectable() {
- if (_deliveryServiceInjectable == null) {
- final DeliveryService deliveryService = new DeliveryService();
- _deliveryServiceInjectable = new Injectable() {
- @Override
- public DeliveryService getValue() {
- return deliveryService;
- }
- };
- }
- return _deliveryServiceInjectable;
- }
-
- private synchronized Injectable getHallServerInjectable() {
- if (_hallServerInjectable == null) {
- final HallServer hallServer = new HallServer(
- getLotroServerInjectable().getValue(),
- getDraftServerInjectable().getValue(),
- getChatServerInjectable().getValue(), getLeagueServiceInjectable().getValue(),
- getTournamentServiceInjectable().getValue(), _library,
- getLotroFormatLibraryInjectable().getValue(), getCollectionsManagerInjectable().getValue(), false);
- hallServer.startServer();
- _hallServerInjectable = new Injectable() {
- @Override
- public HallServer getValue() {
- return hallServer;
- }
- };
- }
- return _hallServerInjectable;
- }
-
-// private synchronized Injectable getTradeServerInjectable() {
-// if (_tradeServerInjectable == null) {
-// final TradeServer tradeServer = new TradeServer(getChatServerInjectable().getValue());
-// tradeServer.startServer();
-// _tradeServerInjectable = new Injectable() {
-// @Override
-// public TradeServer getValue() {
-// return tradeServer;
-// }
-// };
-// }
-// return _tradeServerInjectable;
-// }
-
- //
-
- private synchronized Injectable getLotroServerInjectable() {
- if (_lotroServerInjectable == null) {
- final LotroServer lotroServer = new LotroServer(_deckDao, _library, getChatServerInjectable().getValue(), getGameRecorderInjectable().getValue());
- lotroServer.startServer();
- _lotroServerInjectable = new Injectable() {
- @Override
- public LotroServer getValue() {
- return lotroServer;
- }
- };
- }
- return _lotroServerInjectable;
- }
-
- private synchronized Injectable getDraftServerInjectable() {
- if (_draftServerInjectable == null) {
- final DraftServer draftServer = new DraftServer();
- draftServer.startServer();
- _draftServerInjectable = new Injectable() {
- @Override
- public DraftServer getValue() {
- return draftServer;
- }
- };
- }
- return _draftServerInjectable;
- }
-
- private synchronized Injectable getChatServerInjectable() {
- if (_chatServerInjectable == null) {
- final ChatServer chatServer = new ChatServer();
- chatServer.startServer();
- _chatServerInjectable = new Injectable() {
- @Override
- public ChatServer getValue() {
- return chatServer;
- }
- };
- }
- return _chatServerInjectable;
- }
-
- private synchronized Injectable getCollectionsManagerInjectable() {
- if (_collectionsManagerInjectable == null) {
- final CollectionsManager collectionsManager = new CollectionsManager(_playerDao, _collectionDao, getDeliveryServiceInjectable().getValue(), _library);
- _collectionsManagerInjectable = new Injectable() {
- @Override
- public CollectionsManager getValue() {
- return collectionsManager;
- }
- };
- }
- return _collectionsManagerInjectable;
- }
-
- @Override
- public ComponentScope getScope() {
- return ComponentScope.Singleton;
- }
-}
diff --git a/gemp-lotr/gemp-lotr-web-server/src/main/resources/log4j.xml b/gemp-lotr/gemp-lotr-web-server/src/main/resources/log4j.xml
index cedd35f8d..7d9c83cc9 100644
--- a/gemp-lotr/gemp-lotr-web-server/src/main/resources/log4j.xml
+++ b/gemp-lotr/gemp-lotr-web-server/src/main/resources/log4j.xml
@@ -22,5 +22,6 @@
+
\ No newline at end of file
diff --git a/gemp-lotr/gemp-lotr-web-server/src/test/java/com/gempukku/lotro/server/provider/MapProviderTest.java b/gemp-lotr/gemp-lotr-web-server/src/test/java/com/gempukku/lotro/server/provider/MapProviderTest.java
new file mode 100644
index 000000000..09c6362e9
--- /dev/null
+++ b/gemp-lotr/gemp-lotr-web-server/src/test/java/com/gempukku/lotro/server/provider/MapProviderTest.java
@@ -0,0 +1,10 @@
+package com.gempukku.lotro.server.provider;
+
+import org.junit.Test;
+
+public class MapProviderTest {
+ @Test
+ public void testCreate() {
+ MapProvider provider = new MapProvider();
+ }
+}