Modify

Opened 14 years ago

Closed 14 years ago

#5152 closed enhancement (fixed)

[patch] Maximum number of concurrent connections

Reported by: matgott@… Owned by: team
Priority: normal Milestone:
Component: Core imagery Version:
Keywords: Cc:

Description

With this patch is possible to specify the number of concurrent connections to the wms service.

Attachments (0)

Change History (3)

comment:1 by matgott@…, 14 years ago

It seems that file upload is not working now, so I'll paste the patch here:

From 4e017f9db577a2fddfaf322e996923460700fcba Mon Sep 17 00:00:00 2001
From: gomatteo <matgott@tin.it>
Date: Wed, 16 Jun 2010 12:05:59 +0200
Subject: [PATCH] max number of concurrent connections

---
 src/wmsplugin/WMSLayer.java            |   15 +++++++++++++--
 src/wmsplugin/WMSPlugin.java           |    6 ++++++
 src/wmsplugin/WMSPreferenceEditor.java |   14 ++++++++++++--
 3 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/src/wmsplugin/WMSLayer.java b/src/wmsplugin/WMSLayer.java
index cd6fe54..69c55d0 100644
--- a/src/wmsplugin/WMSLayer.java
+++ b/src/wmsplugin/WMSLayer.java
@@ -37,12 +37,14 @@ import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
 import org.openstreetmap.josm.gui.layer.Layer;
 import org.openstreetmap.josm.io.CacheFiles;
 import org.openstreetmap.josm.tools.ImageProvider;
+import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent;
+import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
 
 /**
  * This is a layer that grabs the current screen from an WMS server. The data
  * fetched this way is tiled and managed to the disc to reduce server load.
  */
-public class WMSLayer extends Layer {
+public class WMSLayer extends Layer implements PreferenceChangedListener {
 	protected static final Icon icon =
 		new ImageIcon(Toolkit.getDefaultToolkit().createImage(WMSPlugin.class.getResource("/images/wms_small.png")));
 
@@ -96,7 +98,7 @@ public class WMSLayer extends Layer {
 		}
 		resolution = mv.getDist100PixelText();
 
-		executor = Executors.newFixedThreadPool(3);
+		executor = Executors.newFixedThreadPool( Main.pref.getInteger("wmsplugin.numThreads", WMSPlugin.simultaneousConnections) );
 		if (baseURL != null && !baseURL.startsWith("html:") && !WMSGrabber.isUrlWithPatterns(baseURL)) {
 			if (!(baseURL.endsWith("&") || baseURL.endsWith("?"))) {
 				if (!confirmMalformedUrl(baseURL)) {
@@ -109,6 +111,8 @@ public class WMSLayer extends Layer {
 				}
 			}
 		}
+
+		Main.pref.addPreferenceChangeListener(this);
 	}
 
 	public boolean hasAutoDownload(){
@@ -475,4 +479,11 @@ public class WMSLayer extends Layer {
 			WMSPlugin.refreshMenu();
 		}
 	}
+	
+	public void preferenceChanged(PreferenceChangeEvent event) {
+		if (event.getKey().equals("wmsplugin.simultaneousConnections")) {
+			executor.shutdownNow();
+			executor = Executors.newFixedThreadPool( Main.pref.getInteger("wmsplugin.numThreads", WMSPlugin.simultaneousConnections) );
+		}
+	}
 }
diff --git a/src/wmsplugin/WMSPlugin.java b/src/wmsplugin/WMSPlugin.java
index 4a462a2..cb11eb9 100644
--- a/src/wmsplugin/WMSPlugin.java
+++ b/src/wmsplugin/WMSPlugin.java
@@ -52,6 +52,7 @@ public class WMSPlugin extends Plugin {
     static boolean doOverlap = false;
     static int overlapEast = 14;
     static int overlapNorth = 4;
+    static int simultaneousConnections = 3;
 
     // remember state of menu item to restore on changed preferences
     static private boolean menuEnabled = false;
@@ -109,6 +110,11 @@ public class WMSPlugin extends Plugin {
         try {
             overlapNorth = Integer.valueOf(prefs.get("wmsplugin.url.overlapNorth"));
         } catch (Exception e) {} // If sth fails, we drop to default settings.
+		
+        // Load the settings for number of simultaneous connections
+        try {
+            simultaneousConnections = Integer.valueOf(prefs.get("wmsplugin.simultanousConnections"));
+        } catch (Exception e) {} // If sth fails, we drop to default settings.
 
         // And then the names+urls of WMS servers
         int prefid = 0;
diff --git a/src/wmsplugin/WMSPreferenceEditor.java b/src/wmsplugin/WMSPreferenceEditor.java
index 42c8b28..8866d38 100644
--- a/src/wmsplugin/WMSPreferenceEditor.java
+++ b/src/wmsplugin/WMSPreferenceEditor.java
@@ -38,6 +38,7 @@ public class WMSPreferenceEditor implements PreferenceSetting {
     JCheckBox overlapCheckBox;
     JSpinner spinEast;
     JSpinner spinNorth;
+    JSpinner spinSimConn;
 
     public void addGui(final PreferenceTabbedPane gui) {
         JPanel p = gui.createPreferenceTab("wms", tr("WMS Plugin Preferences"), tr("Modify list of WMS servers displayed in the WMS plugin menu"));
@@ -162,7 +163,6 @@ public class WMSPreferenceEditor implements PreferenceSetting {
         p.add(new JLabel(tr("Downloader:")), GBC.eol().fill(GridBagConstraints.HORIZONTAL));
         p.add(browser);
 
-
         //Overlap
         p.add(Box.createHorizontalGlue(), GBC.eol().fill(GridBagConstraints.HORIZONTAL));
 
@@ -180,6 +180,15 @@ public class WMSPreferenceEditor implements PreferenceSetting {
         overlapPanel.add(spinNorth);
 
         p.add(overlapPanel);
+		
+        // Simultaneous connections
+        p.add(Box.createHorizontalGlue(), GBC.eol().fill(GridBagConstraints.HORIZONTAL));
+        JLabel labelSimConn = new JLabel(tr("Simultaneous connections"));
+        spinSimConn = new JSpinner(new SpinnerNumberModel(WMSPlugin.simultaneousConnections, 1, 30, 1));
+        JPanel overlapPanelSimConn = new JPanel(new FlowLayout());
+        overlapPanelSimConn.add(labelSimConn);
+        overlapPanelSimConn.add(spinSimConn);
+        p.add(overlapPanelSimConn);
     }
 
     public boolean ok() {
@@ -222,12 +231,13 @@ public class WMSPreferenceEditor implements PreferenceSetting {
         WMSPlugin.doOverlap = overlapCheckBox.getModel().isSelected();
         WMSPlugin.overlapEast = (Integer) spinEast.getModel().getValue();
         WMSPlugin.overlapNorth = (Integer) spinNorth.getModel().getValue();
+        WMSPlugin.simultaneousConnections = (Integer) spinSimConn.getModel().getValue();
 
         Main.pref.put("wmsplugin.url.overlap",    String.valueOf(WMSPlugin.doOverlap));
         Main.pref.put("wmsplugin.url.overlapEast", String.valueOf(WMSPlugin.overlapEast));
         Main.pref.put("wmsplugin.url.overlapNorth", String.valueOf(WMSPlugin.overlapNorth));
 
-        Main.pref.put("wmsplugin.browser", browser.getEditor().getItem().toString());
+        Main.pref.put("wmsplugin.simultaneousConnections", String.valueOf(WMSPlugin.simultaneousConnections));
         return false;
     }
 
-- 
1.7.1


comment:2 by stoecker, 14 years ago

Summary: Maximum number of concurrent connections[patch] Maximum number of concurrent connections

comment:3 by stoecker, 14 years ago

Resolution: fixed
Status: newclosed

In [o21796].

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.