FELIX-2647 : Implement Coordinator Service - minor updated to orphaned coordination handling, remove unused command code
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1553641 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/coordinator/pom.xml b/coordinator/pom.xml
index e34f5af..fee9584 100644
--- a/coordinator/pom.xml
+++ b/coordinator/pom.xml
@@ -45,18 +45,6 @@
</configuration>
</plugin>
<plugin>
- <artifactId>maven-javadoc-plugin</artifactId>
- <configuration>
- <tags>
- <tag>
- <name>ThreadSafe</name>
- <placement>a</placement>
- <head>ThreadSafe</head>
- </tag>
- </tags>
- </configuration>
- </plugin>
- <plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
diff --git a/coordinator/src/main/java/org/apache/felix/coordinator/impl/Activator.java b/coordinator/src/main/java/org/apache/felix/coordinator/impl/Activator.java
index 33ba33f..14fe169 100644
--- a/coordinator/src/main/java/org/apache/felix/coordinator/impl/Activator.java
+++ b/coordinator/src/main/java/org/apache/felix/coordinator/impl/Activator.java
@@ -38,8 +38,6 @@
private ServiceRegistration coordinatorService;
-// private ServiceRegistration coordinatorCommand;
-
public void start(BundleContext context)
{
mgr = new CoordinationMgr();
@@ -59,26 +57,10 @@
props.put(Constants.SERVICE_DESCRIPTION, "Coordinator Service Implementation");
props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
coordinatorService = context.registerService(Coordinator.class.getName(), factory, props);
-/*
- try
- {
- coordinatorCommand = CrdCommand.create(context, mgr);
- }
- catch (Throwable t)
- {
- // most probably missing resolved packages, ignore
- }
-*/
}
public void stop(BundleContext context)
{
-/* if (coordinatorCommand != null)
- {
- coordinatorCommand.unregister();
- coordinatorCommand = null;
- }
-*/
if (coordinatorService != null)
{
coordinatorService.unregister();
diff --git a/coordinator/src/main/java/org/apache/felix/coordinator/impl/CoordinationImpl.java b/coordinator/src/main/java/org/apache/felix/coordinator/impl/CoordinationImpl.java
index 1805f96..6db9ff1 100644
--- a/coordinator/src/main/java/org/apache/felix/coordinator/impl/CoordinationImpl.java
+++ b/coordinator/src/main/java/org/apache/felix/coordinator/impl/CoordinationImpl.java
@@ -18,6 +18,7 @@
*/
package org.apache.felix.coordinator.impl;
+import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -48,6 +49,8 @@
TERMINATED
}
+ private final WeakReference<CoordinationHolder> holderRef;
+
private final CoordinatorImpl owner;
private final long id;
@@ -87,6 +90,8 @@
this.variables = new HashMap<Class<?>, Object>();
this.deadLine = (timeOutInMs > 0) ? System.currentTimeMillis() + timeOutInMs : 0;
+ this.holderRef = new WeakReference<CoordinationHolder>(new CoordinationHolder(this));
+
scheduleTimeout(deadLine);
}
@@ -420,7 +425,7 @@
Coordination c = this.owner.getEnclosingCoordination(this);
if ( c != null )
{
- c = new CoordinationHolder((CoordinationImpl)c);
+ c = ((CoordinationImpl)c).holderRef.get();
}
return c;
}
@@ -521,4 +526,8 @@
void setAssociatedThread(final Thread t) {
this.associatedThread = t;
}
+
+ public Coordination getHolder() {
+ return this.holderRef.get();
+ }
}
diff --git a/coordinator/src/main/java/org/apache/felix/coordinator/impl/CoordinationMgr.java b/coordinator/src/main/java/org/apache/felix/coordinator/impl/CoordinationMgr.java
index 23758aa..e0b5e18 100644
--- a/coordinator/src/main/java/org/apache/felix/coordinator/impl/CoordinationMgr.java
+++ b/coordinator/src/main/java/org/apache/felix/coordinator/impl/CoordinationMgr.java
@@ -281,7 +281,7 @@
{
for(final CoordinationImpl c : this.coordinations.values() )
{
- result.add(new CoordinationHolder(c));
+ result.add(c.getHolder());
}
}
return result;
diff --git a/coordinator/src/main/java/org/apache/felix/coordinator/impl/CoordinatorImpl.java b/coordinator/src/main/java/org/apache/felix/coordinator/impl/CoordinatorImpl.java
index 2800e4a..ca254e6 100644
--- a/coordinator/src/main/java/org/apache/felix/coordinator/impl/CoordinatorImpl.java
+++ b/coordinator/src/main/java/org/apache/felix/coordinator/impl/CoordinatorImpl.java
@@ -152,7 +152,7 @@
// create coordination
final CoordinationImpl c = mgr.create(this, name, timeout);
- return new CoordinationHolder(c);
+ return c.getHolder();
}
/**
@@ -187,7 +187,7 @@
Coordination c = mgr.peek();
if ( c != null )
{
- c = new CoordinationHolder((CoordinationImpl)c);
+ c = ((CoordinationImpl)c).getHolder();
}
return c;
}
@@ -209,7 +209,7 @@
// create coordination
final CoordinationImpl c = mgr.create(this, name, timeout);
this.mgr.push(c);
- return new CoordinationHolder(c);
+ return c.getHolder();
}
/**
@@ -221,7 +221,7 @@
Coordination c = mgr.pop();
if ( c != null )
{
- c = new CoordinationHolder((CoordinationImpl)c);
+ c = ((CoordinationImpl)c).getHolder();
}
return c;
}
@@ -250,7 +250,7 @@
Coordination c = mgr.getCoordinationById(id);
if ( c != null )
{
- c = new CoordinationHolder((CoordinationImpl)c);
+ c = ((CoordinationImpl)c).getHolder();
}
return c;
}
diff --git a/coordinator/src/main/java/org/apache/felix/coordinator/impl/CrdCommand.java b/coordinator/src/main/java/org/apache/felix/coordinator/impl/CrdCommand.java
deleted file mode 100644
index 65e6e19..0000000
--- a/coordinator/src/main/java/org/apache/felix/coordinator/impl/CrdCommand.java
+++ /dev/null
@@ -1,137 +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.felix.coordinator.impl;
-
-import java.util.Collection;
-import java.util.Hashtable;
-
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.coordinator.Coordination;
-import org.osgi.service.coordinator.Participant;
-
-/**
- * The <code>CrdCommand</code> class implements the required Command Line
- * interface commands for the Coordinator Service.
- * <p>
- * This class depends on the CommandLine API support (namely the annotations)
- * which are optionally wired to this bundle. Thus this class may fail to load
- * and calling the CrdCommand.create method may throw an Error.
- * <p>
- * In addition this class implements the Converter interface and is able to
- * convert Coordination IDs and names to Coordinations and bundles to the
- * list of Coordinations for the given bundle
- */
-class CrdCommand /* implements Converter */
-{
- /*
- * Register as a service with the properties:
- * osgi.command.scope = crd
- * osgi.command.function = [ list, fail, participants, details ]
- * osgi.command.description = scope description
- *
- * crd list [ -f, --full ] [ <regex filter on name> ]
- * crd fail [ -r, --reason <reason> ] [-b,--bundle <bundle>] <coordination> ...
- * crd participants <coordination> ���
- * crd details <coordination> ���
- *
- * A Coordinator must provide a converter to a Coordination based on the
- * following inputs:
- * id ��� the Coordination id
- * name ��� the Coordination name. Must be unique
- * bundle ��� Must translate to all coordinations of a specific bundle
- */
-
- static ServiceRegistration create(final BundleContext context, final CoordinationMgr mgr)
- {
- CrdCommand command = new CrdCommand(mgr);
-
- Hashtable<String, Object> props = new Hashtable<String, Object>();
- props.put(Constants.SERVICE_DESCRIPTION, "Coordinator Service Command Implementation");
- props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
-
- // Shell command registration
- props.put("osgi.command.scope", "crd");
- props.put("osgi.command.function", new String[]
- { "list", "fail", "participants", "details" });
- props.put("osgi.command.description", "Coordinator Service Commands");
-
- // Coordination conversion
- props.put("", Coordination.class.getName());
-
- return context.registerService(Object/*Converter*/.class.getName(), command, props);
- }
-
- private CrdCommand(final CoordinationMgr mgr)
- {
-
- }
-
-
- /* @Description("The list does ....") */
- public void list(
- /* CommandSession session, */
- /* @Parameter(alias={"-f","--full"}, ifPresent=true, ifAbsent=false) */ boolean full,
- /* @Description("...") */ String filter
- ){}
-
- /* @Description("The fail does ....") */
- public void fail(
- /* CommandSession session, */
- /* Parameter(alias={"-r","--reason"}, ifAbsent=NOT_SET) */ String reason,
- /* Parameter(alias={"-b","--bundle"}, ifAbsent=NOT_SET) */ Bundle bundle,
- /* @Description("coordinations to fail") */ Coordination[] coordinations
- ){}
- /* @Description("The participants does ....") */
- public void participants(
- /* CommandSession session, */
- /* @Description("coordinations") */ Coordination[] coordinations
- )
- {
- for (Coordination coordination : coordinations) {
- Collection<Participant> participants = coordination.getParticipants();
- /* FormatterService.format(coordination, INSPECT, null); */
- }
- }
-
-
- /* @Description("The details does ....") */
- public void details(
- /* CommandSession session, */
- /* @Description("coordinations") */ Coordination[] coordinations
- )
- {
- for (Coordination coordination : coordinations) {
- /* FormatterService.format(coordination, INSPECT, null); */
- }
- }
-
- //---------- Converter service
-
- /* Converts int/String to Coordination
- <T> boolean canConvert(Object sourceObject, ReifiedType<T> targetType)
- {
- true if targetType is Coordination or Collection<Coordination> or
- Coordination[] and sourceObject is a Bundle, int, or String
- }
- <T> T convert(Object sourceObject, ReifiedType<T> targetType);
- */
-}