Skip to content

Commit

Permalink
Fix javadoc. Add binding to command line arguments as @arguments Stri…
Browse files Browse the repository at this point in the history
…ng[]
  • Loading branch information
elandau committed Nov 24, 2015
1 parent 4ede8af commit 8dc570b
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 61 deletions.
4 changes: 2 additions & 2 deletions karyon3-core/src/main/java/com/netflix/karyon/AutoBinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public interface AutoBinder {
/**
* Create a bindings for the specified type literal.
*
* @param binder
* @param key
* @param binder Binder on which bindings may be created
* @param key Key for which no binding was found
*
* @return True if bindings was created or false if not.
*/
Expand Down
78 changes: 55 additions & 23 deletions karyon3-core/src/main/java/com/netflix/karyon/Karyon.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.netflix.governator.ElementsEx;
import com.netflix.governator.LifecycleInjector;
import com.netflix.governator.LifecycleManager;
import com.netflix.karyon.annotations.Arguments;
import com.netflix.karyon.annotations.Profiles;
import com.netflix.karyon.conditional.ConditionalSupportModule;
import com.netflix.karyon.spi.ModuleListTransformer;
Expand Down Expand Up @@ -123,6 +124,7 @@ protected Karyon(String applicationName) {
*
* @param modules Guice modules to add. These modules my also implement KaryonModule to further
* extend Karyon.
* @return this
*/
public Karyon addModules(Module ... modules) {
if (modules != null) {
Expand All @@ -136,6 +138,7 @@ public Karyon addModules(Module ... modules) {
*
* @param modules Guice modules to add. These modules my also implement KaryonModule to further
* extend Karyon.
* @return this
*/
public Karyon addModules(List<Module> modules) {
if (modules != null) {
Expand All @@ -149,7 +152,9 @@ public Karyon addModules(List<Module> modules) {
* conditionally loaded. This is useful for testing or when an application
* absolutely needs to override a binding to fix a binding problem in the
* code modules
* @param modules
* @param modules Modules that will be applied as overrides to modules add
* or installed via {@link Karyon#addModules(Module...)}
* @return this
*/
public Karyon addOverrideModules(Module ... modules) {
if (modules != null) {
Expand All @@ -163,7 +168,9 @@ public Karyon addOverrideModules(Module ... modules) {
* conditionally loaded. This is useful for testing or when an application
* absolutely needs to override a binding to fix a binding problem in the
* code modules
* @param modules
* @param modules Modules that will be applied as overrides to modules add
* or installed via {@link Karyon#addModules(Module...)}
* @return this
*/
public Karyon addOverrideModules(List<Module> modules) {
if (modules != null) {
Expand All @@ -175,7 +182,8 @@ public Karyon addOverrideModules(List<Module> modules) {
/**
* Specify the Guice stage in which the application is running. By default Karyon
* runs in Stage.DEVELOPMENT to achieve default lazy singleton behavior.
* @param stage
* @param stage Guice stage
* @return this
*/
public Karyon inStage(Stage stage) {
this.stage = stage;
Expand All @@ -187,16 +195,19 @@ public Karyon inStage(Stage stage) {
* @param provider
*
* @deprecated Module auto loading no longer supported. Install modules directly and use {@literal @}ProvidesConditionally
* @return this
*/
@Deprecated
public Karyon addAutoModuleListProvider(ModuleListProvider provider) {
return this;
}

/**
* Add a runtime profile
* Add a runtime profile. Profiles are processed by the conditional binding {@literal @}ConditionalOnProfile and
* are injectable as {@literal @}Profiles Set{@literal <}String{@literal >}.
*
* @param profile
* @param profile A profile
* @return this
*/
public Karyon addProfile(String profile) {
if (profile != null) {
Expand All @@ -206,21 +217,26 @@ public Karyon addProfile(String profile) {
}

/**
* Add a runtime profiles
* Add a runtime profiles. Profiles are processed by the conditional binding {@literal @}ConditionalOnProfile and
* are injectable as {@literal @}Profiles Set{@literal <}String{@literal >}.
*
* @param profiles
* @param profiles Set of profiles
* @return this
*/
public Karyon addProfiles(String... profiles) {
public Karyon addProfiles(String profile, String... profiles) {
this.profiles.add(profile);
if (profiles != null) {
this.profiles.addAll(Arrays.asList(profiles));
}
return this;
}

/**
* Add a runtime profiles
* Add a runtime profiles. Profiles are processed by the conditional binding {@literal @}ConditionalOnProfile and
* are injectable as {@literal @}Profiles Set{@literal <}String{@literal >}.
*
* @param profiles
* @param profiles Set of profiles
* @return this
*/
public Karyon addProfiles(Collection<String> profiles) {
if (profiles != null) {
Expand All @@ -231,31 +247,35 @@ public Karyon addProfiles(Collection<String> profiles) {

/**
* Enable the specified feature
* @param feature
* @param feature Boolean feature to enable
* @return this
*/
public Karyon enableFeature(KaryonFeature<Boolean> feature) {
return setFeature(feature, true);
}

/**
* Enable or disable the specified feature
* @param feature
* @param feature Boolean feature to disable
* @return this
*/
public Karyon enableFeature(KaryonFeature<Boolean> feature, boolean enabled) {
return setFeature(feature, enabled);
}

/**
* Disable the specified feature
* @param feature
* @param feature Boolean feature to enable/disable
* @return this
*/
public Karyon disableFeature(KaryonFeature<Boolean> feature) {
return setFeature(feature, false);
}

/**
* Disable the specified feature
* @param feature
* Set a feature
* @param feature Feature to set
* @return this
*/
public <T> Karyon setFeature(KaryonFeature<T> feature, T value) {
this.features.put(feature, value);
Expand All @@ -267,7 +287,8 @@ public <T> Karyon setFeature(KaryonFeature<T> feature, T value) {
* prior to creating the injectors. Multiple transformers may be added with each
* transforming the result of the previous one.
*
* @param transformer
* @param transformer A transformer
* @return this
*/
public Karyon addModuleListTransformer(ModuleListTransformer transformer) {
if (transformer != null) {
Expand All @@ -282,6 +303,7 @@ public Karyon addModuleListTransformer(ModuleListTransformer transformer) {
* @param matcher Matcher to restrict the types for which the AutoBinder can be used. See {@link TypeLiteralMatchers} for
* specifying common matchers.
* @param autoBinder The auto binder
* @return this
*/
public <T extends TypeLiteral<?>> Karyon addAutoBinder(Matcher<T> matcher, AutoBinder autoBinder) {
this.autoBinders.add(new MatchingAutoBinder<T>(matcher, autoBinder));
Expand All @@ -295,15 +317,19 @@ public Karyon apply(Module ... modules) {
}

/**
*
* Create the injector and call any LifecycleListeners
* @return the LifecycleInjector for this run
*/
public LifecycleInjector start() {
return start(null);
}

/**
* Create the injector and call any LifecycleListeners
* @param args - Runtime parameter (from main) injectable as {@literal @}Arguments String[]
* @return the LifecycleInjector for this run
*/
public LifecycleInjector start(String[] args) {
public LifecycleInjector start(final String[] args) {
for (Module module : modules) {
if (module instanceof KaryonModule) {
((KaryonModule)module).configure(new KaryonBinder() {
Expand Down Expand Up @@ -345,6 +371,13 @@ protected void configure() {
for (String profile : Karyon.this.profiles) {
profiles.addBinding().toInstance(profile);
}

if (args != null) {
bind(String[].class).annotatedWith(Arguments.class).toInstance(args);
}
else {
bind(String[].class).annotatedWith(Arguments.class).toInstance(new String[]{});
}
}
})
.build())
Expand Down Expand Up @@ -394,15 +427,14 @@ protected void configure() {
}
}

/**
* Construct a new Karyon instance
* @return Karyon instance
*/
public static Karyon newBuilder() {
return new Karyon();
}

/**
* Starting point for creating a Karyon application.
*
* @param applicationName
*/
@Deprecated
public static Karyon forApplication(String applicationName) {
return new Karyon(applicationName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ public interface KaryonBinder {
/**
* Add an AutoBinder to be used when no binding is provided for a type matched by the matcher
*
* @param matcher
* @param autoBinder
* @param matcher Logic for matching an unbound TypeLiteral. See {@link TypeLiteralMatchers} for
* pre-defined matchers.
* @param autoBinder AutoBinder that will created the bindings for any type matched by the matcher
*/
<T extends TypeLiteral<?>> void bindAutoBinder(Matcher<T> matcher, AutoBinder autoBinder);
}
22 changes: 11 additions & 11 deletions karyon3-core/src/main/java/com/netflix/karyon/PropertySource.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,37 @@ public interface PropertySource {
/**
* Get the value of a property or null if not found
*
* @param key
* @return
* @param key Name of property to fetch
* @return Value or null if not found
*/
public String get(String key);

/**
* Get the value of a property or default if not found
*
* @param key
* @param key Name of property to fetch
* @param defaultValue
* @return
* @return Value or defaultValue if not found
*/
public String get(String key, String defaultValue);

/**
* Get a property value of a specific type
*
* @param key
* @param type
* @return
* @param key Name of property to fetch
* @param type Type of value requested
* @return Value of the request type or null if not found
*/
public <T> T get(String key, Class<T> type);

/**
* Get a property value of a specific type while returning a
* default value if the property is not set.
*
* @param key
* @param type
* @param defaultValue
* @return
* @param key Name of property to fetch
* @param type Type of value requested
* @param defaultValue Default value to return if key not found
* @return Value or defaultValue if not found
*/
public <T> T get(String key, Class<T> type, T defaultValue);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.netflix.karyon.annotations;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import javax.inject.Qualifier;

/**
* Qualifier associated with String[] arguments passed to Karyon.start(args)
*/
@Target({ ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Qualifier
public @interface Arguments {

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ConditionalBinder<T> {
/**
* Used to generate unique bindings for conditional T keys that will not conflict
* with annotated T
* @return
* @return Unique annotation
*/
public static IdQualifier newIdQualifier() {
final int id = counter.incrementAndGet();
Expand Down
Loading

0 comments on commit 8dc570b

Please sign in to comment.