| /* |
| * 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.karaf.webconsole.blueprint.internal; |
| |
| import java.util.Map; |
| import java.util.concurrent.ConcurrentHashMap; |
| |
| import org.osgi.framework.Bundle; |
| import org.osgi.framework.BundleEvent; |
| import org.osgi.framework.BundleListener; |
| import org.osgi.service.blueprint.container.BlueprintEvent; |
| import org.osgi.service.blueprint.container.BlueprintListener; |
| |
| public class BlueprintBundleStateTracker implements IBlueprintBundleStateTracker, |
| BundleListener, BlueprintListener { |
| |
| private Map<Long, BlueprintState> states = new ConcurrentHashMap<Long, BlueprintState>(); |
| |
| public BlueprintState getState(Bundle bundle) { |
| return states.get(bundle.getBundleId()); |
| } |
| |
| public void blueprintEvent(BlueprintEvent event) { |
| states.put(event.getBundle().getBundleId(), getState(event)); |
| } |
| |
| public void bundleChanged(BundleEvent event) { |
| if (event.getType() == BundleEvent.UNINSTALLED) { |
| states.remove(event.getBundle().getBundleId()); |
| } |
| } |
| |
| private BlueprintState getState(BlueprintEvent blueprintEvent) { |
| switch (blueprintEvent.getType()) { |
| case BlueprintEvent.CREATING: |
| return BlueprintState.Creating; |
| case BlueprintEvent.CREATED: |
| return BlueprintState.Created; |
| case BlueprintEvent.DESTROYING: |
| return BlueprintState.Destroying; |
| case BlueprintEvent.DESTROYED: |
| return BlueprintState.Destroyed; |
| case BlueprintEvent.FAILURE: |
| return BlueprintState.Failure; |
| case BlueprintEvent.GRACE_PERIOD: |
| return BlueprintState.GracePeriod; |
| case BlueprintEvent.WAITING: |
| return BlueprintState.Waiting; |
| default: |
| return BlueprintState.Unknown; |
| } |
| } |
| } |