/** * 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.gecko.rsa.discovery; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; import org.osgi.service.remoteserviceadmin.EndpointEvent; import org.osgi.service.remoteserviceadmin.EndpointEventListener; import org.osgi.util.tracker.ServiceTracker; /** * Tracks EndpointEventListeners. This means tracking the Topology-Managers, that needs to be informed * about new remote services that are announced from foreign frameworks. * * Changes are delegated to the {@link ImportingEndpointEventManager}. This then handles the cache and the lifecycle of * the descriptions that needs to be sent and the correct cache handling of all the topology managers * * @author Mark Hoffmann * @since 06.07.2018 */ public class ImportingTopologyManagerTracker extends ServiceTracker { private final ImportingEndpointEventManager importingManager; public ImportingTopologyManagerTracker(BundleContext bctx, ImportingEndpointEventManager importingManager) { super(bctx, EndpointEventListener.class, null); this.importingManager = importingManager; } /* * (non-Javadoc) * @see org.osgi.util.tracker.ServiceTracker#addingService(org.osgi.framework.ServiceReference) */ @Override public EndpointEventListener addingService(ServiceReference topologyManagerRef) { EndpointEventListener topologyManager = super.addingService(topologyManagerRef); importingManager.modifyTopologyManager(topologyManagerRef, topologyManager, EndpointEvent.ADDED); return topologyManager; } /* * (non-Javadoc) * @see org.osgi.util.tracker.ServiceTracker#modifiedService(org.osgi.framework.ServiceReference, java.lang.Object) */ @Override public void modifiedService(ServiceReference topologyManagerRef, EndpointEventListener topologyManager) { /* * Called when an topology manager updates its service properties. * This usually happens, when the EndpointEventListener.ENDPOINT_LISTENER_SCOPE changes property * of the topology manager / endpoint event listener changes */ importingManager.modifyTopologyManager(topologyManagerRef, topologyManager, EndpointEvent.MODIFIED); } /* * (non-Javadoc) * @see org.osgi.util.tracker.ServiceTracker#removedService(org.osgi.framework.ServiceReference, java.lang.Object) */ @Override public void removedService(ServiceReference topologyManagerRef, EndpointEventListener topologyManager) { importingManager.removeTopologyManager(topologyManagerRef); super.removedService(topologyManagerRef, topologyManager); } }