Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.virgo.kernel.artifact/.classpath4
-rw-r--r--org.eclipse.virgo.shell.command/src/main/java/org/eclipse/virgo/shell/internal/ServiceUtils.java84
-rwxr-xr-xorg.eclipse.virgo.shell.command/src/main/java/org/eclipse/virgo/shell/osgicommand/Activator.java58
3 files changed, 15 insertions, 131 deletions
diff --git a/org.eclipse.virgo.kernel.artifact/.classpath b/org.eclipse.virgo.kernel.artifact/.classpath
index ec8f1bbf..3f18dc22 100644
--- a/org.eclipse.virgo.kernel.artifact/.classpath
+++ b/org.eclipse.virgo.kernel.artifact/.classpath
@@ -23,10 +23,10 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="var" path="IVY_CACHE/org.junit/com.springsource.org.junit/4.7.0/com.springsource.org.junit-4.7.0.jar" sourcepath="/IVY_CACHE/org.junit/com.springsource.org.junit/4.7.0/com.springsource.org.junit-sources-4.7.0.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.eclipse.virgo.repository/org.eclipse.virgo.repository/3.6.0.M05/org.eclipse.virgo.repository-3.6.0.M05.jar" sourcepath="/IVY_CACHE/org.eclipse.virgo.repository/org.eclipse.virgo.repository/3.5.0.D-20120615071313/org.eclipse.virgo.repository-sources-3.5.0.D-20120615071313.jar"/>
- <classpathentry kind="var" path="IVY_CACHE/org.eclipse.virgo.util/org.eclipse.virgo.util.io/3.6.0.M05/org.eclipse.virgo.util.io-3.6.0.M05.jar" sourcepath="/IVY_CACHE/org.eclipse.virgo.util/org.eclipse.virgo.util.io/3.6.0.D-20120711093140/org.eclipse.virgo.util.io-sources-3.6.0.D-20120711093140.jar"/>
+ <classpathentry kind="var" path="IVY_CACHE/org.eclipse.virgo.util/org.eclipse.virgo.util.io/3.6.0.M05/org.eclipse.virgo.util.io-3.6.0.M05.jar" sourcepath="/IVY_CACHE/org.eclipse.virgo.util/org.eclipse.virgo.util.io/3.6.0.M05/org.eclipse.virgo.util.io-sources-3.6.0.M05.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.eclipse.virgo.util/org.eclipse.virgo.util.osgi.manifest/3.6.0.M05/org.eclipse.virgo.util.osgi.manifest-3.6.0.M05.jar" sourcepath="/IVY_CACHE/org.eclipse.virgo.util/org.eclipse.virgo.util.osgi.manifest/3.5.0.D-20120615065828/org.eclipse.virgo.util.osgi.manifest-sources-3.5.0.D-20120615065828.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.eclipse.virgo.util/org.eclipse.virgo.util.parser.manifest/3.6.0.M05/org.eclipse.virgo.util.parser.manifest-3.6.0.M05.jar" sourcepath="/IVY_CACHE/org.eclipse.virgo.util/org.eclipse.virgo.util.parser.manifest/3.5.0.D-20120615065828/org.eclipse.virgo.util.parser.manifest-sources-3.5.0.D-20120615065828.jar"/>
- <classpathentry kind="var" path="IVY_CACHE/org.eclipse.virgo.util/org.eclipse.virgo.util.common/3.6.0.M05/org.eclipse.virgo.util.common-3.6.0.M05.jar" sourcepath="/IVY_CACHE/org.eclipse.virgo.util/org.eclipse.virgo.util.common/3.5.0.D-20120615065828/org.eclipse.virgo.util.common-sources-2.0019103807.jar"/>
+ <classpathentry kind="var" path="IVY_CACHE/org.eclipse.virgo.util/org.eclipse.virgo.util.common/3.6.0.M05/org.eclipse.virgo.util.common-3.6.0.M05.jar" sourcepath="/IVY_CACHE/org.eclipse.virgo.util/org.eclipse.virgo.util.common/3.6.0.M05/org.eclipse.virgo.util.common-sources-3.6.0.M05.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.eclipse.virgo.mirrored/org.slf4j.api/1.7.2.v20121108-1250/org.slf4j.api-1.7.2.v20121108-1250.jar" sourcepath="/IVY_CACHE/org.eclipse.virgo.mirrored/org.slf4j.api/1.7.2.v20121108-1250/org.slf4j.api.source-1.7.2.v20121108-1250.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.eclipse.virgo.mirrored/org.slf4j.nop/1.7.2.v201212060727/org.slf4j.nop-1.7.2.v201212060727.jar" sourcepath="/IVY_CACHE/org.eclipse.virgo.mirrored/org.slf4j.nop/1.7.2.v201212060727/org.slf4j.nop.source-1.7.2.v201212060727.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.eclipse.virgo.mirrored/org.eclipse.osgi/3.8.1.v20120830-144521/org.eclipse.osgi-3.8.1.v20120830-144521.jar" sourcepath="/IVY_CACHE/org.eclipse.osgi/org.eclipse.osgi/3.7.1.R37x_v20110808-1106/org.eclipse.osgi-sources-3.7.1.R37x_v20110808-1106.jar"/>
diff --git a/org.eclipse.virgo.shell.command/src/main/java/org/eclipse/virgo/shell/internal/ServiceUtils.java b/org.eclipse.virgo.shell.command/src/main/java/org/eclipse/virgo/shell/internal/ServiceUtils.java
deleted file mode 100644
index aa6fe3a2..00000000
--- a/org.eclipse.virgo.shell.command/src/main/java/org/eclipse/virgo/shell/internal/ServiceUtils.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2010 VMware Inc.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * VMware Inc. - initial contribution
- *******************************************************************************/
-
-package org.eclipse.virgo.shell.internal;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-/**
- * Utility methods for working with services in the OSGi service registry.
- * <p />
- *
- * <strong>Concurrent Semantics</strong><br />
- *
- * Thread-safe.
- *
- */
-public final class ServiceUtils {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(ServiceUtils.class);
-
- public static <T> T getService(BundleContext bundleContext, Class<T> clazz, String requiredProperty, String requiredPropertyValue) {
- T result = null;
- try {
- ServiceReference<?>[] serviceReferences = bundleContext.getServiceReferences((String)null, String.format("(%s=*)", requiredProperty));
- if (serviceReferences != null) {
- for (ServiceReference<?> serviceReference : serviceReferences) {
- Object offeredPropertyValue = serviceReference.getProperty(requiredProperty);
- if (offeredPropertyValue instanceof String) { // String value
- String offeredProperty = (String) offeredPropertyValue;
- if (offeredProperty != null && requiredPropertyValue.equals(offeredProperty)) {
- Object potentialResult = bundleContext.getService(serviceReference);
- if (clazz.isInstance(potentialResult)) {
- result = clazz.cast(bundleContext.getService(serviceReference));
- break;
- }
- }
- } else if (offeredPropertyValue instanceof String[]) { // String[] value
- String[] offeredProperties = (String[]) offeredPropertyValue;
- if (offeredProperties != null && arrayContainsEntry(offeredProperties, requiredPropertyValue)) {
- Object potentialResult = bundleContext.getService(serviceReference);
- if (clazz.isInstance(potentialResult)) {
- result = clazz.cast(bundleContext.getService(serviceReference));
- break;
- }
- }
- } else {
- LOGGER.warn(String.format(
- "Matching service found from bundle %d but with a bad type for the '%s' property, String or String[] expected.",
- serviceReference.getBundle().getBundleId(), requiredProperty));
- }
- }
- }
- } catch (InvalidSyntaxException e) {
- throw new RuntimeException("Unexpected InvalidSyntaxException", e);
- }
-
- return result;
- }
-
- private static <T> boolean arrayContainsEntry(T[] array, T entry) {
- if (entry == null || array == null) {
- return false;
- }
- for (T arrayEntry : array) {
- if (arrayEntry != null && arrayEntry.equals(entry)) {
- return true;
- }
- }
- return false;
- }
-}
diff --git a/org.eclipse.virgo.shell.command/src/main/java/org/eclipse/virgo/shell/osgicommand/Activator.java b/org.eclipse.virgo.shell.command/src/main/java/org/eclipse/virgo/shell/osgicommand/Activator.java
index 43df9cea..799ba511 100755
--- a/org.eclipse.virgo.shell.command/src/main/java/org/eclipse/virgo/shell/osgicommand/Activator.java
+++ b/org.eclipse.virgo.shell.command/src/main/java/org/eclipse/virgo/shell/osgicommand/Activator.java
@@ -16,13 +16,14 @@ package org.eclipse.virgo.shell.osgicommand;
import java.lang.management.ManagementFactory;
import java.util.Dictionary;
import java.util.Hashtable;
+import java.util.concurrent.TimeoutException;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
-import org.eclipse.virgo.kernel.osgi.framework.OsgiFrameworkUtils;
-import org.eclipse.virgo.kernel.osgi.framework.OsgiServiceHolder;
+import org.eclipse.virgo.kernel.osgi.framework.ServiceUtils;
+
import org.eclipse.virgo.shell.CommandExecutor;
import org.eclipse.virgo.shell.osgicommand.internal.GogoClassLoadingCommand;
import org.eclipse.virgo.shell.osgicommand.internal.GogoKernelShellCommand;
@@ -42,15 +43,10 @@ public class Activator implements BundleActivator {
private static final String KERNEL_SHELL_COMMAND = "vsh";
- private static final String[] KERNEL_SHELL_SUBCOMMANDS = new String[] { "bundle", "config", "install", "packages", "par", "plan", "service",
- "shutdown" };
+ private static final String[] KERNEL_SHELL_SUBCOMMANDS = new String[] { "bundle", "config", "install", "packages", "par", "plan", "service", "shutdown" };
private static final String[] CLASS_LOADING_SUBCOMMANDS = new String[] { "clhas", "clload", "clexport" };
- private static final int COMMAND_EXECUTOR_SERVICE_WAIT = 20 * 1000; // 20 seconds
-
- private static final int SERVICE_WAIT_PAUSE = 100; // 100 milliseconds
-
private final ServiceRegistrationTracker registrationTracker = new ServiceRegistrationTracker();
private final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
@@ -93,40 +89,6 @@ public class Activator implements BundleActivator {
this.server.unregisterMBean(this.classLoadingObjectName);
}
- /**
- * Get a service which might not be immediately available
- *
- * @param <T> type of service to get
- * @param context in which to search for service
- * @param serviceClass of service to locate
- * @param millis maximum time to delay in milliseconds
- * @return null if timeout before getting service, otherwise service
- */
- private static <T> T getPotentiallyDelayedService(BundleContext context, Class<T> serviceClass, long millis) {
- T service = null;
-
- while (service == null) {
- try {
- OsgiServiceHolder<T> serviceHolder = OsgiFrameworkUtils.getService(context, serviceClass);
- if (serviceHolder != null) {
- service = serviceHolder.getService();
- }
- } catch (IllegalStateException e) {
- try {
- millis -= SERVICE_WAIT_PAUSE;
- if (millis > 0) {
- Thread.sleep(SERVICE_WAIT_PAUSE);
- } else {
- return null;
- }
- } catch (InterruptedException ie) {
- }
- }
- }
-
- return service;
- }
-
private static final class PostStartInitialisationRunnable implements Runnable {
private final BundleContext context;
@@ -143,7 +105,14 @@ public class Activator implements BundleActivator {
*/
@Override
public void run() {
- CommandExecutor commandExecutor = getPotentiallyDelayedService(this.context, CommandExecutor.class, COMMAND_EXECUTOR_SERVICE_WAIT);
+ CommandExecutor commandExecutor = null;
+ try {
+ commandExecutor = ServiceUtils.getPotentiallyDelayedService(this.context, CommandExecutor.class);
+ } catch (TimeoutException e) {
+ // no-op
+ } catch (InterruptedException e) {
+ // no-op
+ }
if (commandExecutor == null) {
return; // TODO: report this failure -- but where?
}
@@ -152,8 +121,7 @@ public class Activator implements BundleActivator {
Dictionary<String, Object> properties = new Hashtable<String, Object>();
properties.put(org.apache.felix.service.command.CommandProcessor.COMMAND_SCOPE, KERNEL_SHELL_COMMAND);
properties.put(org.apache.felix.service.command.CommandProcessor.COMMAND_FUNCTION, KERNEL_SHELL_SUBCOMMANDS);
- this.registrationTracker.track(context.registerService(GogoKernelShellCommand.class, new GogoKernelShellCommand(commandExecutor),
- properties));
+ this.registrationTracker.track(context.registerService(GogoKernelShellCommand.class, new GogoKernelShellCommand(commandExecutor), properties));
}
}
}

Back to the top