mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 03:22:00 -08:00
Merge with version 0.8
This commit is contained in:
commit
9ddea9d9c5
67 changed files with 2510 additions and 2646 deletions
124
Mage.Common/src/mage/interfaces/MageServer.java
Normal file
124
Mage.Common/src/mage/interfaces/MageServer.java
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.interfaces;
|
||||
|
||||
import mage.game.match.MatchOptions;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.MageException;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.game.GameException;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.utils.MageVersion;
|
||||
import mage.view.DraftPickView;
|
||||
import mage.view.TableView;
|
||||
import mage.view.GameView;
|
||||
import mage.view.TournamentView;
|
||||
import mage.view.UserView;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public interface MageServer {
|
||||
|
||||
public boolean registerClient(String userName, String sessionId, MageVersion version) throws MageException;
|
||||
public boolean registerAdmin(String password, String sessionId, MageVersion version) throws MageException;
|
||||
public void deregisterClient(String sessionId) throws MageException;
|
||||
|
||||
public ServerState getServerState() throws MageException;
|
||||
|
||||
//table methods
|
||||
public TableView createTable(String sessionId, UUID roomId, MatchOptions matchOptions) throws MageException;
|
||||
public TableView createTournamentTable(String sessionId, UUID roomId, TournamentOptions tournamentOptions) throws MageException;
|
||||
public boolean joinTable(String sessionId, UUID roomId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException, GameException;
|
||||
public boolean joinTournamentTable(String sessionId, UUID roomId, UUID tableId, String name, String playerType, int skill) throws MageException, GameException;
|
||||
public boolean submitDeck(String sessionId, UUID tableId, DeckCardLists deckList) throws MageException, GameException;
|
||||
public boolean watchTable(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
public void leaveTable(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
public void swapSeats(String sessionId, UUID roomId, UUID tableId, int seatNum1, int seatNum2) throws MageException;
|
||||
public void removeTable(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
public boolean isTableOwner(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
public TableView getTable(UUID roomId, UUID tableId) throws MageException;
|
||||
public List<TableView> getTables(UUID roomId) throws MageException;
|
||||
public List<String> getConnectedPlayers(UUID roomId) throws MageException;
|
||||
|
||||
//chat methods
|
||||
public void sendChatMessage(UUID chatId, String userName, String message) throws MageException;
|
||||
public void joinChat(UUID chatId, String sessionId, String userName) throws MageException;
|
||||
public void leaveChat(UUID chatId, String sessionId) throws MageException;
|
||||
public UUID getTableChatId(UUID tableId) throws MageException;
|
||||
public UUID getGameChatId(UUID gameId) throws MageException;
|
||||
public UUID getRoomChatId(UUID roomId) throws MageException;
|
||||
public UUID getTournamentChatId(UUID tournamentId) throws MageException;
|
||||
|
||||
//room methods
|
||||
public UUID getMainRoomId() throws MageException;
|
||||
|
||||
//game methods
|
||||
public void startMatch(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
public void joinGame(UUID gameId, String sessionId) throws MageException;
|
||||
public void watchGame(UUID gameId, String sessionId) throws MageException;
|
||||
public void stopWatching(UUID gameId, String sessionId) throws MageException;
|
||||
public void sendPlayerUUID(UUID gameId, String sessionId, UUID data) throws MageException;
|
||||
public void sendPlayerString(UUID gameId, String sessionId, String data) throws MageException;
|
||||
public void sendPlayerBoolean(UUID gameId, String sessionId, Boolean data) throws MageException;
|
||||
public void sendPlayerInteger(UUID gameId, String sessionId, Integer data) throws MageException;
|
||||
public void concedeGame(UUID gameId, String sessionId) throws MageException;
|
||||
|
||||
//tournament methods
|
||||
public void startTournament(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
public void joinTournament(UUID draftId, String sessionId) throws MageException;
|
||||
public TournamentView getTournament(UUID tournamentId) throws MageException;
|
||||
|
||||
//draft methods
|
||||
public void joinDraft(UUID draftId, String sessionId) throws MageException;
|
||||
public DraftPickView sendCardPick(UUID draftId, String sessionId, UUID cardId) throws MageException;
|
||||
|
||||
//challenge methods
|
||||
public void startChallenge(String sessionId, UUID roomId, UUID tableId, UUID challengeId) throws MageException;
|
||||
|
||||
//replay methods
|
||||
public void replayGame(UUID gameId, String sessionId) throws MageException;
|
||||
public void startReplay(UUID gameId, String sessionId) throws MageException;
|
||||
public void stopReplay(UUID gameId, String sessionId) throws MageException;
|
||||
public void nextPlay(UUID gameId, String sessionId) throws MageException;
|
||||
public void previousPlay(UUID gameId, String sessionId) throws MageException;
|
||||
|
||||
//test methods
|
||||
public void cheat(UUID gameId, String sessionId, UUID playerId, DeckCardLists deckList) throws MageException;
|
||||
public boolean cheat(UUID gameId, String sessionId, UUID playerId, String cardName) throws MageException;
|
||||
public GameView getGameView(UUID gameId, String sessionId, UUID playerId) throws MageException;
|
||||
|
||||
//admin methods
|
||||
public List<UserView> getUsers(String sessionId) throws MageException;
|
||||
public void disconnectUser(String sessionId, String userSessionId) throws MageException;
|
||||
public void removeTable(String sessionId, UUID tableId) throws MageException;
|
||||
|
||||
}
|
||||
|
|
@ -1,129 +0,0 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.interfaces;
|
||||
|
||||
import mage.game.match.MatchOptions;
|
||||
import java.rmi.Remote;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.MageException;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.game.GameException;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.interfaces.callback.CallbackServer;
|
||||
import mage.utils.MageVersion;
|
||||
import mage.view.DraftPickView;
|
||||
import mage.view.TableView;
|
||||
import mage.view.GameView;
|
||||
import mage.view.TournamentView;
|
||||
import mage.view.UserView;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public interface Server extends Remote, CallbackServer {
|
||||
|
||||
public UUID registerClient(String userName, UUID clientId, MageVersion version) throws RemoteException, MageException;
|
||||
public UUID registerAdmin(String password, MageVersion version) throws RemoteException, MageException;
|
||||
public void deregisterClient(UUID sessionId) throws RemoteException, MageException;
|
||||
public void ack(String message, UUID sessionId) throws RemoteException, MageException;
|
||||
public boolean ping(UUID sessionId) throws RemoteException, MageException;
|
||||
|
||||
public ServerState getServerState() throws RemoteException, MageException;
|
||||
|
||||
//table methods
|
||||
public TableView createTable(UUID sessionId, UUID roomId, MatchOptions matchOptions) throws RemoteException, MageException;
|
||||
public TableView createTournamentTable(UUID sessionId, UUID roomId, TournamentOptions tournamentOptions) throws RemoteException, MageException;
|
||||
public boolean joinTable(UUID sessionId, UUID roomId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws RemoteException, MageException, GameException;
|
||||
public boolean joinTournamentTable(UUID sessionId, UUID roomId, UUID tableId, String name, String playerType, int skill) throws RemoteException, MageException, GameException;
|
||||
public boolean submitDeck(UUID sessionId, UUID tableId, DeckCardLists deckList) throws RemoteException, MageException, GameException;
|
||||
public boolean watchTable(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException;
|
||||
public void leaveTable(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException;
|
||||
public void swapSeats(UUID sessionId, UUID roomId, UUID tableId, int seatNum1, int seatNum2) throws RemoteException, MageException;
|
||||
public void removeTable(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException;
|
||||
public boolean isTableOwner(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException;
|
||||
public TableView getTable(UUID roomId, UUID tableId) throws RemoteException, MageException;
|
||||
public List<TableView> getTables(UUID roomId) throws RemoteException, MageException;
|
||||
public List<String> getConnectedPlayers(UUID roomId) throws RemoteException, MageException;
|
||||
|
||||
//chat methods
|
||||
public void sendChatMessage(UUID chatId, String userName, String message) throws RemoteException, MageException;
|
||||
public void joinChat(UUID chatId, UUID sessionId, String userName) throws RemoteException, MageException;
|
||||
public void leaveChat(UUID chatId, UUID sessionId) throws RemoteException, MageException;
|
||||
public UUID getTableChatId(UUID tableId) throws RemoteException, MageException;
|
||||
public UUID getGameChatId(UUID gameId) throws RemoteException, MageException;
|
||||
public UUID getRoomChatId(UUID roomId) throws RemoteException, MageException;
|
||||
public UUID getTournamentChatId(UUID tournamentId) throws RemoteException, MageException;
|
||||
|
||||
//room methods
|
||||
public UUID getMainRoomId() throws RemoteException, MageException;
|
||||
|
||||
//game methods
|
||||
public void startMatch(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException;
|
||||
public void joinGame(UUID gameId, UUID sessionId) throws RemoteException, MageException;
|
||||
public void watchGame(UUID gameId, UUID sessionId) throws RemoteException, MageException;
|
||||
public void stopWatching(UUID gameId, UUID sessionId) throws RemoteException, MageException;
|
||||
public void sendPlayerUUID(UUID gameId, UUID sessionId, UUID data) throws RemoteException, MageException;
|
||||
public void sendPlayerString(UUID gameId, UUID sessionId, String data) throws RemoteException, MageException;
|
||||
public void sendPlayerBoolean(UUID gameId, UUID sessionId, Boolean data) throws RemoteException, MageException;
|
||||
public void sendPlayerInteger(UUID gameId, UUID sessionId, Integer data) throws RemoteException, MageException;
|
||||
public void concedeGame(UUID gameId, UUID sessionId) throws RemoteException, MageException;
|
||||
|
||||
//tournament methods
|
||||
public void startTournament(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException;
|
||||
public void joinTournament(UUID draftId, UUID sessionId) throws RemoteException, MageException;
|
||||
public TournamentView getTournament(UUID tournamentId) throws RemoteException, MageException;
|
||||
|
||||
//draft methods
|
||||
public void joinDraft(UUID draftId, UUID sessionId) throws RemoteException, MageException;
|
||||
public DraftPickView sendCardPick(UUID draftId, UUID sessionId, UUID cardId) throws RemoteException, MageException;
|
||||
|
||||
//challenge methods
|
||||
public void startChallenge(UUID sessionId, UUID roomId, UUID tableId, UUID challengeId) throws RemoteException, MageException;
|
||||
|
||||
//replay methods
|
||||
public void replayGame(UUID gameId, UUID sessionId) throws RemoteException, MageException;
|
||||
public void startReplay(UUID gameId, UUID sessionId) throws RemoteException, MageException;
|
||||
public void stopReplay(UUID gameId, UUID sessionId) throws RemoteException, MageException;
|
||||
public void nextPlay(UUID gameId, UUID sessionId) throws RemoteException, MageException;
|
||||
public void previousPlay(UUID gameId, UUID sessionId) throws RemoteException, MageException;
|
||||
|
||||
//test methods
|
||||
public void cheat(UUID gameId, UUID sessionId, UUID playerId, DeckCardLists deckList) throws RemoteException, MageException;
|
||||
public boolean cheat(UUID gameId, UUID sessionId, UUID playerId, String cardName) throws RemoteException, MageException;
|
||||
public GameView getGameView(UUID gameId, UUID sessionId, UUID playerId) throws RemoteException, MageException;
|
||||
|
||||
//admin methods
|
||||
public List<UserView> getUsers(UUID sessionId) throws RemoteException, MageException;
|
||||
public void disconnectUser(UUID sessionId, UUID userSessionId) throws RemoteException, MageException;
|
||||
public void removeTable(UUID sessionId, UUID tableId) throws RemoteException, MageException;
|
||||
|
||||
}
|
||||
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.interfaces.callback;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class CallbackClientDaemon extends Thread {
|
||||
|
||||
private final static Logger logger = Logger.getLogger(CallbackClientDaemon.class);
|
||||
|
||||
private static ExecutorService callbackExecutor = Executors.newCachedThreadPool();
|
||||
private final CallbackClient client;
|
||||
private final CallbackServer server;
|
||||
private final UUID id;
|
||||
|
||||
public CallbackClientDaemon(UUID id, CallbackClient client, CallbackServer server) {
|
||||
this.client = client;
|
||||
this.server = server;
|
||||
this.id = id;
|
||||
setDaemon(true);
|
||||
start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
while(true) {
|
||||
final ClientCallback callback = server.callback(id);
|
||||
callbackExecutor.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (callback != null) {
|
||||
client.processCallback(callback);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
logger.fatal("CallbackClientDaemon error ", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
} catch(Exception ex) {
|
||||
logger.fatal("CallbackClientDaemon error ", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.interfaces.callback;
|
||||
|
||||
import mage.MageException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class CallbackException extends MageException {
|
||||
|
||||
public CallbackException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public CallbackException(Throwable t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.interfaces.callback;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public interface CallbackServer {
|
||||
|
||||
public ClientCallback callback(UUID clientId) throws RemoteException;
|
||||
|
||||
}
|
||||
|
|
@ -1,110 +0,0 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.interfaces.callback;
|
||||
|
||||
import java.util.concurrent.locks.Condition;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class CallbackServerSession {
|
||||
|
||||
private final static Logger logger = Logger.getLogger(CallbackServerSession.class);
|
||||
|
||||
private final ClientCallback callback = new ClientCallback();
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
private final Condition waiting = lock.newCondition();
|
||||
private final Condition callbackCalled = lock.newCondition();
|
||||
private boolean waitingForCallback;
|
||||
private boolean threadAlive = true;
|
||||
|
||||
/**
|
||||
*
|
||||
* blocks the thread until a callback is requested
|
||||
*
|
||||
* @return ClientCallback - the callback requested
|
||||
*/
|
||||
public ClientCallback callback() throws InterruptedException {
|
||||
callback.clear();
|
||||
lock.lock();
|
||||
try {
|
||||
waitingForCallback = true;
|
||||
waiting.signal();
|
||||
while (callback.getMethod() == null && threadAlive) {
|
||||
logger.trace("waiting for callback");
|
||||
callbackCalled.await();
|
||||
}
|
||||
waitingForCallback = false;
|
||||
logger.trace("callback called:" + callback.getMethod());
|
||||
return callback;
|
||||
}
|
||||
finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* requests a callback
|
||||
*
|
||||
* @param call - the callback to request
|
||||
*/
|
||||
public void setCallback(ClientCallback call) throws InterruptedException {
|
||||
lock.lock();
|
||||
try {
|
||||
while (!waitingForCallback) {
|
||||
logger.trace("waiting for callback state to call:" + call.getMethod());
|
||||
waiting.await();
|
||||
}
|
||||
callback.setMethod(call.getMethod());
|
||||
callback.setData(call.getData());
|
||||
callback.setObjectId(call.getObjectId());
|
||||
callback.setMessageId(call.getMessageId());
|
||||
callbackCalled.signal();
|
||||
}
|
||||
finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
lock.lock();
|
||||
try {
|
||||
threadAlive = false;
|
||||
callbackCalled.signal();
|
||||
}
|
||||
finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -28,9 +28,12 @@
|
|||
|
||||
package mage.remote;
|
||||
|
||||
import java.rmi.registry.LocateRegistry;
|
||||
import java.rmi.registry.Registry;
|
||||
import mage.interfaces.Server;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InterfaceAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -47,20 +50,13 @@ public class Connection {
|
|||
private int proxyPort;
|
||||
private String proxyUsername;
|
||||
private String proxyPassword;
|
||||
|
||||
// protected Server getServer() {
|
||||
// Server server = null;
|
||||
// try {
|
||||
// Registry reg = LocateRegistry.getRegistry(host, port);
|
||||
// server = (Server) reg.lookup("mage-server");
|
||||
// }
|
||||
// catch (Exception ignored) {}
|
||||
// return server;
|
||||
// }
|
||||
|
||||
private static final String serialization = "?serializationtype=jboss";
|
||||
private static final String transport = "bisocket";
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (host + Integer.toString(port) + proxyType.toString()).hashCode();
|
||||
return (transport + host + Integer.toString(port) + proxyType.toString()).hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -74,11 +70,18 @@ public class Connection {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return host + ":" + Integer.toString(port);
|
||||
return host + ":" + Integer.toString(port) + "/" + serialization;
|
||||
}
|
||||
|
||||
public String getURI() {
|
||||
return "bisocket://" + host + ":" + port;
|
||||
if (host.equals("localhost")) {
|
||||
try {
|
||||
return transport + "://" + getLocalAddress().getHostAddress() + ":" + port + "/" + serialization;
|
||||
} catch (SocketException ex) {
|
||||
// just use localhost if can't find local ip
|
||||
}
|
||||
}
|
||||
return transport + "://" + host + ":" + port + "/" + serialization;
|
||||
}
|
||||
|
||||
public ProxyType getProxyType() {
|
||||
|
|
@ -174,5 +177,21 @@ public class Connection {
|
|||
public void setProxyPassword(String proxyPassword) {
|
||||
this.proxyPassword = proxyPassword;
|
||||
}
|
||||
|
||||
public static InetAddress getLocalAddress() throws SocketException {
|
||||
for (Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); interfaces.hasMoreElements(); ) {
|
||||
NetworkInterface iface = interfaces.nextElement( );
|
||||
if (iface.isLoopback())
|
||||
continue;
|
||||
for (InterfaceAddress addr: iface.getInterfaceAddresses())
|
||||
{
|
||||
InetAddress iaddr = addr.getAddress();
|
||||
if (iaddr instanceof Inet4Address) {
|
||||
return iaddr;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -39,10 +39,10 @@ public class UserView implements Serializable {
|
|||
|
||||
private String userName;
|
||||
private String host;
|
||||
private UUID sessionId;
|
||||
private String sessionId;
|
||||
private Date timeConnected;
|
||||
|
||||
public UserView(String userName, String host, UUID sessionId, Date timeConnected) {
|
||||
public UserView(String userName, String host, String sessionId, Date timeConnected) {
|
||||
this.userName = userName;
|
||||
this.host = host;
|
||||
this.sessionId = sessionId;
|
||||
|
|
@ -57,7 +57,7 @@ public class UserView implements Serializable {
|
|||
return host;
|
||||
}
|
||||
|
||||
public UUID getSessionId() {
|
||||
public String getSessionId() {
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue