This is an automated email from the ASF dual-hosted git repository. amichair pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/aries-rsa.git
commit d13e90db515b8dea366567e668aa892c22481106 Author: Amichai Rothman <[email protected]> AuthorDate: Mon Mar 23 23:41:52 2026 +0200 ARIES-2209 Merge ExportReferenceImpl into ExportRegistrationImpl --- .../apache/aries/rsa/core/ExportReferenceImpl.java | 77 ---------------------- .../aries/rsa/core/ExportRegistrationImpl.java | 48 ++++++++------ .../aries/rsa/core/RemoteServiceAdminCore.java | 2 +- 3 files changed, 30 insertions(+), 97 deletions(-) diff --git a/rsa/src/main/java/org/apache/aries/rsa/core/ExportReferenceImpl.java b/rsa/src/main/java/org/apache/aries/rsa/core/ExportReferenceImpl.java deleted file mode 100644 index 11e4f289..00000000 --- a/rsa/src/main/java/org/apache/aries/rsa/core/ExportReferenceImpl.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.aries.rsa.core; - -import org.osgi.framework.ServiceReference; -import org.osgi.service.remoteserviceadmin.EndpointDescription; -import org.osgi.service.remoteserviceadmin.ExportReference; - -import java.util.Objects; - -@SuppressWarnings("rawtypes") -public class ExportReferenceImpl implements ExportReference { - - private ServiceReference serviceReference; - private EndpointDescription endpoint; - - public ExportReferenceImpl(ServiceReference serviceReference, EndpointDescription endpoint) { - this.serviceReference = serviceReference; - this.endpoint = endpoint; - } - - public ExportReferenceImpl(ExportReference exportReference) { - this(exportReference.getExportedService(), exportReference.getExportedEndpoint()); - } - - public EndpointDescription getExportedEndpoint() { - return endpoint; - } - - public ServiceReference<?> getExportedService() { - return serviceReference; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + (endpoint == null ? 0 : endpoint.hashCode()); - result = prime * result + (serviceReference == null ? 0 : serviceReference.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null || getClass() != obj.getClass()) { - return false; - } - ExportReferenceImpl other = (ExportReferenceImpl) obj; - boolean ed = Objects.equals(endpoint, other.endpoint); - boolean sr = Objects.equals(serviceReference, other.serviceReference); - return ed && sr; - } - - synchronized void close() { - this.endpoint = null; - this.serviceReference = null; - } -} diff --git a/rsa/src/main/java/org/apache/aries/rsa/core/ExportRegistrationImpl.java b/rsa/src/main/java/org/apache/aries/rsa/core/ExportRegistrationImpl.java index 3c919c20..3f8a43d8 100644 --- a/rsa/src/main/java/org/apache/aries/rsa/core/ExportRegistrationImpl.java +++ b/rsa/src/main/java/org/apache/aries/rsa/core/ExportRegistrationImpl.java @@ -38,8 +38,14 @@ import org.osgi.service.remoteserviceadmin.RemoteConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * Implements an ExportRegistration. Since there is a 1:1 relationship between + * an ExportRegistration and its ExportReference (they are basically two views + * of the same underlying data - one is the modifiable part and one the read-only + * part), this class implements both interfaces together. + */ @SuppressWarnings("rawtypes") -public class ExportRegistrationImpl implements ExportRegistration { +public class ExportRegistrationImpl implements ExportRegistration, ExportReference { private static final Logger LOG = LoggerFactory.getLogger(ExportRegistrationImpl.class); @@ -52,6 +58,8 @@ public class ExportRegistrationImpl implements ExportRegistration { private Set<CloseHandler> closeHandlers = Collections.newSetFromMap(new ConcurrentHashMap<>()); private EventProducer eventProducer; + private ServiceReference serviceReference; + private volatile EndpointDescription endpoint; private Closeable server; private Throwable exception; @@ -90,7 +98,6 @@ public class ExportRegistrationImpl implements ExportRegistration { private final Shared shared; // per-instance state that is not shared - private volatile ExportReferenceImpl exportReference; private AtomicBoolean closing = new AtomicBoolean(); private volatile boolean closed; @@ -104,7 +111,6 @@ public class ExportRegistrationImpl implements ExportRegistration { * @param er the export registration that this instance is linked to */ public ExportRegistrationImpl(ExportRegistrationImpl er) { - exportReference = new ExportReferenceImpl(er.exportReference); shared = er.shared; shared.addInstance(); } @@ -123,9 +129,10 @@ public class ExportRegistrationImpl implements ExportRegistration { // create a new (parent) instance which was exported successfully with the given server public ExportRegistrationImpl(ServiceReference sref, Endpoint endpoint, CloseHandler closeHandler, EventProducer eventProducer) { - exportReference = new ExportReferenceImpl(sref, endpoint.description()); shared = new Shared(); shared.eventProducer = eventProducer; + shared.serviceReference = sref; + shared.endpoint = endpoint.description(); shared.server = endpoint; addCloseHandler(closeHandler); shared.addInstance(); @@ -159,6 +166,16 @@ public class ExportRegistrationImpl implements ExportRegistration { return shared.exception != null || closed; } + @Override + public EndpointDescription getExportedEndpoint() { + return isInvalid() ? null : shared.endpoint; + } + + @Override + public ServiceReference<?> getExportedService() { + return isInvalid() ? null : shared.serviceReference; + } + @Override public ExportReference getExportReference() { if (closed) { @@ -167,7 +184,7 @@ public class ExportRegistrationImpl implements ExportRegistration { if (shared.exception != null) { throw new IllegalStateException("export registration is invalid"); } - return exportReference; + return this; // this instance implements both interfaces } @Override @@ -191,9 +208,6 @@ public class ExportRegistrationImpl implements ExportRegistration { return; } shared.closeHandlers.forEach(h -> h.onClose(this)); - if (exportReference != null) { - exportReference.close(); - } shared.removeInstance(); closed = true; } @@ -203,15 +217,13 @@ public class ExportRegistrationImpl implements ExportRegistration { if (closed) { return "ExportRegistration closed"; } - EndpointDescription endpoint = exportReference.getExportedEndpoint(); - ServiceReference serviceReference = exportReference.getExportedService(); - String s = "EndpointDescription for ServiceReference " + serviceReference; + String s = "EndpointDescription for ServiceReference " + shared.serviceReference; s += "\n*** EndpointDescription: ****\n"; - if (endpoint == null) { + if (shared.endpoint == null) { s += "---> NULL <---- \n"; } else { - Set<Map.Entry<String, Object>> props = endpoint.getProperties().entrySet(); + Set<Map.Entry<String, Object>> props = shared.endpoint.getProperties().entrySet(); for (Map.Entry<String, Object> entry : props) { Object value = entry.getValue(); s += entry.getKey() + " => " @@ -227,15 +239,13 @@ public class ExportRegistrationImpl implements ExportRegistration { throw new IllegalStateException("export registration is invalid or closed"); } - Map<String, Object> oldProps = exportReference.getExportedEndpoint().getProperties(); + Map<String, Object> oldProps = shared.endpoint.getProperties(); Map<String, Object> props = new HashMap<>(properties); props.putIfAbsent(RemoteConstants.ENDPOINT_ID, oldProps.get(RemoteConstants.ENDPOINT_ID)); props.putIfAbsent(RemoteConstants.SERVICE_IMPORTED_CONFIGS, oldProps.get(RemoteConstants.SERVICE_IMPORTED_CONFIGS)); - ServiceReference<?> sref = exportReference.getExportedService(); - EndpointDescription endpoint = new EndpointDescription(sref, props); - exportReference = new ExportReferenceImpl(sref, endpoint); - shared.eventProducer.notifyUpdate(exportReference); - return endpoint; + shared.endpoint = new EndpointDescription(shared.serviceReference, props); + shared.eventProducer.notifyUpdate(this); + return shared.endpoint; } } diff --git a/rsa/src/main/java/org/apache/aries/rsa/core/RemoteServiceAdminCore.java b/rsa/src/main/java/org/apache/aries/rsa/core/RemoteServiceAdminCore.java index c3f74f51..bcf62eb5 100644 --- a/rsa/src/main/java/org/apache/aries/rsa/core/RemoteServiceAdminCore.java +++ b/rsa/src/main/java/org/apache/aries/rsa/core/RemoteServiceAdminCore.java @@ -365,7 +365,7 @@ public class RemoteServiceAdminCore implements RemoteServiceAdmin { for (Collection<ExportRegistration> exportRegistrations : exportedServices.values()) { for (ExportRegistration er : exportRegistrations) { if (er.getException() == null && er.getExportReference() != null) { - ers.add(new ExportReferenceImpl(er.getExportReference())); + ers.add(er.getExportReference()); } } }
