Finxing possible dead-lock.

This commit is contained in:
marcins78@gmail.com
2013-01-20 02:03:10 +00:00
parent dd15fc3a47
commit 513dad51f1
4 changed files with 14 additions and 28 deletions

View File

@@ -77,6 +77,7 @@ public class ChatRequestHandler extends LotroServerRequestHandler implements Uri
}
private class ChatUpdateLongPollingResource implements LongPollingResource {
private ChatCommunicationChannel _chatCommunicationChannel;
private ChatRoomMediator _chatRoom;
private String _room;
private String _playerId;

View File

@@ -87,7 +87,7 @@ public class GameRequestHandler extends LotroServerRequestHandler implements Uri
try {
GameCommunicationChannel pollableResource = gameMediator.getCommunicationChannel(resourceOwner, channelNumber);
GameUpdateLongPollingResource pollingResource = new GameUpdateLongPollingResource(channelNumber, gameMediator, resourceOwner, responseWriter);
GameUpdateLongPollingResource pollingResource = new GameUpdateLongPollingResource(pollableResource, channelNumber, gameMediator, resourceOwner, responseWriter);
_longPollingSystem.processLongPollingResource(pollingResource, pollableResource);
} catch (SubscriptionConflictException exp) {
responseWriter.writeError(409);
@@ -99,13 +99,15 @@ public class GameRequestHandler extends LotroServerRequestHandler implements Uri
}
private class GameUpdateLongPollingResource implements LongPollingResource {
private GameCommunicationChannel _gameCommunicationChannel;
private LotroGameMediator _gameMediator;
private Player _resourceOwner;
private int _channelNumber;
private ResponseWriter _responseWriter;
private boolean _processed;
private GameUpdateLongPollingResource(int channelNumber, LotroGameMediator gameMediator, Player resourceOwner, ResponseWriter responseWriter) {
private GameUpdateLongPollingResource(GameCommunicationChannel gameCommunicationChannel, int channelNumber, LotroGameMediator gameMediator, Player resourceOwner, ResponseWriter responseWriter) {
_gameCommunicationChannel = gameCommunicationChannel;
_channelNumber = channelNumber;
_gameMediator = gameMediator;
_resourceOwner = resourceOwner;
@@ -127,18 +129,11 @@ public class GameRequestHandler extends LotroServerRequestHandler implements Uri
Document doc = documentBuilder.newDocument();
Element update = doc.createElement("update");
GameCommunicationChannel communicationChannel = _gameMediator.getCommunicationChannel(_resourceOwner, _channelNumber);
_gameMediator.processVisitor(communicationChannel, _channelNumber, _resourceOwner.getName(), new SerializationVisitor(doc, update));
_gameMediator.processVisitor(_gameCommunicationChannel, _channelNumber, _resourceOwner.getName(), new SerializationVisitor(doc, update));
doc.appendChild(update);
_responseWriter.writeXmlResponse(doc);
} catch (SubscriptionConflictException exp) {
_responseWriter.writeError(409);
} catch (PrivateInformationException e) {
_responseWriter.writeError(403);
} catch (SubscriptionExpiredException e) {
_responseWriter.writeError(410);
} catch (Exception e) {
_responseWriter.writeError(500);
}

View File

@@ -442,7 +442,7 @@ public class HallRequestHandler extends LotroServerRequestHandler implements Uri
try {
HallCommunicationChannel pollableResource = _hallServer.getCommunicationChannel(resourceOwner, channelNumber);
HallUpdateLongPollingResource polledResource = new HallUpdateLongPollingResource(request, resourceOwner, channelNumber, responseWriter);
HallUpdateLongPollingResource polledResource = new HallUpdateLongPollingResource(pollableResource, request, resourceOwner, responseWriter);
_longPollingSystem.processLongPollingResource(polledResource, pollableResource);
} catch (SubscriptionExpiredException exp) {
responseWriter.writeError(410);
@@ -453,15 +453,15 @@ public class HallRequestHandler extends LotroServerRequestHandler implements Uri
private class HallUpdateLongPollingResource implements LongPollingResource {
private HttpRequest _request;
private HallCommunicationChannel _hallCommunicationChannel;
private Player _resourceOwner;
private int _channelNumber;
private ResponseWriter _responseWriter;
private boolean _processed;
private HallUpdateLongPollingResource(HttpRequest request, Player resourceOwner, int channelNumber, ResponseWriter responseWriter) {
private HallUpdateLongPollingResource(HallCommunicationChannel hallCommunicationChannel, HttpRequest request, Player resourceOwner, ResponseWriter responseWriter) {
_hallCommunicationChannel = hallCommunicationChannel;
_request = request;
_resourceOwner = resourceOwner;
_channelNumber = channelNumber;
_responseWriter = responseWriter;
}
@@ -480,7 +480,7 @@ public class HallRequestHandler extends LotroServerRequestHandler implements Uri
Document doc = documentBuilder.newDocument();
Element hall = doc.createElement("hall");
_hallServer.getCommunicationChannel(_resourceOwner, _channelNumber).processCommunicationChannel(_hallServer, _resourceOwner, new SerializeHallInfoVisitor(doc, hall));
_hallCommunicationChannel.processCommunicationChannel(_hallServer, _resourceOwner, new SerializeHallInfoVisitor(doc, hall));
hall.setAttribute("currency", String.valueOf(_collectionManager.getPlayerCollection(_resourceOwner, "permanent").getCurrency()));
doc.appendChild(hall);
@@ -489,10 +489,6 @@ public class HallRequestHandler extends LotroServerRequestHandler implements Uri
processDeliveryServiceNotification(_request, headers);
_responseWriter.writeXmlResponse(doc, headers);
} catch (SubscriptionExpiredException exp) {
_responseWriter.writeError(410);
} catch (SubscriptionConflictException exp) {
_responseWriter.writeError(409);
} catch (Exception exp) {
_responseWriter.writeError(500);
}

View File

@@ -16,7 +16,7 @@ public class HallCommunicationChannel implements LongPollableResource {
private Map<String, Map<String, String>> _tournamentPropsOnClient = new LinkedHashMap<String, Map<String, String>>();
private Map<String, Map<String, String>> _tablePropsOnClient = new LinkedHashMap<String, Map<String, String>>();
private Set<String> _playedGames = new HashSet<String>();
private boolean _changed;
private volatile boolean _changed;
private WaitingRequest _waitingRequest;
public HallCommunicationChannel(int channelNumber) {
@@ -29,7 +29,7 @@ public class HallCommunicationChannel implements LongPollableResource {
}
@Override
public boolean registerRequest(WaitingRequest waitingRequest) {
public synchronized boolean registerRequest(WaitingRequest waitingRequest) {
if (_changed)
return true;
@@ -55,13 +55,7 @@ public class HallCommunicationChannel implements LongPollableResource {
return _lastConsumed;
}
public synchronized boolean hasChangesInCommunicationChannel() {
updateLastAccess();
return _changed;
}
public synchronized void processCommunicationChannel(HallServer hallServer, final Player player, final HallChannelVisitor hallChannelVisitor) {
public void processCommunicationChannel(HallServer hallServer, final Player player, final HallChannelVisitor hallChannelVisitor) {
updateLastAccess();
hallChannelVisitor.channelNumber(_channelNumber);