summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgjoranv <gv@verizonmedia.com>2019-10-01 15:43:15 +0200
committerGitHub <noreply@github.com>2019-10-01 15:43:15 +0200
commitf7caa458f044780fa005683145deeb346470ab5f (patch)
tree814742c4d103c1bca3df36d307b79c51e5be9451
parentc53863267d4838a981171dcc060ff6efdedb2ace (diff)
parent16097dda02938e83a490cfb518c60f50ea4c605c (diff)
Merge pull request #10833 from vespa-engine/bratseth/cleanup
Nonfunctional changes only
-rw-r--r--container-core/src/main/java/com/yahoo/container/core/config/BundleLoader.java16
-rw-r--r--container-core/src/main/java/com/yahoo/osgi/Osgi.java2
-rw-r--r--container-core/src/main/java/com/yahoo/osgi/OsgiImpl.java35
-rw-r--r--container-di/src/main/java/com/yahoo/container/bundle/BundleInstantiationSpecification.java6
-rw-r--r--jdisc_core/src/main/java/com/yahoo/jdisc/application/OsgiFramework.java57
-rw-r--r--jdisc_core/src/main/java/com/yahoo/jdisc/core/FelixFramework.java21
6 files changed, 66 insertions, 71 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/core/config/BundleLoader.java b/container-core/src/main/java/com/yahoo/container/core/config/BundleLoader.java
index 0a97a4d5d2f..2b3a272fadc 100644
--- a/container-core/src/main/java/com/yahoo/container/core/config/BundleLoader.java
+++ b/container-core/src/main/java/com/yahoo/container/core/config/BundleLoader.java
@@ -46,9 +46,7 @@ public class BundleLoader {
return osgi.install(file.getAbsolutePath());
}
- /**
- * @return the number of bundles installed by this call.
- */
+ /** Returns the number of bundles installed by this call. */
private int install(List<FileReference> references) {
Set<FileReference> bundlesToInstall = new HashSet<>(references);
bundlesToInstall.removeAll(reference2Bundles.keySet());
@@ -115,12 +113,12 @@ public class BundleLoader {
}
}
- //all bundles must have been started first to ensure correct package resolution.
+ // All bundles must have been started first to ensure correct package resolution.
private void startBundles() {
for (List<Bundle> bundles : reference2Bundles.values()) {
for (Bundle bundle : bundles) {
try {
- if (!isFragment(bundle))
+ if ( ! isFragment(bundle))
bundle.start();
} catch(Exception e) {
throw new RuntimeException("Could not start bundle '" + bundle.getSymbolicName() + "'", e);
@@ -129,18 +127,15 @@ public class BundleLoader {
}
}
- // The OSGi APIs are just getting worse...
private boolean isFragment(Bundle bundle) {
BundleRevision bundleRevision = bundle.adapt(BundleRevision.class);
if (bundleRevision == null)
throw new NullPointerException("Null bundle revision means that bundle has probably been uninstalled: " +
- bundle.getSymbolicName() + ":" + bundle.getVersion());
+ bundle.getSymbolicName() + ":" + bundle.getVersion());
return (bundleRevision.getTypes() & BundleRevision.TYPE_FRAGMENT) != 0;
}
- /**
- * Returns the number of uninstalled bundles
- */
+ /** Returns the number of uninstalled bundles */
private int retainOnly(List<FileReference> newReferences) {
Set<Bundle> bundlesToRemove = new HashSet<>(Arrays.asList(osgi.getBundles()));
@@ -182,4 +177,5 @@ public class BundleLoader {
sb.append("}");
return sb.toString();
}
+
}
diff --git a/container-core/src/main/java/com/yahoo/osgi/Osgi.java b/container-core/src/main/java/com/yahoo/osgi/Osgi.java
index 31f1146c311..c94eaf43deb 100644
--- a/container-core/src/main/java/com/yahoo/osgi/Osgi.java
+++ b/container-core/src/main/java/com/yahoo/osgi/Osgi.java
@@ -2,9 +2,7 @@
package com.yahoo.osgi;
import com.yahoo.component.ComponentSpecification;
-import com.yahoo.container.bundle.BundleInstantiationSpecification;
import org.osgi.framework.Bundle;
-import org.osgi.framework.ServiceReference;
import java.util.List;
diff --git a/container-core/src/main/java/com/yahoo/osgi/OsgiImpl.java b/container-core/src/main/java/com/yahoo/osgi/OsgiImpl.java
index 2e37a278387..8b2f20a1c13 100644
--- a/container-core/src/main/java/com/yahoo/osgi/OsgiImpl.java
+++ b/container-core/src/main/java/com/yahoo/osgi/OsgiImpl.java
@@ -2,17 +2,17 @@
package com.yahoo.osgi;
import com.yahoo.component.ComponentSpecification;
+import com.yahoo.component.Version;
import com.yahoo.container.bundle.BundleInstantiationSpecification;
import com.yahoo.jdisc.application.OsgiFramework;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
-import org.osgi.framework.ServiceReference;
import java.util.List;
-import java.util.logging.Logger;
/**
* @author Tony Vaagenes
+ * @author bratseth
*/
public class OsgiImpl implements Osgi {
@@ -62,13 +62,13 @@ public class OsgiImpl implements Osgi {
}
private static void ensureBundleActive(Bundle bundle) throws IllegalStateException {
- final int state = bundle.getState();
+ int state = bundle.getState();
Throwable cause = null;
if (state != Bundle.ACTIVE) {
try {
- //Get the reason why the bundle isn't active.
- //Do not change this method to not fail if start is successful without carefully analyzing
- //why there are non-active bundles.
+ // Get the reason why the bundle isn't active.
+ // Do not change this method to not fail if start is successful without carefully analyzing
+ // why there are non-active bundles.
bundle.start();
} catch (BundleException e) {
cause = e;
@@ -81,29 +81,29 @@ public class OsgiImpl implements Osgi {
* Returns the bundle of a given name having the highest matching version
*
* @param id the id of the component to return. May not include a version, or include
- * an underspecified version, in which case the highest (mathcing) version which
+ * an underspecified version, in which case the highest (matching) version which
* does not contain a qualifier is returned
* @return the bundle match having the highest version, or null if there was no matches
*/
public Bundle getBundle(ComponentSpecification id) {
- Bundle highestMatch=null;
+ Bundle highestMatch = null;
for (Bundle bundle : getBundles()) {
assert bundle.getSymbolicName() != null : "ensureHasBundleSymbolicName not called during installation";
if ( ! bundle.getSymbolicName().equals(id.getName())) continue;
if ( ! id.getVersionSpecification().matches(versionOf(bundle))) continue;
- if (highestMatch==null || versionOf(highestMatch).compareTo(versionOf(bundle))<0)
- highestMatch=bundle;
+ if (highestMatch == null || versionOf(highestMatch).compareTo(versionOf(bundle)) < 0)
+ highestMatch = bundle;
}
return highestMatch;
}
- /** returns the version of a bundle, as specified by Bundle-Version in the manifest */
- private static com.yahoo.component.Version versionOf(Bundle bundle) {
- Object bundleVersion=bundle.getHeaders().get("Bundle-Version");
- if (bundleVersion==null) return com.yahoo.component.Version.emptyVersion;
- return new com.yahoo.component.Version(bundleVersion.toString());
+ /** Returns the version of a bundle, as specified by Bundle-Version in the manifest */
+ private static Version versionOf(Bundle bundle) {
+ Object bundleVersion = bundle.getHeaders().get("Bundle-Version");
+ if (bundleVersion == null) return Version.emptyVersion;
+ return new Version(bundleVersion.toString());
}
@Override
@@ -116,8 +116,8 @@ public class OsgiImpl implements Osgi {
}
private static String normalizeLocation(String location) {
- if (location.indexOf(':')<0)
- location="file:" + location;
+ if (location.indexOf(':') < 0)
+ location = "file:" + location;
return location;
}
@@ -134,4 +134,5 @@ public class OsgiImpl implements Osgi {
public void refreshPackages() {
jdiscOsgi.refreshPackages();
}
+
}
diff --git a/container-di/src/main/java/com/yahoo/container/bundle/BundleInstantiationSpecification.java b/container-di/src/main/java/com/yahoo/container/bundle/BundleInstantiationSpecification.java
index 440a687a671..0fb8a99a957 100644
--- a/container-di/src/main/java/com/yahoo/container/bundle/BundleInstantiationSpecification.java
+++ b/container-di/src/main/java/com/yahoo/container/bundle/BundleInstantiationSpecification.java
@@ -63,13 +63,13 @@ public final class BundleInstantiationSpecification {
new ComponentSpecification(idSpec),
(classSpec == null || classSpec.isEmpty())? null : new ComponentSpecification(classSpec),
(bundleSpec == null || bundleSpec.isEmpty())? null : new ComponentSpecification(bundleSpec));
-
}
/**
* Return a new instance of the specification with bundle name altered
- * @param bundleName New name of bundle
- * @return the new instance of the specification.
+ *
+ * @param bundleName the new name of the bundle
+ * @return the new instance of the specification
*/
public BundleInstantiationSpecification inBundle(String bundleName) {
return new BundleInstantiationSpecification(this.id, this.classId, new ComponentSpecification(bundleName));
diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/application/OsgiFramework.java b/jdisc_core/src/main/java/com/yahoo/jdisc/application/OsgiFramework.java
index 5abc95cc610..f5346a21a4f 100644
--- a/jdisc_core/src/main/java/com/yahoo/jdisc/application/OsgiFramework.java
+++ b/jdisc_core/src/main/java/com/yahoo/jdisc/application/OsgiFramework.java
@@ -8,9 +8,9 @@ import org.osgi.framework.BundleException;
import java.util.List;
/**
- * <p>This is an abstraction of the OSGi framework that hides the actual implementation details. If you need access to
+ * This is an abstraction of the OSGi framework that hides the actual implementation details. If you need access to
* this interface, simply inject it into your Application. In most cases, however, you are better of injecting a
- * {@link BundleInstaller} since that provides common convenience methods.</p>
+ * {@link BundleInstaller} since that provides common convenience methods.
*
* @author Simon Thoresen Hult
*/
@@ -24,7 +24,7 @@ public interface OsgiFramework {
* argument.</p>
*
* <p><b>NOTE:</b> When this method installs more than one bundle, <em>AND</em> one of those bundles throw an
- * exception during installation, the bundles installed prior to throwing the expcetion will remain installed. To
+ * exception during installation, the bundles installed prior to throwing the exception will remain installed. To
* enable the caller to recover from such a situation, this method wraps any thrown exception within a {@link
* BundleInstallationException} that contains the list of successfully installed bundles.</p>
*
@@ -32,67 +32,66 @@ public interface OsgiFramework {
* case of an exception), but that can not be implemented thread-safely since an <code>Application</code> may choose to
* install bundles concurrently through any available <code>BundleContext</code>.</p>
*
- * @param bundleLocation The location identifier of the bundle to install.
- * @return The list of Bundle objects installed, the object at index 0 matches the given location.
- * @throws BundleInstallationException If the input stream cannot be read, or the installation of a bundle failed,
+ * @param bundleLocation the location identifier of the bundle to install
+ * @return the list of Bundle objects installed, the object at index 0 matches the given location
+ * @throws BundleInstallationException if the input stream cannot be read, or the installation of a bundle failed,
* or the caller does not have the appropriate permissions, or the system {@link
- * BundleContext} is no longer valid.
+ * BundleContext} is no longer valid
*/
List<Bundle> installBundle(String bundleLocation) throws BundleException;
/**
- * <p>Starts the given {@link Bundle}s. The parameter <code>privileged</code> tells the framework whether or not
+ * Starts the given {@link Bundle}s. The parameter <code>privileged</code> tells the framework whether or not
* privileges are available, and is checked against the {@link OsgiHeader#PRIVILEGED_ACTIVATOR} header of each
- * Bundle being started. Any bundle that is a fragment is silently ignored.</p>
+ * Bundle being started. Any bundle that is a fragment is silently ignored.
*
- * @param bundles The bundles to start.
- * @param privileged Whether or not privileges are available.
- * @throws BundleException If a bundle could not be started. This could be because a code dependency could not
+ * @param bundles the bundles to start
+ * @param privileged whether or not privileges are available
+ * @throws BundleException if a bundle could not be started. This could be because a code dependency could not
* be resolved or the specified BundleActivator could not be loaded or threw an
* exception.
- * @throws SecurityException If the caller does not have the appropriate permissions.
- * @throws IllegalStateException If this bundle has been uninstalled or this bundle tries to change its own state.
+ * @throws SecurityException if the caller does not have the appropriate permissions
+ * @throws IllegalStateException if this bundle has been uninstalled or this bundle tries to change its own state
*/
void startBundles(List<Bundle> bundles, boolean privileged) throws BundleException;
/**
- * <p>This method <em>synchronously</em> refreshes all bundles currently loaded. Once this method returns, the
- * class loaders of all bundles will reflect on the current set of loaded bundles.</p>
+ * Synchronously refresh all bundles currently loaded. Once this method returns, the
+ * class loaders of all bundles will reflect on the current set of loaded bundles.
*/
void refreshPackages();
/**
- * <p>Returns the BundleContext of this framework's system bundle. The returned BundleContext can be used by the
+ * Returns the BundleContext of this framework's system bundle. The returned BundleContext can be used by the
* caller to act on behalf of this bundle. This method may return <code>null</code> if it has no valid
- * BundleContext.</p>
+ * BundleContext.
*
- * @return A <code>BundleContext</code> for the system bundle, or <code>null</code>.
- * @throws SecurityException If the caller does not have the appropriate permissions.
+ * @return a <code>BundleContext</code> for the system bundle, or <code>null</code>
+ * @throws SecurityException if the caller does not have the appropriate permissions
*/
BundleContext bundleContext();
/**
- * <p>Returns an iterable collection of all installed bundles. This method returns a list of all bundles installed
+ * Returns an iterable collection of all installed bundles. This method returns a list of all bundles installed
* in the OSGi environment at the time of the call to this method. However, since the OsgiFramework is a very
- * dynamic environment, bundles can be installed or uninstalled at anytime.</p>
+ * dynamic environment, bundles can be installed or uninstalled at anytime.
*
- * @return An iterable collection of Bundle objects, one object per installed bundle.
+ * @return an iterable collection of Bundle objects, one object per installed bundle
*/
List<Bundle> bundles();
/**
- * <p>This method starts the framework instance. Before this method is called, any call to {@link
- * #installBundle(String)} or {@link #bundles()} will generate a {@link NullPointerException}.</p>
+ * This method starts the framework instance. Before this method is called, any call to {@link
+ * #installBundle(String)} or {@link #bundles()} will generate a {@link NullPointerException}.
*
- * @throws BundleException If any error occurs.
+ * @throws BundleException if any error occurs
*/
void start() throws BundleException;
/**
- * <p>This method <em>synchronously</em> shuts down the framework. It must be called at the end of a session in
- * order to shutdown all active bundles.</p>
+ * Synchronously shut down the framework. It must be called at the end of a session to shutdown all active bundles.
*
- * @throws BundleException If any error occurs.
+ * @throws BundleException if any error occurs
*/
void stop() throws BundleException;
diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/core/FelixFramework.java b/jdisc_core/src/main/java/com/yahoo/jdisc/core/FelixFramework.java
index 7de4a9273bd..96fc0c91d2d 100644
--- a/jdisc_core/src/main/java/com/yahoo/jdisc/core/FelixFramework.java
+++ b/jdisc_core/src/main/java/com/yahoo/jdisc/core/FelixFramework.java
@@ -117,19 +117,19 @@ public class FelixFramework implements OsgiFramework {
wiring.refreshBundles(null,
event -> {
switch (event.getType()) {
- case FrameworkEvent.PACKAGES_REFRESHED:
- latch.countDown();
- break;
- case FrameworkEvent.ERROR:
- log.log(Level.SEVERE, "ERROR FrameworkEvent received.", event.getThrowable());
- break;
+ case FrameworkEvent.PACKAGES_REFRESHED:
+ latch.countDown();
+ break;
+ case FrameworkEvent.ERROR:
+ log.log(Level.SEVERE, "ERROR FrameworkEvent received.", event.getThrowable());
+ break;
}
});
try {
long TIMEOUT_SECONDS = 60L;
- if (!latch.await(TIMEOUT_SECONDS, TimeUnit.SECONDS)) {
+ if ( ! latch.await(TIMEOUT_SECONDS, TimeUnit.SECONDS)) {
log.warning("No PACKAGES_REFRESHED FrameworkEvent received within " + TIMEOUT_SECONDS +
- " seconds of calling FrameworkWiring.refreshBundles()");
+ " seconds of calling FrameworkWiring.refreshBundles()");
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
@@ -176,9 +176,10 @@ public class FelixFramework implements OsgiFramework {
deleteDirContents(child);
boolean deleted = child.delete();
if (! deleted)
- throw new RuntimeException(
- "Could not delete file '" + child.getAbsolutePath() +"'. Please check file permissions!");
+ throw new RuntimeException("Could not delete file '" + child.getAbsolutePath() +
+ "'. Please check file permissions!");
}
}
}
+
}