Skip to content

Commit

Permalink
Change dynodb to use config injection
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Apr 20, 2020
1 parent 6405b14 commit f425263
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.BeanContainerBuildItem;
import io.quarkus.arc.deployment.BeanContainerListenerBuildItem;
import io.quarkus.arc.deployment.BeanRegistrationPhaseBuildItem;
import io.quarkus.arc.processor.BuildExtension;
import io.quarkus.arc.processor.InjectionPointInfo;
Expand Down Expand Up @@ -145,20 +144,12 @@ DynamodbClientBuildItem analyzeDynamodbClientInjectionPoints(BeanRegistrationPha
return new DynamodbClientBuildItem(createSyncClient, createAsyncClient);
}

@BuildStep
@Record(ExecutionTime.STATIC_INIT)
void initializeConfiguration(BuildProducer<BeanContainerListenerBuildItem> containerListenerProducer,
DynamodbRecorder recorder) {
containerListenerProducer.produce(new BeanContainerListenerBuildItem(recorder.setDynamodbBuildConfig(buildTimeConfig)));
}

@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
void buildClients(DynamodbClientBuildItem clientBuildItem, DynamodbConfig runtimeConfig, DynamodbRecorder recorder,
BeanContainerBuildItem beanContainer, ShutdownContextBuildItem shutdown) {

if (clientBuildItem.isCreateSyncClient() || clientBuildItem.isCreateAsyncClient()) {
recorder.configureRuntimeConfig(runtimeConfig);

if (clientBuildItem.isCreateSyncClient()) {
recorder.createClient(beanContainer.getValue(), shutdown);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import javax.annotation.PreDestroy;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down Expand Up @@ -35,18 +36,12 @@
public class DynamodbClientProducer {
private static final Log LOG = LogFactory.getLog(DynamodbClientProducer.class);

private DynamodbConfig runtimeConfig;
@Inject
DynamodbConfig runtimeConfig;
private DynamoDbClient client;
private DynamoDbAsyncClient asyncClient;
private DynamodbBuildTimeConfig buildTimeConfig;

public void setBuildTimeConfig(DynamodbBuildTimeConfig buildTimeConfig) {
this.buildTimeConfig = buildTimeConfig;
}

public void setRuntimeConfig(DynamodbConfig runtimeConfig) {
this.runtimeConfig = runtimeConfig;
}
@Inject
DynamodbBuildTimeConfig buildTimeConfig;

@Produces
@ApplicationScoped
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package io.quarkus.dynamodb.runtime;

import io.quarkus.arc.Arc;
import io.quarkus.arc.runtime.BeanContainer;
import io.quarkus.arc.runtime.BeanContainerListener;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.ShutdownContext;
import io.quarkus.runtime.annotations.Recorder;
Expand All @@ -12,17 +10,6 @@
@Recorder
public class DynamodbRecorder {

public BeanContainerListener setDynamodbBuildConfig(DynamodbBuildTimeConfig buildConfig) {
return beanContainer -> {
DynamodbClientProducer producer = beanContainer.instance(DynamodbClientProducer.class);
producer.setBuildTimeConfig(buildConfig);
};
}

public void configureRuntimeConfig(DynamodbConfig dynamodbConfig) {
Arc.container().instance(DynamodbClientProducer.class).get().setRuntimeConfig(dynamodbConfig);
}

public RuntimeValue<DynamoDbClient> createClient(
BeanContainer beanContainer, ShutdownContext shutdown) {

Expand Down

0 comments on commit f425263

Please sign in to comment.