cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1467958 - in /cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service: EventAdminHelper.java ImportReferenceImpl.java ImportRegistrationImpl.java
Date Mon, 15 Apr 2013 12:12:30 GMT
Author: cschneider
Date: Mon Apr 15 12:12:30 2013
New Revision: 1467958

URL: http://svn.apache.org/r1467958
Log:
DOSGI-163 refactoring. Applying patch with thanks to Amichai

Removed:
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ImportReferenceImpl.java
Modified:
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ImportRegistrationImpl.java

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java?rev=1467958&r1=1467957&r2=1467958&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java
Mon Apr 15 12:12:30 2013
@@ -73,7 +73,7 @@ public class EventAdminHelper {
 
         EndpointDescription epd = null;
         if (rsae.getImportReference() != null) {
-            epd = ((ImportReferenceImpl)rsae.getImportReference()).getImportedEndpointAlways();
+            epd = ((ImportRegistrationImpl)rsae.getImportReference()).getImportedEndpointAlways();
             setIfNotNull(props, "import.registration", epd);
         } else if (rsae.getExportReference() != null) {
             epd = ((ExportReferenceImpl)rsae.getExportReference()).getExportedEndpoint();

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ImportRegistrationImpl.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ImportRegistrationImpl.java?rev=1467958&r1=1467957&r2=1467958&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ImportRegistrationImpl.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ImportRegistrationImpl.java
Mon Apr 15 12:12:30 2013
@@ -29,87 +29,72 @@ import org.osgi.service.remoteserviceadm
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-// *************************** FIXME: some old methods might be in here ****
-public class ImportRegistrationImpl implements ImportRegistration {
+public class ImportRegistrationImpl implements ImportRegistration, ImportReference {
 
     private static final Logger LOG = LoggerFactory.getLogger(ImportRegistrationImpl.class);
 
     private Throwable exception;
-    private ServiceRegistration importedService;
+    private ServiceRegistration importedService; // used only in parent
     private EndpointDescription importedEndpoint;
     private ClientServiceFactory clientServiceFactory;
     private RemoteServiceAdminCore rsaCore;
     private boolean closed;
-    private boolean detatched;
+    private boolean detached; // used only in parent
 
     private ImportRegistrationImpl parent;
-    private List<ImportRegistrationImpl> childs;
+    private List<ImportRegistrationImpl> children; // used only in parent
 
-    private ImportReference importReference;
-    
     public ImportRegistrationImpl(Throwable ex) {
         exception = ex;
-        init();
+        initParent();
     }
 
     public ImportRegistrationImpl(EndpointDescription endpoint, RemoteServiceAdminCore rsac)
{
         importedEndpoint = endpoint;
         rsaCore = rsac;
-        init();
+        initParent();
     }
 
     /**
-     * Create a clone of this object which is linked to this object
+     * Creates a clone of the given parent instance.
      */
     public ImportRegistrationImpl(ImportRegistrationImpl ir) {
         // we always want a link to the parent ...
-        ir = ir.getParent();
-
-        parent = ir;
-        exception = ir.getException();
-        importedEndpoint = ir.getImportedEndpointDescription();
-        importedService = ir.getImportedServiceRegistration();
-        clientServiceFactory = ir.getClientServiceFactory();
-        rsaCore = ir.getRsaCore();
+        parent = ir.getParent();
+        exception = parent.getException();
+        importedEndpoint = parent.getImportedEndpointDescription();
+        clientServiceFactory = parent.clientServiceFactory;
+        rsaCore = parent.rsaCore;
 
         parent.instanceAdded(this);
     }
 
-    private void init() {
+    private void initParent() {
         parent = this;
-        childs = new ArrayList<ImportRegistrationImpl>(1);
-    }
-
-    private synchronized void instanceAdded(ImportRegistrationImpl i) {
-        childs.add(i);
+        children = new ArrayList<ImportRegistrationImpl>(1);
     }
 
-    public synchronized void close() {
-        LOG.debug("close() called ");
-
-        if (isFailure()) {
-            return;
-        }
-
-        if (closed) {
-            return;
-        }
-
-        closed = true;
-        rsaCore.removeImportRegistration(this);
-        parent.instanceClosed(this);
+    /**
+     * Called on parent when a child is added.
+     *
+     * @param iri the child
+     */
+    private synchronized void instanceAdded(ImportRegistrationImpl iri) {
+        children.add(iri);
     }
 
     /**
-     * only called on the parent object
+     * Called on parent when a child is closed.
+     *
+     * @param iri the child
      */
-    private synchronized void instanceClosed(ImportRegistrationImpl i) {
-        childs.remove(i);
+    private synchronized void instanceClosed(ImportRegistrationImpl iri) {
+        children.remove(iri);
 
-        if (childs.isEmpty() && !detatched && closed) {
-            detatched = true; 
-            
-            LOG.debug("really closing ImportRegistartion now! ");
+        if (children.isEmpty() && !detached && closed) {
+            detached = true;
+
+            LOG.debug("really closing ImportRegistartion now");
 
             if (clientServiceFactory != null) {
                 clientServiceFactory.setCloseable(true);
@@ -120,109 +105,90 @@ public class ImportRegistrationImpl impl
         }
     }
 
+    public synchronized void close() {
+        LOG.debug("close() called");
+
+        if (isInvalid()) {
+            return;
+        }
+
+        closed = true;
+        rsaCore.removeImportRegistration(this);
+        parent.instanceClosed(this);
+    }
+
     /**
-     * used to close all ImportRegistrations in the case of an error ...
+     * Closes all ImportRegistrations which share the same parent as this one.
      */
     public synchronized void closeAll() {
         if (this == parent) {
             LOG.info("closing down all child ImportRegistrations");
 
-            for (ImportRegistrationImpl ir : new ArrayList<ImportRegistrationImpl>(childs))
{
+            // we must iterate over a copy of children since close() removes the child
+            // from the list (which would cause a ConcurrentModificationException)
+            for (ImportRegistrationImpl ir : new ArrayList<ImportRegistrationImpl>(children))
{
                 ir.close();
             }
-            if (!closed) {
-                this.close();
-            }
+            this.close();
         } else {
             parent.closeAll();
         }
     }
 
-    private ServiceRegistration getImportedServiceRegistration() {
-        return importedService;
-    }
-
-    public Throwable getException() {
-        return exception;
+    public EndpointDescription getImportedEndpointDescription() {
+        return isInvalid() ? null : importedEndpoint;
     }
 
-    public EndpointDescription getImportedEndpointDescription() {
-        if (isFailure()) {
-            return null;
-        }
-        if (closed) {
-            return null;
-        }
-        
-        return importedEndpoint;
+    @Override
+    public EndpointDescription getImportedEndpoint() {
+        return getImportedEndpointDescription();
     }
 
+    @Override
     public ServiceReference getImportedService() {
-        if (isFailure() || closed) {
-            return null;
-        }
+        return isInvalid() || parent.importedService == null ? null : parent.importedService.getReference();
+    }
 
-        if (importedService == null) {
-            return null;
-        }
+    @Override
+    public ImportReference getImportReference() {
+        return this;
+    }
 
-        return importedService.getReference();
+    @Override
+    public Throwable getException() {
+        return exception;
     }
 
     public void setException(Throwable ex) {
         exception = ex;
     }
 
-    private boolean isFailure() {
-        return exception != null;
-    }
-
-    private void setImportedServiceRegistrationInternal(ServiceRegistration proxyRegistration)
{
-        importedService = proxyRegistration;
+    private boolean isInvalid() {
+        return exception != null || closed;
     }
 
     public synchronized void setImportedServiceRegistration(ServiceRegistration proxyRegistration)
{
         if (parent != this) {
-            throw new IllegalStateException("this method may only be called on the parent
!");
+            throw new IllegalStateException("this method may only be called on the parent");
         }
 
-        setImportedServiceRegistrationInternal(proxyRegistration);
-        for (ImportRegistrationImpl ir : childs) {
-            ir.setImportedServiceRegistrationInternal(proxyRegistration);
-        }
+        importedService = proxyRegistration;
     }
 
     public void setClientServiceFactory(ClientServiceFactory csf) {
         clientServiceFactory = csf;
     }
 
-    public RemoteServiceAdminCore getRsaCore() {
-        return rsaCore;
-    }
-
-    public void setRsaCore(RemoteServiceAdminCore rsaCore) {
-        this.rsaCore = rsaCore;
-    }
-
-    public ClientServiceFactory getClientServiceFactory() {
-        return clientServiceFactory;
-    }
-
-    public void setParent(ImportRegistrationImpl parent) {
-        this.parent = parent;
-    }
-
     public ImportRegistrationImpl getParent() {
         return parent;
     }
 
-    public ImportReference getImportReference() {
-        if (importReference == null) {
-            importReference = new ImportReferenceImpl(this);
-        }
-        return importReference;
-    }
-
+    /**
+     * Returns the imported endpoint even if this
+     * instance is closed or has an exception.
+     *
+     * @return the imported endpoint
+     */
     public EndpointDescription getImportedEndpointAlways() {
         return importedEndpoint;
     }



Mime
View raw message