You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:28:23 UTC

[sling-org-apache-sling-discovery-standalone] annotated tag org.apache.sling.discovery.standalone-1.0.0 created (now 159bdb6)

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a change to annotated tag org.apache.sling.discovery.standalone-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-discovery-standalone.git.


      at 159bdb6  (tag)
 tagging 7a55b8e0013eebe743608396efe379b7f8775ea3 (commit)
      by Carsten Ziegeler
      on Fri Aug 9 07:04:44 2013 +0000

- Log -----------------------------------------------------------------
org.apache.sling.discovery.standalone-1.0.0
-----------------------------------------------------------------------

This annotated tag includes the following new commits:

     new f24d72f  Create new standalone module
     new 436d36c  Create new standalone module
     new 6ae6308  Create new support module
     new b986961  Create new support module
     new 5404e69  Add missing poms
     new fc3f08e  Update to latest parent pom
     new d131e9a  Use released discovery api
     new 9a1ad1b  [maven-release-plugin] prepare release org.apache.sling.discovery.standalone-1.0.0
     new 7a55b8e  [maven-release-plugin]  copy for tag org.apache.sling.discovery.standalone-1.0.0

The 9 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


-- 
To stop receiving notification emails like this one, please contact
['"commits@sling.apache.org" <co...@sling.apache.org>'].

[sling-org-apache-sling-discovery-standalone] 04/09: Create new support module

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.discovery.standalone-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-discovery-standalone.git

commit b986961c7e4fb60b08f0512d77e511a9c14be171
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue May 14 08:09:45 2013 +0000

    Create new support module
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/discovery/standalone@1482245 13f79535-47bb-0310-9956-ffa450edef68
---
 .../impl/standalone/StandardPropertyProvider.java  | 219 ---------------------
 1 file changed, 219 deletions(-)

diff --git a/src/main/java/org/apache/sling/discovery/impl/standalone/StandardPropertyProvider.java b/src/main/java/org/apache/sling/discovery/impl/standalone/StandardPropertyProvider.java
deleted file mode 100644
index dacdb7a..0000000
--- a/src/main/java/org/apache/sling/discovery/impl/standalone/StandardPropertyProvider.java
+++ /dev/null
@@ -1,219 +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.sling.discovery.impl.standalone;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Dictionary;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Deactivate;
-import org.apache.felix.scr.annotations.Modified;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.ReferenceCardinality;
-import org.apache.felix.scr.annotations.ReferencePolicy;
-import org.apache.sling.discovery.InstanceDescription;
-import org.apache.sling.discovery.PropertyProvider;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.component.ComponentContext;
-import org.osgi.service.http.HttpService;
-
-/**
- * This service provides the standard instance properties (if available)
- */
-@Component(immediate=true)
-@Reference(referenceInterface=HttpService.class,
-           cardinality=ReferenceCardinality.OPTIONAL_MULTIPLE,
-           policy=ReferencePolicy.DYNAMIC)
-public class StandardPropertyProvider {
-
-    /** Endpoint service registration property from RFC 189 */
-    private static final String REG_PROPERTY_ENDPOINTS = "osgi.http.service.endpoints";
-
-    private volatile long changeCount;
-
-    private String instanceName;
-
-    private String instanceDescription;
-
-    private ServiceRegistration propagationService;
-
-    private final Map<Long, String[]> endpoints = new HashMap<Long, String[]>();
-
-    private String endpointString;
-
-    private Dictionary<String, Object> getRegistrationProperties() {
-        final List<String> names = new ArrayList<String>();
-        if ( this.instanceName != null ) {
-            names.add(InstanceDescription.PROPERTY_NAME);
-        }
-        if ( this.instanceDescription != null ) {
-            names.add(InstanceDescription.PROPERTY_DESCRIPTION);
-        }
-        names.add(InstanceDescription.PROPERTY_ENDPOINTS);
-
-        final StringBuilder sb = new StringBuilder();
-        boolean first = true;
-        synchronized ( this.endpoints ) {
-            for(final String[] points : endpoints.values()) {
-                for(final String point : points) {
-                    if ( first ) {
-                        first = false;
-                    } else {
-                        sb.append(",");
-                    }
-                    sb.append(point);
-                }
-            }
-        }
-        this.endpointString = sb.toString();
-
-        final Dictionary<String, Object> serviceProps = new Hashtable<String, Object>();
-        serviceProps.put(PropertyProvider.PROPERTY_PROPERTIES, names.toArray(new String[names.size()]));
-        // we add a changing property to the service registration
-        // to make sure a modification event is really sent
-        synchronized ( this ) {
-            serviceProps.put("changeCount", this.changeCount++);
-        }
-        return serviceProps;
-    }
-
-    private String getPropertyValue(final ComponentContext bc, final String key) {
-        Object value = bc.getProperties().get(key);
-        if ( value == null ) {
-            value = bc.getBundleContext().getProperty(key);
-        }
-        if ( value != null ) {
-            return value.toString();
-        }
-        return null;
-    }
-
-    @Activate
-    protected void activate(final ComponentContext cc) {
-        this.modified(cc);
-    }
-
-    @Modified
-    protected void modified(final ComponentContext cc) {
-        this.instanceName = this.getPropertyValue(cc, "sling.name");
-        this.instanceDescription = this.getPropertyValue(cc, "sling.description");
-
-        this.propagationService = cc.getBundleContext().registerService(PropertyProvider.class.getName(),
-                new PropertyProvider() {
-
-                    public String getProperty(final String name) {
-                        if ( InstanceDescription.PROPERTY_DESCRIPTION.equals(name) ) {
-                            return instanceDescription;
-                        }
-                        if ( InstanceDescription.PROPERTY_NAME.equals(name) ) {
-                            return instanceName;
-                        }
-                        if ( InstanceDescription.PROPERTY_ENDPOINTS.equals(name) ) {
-                            return endpointString;
-                        }
-                        return null;
-                    }
-                }, this.getRegistrationProperties());
-    }
-
-    @Deactivate
-    protected void deactivate() {
-        if ( this.propagationService != null ) {
-            this.propagationService.unregister();
-            this.propagationService = null;
-        }
-    }
-
-    /**
-     * Bind a http service
-     */
-    protected void bindHttpService(final ServiceReference reference) {
-        final String[] endpointUrls = toStringArray(reference.getProperty(REG_PROPERTY_ENDPOINTS));
-        if ( endpointUrls != null ) {
-            synchronized ( this.endpoints ) {
-                this.endpoints.put((Long)reference.getProperty(Constants.SERVICE_ID), endpointUrls);
-            }
-            if ( this.propagationService != null ) {
-                this.propagationService.setProperties(this.getRegistrationProperties());
-            }
-        }
-    }
-
-    /**
-     * Unbind a http service
-     */
-    protected void unbindHttpService(final ServiceReference reference) {
-        boolean changed = false;
-        synchronized ( this.endpoints ) {
-            if ( this.endpoints.remove(reference.getProperty(Constants.SERVICE_ID)) != null ) {
-                changed = true;
-            }
-        }
-        if ( changed && this.propagationService != null ) {
-            this.propagationService.setProperties(this.getRegistrationProperties());
-        }
-    }
-
-    private String[] toStringArray(final Object propValue) {
-        if (propValue == null) {
-            // no value at all
-            return null;
-
-        } else if (propValue instanceof String) {
-            // single string
-            return new String[] { (String) propValue };
-
-        } else if (propValue instanceof String[]) {
-            // String[]
-            return (String[]) propValue;
-
-        } else if (propValue.getClass().isArray()) {
-            // other array
-            Object[] valueArray = (Object[]) propValue;
-            List<String> values = new ArrayList<String>(valueArray.length);
-            for (Object value : valueArray) {
-                if (value != null) {
-                    values.add(value.toString());
-                }
-            }
-            return values.toArray(new String[values.size()]);
-
-        } else if (propValue instanceof Collection<?>) {
-            // collection
-            Collection<?> valueCollection = (Collection<?>) propValue;
-            List<String> valueList = new ArrayList<String>(valueCollection.size());
-            for (Object value : valueCollection) {
-                if (value != null) {
-                    valueList.add(value.toString());
-                }
-            }
-            return valueList.toArray(new String[valueList.size()]);
-        }
-
-        return null;
-    }
-}

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-discovery-standalone] 01/09: Create new standalone module

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.discovery.standalone-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-discovery-standalone.git

commit f24d72fc9ec4f1d7ef622836885519756036b52c
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue May 14 07:46:40 2013 +0000

    Create new standalone module
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/discovery/standalone@1482238 13f79535-47bb-0310-9956-ffa450edef68

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-discovery-standalone] 07/09: Use released discovery api

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.discovery.standalone-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-discovery-standalone.git

commit d131e9a943c9ed63bb1a7b68538ca132319ba1f8
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Fri Jul 19 07:11:07 2013 +0000

    Use released discovery api
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/discovery/standalone@1504792 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index f7cc47f..8f5f417 100644
--- a/pom.xml
+++ b/pom.xml
@@ -79,7 +79,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.discovery.api</artifactId>
-            <version>1.0.1-SNAPSHOT</version>
+            <version>1.0.0</version>
             <scope>provided</scope>
         </dependency>
         <dependency>

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-discovery-standalone] 02/09: Create new standalone module

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.discovery.standalone-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-discovery-standalone.git

commit 436d36c468c6bb49b62bb5d8859d8141b02f4308
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue May 14 07:47:45 2013 +0000

    Create new standalone module
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/discovery/standalone@1482239 13f79535-47bb-0310-9956-ffa450edef68
---
 .../impl/standalone/NoClusterDiscoveryService.java | 392 +++++++++++++++++++++
 .../impl/standalone/StandardPropertyProvider.java  | 219 ++++++++++++
 2 files changed, 611 insertions(+)

diff --git a/src/main/java/org/apache/sling/discovery/impl/standalone/NoClusterDiscoveryService.java b/src/main/java/org/apache/sling/discovery/impl/standalone/NoClusterDiscoveryService.java
new file mode 100644
index 0000000..cfb3c6b
--- /dev/null
+++ b/src/main/java/org/apache/sling/discovery/impl/standalone/NoClusterDiscoveryService.java
@@ -0,0 +1,392 @@
+/*
+ * 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.sling.discovery.impl;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.ConfigurationPolicy;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.ReferencePolicy;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.discovery.ClusterView;
+import org.apache.sling.discovery.DiscoveryService;
+import org.apache.sling.discovery.InstanceDescription;
+import org.apache.sling.discovery.InstanceFilter;
+import org.apache.sling.discovery.PropertyProvider;
+import org.apache.sling.discovery.TopologyEvent;
+import org.apache.sling.discovery.TopologyEvent.Type;
+import org.apache.sling.discovery.TopologyEventListener;
+import org.apache.sling.discovery.TopologyView;
+import org.apache.sling.settings.SlingSettingsService;
+import org.osgi.framework.Constants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This is a simple implementation of the discovery service
+ * which can be used for a cluster less installation (= single instance).
+ * It is disabled by default and can be enabled through a OSGi configuration.
+ */
+@Component(policy = ConfigurationPolicy.REQUIRE, immediate=true)
+@Service(value = {DiscoveryService.class})
+public class NoClusterDiscoveryService implements DiscoveryService {
+
+    /** The logger. */
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+    /**
+     * Sling settings service to get the Sling ID and run modes.
+     */
+    @Reference
+    private SlingSettingsService settingsService;
+
+    /**
+     * All topology event listeners.
+     */
+    @Reference(cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC)
+    private TopologyEventListener[] listeners = new TopologyEventListener[0];
+
+    /**
+     * All property providers.
+     */
+    @Reference(cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC,
+               referenceInterface=PropertyProvider.class, updated="updatedPropertyProvider")
+    private List<ProviderInfo> providerInfos = new ArrayList<ProviderInfo>();
+
+    /**
+     * Special lock object to sync data structure access
+     */
+    private final Object lock = new Object();
+
+    /**
+     * The current topology view.
+     */
+    private TopologyView topologyView;
+
+    private Map<String, String> cachedProperties = new HashMap<String, String>();
+
+    /**
+     * Activate this service
+     * Create a new description.
+     */
+    @Activate
+    protected void activate() {
+        logger.debug("NoClusterDiscoveryService started.");
+        final InstanceDescription myDescription = new InstanceDescription() {
+
+            public boolean isLocal() {
+                return true;
+            }
+
+            public boolean isLeader() {
+                return true;
+            }
+
+            public String getSlingId() {
+                return settingsService.getSlingId();
+            }
+
+            public String getProperty(final String name) {
+            	synchronized(lock) {
+            		return cachedProperties.get(name);
+            	}
+            }
+
+			public Map<String, String> getProperties() {
+				synchronized(lock) {
+					return Collections.unmodifiableMap(cachedProperties);
+				}
+			}
+
+			public ClusterView getClusterView() {
+				final Collection<ClusterView> clusters = topologyView.getClusterViews();
+				if (clusters==null || clusters.size()==0) {
+					return null;
+				}
+				return clusters.iterator().next();
+			}
+        };
+        final Set<InstanceDescription> instances = new HashSet<InstanceDescription>();
+        instances.add(myDescription);
+
+        final TopologyEventListener[] registeredServices;
+		synchronized ( lock ) {
+            registeredServices = this.listeners;
+            final ClusterView clusterView = new ClusterView() {
+
+                public InstanceDescription getLeader() {
+                    return myDescription;
+                }
+
+                public List<InstanceDescription> getInstances() {
+                    return new LinkedList<InstanceDescription>(instances);
+                }
+
+				public String getId() {
+					return "0";
+				}
+            };
+            this.topologyView = new TopologyView() {
+
+    			public InstanceDescription getLocalInstance() {
+    				return myDescription;
+    			}
+
+    			public boolean isCurrent() {
+    				return true;
+    			}
+
+    			public Set<InstanceDescription> getInstances() {
+    				return instances;
+    			}
+
+    			public Set<InstanceDescription> findInstances(InstanceFilter picker) {
+    				Set<InstanceDescription> result = new HashSet<InstanceDescription>();
+    				for (Iterator<InstanceDescription> it = getTopology().getInstances().iterator(); it.hasNext();) {
+    					InstanceDescription instance = it.next();
+    					if (picker.accept(instance)) {
+    						result.add(instance);
+    					}
+    				}
+    				return result;
+    			}
+
+    			public Set<ClusterView> getClusterViews() {
+    				Set<ClusterView> clusters = new HashSet<ClusterView>();
+    				clusters.add(clusterView);
+    				return clusters;
+    			}
+
+    		};
+        }
+        for(final TopologyEventListener da: registeredServices) {
+        	da.handleTopologyEvent(new TopologyEvent(Type.TOPOLOGY_INIT, null, topologyView));
+        }
+    }
+
+    /**
+     * Deactivate this service.
+     */
+    @Deactivate
+    protected void deactivate() {
+        logger.debug("NoClusterDiscoveryService stopped.");
+        this.topologyView = null;
+    }
+
+    /**
+     * Bind a new property provider.
+     */
+    @SuppressWarnings("unused")
+	private void bindPropertyProvider(final PropertyProvider propertyProvider, final Map<String, Object> props) {
+    	logger.debug("bindPropertyProvider: Binding PropertyProvider {}", propertyProvider);
+
+        final TopologyEventListener[] awares;
+        synchronized (lock) {
+            final ProviderInfo info = new ProviderInfo(propertyProvider, props);
+            this.providerInfos.add(info);
+            Collections.sort(this.providerInfos);
+            this.updatePropertiesCache();
+            if ( this.topologyView == null ) {
+                awares = null;
+            } else {
+                awares = this.listeners;
+            }
+        }
+        if ( awares != null ) {
+            for(final TopologyEventListener da : awares) {
+                da.handleTopologyEvent(new TopologyEvent(Type.PROPERTIES_CHANGED, this.topologyView, this.topologyView));
+            }
+        }
+    }
+
+    /**
+     * Update a property provider.
+     */
+    @SuppressWarnings("unused")
+    private void updatedPropertyProvider(final PropertyProvider propertyProvider, final Map<String, Object> props) {
+        logger.debug("bindPropertyProvider: Updating PropertyProvider {}", propertyProvider);
+
+        this.unbindPropertyProvider(propertyProvider, props, false);
+        this.bindPropertyProvider(propertyProvider, props);
+    }
+
+    /**
+     * Unbind a property provider
+     */
+    @SuppressWarnings("unused")
+	private void unbindPropertyProvider(final PropertyProvider propertyProvider, final Map<String, Object> props) {
+        this.unbindPropertyProvider(propertyProvider, props, true);
+    }
+
+    /**
+     * Unbind a property provider
+     */
+    @SuppressWarnings("unused")
+    private void unbindPropertyProvider(final PropertyProvider propertyProvider,
+            final Map<String, Object> props,
+            final boolean inform) {
+    	logger.debug("unbindPropertyProvider: Releasing PropertyProvider {}", propertyProvider);
+
+    	final TopologyEventListener[] awares;
+        synchronized (lock) {
+            final ProviderInfo info = new ProviderInfo(propertyProvider, props);
+            this.providerInfos.remove(info);
+            this.updatePropertiesCache();
+            if ( this.topologyView == null ) {
+                awares = null;
+            } else {
+                awares = this.listeners;
+            }
+        }
+        if ( inform && awares != null ) {
+            for(final TopologyEventListener da : awares) {
+                da.handleTopologyEvent(new TopologyEvent(Type.PROPERTIES_CHANGED, this.topologyView, this.topologyView));
+            }
+        }
+    }
+
+    private void updatePropertiesCache() {
+        final Map<String, String> newProps = new HashMap<String, String>();
+        for(final ProviderInfo info : this.providerInfos) {
+            newProps.putAll(info.properties);
+        }
+        this.cachedProperties = newProps;
+        if ( this.logger.isDebugEnabled() ) {
+            this.logger.debug("New properties: {}", this.cachedProperties);
+        }
+    }
+
+    @SuppressWarnings("unused")
+    private void bindTopologyEventListener(final TopologyEventListener clusterAware) {
+
+        logger.debug("bindTopologyEventListener: Binding TopologyEventListener {}", clusterAware);
+
+        boolean inform = true;
+        synchronized (lock) {
+            List<TopologyEventListener> currentList = new ArrayList<TopologyEventListener>(
+                Arrays.asList(listeners));
+            currentList.add(clusterAware);
+            this.listeners = currentList.toArray(new TopologyEventListener[currentList.size()]);
+            if ( this.topologyView == null ) {
+                inform = false;
+            }
+        }
+
+        if ( inform ) {
+        	clusterAware.handleTopologyEvent(new TopologyEvent(Type.TOPOLOGY_INIT, null, topologyView));
+        }
+    }
+
+    @SuppressWarnings("unused")
+    private void unbindTopologyEventListener(final TopologyEventListener clusterAware) {
+
+        logger.debug("unbindTopologyEventListener: Releasing TopologyEventListener {}", clusterAware);
+
+        synchronized (lock) {
+            List<TopologyEventListener> currentList = new ArrayList<TopologyEventListener>(
+                Arrays.asList(listeners));
+            currentList.remove(clusterAware);
+            this.listeners = currentList.toArray(new TopologyEventListener[currentList.size()]);
+        }
+    }
+
+    /**
+     * @see DiscoveryService#getTopology()
+     */
+    public TopologyView getTopology() {
+    	return topologyView;
+    }
+
+    /**
+     * Internal class caching some provider infos like service id and ranking.
+     */
+    private final static class ProviderInfo implements Comparable<ProviderInfo> {
+
+        public final PropertyProvider provider;
+        public final int ranking;
+        public final long serviceId;
+        public final Map<String, String> properties = new HashMap<String, String>();
+
+        public ProviderInfo(final PropertyProvider provider, final Map<String, Object> serviceProps) {
+            this.provider = provider;
+            final Object sr = serviceProps.get(Constants.SERVICE_RANKING);
+            if ( sr == null || !(sr instanceof Integer)) {
+                this.ranking = 0;
+            } else {
+                this.ranking = (Integer)sr;
+            }
+            this.serviceId = (Long)serviceProps.get(Constants.SERVICE_ID);
+            final Object namesObj = serviceProps.get(PropertyProvider.PROPERTY_PROPERTIES);
+            if ( namesObj instanceof String ) {
+                final String val = provider.getProperty((String)namesObj);
+                if ( val != null ) {
+                    this.properties.put((String)namesObj, val);
+                }
+            } else if ( namesObj instanceof String[] ) {
+                for(final String name : (String[])namesObj ) {
+                    final String val = provider.getProperty(name);
+                    if ( val != null ) {
+                        this.properties.put(name, val);
+                    }
+                }
+            }
+        }
+
+        /**
+         * @see java.lang.Comparable#compareTo(java.lang.Object)
+         */
+        public int compareTo(final ProviderInfo o) {
+            // Sort by rank in ascending order.
+            if ( this.ranking < o.ranking ) {
+                return -1; // lower rank
+            } else if (this.ranking > o.ranking ) {
+                return 1; // higher rank
+            }
+            // If ranks are equal, then sort by service id in descending order.
+            return (this.serviceId < o.serviceId) ? 1 : -1;
+        }
+
+        @Override
+        public boolean equals(final Object obj) {
+            if ( obj instanceof ProviderInfo ) {
+                return ((ProviderInfo)obj).serviceId == this.serviceId;
+            }
+            return false;
+        }
+
+        @Override
+        public int hashCode() {
+            return provider.hashCode();
+        }
+    }
+}
diff --git a/src/main/java/org/apache/sling/discovery/impl/standalone/StandardPropertyProvider.java b/src/main/java/org/apache/sling/discovery/impl/standalone/StandardPropertyProvider.java
new file mode 100644
index 0000000..798ff0a
--- /dev/null
+++ b/src/main/java/org/apache/sling/discovery/impl/standalone/StandardPropertyProvider.java
@@ -0,0 +1,219 @@
+/*
+ * 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.sling.discovery.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Modified;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.ReferencePolicy;
+import org.apache.sling.discovery.InstanceDescription;
+import org.apache.sling.discovery.PropertyProvider;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.HttpService;
+
+/**
+ * This service provides the standard instance properties (if available)
+ */
+@Component(immediate=true)
+@Reference(referenceInterface=HttpService.class,
+           cardinality=ReferenceCardinality.OPTIONAL_MULTIPLE,
+           policy=ReferencePolicy.DYNAMIC)
+public class StandardPropertyProvider {
+
+    /** Endpoint service registration property from RFC 189 */
+    private static final String REG_PROPERTY_ENDPOINTS = "osgi.http.service.endpoints";
+
+    private volatile long changeCount;
+
+    private String instanceName;
+
+    private String instanceDescription;
+
+    private ServiceRegistration propagationService;
+
+    private final Map<Long, String[]> endpoints = new HashMap<Long, String[]>();
+
+    private String endpointString;
+
+    private Dictionary<String, Object> getRegistrationProperties() {
+        final List<String> names = new ArrayList<String>();
+        if ( this.instanceName != null ) {
+            names.add(InstanceDescription.PROPERTY_NAME);
+        }
+        if ( this.instanceDescription != null ) {
+            names.add(InstanceDescription.PROPERTY_DESCRIPTION);
+        }
+        names.add(InstanceDescription.PROPERTY_ENDPOINTS);
+
+        final StringBuilder sb = new StringBuilder();
+        boolean first = true;
+        synchronized ( this.endpoints ) {
+            for(final String[] points : endpoints.values()) {
+                for(final String point : points) {
+                    if ( first ) {
+                        first = false;
+                    } else {
+                        sb.append(",");
+                    }
+                    sb.append(point);
+                }
+            }
+        }
+        this.endpointString = sb.toString();
+
+        final Dictionary<String, Object> serviceProps = new Hashtable<String, Object>();
+        serviceProps.put(PropertyProvider.PROPERTY_PROPERTIES, names.toArray(new String[names.size()]));
+        // we add a changing property to the service registration
+        // to make sure a modification event is really sent
+        synchronized ( this ) {
+            serviceProps.put("changeCount", this.changeCount++);
+        }
+        return serviceProps;
+    }
+
+    private String getPropertyValue(final ComponentContext bc, final String key) {
+        Object value = bc.getProperties().get(key);
+        if ( value == null ) {
+            value = bc.getBundleContext().getProperty(key);
+        }
+        if ( value != null ) {
+            return value.toString();
+        }
+        return null;
+    }
+
+    @Activate
+    protected void activate(final ComponentContext cc) {
+        this.modified(cc);
+    }
+
+    @Modified
+    protected void modified(final ComponentContext cc) {
+        this.instanceName = this.getPropertyValue(cc, "sling.name");
+        this.instanceDescription = this.getPropertyValue(cc, "sling.description");
+
+        this.propagationService = cc.getBundleContext().registerService(PropertyProvider.class.getName(),
+                new PropertyProvider() {
+
+                    public String getProperty(final String name) {
+                        if ( InstanceDescription.PROPERTY_DESCRIPTION.equals(name) ) {
+                            return instanceDescription;
+                        }
+                        if ( InstanceDescription.PROPERTY_NAME.equals(name) ) {
+                            return instanceName;
+                        }
+                        if ( InstanceDescription.PROPERTY_ENDPOINTS.equals(name) ) {
+                            return endpointString;
+                        }
+                        return null;
+                    }
+                }, this.getRegistrationProperties());
+    }
+
+    @Deactivate
+    protected void deactivate() {
+        if ( this.propagationService != null ) {
+            this.propagationService.unregister();
+            this.propagationService = null;
+        }
+    }
+
+    /**
+     * Bind a http service
+     */
+    protected void bindHttpService(final ServiceReference reference) {
+        final String[] endpointUrls = toStringArray(reference.getProperty(REG_PROPERTY_ENDPOINTS));
+        if ( endpointUrls != null ) {
+            synchronized ( this.endpoints ) {
+                this.endpoints.put((Long)reference.getProperty(Constants.SERVICE_ID), endpointUrls);
+            }
+            if ( this.propagationService != null ) {
+                this.propagationService.setProperties(this.getRegistrationProperties());
+            }
+        }
+    }
+
+    /**
+     * Unbind a http service
+     */
+    protected void unbindHttpService(final ServiceReference reference) {
+        boolean changed = false;
+        synchronized ( this.endpoints ) {
+            if ( this.endpoints.remove(reference.getProperty(Constants.SERVICE_ID)) != null ) {
+                changed = true;
+            }
+        }
+        if ( changed && this.propagationService != null ) {
+            this.propagationService.setProperties(this.getRegistrationProperties());
+        }
+    }
+
+    private String[] toStringArray(final Object propValue) {
+        if (propValue == null) {
+            // no value at all
+            return null;
+
+        } else if (propValue instanceof String) {
+            // single string
+            return new String[] { (String) propValue };
+
+        } else if (propValue instanceof String[]) {
+            // String[]
+            return (String[]) propValue;
+
+        } else if (propValue.getClass().isArray()) {
+            // other array
+            Object[] valueArray = (Object[]) propValue;
+            List<String> values = new ArrayList<String>(valueArray.length);
+            for (Object value : valueArray) {
+                if (value != null) {
+                    values.add(value.toString());
+                }
+            }
+            return values.toArray(new String[values.size()]);
+
+        } else if (propValue instanceof Collection<?>) {
+            // collection
+            Collection<?> valueCollection = (Collection<?>) propValue;
+            List<String> valueList = new ArrayList<String>(valueCollection.size());
+            for (Object value : valueCollection) {
+                if (value != null) {
+                    valueList.add(value.toString());
+                }
+            }
+            return valueList.toArray(new String[valueList.size()]);
+        }
+
+        return null;
+    }
+}

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-discovery-standalone] 05/09: Add missing poms

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.discovery.standalone-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-discovery-standalone.git

commit 5404e69bafcc9d6ce3d825240042d453b7642703
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue May 14 10:56:24 2013 +0000

    Add missing poms
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/discovery/standalone@1482297 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 92 insertions(+)

diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..f71ab11
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>16</version>
+        <relativePath>../../../parent/pom.xml</relativePath>
+    </parent>
+
+    <artifactId>org.apache.sling.discovery.standalone</artifactId>
+    <packaging>bundle</packaging>
+    <version>0.0.1-SNAPSHOT</version>
+
+    <name>Apache Sling Discovery Standalone Implementation</name>
+    <description>
+        Implementation of the discovery API for standalone instances
+    </description>
+
+    <scm>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/discovery/standalone</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/discovery/standalone</developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/discovery/standalone</url>
+    </scm>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-scr-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+            </plugin>
+        </plugins>
+    </build>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.scr.annotations</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>biz.aQute</groupId>
+            <artifactId>bndlib</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.discovery.api</artifactId>
+            <version>1.0.1-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.settings</artifactId>
+            <version>1.1.0</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+</project>

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-discovery-standalone] 06/09: Update to latest parent pom

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.discovery.standalone-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-discovery-standalone.git

commit fc3f08edbb7903c80f2bc9b7080b49d325a721fa
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Fri Jul 19 07:04:15 2013 +0000

    Update to latest parent pom
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/discovery/standalone@1504788 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index f71ab11..f7cc47f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.apache.sling</groupId>
         <artifactId>sling</artifactId>
-        <version>16</version>
+        <version>17</version>
         <relativePath>../../../parent/pom.xml</relativePath>
     </parent>
 

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-discovery-standalone] 08/09: [maven-release-plugin] prepare release org.apache.sling.discovery.standalone-1.0.0

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.discovery.standalone-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-discovery-standalone.git

commit 9a1ad1b0e08082c61edd8c6f0671c8647589929d
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Fri Aug 9 07:04:19 2013 +0000

    [maven-release-plugin] prepare release org.apache.sling.discovery.standalone-1.0.0
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/discovery/standalone@1512176 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index 8f5f417..8a4cd68 100644
--- a/pom.xml
+++ b/pom.xml
@@ -29,7 +29,7 @@
 
     <artifactId>org.apache.sling.discovery.standalone</artifactId>
     <packaging>bundle</packaging>
-    <version>0.0.1-SNAPSHOT</version>
+    <version>1.0.0</version>
 
     <name>Apache Sling Discovery Standalone Implementation</name>
     <description>
@@ -37,9 +37,9 @@
     </description>
 
     <scm>
-        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/discovery/standalone</connection>
-        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/discovery/standalone</developerConnection>
-        <url>http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/discovery/standalone</url>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.discovery.standalone-1.0.0</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.discovery.standalone-1.0.0</developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.discovery.standalone-1.0.0</url>
     </scm>
 
     <build>

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-discovery-standalone] 09/09: [maven-release-plugin] copy for tag org.apache.sling.discovery.standalone-1.0.0

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.discovery.standalone-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-discovery-standalone.git

commit 7a55b8e0013eebe743608396efe379b7f8775ea3
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Fri Aug 9 07:04:44 2013 +0000

    [maven-release-plugin]  copy for tag org.apache.sling.discovery.standalone-1.0.0
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.discovery.standalone-1.0.0@1512177 13f79535-47bb-0310-9956-ffa450edef68

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-discovery-standalone] 03/09: Create new support module

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.discovery.standalone-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-discovery-standalone.git

commit 6ae63084a6fc63d7b628babea0dbe26b539dfa64
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue May 14 08:07:01 2013 +0000

    Create new support module
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/discovery/standalone@1482243 13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/discovery/impl/standalone/NoClusterDiscoveryService.java   | 5 ++---
 .../sling/discovery/impl/standalone/StandardPropertyProvider.java    | 2 +-
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/sling/discovery/impl/standalone/NoClusterDiscoveryService.java b/src/main/java/org/apache/sling/discovery/impl/standalone/NoClusterDiscoveryService.java
index cfb3c6b..e495e99 100644
--- a/src/main/java/org/apache/sling/discovery/impl/standalone/NoClusterDiscoveryService.java
+++ b/src/main/java/org/apache/sling/discovery/impl/standalone/NoClusterDiscoveryService.java
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.discovery.impl;
+package org.apache.sling.discovery.impl.standalone;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -32,7 +32,6 @@ import java.util.Set;
 
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.ConfigurationPolicy;
 import org.apache.felix.scr.annotations.Deactivate;
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.ReferenceCardinality;
@@ -57,7 +56,7 @@ import org.slf4j.LoggerFactory;
  * which can be used for a cluster less installation (= single instance).
  * It is disabled by default and can be enabled through a OSGi configuration.
  */
-@Component(policy = ConfigurationPolicy.REQUIRE, immediate=true)
+@Component(immediate=true)
 @Service(value = {DiscoveryService.class})
 public class NoClusterDiscoveryService implements DiscoveryService {
 
diff --git a/src/main/java/org/apache/sling/discovery/impl/standalone/StandardPropertyProvider.java b/src/main/java/org/apache/sling/discovery/impl/standalone/StandardPropertyProvider.java
index 798ff0a..dacdb7a 100644
--- a/src/main/java/org/apache/sling/discovery/impl/standalone/StandardPropertyProvider.java
+++ b/src/main/java/org/apache/sling/discovery/impl/standalone/StandardPropertyProvider.java
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.discovery.impl;
+package org.apache.sling.discovery.impl.standalone;
 
 import java.util.ArrayList;
 import java.util.Collection;

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.