From: <an...@us...> - 2007-03-19 15:34:45
|
Revision: 605 http://svn.sourceforge.net/magicmap/?rev=605&view=rev Author: anweiss Date: 2007-03-19 08:18:24 -0700 (Mon, 19 Mar 2007) Log Message: ----------- fixed bug 1683705 (exceptions on disconect) and moved all communication callbacks from the MainFrame to the controller Modified Paths: -------------- trunk/magicmapclient/src/net/sf/magicmap/client/controller/Controller.java trunk/magicmapclient/src/net/sf/magicmap/client/controller/IController.java trunk/magicmapclient/src/net/sf/magicmap/client/controller/PollHandler.java trunk/magicmapclient/src/net/sf/magicmap/client/controller/SOAPServerManager.java trunk/magicmapclient/src/net/sf/magicmap/client/controller/ServerPoller.java trunk/magicmapclient/src/net/sf/magicmap/client/controller/VirtualServerManager.java trunk/magicmapclient/src/net/sf/magicmap/client/gui/MainFrame.java Modified: trunk/magicmapclient/src/net/sf/magicmap/client/controller/Controller.java =================================================================== --- trunk/magicmapclient/src/net/sf/magicmap/client/controller/Controller.java 2007-03-19 15:14:34 UTC (rev 604) +++ trunk/magicmapclient/src/net/sf/magicmap/client/controller/Controller.java 2007-03-19 15:18:24 UTC (rev 605) @@ -5,6 +5,8 @@ package net.sf.magicmap.client.controller; import java.net.MalformedURLException; +import java.net.SocketTimeoutException; +import java.rmi.UnknownHostException; import java.util.ArrayList; import java.util.Collection; @@ -42,36 +44,43 @@ * * @author thuebner */ -public class Controller implements IController { +public class Controller + implements + IController, + ServerDisconnectCallback, + ServerConnectCallback, + CreateNewMapCallback, + MapNamesCallback { - private static int numCalled = 0; + private static int numCalled = 0; + private static int disconnectAttempts = 0; /** * Die Instanz. */ - private static Controller controller = null; + private static Controller controller = null; /** * Das Knotenmodel. */ - private INodeModel nodeModel; // Model f\xFCr Graphen + private INodeModel nodeModel; // Model f\xFCr Graphen - private ClientNode client; // Ausgezeichneter Knoten + private ClientNode client; // Ausgezeichneter Knoten - private ServerPoller poller; // Server st\xE4ndig nach \xC4nderungen fragen + private ServerPoller poller; // Server st\xE4ndig nach \xC4nderungen fragen - private PollHandler pollhandler; // Klasse zur Verarbeitung der Pollergebnisse + private PollHandler pollhandler; // Klasse zur Verarbeitung der Pollergebnisse - private ServerManager serverManager; // Manager f\xFCr die Verbindung zum Server + private ServerManager serverManager; // Manager f\xFCr die Verbindung zum Server // private CallbackHandler callbackHandler; // S\xE4mtliche callbacks werden dort behandelt - private MapInfo currentMap; + private MapInfo currentMap; - private boolean invisble; // Invisible-Modus (keine Daten an Server) + private boolean invisble; // Invisible-Modus (keine Daten an Server) - private ScannerAllocator scannerAllocator; - private PluginManager pluginManager; + private ScannerAllocator scannerAllocator; + private PluginManager pluginManager; /** * Private constructor for singleton instance @@ -169,8 +178,8 @@ if (this.currentMap.realheight > 0 && this.currentMap.realwidth > 0) // TODO: Interface f\xFCr GUI mit methode setMapTitle() - ((MapView) MainGUI.getInstance().getJComponent("mapView")).setTitle(GUIUtils.i18n("map", false) - + " - " + this.currentMap.name + " Gr\xF6\xDFe: " + this.currentMap.realwidth + " X " + ((MapView) MainGUI.getInstance().getJComponent("mapView")).setTitle(GUIUtils.i18n("map", false) + " - " + + this.currentMap.name + " Gr\xF6\xDFe: " + this.currentMap.realwidth + " X " + this.currentMap.realheight + " cm"); } } @@ -288,12 +297,8 @@ this.pluginManager.connect(); } - public void disconnect(ServerDisconnectCallback callback){ - this.pluginManager.dispose(); - - if (isMapLoaded()) closeMap(); - this.serverManager.disconnect(callback); - this.client = null; + public void disconnect(){ + this.serverManager.disconnect(this); } /** @@ -414,8 +419,7 @@ public void retrieveMap(String name, MapCallback callback){ this.serverManager.retrieveMap(name, callback); // TODO: Interface f\xFCr GUI mit methode setMapTitle() - ((MapView) MainGUI.getInstance().getJComponent("mapView")).setTitle(GUIUtils.i18n("map", false) + " - " - + name); + ((MapView) MainGUI.getInstance().getJComponent("mapView")).setTitle(GUIUtils.i18n("map", false) + " - " + name); } public void retrieveMapNames(MapNamesCallback callback, boolean openMapDialog){ @@ -446,7 +450,52 @@ } catch (MalformedURLException e) { throw new RuntimeException(e.getMessage()); } + } + public void disconnected(){ + disconnectAttempts = 0; + if (isMapLoaded()) closeMap(); + this.pluginManager.dispose(); + this.client = null; + MainGUI.getInstance().getMainFrame().disconnected(); } + public void disconnectionError(Exception e){ + if (++disconnectAttempts < 4) { + disconnect(); + } else { + disconnectAttempts = 0; + if (isMapLoaded()) closeMap(); + this.pluginManager.dispose(); + this.client = null; + MainGUI.getInstance().getMainFrame().disconnectionError(e); + } + } + + public void connected(long sesssionId){ + MainGUI.getInstance().getMainFrame().connected(sesssionId); + } + + public void connectionError(Exception e){ + e.printStackTrace(); + MainGUI.getInstance().getMainFrame().connectionError(e); + } + + public void createNewMapError(Exception e){ + e.printStackTrace(); + MainGUI.getInstance().getMainFrame().createNewMapError(e); + } + + public void newMapCreated(MapInfo map){ + MainGUI.getInstance().getMainFrame().newMapCreated(map); + } + + public void getMapNamesError(Exception e){ + e.printStackTrace(); + MainGUI.getInstance().getMainFrame().getMapNamesError(e); + } + + public void openMapDialog(String[] names){ + MainGUI.getInstance().getMainFrame().openMapDialog(names); + } } Modified: trunk/magicmapclient/src/net/sf/magicmap/client/controller/IController.java =================================================================== --- trunk/magicmapclient/src/net/sf/magicmap/client/controller/IController.java 2007-03-19 15:14:34 UTC (rev 604) +++ trunk/magicmapclient/src/net/sf/magicmap/client/controller/IController.java 2007-03-19 15:18:24 UTC (rev 605) @@ -120,7 +120,7 @@ void connect(ServerConnectCallback callback); - void disconnect(ServerDisconnectCallback callback); + void disconnect(); /** * Erzeugt einen Referenzpunkt auf der aktuellen Karte mit den aktuellen Modified: trunk/magicmapclient/src/net/sf/magicmap/client/controller/PollHandler.java =================================================================== --- trunk/magicmapclient/src/net/sf/magicmap/client/controller/PollHandler.java 2007-03-19 15:14:34 UTC (rev 604) +++ trunk/magicmapclient/src/net/sf/magicmap/client/controller/PollHandler.java 2007-03-19 15:18:24 UTC (rev 605) @@ -58,6 +58,9 @@ public void run(){ try { + if (!controller.isConnected()){ + return; + } INodeModel nodeModel = PollHandler.this.controller.getNodeModel(); Node node = nodeModel.findNode(position.getName()); Modified: trunk/magicmapclient/src/net/sf/magicmap/client/controller/SOAPServerManager.java =================================================================== --- trunk/magicmapclient/src/net/sf/magicmap/client/controller/SOAPServerManager.java 2007-03-19 15:14:34 UTC (rev 604) +++ trunk/magicmapclient/src/net/sf/magicmap/client/controller/SOAPServerManager.java 2007-03-19 15:18:24 UTC (rev 605) @@ -103,6 +103,7 @@ @Override public void run(){ synchronized (SOAPServerManager.mutex) { + if (!isConnected()) return; try { SOAPServerManager.this.sessionDelegate.disconnect(Settings.getClientName(), Settings .getClientMAC(), Settings.getClientPassword(), SOAPServerManager.this.sessionId); @@ -110,10 +111,10 @@ SOAPServerManager.this.mapDelegate = null; SOAPServerManager.this.sessionDelegate = null; callback.disconnected(); + SOAPServerManager.this.sessionId = -1; } catch (Exception e) { callback.disconnectionError(e); } - SOAPServerManager.this.sessionId = -1; } } }; @@ -138,6 +139,7 @@ @Override public void run(){ synchronized (SOAPServerManager.mutex) { + if (!isConnected()) return; try { SOAPServerManager.this.mapDelegate.createNewMap(SOAPServerManager.this.sessionId, name, URL, imageWidth, imageHeight, width, height); @@ -178,6 +180,7 @@ @Override public void run(){ synchronized (SOAPServerManager.mutex) { + if (!isConnected()) return; try { String[] names = SOAPServerManager.this.mapDelegate.getMapNames(); if (openDialog) @@ -208,6 +211,7 @@ @Override public void run(){ synchronized (SOAPServerManager.mutex) { + if (!isConnected()) return; try { MapDTO mapDTO = SOAPServerManager.this.mapDelegate.getMap(name); callback.mapReceived(mapDTO); @@ -262,6 +266,7 @@ @Override public void run(){ synchronized (SOAPServerManager.mutex) { + if (!isConnected()) return; try { SOAPServerManager.this.positionDelgate.createOrUpdatePosition( SOAPServerManager.this.sessionId, @@ -303,6 +308,7 @@ @Override public void run(){ synchronized (SOAPServerManager.mutex) { + if (!isConnected()) return; try { SOAPServerManager.this.mapDelegate.createGeoPoint(SOAPServerManager.this.sessionId, mapName, x, y, geoPos.getLongitude(), geoPos.getLatitude(), geoPos.getAltitude()); @@ -335,6 +341,7 @@ @Override public void run(){ synchronized (SOAPServerManager.mutex) { + if (!isConnected()) return; try { SOAPServerManager.this.positionDelgate.deletePosition(SOAPServerManager.this.sessionId, mapname, positionId); @@ -366,6 +373,7 @@ @Override public void run(){ synchronized (SOAPServerManager.mutex) { + if (!isConnected()) return; try { SOAPServerManager.this.mapDelegate.deleteGeoPoint(SOAPServerManager.this.sessionId, id); callback.positionDeleted(id); @@ -396,6 +404,7 @@ @Override public void run(){ synchronized (SOAPServerManager.mutex) { + if (!isConnected()) return; try { SOAPServerManager.this.positionDelgate.movePosition(SOAPServerManager.this.sessionId, mapname, positionId, x, y, z, fixed); @@ -445,6 +454,7 @@ @Override public void run(){ synchronized (SOAPServerManager.mutex) { + if (!isConnected()) return; try { SOAPServerManager.this.positionDelgate.createOrUpdateClientPosition( SOAPServerManager.this.sessionId, @@ -485,6 +495,7 @@ @Override public void run(){ synchronized (SOAPServerManager.mutex) { + if (!isConnected()) return; try { SOAPServerManager.this.positionDelgate.createOrUpdateAccessPosition( SOAPServerManager.this.sessionId, @@ -518,6 +529,7 @@ @Override public void run(){ synchronized (SOAPServerManager.mutex) { + if (!isConnected()) return; try { SOAPServerManager.this.positionDelgate.setAccessPointHiddenStatus( SOAPServerManager.this.sessionId, @@ -546,6 +558,7 @@ @Override public void run(){ synchronized (SOAPServerManager.mutex) { + if (!isConnected()) return; // retrieve and communicate common positions (WLAN, i.e. // APs, // clients,...) @@ -598,6 +611,7 @@ @Override public void run(){ synchronized (SOAPServerManager.mutex) { + if (!isConnected()) return; try { int x = SOAPServerManager.this.controller.getClientPosX(); int y = SOAPServerManager.this.controller.getClientPosY(); @@ -675,6 +689,7 @@ @Override public void run(){ synchronized (SOAPServerManager.mutex) { + if (!isConnected()) return; try { // retrieve geo points GeoPointDTO[] geoPoses = SOAPServerManager.this.mapDelegate.getGeoPointsForMap( @@ -706,6 +721,7 @@ @Override public void run(){ synchronized (SOAPServerManager.mutex) { + if (!isConnected()) return; try { // retrieve maps String[] names = SOAPServerManager.this.mapDelegate.getMapNames(); Modified: trunk/magicmapclient/src/net/sf/magicmap/client/controller/ServerPoller.java =================================================================== --- trunk/magicmapclient/src/net/sf/magicmap/client/controller/ServerPoller.java 2007-03-19 15:14:34 UTC (rev 604) +++ trunk/magicmapclient/src/net/sf/magicmap/client/controller/ServerPoller.java 2007-03-19 15:18:24 UTC (rev 605) @@ -123,8 +123,6 @@ } - - /** * Wird aufgerufen wenn beim \xDCbermitteln der Position irgendwelche Fehler auftreten. * @see net.sf.magicmap.client.interfaces.FetchPositionsCallback#positionFetchError(java.lang.Exception) @@ -145,15 +143,4 @@ this.isFetching = false; } } - - /* (non-Javadoc) - * @see net.sf.magicmap.client.interfaces.FetchInfoPointsCallback#infoPointFetchError(java.lang.Exception) - */ - public void infoPointFetchError(Exception e){ - e.printStackTrace(); - synchronized (ServerPoller.syncObj) { - this.isFetching = false; - } - } - } Modified: trunk/magicmapclient/src/net/sf/magicmap/client/controller/VirtualServerManager.java =================================================================== --- trunk/magicmapclient/src/net/sf/magicmap/client/controller/VirtualServerManager.java 2007-03-19 15:14:34 UTC (rev 604) +++ trunk/magicmapclient/src/net/sf/magicmap/client/controller/VirtualServerManager.java 2007-03-19 15:18:24 UTC (rev 605) @@ -483,6 +483,7 @@ public void run(){ synchronized (mutex) { + if (!isConnected()) return; try { int x = controller.getClientPosX(); int y = controller.getClientPosY(); Modified: trunk/magicmapclient/src/net/sf/magicmap/client/gui/MainFrame.java =================================================================== --- trunk/magicmapclient/src/net/sf/magicmap/client/gui/MainFrame.java 2007-03-19 15:14:34 UTC (rev 604) +++ trunk/magicmapclient/src/net/sf/magicmap/client/gui/MainFrame.java 2007-03-19 15:18:24 UTC (rev 605) @@ -55,13 +55,7 @@ import com.brunchboy.util.swing.relativelayout.RelativeLayout; import com.jgoodies.uif_lite.component.UIFSplitPane; -public class MainFrame extends JFrame - implements - ServerConnectCallback, - ServerDisconnectCallback, - CreateNewMapCallback, - MapNamesCallback, - LoadMapDialogListener { +public class MainFrame extends JFrame implements LoadMapDialogListener { /** * serial version id @@ -285,8 +279,7 @@ this.outlineView = new OutlineView(Controller.getInstance().getNodeModel(), "outlineView"); this.consoleView = new ConsoleView("consoleView"); this.mapView = new MapView(Controller.getInstance().getNodeModel(), null, "mapView"); - this.measurementView = new MeasurementView(Controller - .getInstance().getNodeModel(), "measurementView"); + this.measurementView = new MeasurementView(Controller.getInstance().getNodeModel(), "measurementView"); this.mapPanel = new MapPanel("mapPanel"); this.mapPanel.setMapView(this.mapView); } @@ -366,10 +359,11 @@ */ public void disconnectionError(Exception e){ this.connectAction.setEnabled(true); - this.disconnectAction.setEnabled(false); this.statusBar.setInvisible(Controller.getInstance().isInvisible()); + this.disconnectAction.setEnabled(false); + this.newMapAction.setEnabled(false); + this.loadMapAction.setEnabled(false); this.statusBar.setMessage(GUIUtils.i18n(GUIConstants.STATE_DISCONNECTED)); - //JOptionPane.showMessageDialog(this, "Fehler beim Trennen der Verbindung:\n\n " + e.getMessage()); } /* (non-Javadoc) @@ -433,7 +427,7 @@ setCursor(new Cursor(Cursor.WAIT_CURSOR)); this.statusBar.setMessage(GUIUtils.i18n(GUIConstants.STATE_CONNECTING)); this.statusBar.setInvisible(Controller.getInstance().isInvisible()); - Controller.getInstance().connect(this); + Controller.getInstance().connect(Controller.getInstance()); } /** @@ -501,7 +495,7 @@ */ @Override public void actionPerformed(ActionEvent e){ - Controller.getInstance().disconnect(MainFrame.this); + Controller.getInstance().disconnect(); } }; @@ -520,7 +514,7 @@ MapInfo info = NewMapDialog.showDialog(MainFrame.this); if (info != null) Controller.getInstance().createNewMap(info.name, info.imageURL, info.width, info.height, - info.realwidth, info.realheight, MainFrame.this); + info.realwidth, info.realheight, Controller.getInstance()); } }; @@ -536,7 +530,7 @@ */ @Override public void actionPerformed(ActionEvent e){ - Controller.getInstance().retrieveMapNames(MainFrame.this, true); + Controller.getInstance().retrieveMapNames(Controller.getInstance(), true); } }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |