diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
commit | 72231250ed81e10d66bfe70701e64fa5fe50f712 (patch) | |
tree | 2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /container-di/src/main/java/com/yahoo/container/di |
Publish
Diffstat (limited to 'container-di/src/main/java/com/yahoo/container/di')
10 files changed, 212 insertions, 0 deletions
diff --git a/container-di/src/main/java/com/yahoo/container/di/ComponentDeconstructor.java b/container-di/src/main/java/com/yahoo/container/di/ComponentDeconstructor.java new file mode 100644 index 00000000000..8681d0bc595 --- /dev/null +++ b/container-di/src/main/java/com/yahoo/container/di/ComponentDeconstructor.java @@ -0,0 +1,10 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.container.di; + +/** + * @author gjoranv + * @author tonytv + */ +public interface ComponentDeconstructor { + void deconstruct(Object component); +} diff --git a/container-di/src/main/java/com/yahoo/container/di/componentgraph/Provider.java b/container-di/src/main/java/com/yahoo/container/di/componentgraph/Provider.java new file mode 100644 index 00000000000..38482371455 --- /dev/null +++ b/container-di/src/main/java/com/yahoo/container/di/componentgraph/Provider.java @@ -0,0 +1,25 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.container.di.componentgraph; + +/** + * <p>Provides a component of the parameter type T. + * If (and only if) dependency injection does not have a component of type T, + * it will request one from the Provider providing type T.</p> + * + * <p>Providers are useful in these situations:</p> + * <ul> + * <li>Some code is needed to create the component instance in question.</li> + * <li>The component creates resources that must be deconstructed.</li> + * <li>A fallback component should be provided in case the application (or system) + * does not provide a component instance.</li> + * </ul> + * + * @author tonytv + * @author gjoranv + */ +public interface Provider<T> { + + T get(); + void deconstruct(); + +} diff --git a/container-di/src/main/java/com/yahoo/container/di/componentgraph/core/package-info.java b/container-di/src/main/java/com/yahoo/container/di/componentgraph/core/package-info.java new file mode 100644 index 00000000000..545b7dabc05 --- /dev/null +++ b/container-di/src/main/java/com/yahoo/container/di/componentgraph/core/package-info.java @@ -0,0 +1,5 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +@ExportPackage +package com.yahoo.container.di.componentgraph.core; + +import com.yahoo.osgi.annotation.ExportPackage; diff --git a/container-di/src/main/java/com/yahoo/container/di/componentgraph/package-info.java b/container-di/src/main/java/com/yahoo/container/di/componentgraph/package-info.java new file mode 100644 index 00000000000..e0333aa8b44 --- /dev/null +++ b/container-di/src/main/java/com/yahoo/container/di/componentgraph/package-info.java @@ -0,0 +1,7 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +@ExportPackage +@PublicApi +package com.yahoo.container.di.componentgraph; + +import com.yahoo.api.annotations.PublicApi; +import com.yahoo.osgi.annotation.ExportPackage; diff --git a/container-di/src/main/java/com/yahoo/container/di/config/ResolveDependencyException.java b/container-di/src/main/java/com/yahoo/container/di/config/ResolveDependencyException.java new file mode 100644 index 00000000000..d4fb1df397a --- /dev/null +++ b/container-di/src/main/java/com/yahoo/container/di/config/ResolveDependencyException.java @@ -0,0 +1,12 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.container.di.config; + +/** + * @author gjoranv + * @since 5.17 + */ +public class ResolveDependencyException extends RuntimeException { + public ResolveDependencyException(String message) { + super(message); + } +} diff --git a/container-di/src/main/java/com/yahoo/container/di/config/RestApiContext.java b/container-di/src/main/java/com/yahoo/container/di/config/RestApiContext.java new file mode 100644 index 00000000000..dcedd442b19 --- /dev/null +++ b/container-di/src/main/java/com/yahoo/container/di/config/RestApiContext.java @@ -0,0 +1,101 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.container.di.config; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Inject; +import com.google.inject.Key; +import com.yahoo.component.ComponentId; +import org.osgi.framework.Version; + +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + +/** + * Only for internal JDisc use. + * + * @author gjoranv + * @since 5.11 + */ +public class RestApiContext { + + private final List<BundleInfo> bundles = new ArrayList<>(); + private final List<Injectable> injectableComponents = new ArrayList<>(); + + public final JerseyBundlesConfig bundlesConfig; + public final JerseyInjectionConfig injectionConfig; + + @Inject + public RestApiContext(JerseyBundlesConfig bundlesConfig, JerseyInjectionConfig injectionConfig) { + this.bundlesConfig = bundlesConfig; + this.injectionConfig = injectionConfig; + } + + public List<BundleInfo> getBundles() { + return Collections.unmodifiableList(bundles); + } + + public void addBundle(BundleInfo bundle) { + bundles.add(bundle); + } + + public List<Injectable> getInjectableComponents() { + return Collections.unmodifiableList(injectableComponents); + } + + public void addInjectableComponent(Key<?> key, ComponentId id, Object component) { + injectableComponents.add(new Injectable(key, id, component)); + } + + public static class Injectable { + public final Key<?> key; + public final ComponentId id; + public final Object instance; + + public Injectable(Key<?> key, ComponentId id, Object instance) { + this.key = key; + this.id = id; + this.instance = instance; + } + @Override + public String toString() { + return id.toString(); + } + } + + public static class BundleInfo { + public final String symbolicName; + public final Version version; + public final String fileLocation; + public final URL webInfUrl; + public final ClassLoader classLoader; + + private Set<String> classEntries; + + public BundleInfo(String symbolicName, Version version, String fileLocation, URL webInfUrl, ClassLoader classLoader) { + this.symbolicName = symbolicName; + this.version = version; + this.fileLocation = fileLocation; + this.webInfUrl = webInfUrl; + this.classLoader = classLoader; + } + + @Override + public String toString() { + return symbolicName + ":" + version; + } + + public void setClassEntries(Collection<String> entries) { + this.classEntries = ImmutableSet.copyOf(entries); + } + + public Set<String> getClassEntries() { + return classEntries; + } + } +} diff --git a/container-di/src/main/java/com/yahoo/container/di/config/Subscriber.java b/container-di/src/main/java/com/yahoo/container/di/config/Subscriber.java new file mode 100644 index 00000000000..fe81e510148 --- /dev/null +++ b/container-di/src/main/java/com/yahoo/container/di/config/Subscriber.java @@ -0,0 +1,21 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.container.di.config; + +import com.yahoo.config.ConfigInstance; +import com.yahoo.vespa.config.ConfigKey; + +import java.util.Map; + +/** + * @author tonytv + * @author gjoranv + */ +public interface Subscriber { + long waitNextGeneration(); + long generation(); + + boolean configChanged(); + Map<ConfigKey<ConfigInstance>, ConfigInstance> config(); + + void close(); +} diff --git a/container-di/src/main/java/com/yahoo/container/di/config/SubscriberFactory.java b/container-di/src/main/java/com/yahoo/container/di/config/SubscriberFactory.java new file mode 100644 index 00000000000..194435d6945 --- /dev/null +++ b/container-di/src/main/java/com/yahoo/container/di/config/SubscriberFactory.java @@ -0,0 +1,18 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.container.di.config; + +import com.google.inject.ProvidedBy; +import com.yahoo.container.di.CloudSubscriberFactory; +import com.yahoo.vespa.config.ConfigKey; + +import java.util.Set; + +/** + * @author tonytv + * @author gjoranv + */ +@ProvidedBy(CloudSubscriberFactory.Provider.class) +public interface SubscriberFactory { + Subscriber getSubscriber(Set<? extends ConfigKey<?>> configKeys); + void reloadActiveSubscribers(long generation); +} diff --git a/container-di/src/main/java/com/yahoo/container/di/config/package-info.java b/container-di/src/main/java/com/yahoo/container/di/config/package-info.java new file mode 100644 index 00000000000..0a04308157a --- /dev/null +++ b/container-di/src/main/java/com/yahoo/container/di/config/package-info.java @@ -0,0 +1,5 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +@ExportPackage +package com.yahoo.container.di.config; + +import com.yahoo.osgi.annotation.ExportPackage; diff --git a/container-di/src/main/java/com/yahoo/container/di/osgi/package-info.java b/container-di/src/main/java/com/yahoo/container/di/osgi/package-info.java new file mode 100644 index 00000000000..fc7e48bc6ef --- /dev/null +++ b/container-di/src/main/java/com/yahoo/container/di/osgi/package-info.java @@ -0,0 +1,8 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +/** + * @author tonytv + */ +@ExportPackage +package com.yahoo.container.di.osgi; + +import com.yahoo.osgi.annotation.ExportPackage; |