You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by gn...@apache.org on 2009/05/07 18:25:04 UTC
svn commit: r772696 - in
/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint:
BlueprintStateManager.java context/DefaultBlueprintContextEventSender.java
Author: gnodet
Date: Thu May 7 16:25:04 2009
New Revision: 772696
URL: http://svn.apache.org/viewvc?rev=772696&view=rev
Log:
Add a service to be able to query the state of blueprint powered bundles
Added:
geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/BlueprintStateManager.java
Modified:
geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/DefaultBlueprintContextEventSender.java
Added: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/BlueprintStateManager.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/BlueprintStateManager.java?rev=772696&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/BlueprintStateManager.java (added)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/BlueprintStateManager.java Thu May 7 16:25:04 2009
@@ -0,0 +1,83 @@
+/**
+ * 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.geronimo.blueprint;
+
+import org.osgi.framework.Bundle;
+
+/**
+ * An OSGi service implementing this interface will be registered in the OSGi registry.
+ * It enables querying the blueprint status for a given bundle.
+ *
+ * @author <a href="mailto:dev@geronimo.apache.org">Apache Geronimo Project</a>
+ * @version $Rev: 760378 $, $Date: 2009-03-31 11:31:38 +0200 (Tue, 31 Mar 2009) $
+ */
+public interface BlueprintStateManager {
+
+ /**
+ * The bundle is not a blueprint bundle or has not been started yet.
+ */
+ int UNKNOWN = 0;
+
+ /**
+ * The blueprint context for the bundle is being created.
+ */
+ int CREATING = 1;
+
+ /**
+ * The bundle is waiting for mandatory service references.
+ */
+ int WAITING = 2;
+
+ /**
+ * The blueprint context has been succesfully created.
+ */
+ int CREATED = 3;
+
+ /**
+ * Creation of the blueprint context has failed.
+ */
+ int FAILED = 4;
+
+ /**
+ * The blueprint context for this bundle is being destroyed.
+ */
+ int DESTROYING = 5;
+
+ /**
+ * The blueprint context for this bundle has been destroyed.
+ */
+ int DESTROYED = 6;
+
+ /**
+ * Retrieve the blueprint state for the given bundle.
+ *
+ * @param bundle the bundle to check
+ * @return the blueprint state
+ */
+ int getState(Bundle bundle);
+
+ /**
+ * Retrieve the cause of the failure for a given bundle.
+ *
+ * @param bundle the bundle to check
+ * @return a <code>Throwable</code> or <code>null</code> if the bundle has not failed or if no failure cause was provided
+ */
+ Throwable getFailure(Bundle bundle);
+
+}
Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/DefaultBlueprintContextEventSender.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/DefaultBlueprintContextEventSender.java?rev=772696&r1=772695&r2=772696&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/DefaultBlueprintContextEventSender.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/DefaultBlueprintContextEventSender.java Thu May 7 16:25:04 2009
@@ -20,11 +20,14 @@
import java.util.Dictionary;
import java.util.Hashtable;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
import org.osgi.framework.Version;
+import org.osgi.framework.ServiceRegistration;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.service.event.EventAdmin;
import org.osgi.service.event.Event;
@@ -33,6 +36,7 @@
import org.osgi.service.blueprint.context.BlueprintContextListener;
import org.apache.geronimo.blueprint.BlueprintConstants;
import org.apache.geronimo.blueprint.BlueprintContextEventSender;
+import org.apache.geronimo.blueprint.BlueprintStateManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -42,13 +46,15 @@
* @author <a href="mailto:dev@geronimo.apache.org">Apache Geronimo Project</a>
* @version $Rev: 760378 $, $Date: 2009-03-31 11:31:38 +0200 (Tue, 31 Mar 2009) $
*/
-public class DefaultBlueprintContextEventSender implements BlueprintContextEventSender, EventConstants {
+public class DefaultBlueprintContextEventSender implements BlueprintContextEventSender, EventConstants, BlueprintStateManager {
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultBlueprintContextEventSender.class);
+ private final ServiceRegistration registration;
private final Bundle extenderBundle;
private final ServiceTracker eventAdminServiceTracker;
private final ServiceTracker contextListenerTracker;
+ private final Map<Bundle, Object> states;
public DefaultBlueprintContextEventSender(BundleContext bundleContext) {
this.extenderBundle = bundleContext.getBundle();
@@ -56,33 +62,62 @@
this.eventAdminServiceTracker.open();
this.contextListenerTracker = new ServiceTracker(bundleContext, BlueprintContextListener.class.getName(), null);
this.contextListenerTracker.open();
+ this.states = new ConcurrentHashMap<Bundle, Object>();
+ this.registration = bundleContext.registerService(BlueprintStateManager.class.getName(), this, null);
+ }
+
+ public int getState(Bundle bundle) {
+ Object obj = states.get(bundle);
+ if (obj instanceof Integer) {
+ return (Integer) obj;
+ } else if (obj instanceof Throwable) {
+ return FAILED;
+ } else {
+ return UNKNOWN;
+ }
+ }
+
+ public Throwable getFailure(Bundle bundle) {
+ Object obj = states.get(bundle);
+ if (obj instanceof Throwable) {
+ return (Throwable) obj;
+ } else {
+ return null;
+ }
}
public void sendCreating(BlueprintContext blueprintContext) {
+ states.put(blueprintContext.getBundleContext().getBundle(), CREATING);
sendEvent(blueprintContext, TOPIC_CREATING, null, null, null);
}
public void sendCreated(BlueprintContext blueprintContext) {
+ states.put(blueprintContext.getBundleContext().getBundle(), CREATED);
sendEvent(blueprintContext, TOPIC_CREATED, null, null, null);
}
public void sendDestroying(BlueprintContext blueprintContext) {
+ states.put(blueprintContext.getBundleContext().getBundle(), DESTROYING);
sendEvent(blueprintContext, TOPIC_DESTROYING, null, null, null);
}
public void sendDestroyed(BlueprintContext blueprintContext) {
+ states.put(blueprintContext.getBundleContext().getBundle(), DESTROYED);
sendEvent(blueprintContext, TOPIC_DESTROYED, null, null, null);
}
public void sendWaiting(BlueprintContext blueprintContext, String[] serviceObjectClass, String serviceFilter) {
+ states.put(blueprintContext.getBundleContext().getBundle(), WAITING);
sendEvent(blueprintContext, TOPIC_WAITING, null, serviceObjectClass, serviceFilter);
}
public void sendFailure(BlueprintContext blueprintContext, Throwable cause) {
+ states.put(blueprintContext.getBundleContext().getBundle(), cause != null ? cause : FAILED);
sendEvent(blueprintContext, TOPIC_FAILURE, cause, null, null);
}
public void sendFailure(BlueprintContext blueprintContext, Throwable cause, String[] serviceObjectClass, String serviceFilter) {
+ states.put(blueprintContext.getBundleContext().getBundle(), cause != null ? cause : FAILED);
sendEvent(blueprintContext, TOPIC_FAILURE, cause, serviceObjectClass, serviceFilter);
}
@@ -158,6 +193,7 @@
}
public void destroy() {
+ this.registration.unregister();
this.eventAdminServiceTracker.close();
this.contextListenerTracker.close();
}