org.apache.karaf.features.internal.service.State Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of org.apache.karaf.features.core Show documentation
Show all versions of org.apache.karaf.features.core Show documentation
This bundle is the core implementation of the Karaf features support.
/*
* 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.features.internal.service;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.karaf.features.internal.util.MapUtils;
/**
* Representation of the state of features service from the point of view of logical requirements
* which are translated into bundles and features installed in {@link org.eclipse.equinox.region.Region regions}.
* It's a collection of:
* - used repositories
* - region -> requirements (logical feature requirements)
* - region -> installed features (actual features installed - including conditionals and dependant features)
* - region -> installed features -> state of feature installation
* - region -> bundle ids (for bundles installed via features service, a.k.a. managed bundles)
* - bundle id -> checksum
*
* State is replaced (swapped) after uninstalling/updating/installing all the bundles as requested, but
* before resolving/refreshing them. Before State is set, work is done on the instance of Deployer.DeploymentState.
*/
public class State {
public final AtomicBoolean bootDone = new AtomicBoolean();
public final Set repositories = new TreeSet<>();
/** Map from region name to Set of feature requirements (feature:name/version-range
) */
public final Map> requirements = new HashMap<>();
/** Map from region name to Set of feature id (name/version
) */
public final Map> installedFeatures = new HashMap<>();
/** State of features by region and feature id (name/version
) */
public final Map> stateFeatures = new HashMap<>();
/** Map from region name to Set of ids of bundles installed via some features or requirements */
public final Map> managedBundles = new HashMap<>();
/** Map from bundle id to bundle's java.util.zip.CRC32 */
public final Map bundleChecksums = new HashMap<>();
public State copy() {
State state = new State();
copy(this, state, false);
return state;
}
public void replace(State state) {
copy(state, this, true);
}
private static void copy(State from, State to, boolean clear) {
if (clear) {
to.repositories.clear();
to.requirements.clear();
to.installedFeatures.clear();
to.stateFeatures.clear();
to.managedBundles.clear();
to.bundleChecksums.clear();
}
to.bootDone.set(from.bootDone.get());
MapUtils.copy(from.repositories, to.repositories);
MapUtils.copy(from.requirements, to.requirements);
MapUtils.copy(from.installedFeatures, to.installedFeatures);
MapUtils.copy(from.stateFeatures, to.stateFeatures);
MapUtils.copy(from.managedBundles, to.managedBundles);
MapUtils.copy(from.bundleChecksums, to.bundleChecksums);
}
}