Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jameskleeh committed Feb 21, 2019
1 parent 3a19961 commit 56e28fa
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import io.micronaut.http.annotation.Patch
import io.micronaut.http.annotation.Post
import io.micronaut.http.client.annotation.Client
import io.micronaut.runtime.server.EmbeddedServer
import io.reactivex.Flowable
import io.reactivex.Single
import spock.lang.AutoCleanup
import spock.lang.Shared
import spock.lang.Specification
Expand Down Expand Up @@ -218,6 +220,12 @@ class BlockingCrudSpec extends Specification {
}
}

@Client("bookService")
public interface BookClient {


}

static interface BookApi {

@Get("/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,29 @@
*/
package io.micronaut.context;

import io.micronaut.core.annotation.Internal;

import javax.annotation.Nullable;
import java.util.List;

/**
* An interface for configuring an application context.
*
* @author Zachary Klein
* @since 1.0
*/
@Internal
public interface ApplicationContextConfiguration {

/**
* Whether to deduce environments.
*
* @return Boolean setting
* @return True if the environments should be deduced
*/
@Nullable
Boolean getDeduceEnvironments();

/**
* @return The environment names
*/
List<String> getEnvironments();

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,7 @@

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

/**
Expand All @@ -70,7 +63,7 @@ public class DefaultApplicationContext extends DefaultBeanContext implements App
* @param environmentNames The environment names
*/
public DefaultApplicationContext(String... environmentNames) {
this(ClassPathResourceLoader.defaultLoader(DefaultBeanContext.class.getClassLoader()), null, environmentNames);
this(ClassPathResourceLoader.defaultLoader(DefaultBeanContext.class.getClassLoader()), environmentNames);
}

/**
Expand All @@ -80,22 +73,31 @@ public DefaultApplicationContext(String... environmentNames) {
* @param resourceLoader The class loader
*/
public DefaultApplicationContext(ClassPathResourceLoader resourceLoader, String... environmentNames) {
this(resourceLoader, null, environmentNames);
this(resourceLoader, new ApplicationContextConfiguration() {
@Override
public Boolean getDeduceEnvironments() {
return null;
}

@Override
public List<String> getEnvironments() {
return Arrays.asList(environmentNames);
}
});
}


/**
* Construct a new ApplicationContext for the given environment name and classloader.
*
* @param environmentNames The environment names
* @param configuration The application context configuration
* @param resourceLoader The class loader
* @param configuration The application context configuration
*/
public DefaultApplicationContext(ClassPathResourceLoader resourceLoader, @Nullable ApplicationContextConfiguration configuration, String... environmentNames) {
public DefaultApplicationContext(ClassPathResourceLoader resourceLoader, ApplicationContextConfiguration configuration) {
super(resourceLoader);
this.conversionService = createConversionService();
this.resourceLoader = resourceLoader;
this.environment = createEnvironment(configuration, environmentNames);
this.environment = createEnvironment(configuration);
}

@Override
Expand All @@ -122,30 +124,34 @@ protected List<BeanDefinitionReference> resolveBeanDefinitionReferences() {
/**
* Creates the default environment for the given environment name.
*
* @deprecated Use {@link #createEnvironment(ApplicationContextConfiguration, String...)} instead
* @deprecated Use {@link #createEnvironment(ApplicationContextConfiguration)} instead
* @param environmentNames The environment name
* @return The environment instance
*/
@Deprecated
protected DefaultEnvironment createEnvironment(String... environmentNames) {
return createEnvironment(null, environmentNames);
return createEnvironment(new ApplicationContextConfiguration() {
@Nullable
@Override
public Boolean getDeduceEnvironments() {
return null;
}

@Override
public List<String> getEnvironments() {
return Arrays.asList(environmentNames);
}
});
}

/**
* Creates the default environment for the given environment name.
*
* @param configuration The application context configuration
* @param environmentNames The environment name
* @return The environment instance
*/
protected DefaultEnvironment createEnvironment(@Nullable ApplicationContextConfiguration configuration, String... environmentNames) {

Boolean deduceEnvironments = null;
if (configuration != null) {
deduceEnvironments = configuration.getDeduceEnvironments();
}

return new RuntimeConfiguredEnvironment(deduceEnvironments, environmentNames);
protected DefaultEnvironment createEnvironment(ApplicationContextConfiguration configuration) {
return new RuntimeConfiguredEnvironment(configuration);
}

/**
Expand Down Expand Up @@ -427,7 +433,7 @@ public int getOrder() {
*/
private static class BootstrapEnvironment extends DefaultEnvironment {
BootstrapEnvironment(ClassPathResourceLoader resourceLoader, ConversionService conversionService, String... activeEnvironments) {
super(resourceLoader, conversionService, null, activeEnvironments);
super(resourceLoader, conversionService, activeEnvironments);
}

@Override
Expand All @@ -449,7 +455,7 @@ private class BootstrapApplicationContext extends DefaultApplicationContext {
private final BootstrapEnvironment bootstrapEnvironment;

BootstrapApplicationContext(BootstrapEnvironment bootstrapEnvironment, String... activeEnvironments) {
super(resourceLoader, null, activeEnvironments);
super(resourceLoader, activeEnvironments);
this.bootstrapEnvironment = bootstrapEnvironment;
}

Expand Down Expand Up @@ -519,8 +525,8 @@ private class RuntimeConfiguredEnvironment extends DefaultEnvironment {
private BootstrapPropertySourceLocator bootstrapPropertySourceLocator;
private BootstrapEnvironment bootstrapEnvironment;

RuntimeConfiguredEnvironment(Boolean deduceEnvironments, String... environmentNames) {
super(DefaultApplicationContext.this.resourceLoader, DefaultApplicationContext.this.conversionService, deduceEnvironments, environmentNames);
RuntimeConfiguredEnvironment(ApplicationContextConfiguration configuration) {
super(DefaultApplicationContext.this.resourceLoader, DefaultApplicationContext.this.conversionService, configuration.getDeduceEnvironments(), configuration.getEnvironments().toArray(new String[]{}));
this.isRuntimeConfigured = Boolean.getBoolean(Environment.BOOTSTRAP_CONTEXT_PROPERTY) ||
DefaultApplicationContext.this.resourceLoader.getResource(Environment.BOOTSTRAP_NAME + ".yml").isPresent() ||
DefaultApplicationContext.this.resourceLoader.getResource(Environment.BOOTSTRAP_NAME + ".properties").isPresent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ public ApplicationContextBuilder singletons(Object... beans) {

@Override
public ApplicationContextBuilder deduceEnvironment(@Nullable Boolean deduceEnvironments) {
if (deduceEnvironments != null) {
this.deduceEnvironments = deduceEnvironments;
}
this.deduceEnvironments = deduceEnvironments;
return this;
}

Expand Down Expand Up @@ -106,6 +104,11 @@ public Boolean getDeduceEnvironments() {
return deduceEnvironments;
}

@Override
public List<String> getEnvironments() {
return environments;
}

@Override
public ApplicationContextBuilder mainClass(Class mainClass) {
if (mainClass != null) {
Expand Down Expand Up @@ -133,8 +136,7 @@ public ApplicationContext build() {
ClassLoader classLoader = ApplicationContext.class.getClassLoader();
DefaultApplicationContext applicationContext = new DefaultApplicationContext(
classPathResourceLoader != null ? classPathResourceLoader : ClassPathResourceLoader.defaultLoader(classLoader),
this,
environments.toArray(new String[0])
this
);

Environment environment = applicationContext.getEnvironment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public DefaultEnvironment(ClassPathResourceLoader resourceLoader, ConversionServ
* @param names The names
*/
@SuppressWarnings("MagicNumber")
public DefaultEnvironment(ClassPathResourceLoader resourceLoader, ConversionService conversionService, Boolean deduceEnvironments, String... names) {
public DefaultEnvironment(ClassPathResourceLoader resourceLoader, ConversionService conversionService, @Nullable Boolean deduceEnvironments, String... names) {
super(conversionService);
Set<String> environments = new LinkedHashSet<>(3);
List<String> specifiedNames = Arrays.asList(names);
Expand All @@ -154,10 +154,10 @@ public DefaultEnvironment(ClassPathResourceLoader resourceLoader, ConversionServ
LOG.info("Established active environments: {}", environments);
}
conversionService.addConverter(
CharSequence.class, Class.class, new StringToClassConverter(classLoader)
CharSequence.class, Class.class, new StringToClassConverter(classLoader)
);
conversionService.addConverter(
Object[].class, Class[].class, new StringArrayToClassArrayConverter(conversionService)
Object[].class, Class[].class, new StringArrayToClassArrayConverter(conversionService)
);
this.resourceLoader = resourceLoader;
this.annotationScanner = createAnnotationScanner(classLoader);
Expand Down Expand Up @@ -339,32 +339,34 @@ public ResourceLoader forBase(String basePath) {
* @return Whether environment names and packages should be deduced
*/
protected boolean shouldDeduceEnvironments() {

if (deduceEnvironments != null) {

if (LOG.isDebugEnabled()) {
LOG.debug("DeduceEnvironment builder setting: " + deduceEnvironments);
LOG.debug("Environment deduction was set explicitly via builder to: " + deduceEnvironments);
}

return deduceEnvironments;
} else {
String deduceProperty = System.getProperty(Environment.DEDUCE_ENVIRONMENT_PROPERTY);
String deduceEnv = System.getenv(Environment.DEDUCE_ENVIRONMENT_ENV);

if (LOG.isDebugEnabled()) {
LOG.debug("DeduceEnvironment system property: " + deduceProperty);
LOG.debug("DeduceEnvironment environment variable: " + deduceEnv);
}

if (StringUtils.isNotEmpty(deduceEnv)) {
return Boolean.valueOf(deduceEnv);
boolean deduce = Boolean.valueOf(deduceEnv);
if (LOG.isDebugEnabled()) {
LOG.debug("Environment deduction was set via environment variable to: " + deduce);
}
return deduce;
} else if (StringUtils.isNotEmpty(deduceProperty)) {
return Boolean.valueOf(deduceProperty);
boolean deduce = Boolean.valueOf(deduceProperty);
if (LOG.isDebugEnabled()) {
LOG.debug("Environment deduction was set via system property to: " + deduce);
}
return deduce;
} else {
boolean deduceDefault = DEDUCE_ENVIRONMENT_DEFAULT;
if (LOG.isDebugEnabled()) {
LOG.debug("DEDUCE_ENVIRONMENT_DEFAULT: " + DEDUCE_ENVIRONMENT_DEFAULT);
LOG.debug("Environment deduction is using the default of: " + deduceDefault);
}
return DEDUCE_ENVIRONMENT_DEFAULT;
return deduceDefault;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.micronaut.messaging;

import io.micronaut.messaging.exceptions.MessageAcknowledgementException;
Expand All @@ -27,13 +28,15 @@ public interface Acknowledgement {

/**
* Acknowledges the message.
* @throws MessageAcknowledgementException may throw a MessageAcknowledgementException
*
* @throws MessageAcknowledgementException if an error occurred acknowledging the message
*/
void ack() throws MessageAcknowledgementException;

/**
* Rejects the message.
* @throws MessageAcknowledgementException may throw a MessageAcknowledgementException
*
* @throws MessageAcknowledgementException if an error occurred rejecting the message
*/
void nack() throws MessageAcknowledgementException;
}

0 comments on commit 56e28fa

Please sign in to comment.