Fixed the whole waiting for collection thing.
This commit is contained in:
@@ -25,7 +25,6 @@ public class ServerManagement {
|
||||
LeagueDAO leagueDao = new LeagueDAO(dbAccess);
|
||||
DefaultCardCollection collection = new DefaultCardCollection();
|
||||
collection.addPacks("FotR - League Starter", 1);
|
||||
collection.finishedReading();
|
||||
|
||||
leagueDao.addLeague("Test league", "league_test", collection, 20111122, 20121123);
|
||||
}
|
||||
|
||||
@@ -127,7 +127,6 @@ public class CollectionSerializer {
|
||||
final String blueprintId = _cardIds.get(i);
|
||||
collection.addCards(blueprintId, cards[i]);
|
||||
}
|
||||
collection.finishedReading();
|
||||
|
||||
return collection;
|
||||
}
|
||||
|
||||
@@ -6,17 +6,10 @@ import com.gempukku.lotro.common.Keyword;
|
||||
import com.gempukku.lotro.packs.PacksStorage;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
public class DefaultCardCollection implements MutableCardCollection {
|
||||
private Map<String, Integer> _counts = new HashMap<String, Integer>();
|
||||
|
||||
private CountDownLatch _collectionReadyLatch = new CountDownLatch(1);
|
||||
|
||||
public void finishedReading() {
|
||||
_collectionReadyLatch.countDown();
|
||||
}
|
||||
|
||||
private static class NameComparator implements Comparator<Item> {
|
||||
private LotroCardBlueprintLibrary _library;
|
||||
|
||||
@@ -187,14 +180,6 @@ public class DefaultCardCollection implements MutableCardCollection {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void waitTillLoaded() {
|
||||
try {
|
||||
_collectionReadyLatch.await();
|
||||
} catch (InterruptedException exp) {
|
||||
throw new RuntimeException(exp);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Integer> getAll() {
|
||||
return Collections.unmodifiableMap(_counts);
|
||||
@@ -202,12 +187,6 @@ public class DefaultCardCollection implements MutableCardCollection {
|
||||
|
||||
@Override
|
||||
public List<Item> getItems(String filter, LotroCardBlueprintLibrary library) {
|
||||
try {
|
||||
_collectionReadyLatch.await();
|
||||
} catch (InterruptedException exp) {
|
||||
throw new RuntimeException(exp);
|
||||
}
|
||||
|
||||
if (filter == null)
|
||||
filter = "";
|
||||
String[] filterParams = filter.split(" ");
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
public class LotroServer extends AbstractServer {
|
||||
private static final Logger log = Logger.getLogger(LotroServer.class);
|
||||
@@ -31,7 +32,10 @@ public class LotroServer extends AbstractServer {
|
||||
|
||||
private DeckDAO _deckDao;
|
||||
private GameHistoryDAO _gameHistoryDao;
|
||||
|
||||
private DefaultCardCollection _defaultCollection;
|
||||
private CountDownLatch _collectionReadyLatch = new CountDownLatch(1);
|
||||
|
||||
private ChatServer _chatServer;
|
||||
private boolean _test;
|
||||
private GameRecorder _gameRecorder;
|
||||
@@ -64,7 +68,7 @@ public class LotroServer extends AbstractServer {
|
||||
}
|
||||
}
|
||||
}
|
||||
_defaultCollection.finishedReading();
|
||||
_collectionReadyLatch.countDown();
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -78,7 +82,11 @@ public class LotroServer extends AbstractServer {
|
||||
}
|
||||
|
||||
public CardCollection getDefaultCollection() {
|
||||
_defaultCollection.waitTillLoaded();
|
||||
try {
|
||||
_collectionReadyLatch.await();
|
||||
} catch (InterruptedException exp) {
|
||||
throw new RuntimeException("Error while awaiting loading a default colleciton", exp);
|
||||
}
|
||||
return _defaultCollection;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,6 @@ public class LeagueService {
|
||||
else
|
||||
collection.addPacks(item.getBlueprintId(), item.getCount());
|
||||
}
|
||||
collection.finishedReading();
|
||||
return collection;
|
||||
}
|
||||
return collectionForPlayer;
|
||||
|
||||
@@ -22,7 +22,6 @@ public class CollectionSerializerTest {
|
||||
collection.addCards("1_23*", 3);
|
||||
collection.addCards("1_237T*", 3);
|
||||
collection.addPacks("FotR - Booster", 2);
|
||||
collection.finishedReading();
|
||||
|
||||
CollectionSerializer serializer = new CollectionSerializer();
|
||||
|
||||
@@ -48,7 +47,6 @@ public class CollectionSerializerTest {
|
||||
|
||||
DefaultCardCollection collection = new DefaultCardCollection();
|
||||
collection.addPacks("FotR - Booster", 8);
|
||||
collection.finishedReading();
|
||||
|
||||
CollectionSerializer serializer = new CollectionSerializer();
|
||||
|
||||
|
||||
@@ -73,7 +73,6 @@ public class AdminResource extends AbstractResource {
|
||||
List<String> packs = getItems(packCollection);
|
||||
for (String pack : packs)
|
||||
collection.addPacks(pack, 1);
|
||||
collection.finishedReading();
|
||||
|
||||
_leagueDao.addLeague(name, type, collection, start, end);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user