cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amic...@apache.org
Subject [5/5] cxf-dosgi git commit: Fix greeter sample issues: - many dialogs created but never disposed (resource leak) - thread never ends (thread leak) - dialog still shown after service bundle is stopped - dialog still shown after client bundle is stopped
Date Fri, 29 Jan 2016 16:15:08 GMT
Fix greeter sample issues:
- many dialogs created but never disposed (resource leak)
- thread never ends (thread leak)
- dialog still shown after service bundle is stopped
- dialog still shown after client bundle is stopped


Project: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/commit/1e102fb8
Tree: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/tree/1e102fb8
Diff: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/diff/1e102fb8

Branch: refs/heads/master
Commit: 1e102fb85054dc958bed74c32f6e7b32c88a55f9
Parents: 2f2bb26
Author: Amichai Rothman <amichai@apache.org>
Authored: Fri Jan 29 17:56:15 2016 +0200
Committer: Amichai Rothman <amichai@apache.org>
Committed: Fri Jan 29 17:56:15 2016 +0200

----------------------------------------------------------------------
 .../dosgi/samples/greeter/client/Activator.java | 26 ++++++++++++++------
 .../samples/greeter/client/GreeterDialog.java   |  4 +++
 2 files changed, 23 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/1e102fb8/samples/greeter/client/src/main/java/org/apache/cxf/dosgi/samples/greeter/client/Activator.java
----------------------------------------------------------------------
diff --git a/samples/greeter/client/src/main/java/org/apache/cxf/dosgi/samples/greeter/client/Activator.java
b/samples/greeter/client/src/main/java/org/apache/cxf/dosgi/samples/greeter/client/Activator.java
index 78b9fe1..121573e 100644
--- a/samples/greeter/client/src/main/java/org/apache/cxf/dosgi/samples/greeter/client/Activator.java
+++ b/samples/greeter/client/src/main/java/org/apache/cxf/dosgi/samples/greeter/client/Activator.java
@@ -19,6 +19,7 @@
 package org.apache.cxf.dosgi.samples.greeter.client;
 
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.cxf.dosgi.samples.greeter.GreeterData;
 import org.apache.cxf.dosgi.samples.greeter.GreeterException;
@@ -32,15 +33,25 @@ import org.osgi.util.tracker.ServiceTracker;
 public class Activator implements BundleActivator {
 
     private ServiceTracker<GreeterService, GreeterService> tracker;
+    private ConcurrentHashMap<GreeterService, GreeterDialog> dialogs =
+                new ConcurrentHashMap<GreeterService, GreeterDialog>();
 
     public void start(final BundleContext bc) {
         tracker = new ServiceTracker<GreeterService, GreeterService>(bc, GreeterService.class,
null) {
             @Override
             public GreeterService addingService(ServiceReference<GreeterService> reference)
{
                 GreeterService service = super.addingService(reference);
+                dialogs.put(service, new GreeterDialog());
                 useService(service);
                 return service;
             }
+
+            @Override
+            public void removedService(ServiceReference<GreeterService> reference,
GreeterService service) {
+                super.removedService(reference, service);
+                GreeterDialog dialog = dialogs.remove(service);
+                dialog.dispose();
+            }
         };
         tracker.open();
     }
@@ -56,8 +67,15 @@ public class Activator implements BundleActivator {
 
     private void greeterUI(final GreeterService greeter) {
         while (true) {
+            GreeterDialog dialog = dialogs.get(greeter);
+            if (dialog == null) {
+                return; // exit thread if service is removed
+            }
             System.out.println("*** Opening greeter client dialog ***");
-            Object gd = getGreeterData();
+            dialog.resetSelection();
+            dialog.setVisible(true); // blocks until dismissed
+            Object gd = dialog.getSelection();
+
             if (gd instanceof String) {
                 System.out.println("*** Invoking greeter ***");
                 Map<GreetingPhrase, String> result = greeter.greetMe((String) gd);
@@ -82,12 +100,6 @@ public class Activator implements BundleActivator {
         }
     }
 
-    private static Object getGreeterData() {
-        GreeterDialog gd = new GreeterDialog();
-        gd.setVisible(true);
-        return gd.getSelection();
-    }
-
     public void stop(BundleContext bc) throws Exception {
         tracker.close();
     }

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/1e102fb8/samples/greeter/client/src/main/java/org/apache/cxf/dosgi/samples/greeter/client/GreeterDialog.java
----------------------------------------------------------------------
diff --git a/samples/greeter/client/src/main/java/org/apache/cxf/dosgi/samples/greeter/client/GreeterDialog.java
b/samples/greeter/client/src/main/java/org/apache/cxf/dosgi/samples/greeter/client/GreeterDialog.java
index 3983a82..fa48792 100644
--- a/samples/greeter/client/src/main/java/org/apache/cxf/dosgi/samples/greeter/client/GreeterDialog.java
+++ b/samples/greeter/client/src/main/java/org/apache/cxf/dosgi/samples/greeter/client/GreeterDialog.java
@@ -186,6 +186,10 @@ public class GreeterDialog extends JDialog {
         return complexPanel;
     }
 
+    public void resetSelection() {
+        selection = null;
+    }
+
     public Object getSelection() {
         return selection;
     }


Mime
View raw message