Skip to content
Permalink
Browse files
GERONIMO-6582 Adding support for configuration of MicroProfile annota…
…tions.
  • Loading branch information
johnament committed Jan 1, 2018
1 parent 27626ff commit 7bff61c41832b63c07fcfd9efc0f101c85e04379
Showing 14 changed files with 414 additions and 108 deletions.
@@ -59,6 +59,8 @@
<arquillian-weld-embedded.version>2.0.0.Final</arquillian-weld-embedded.version>
<cdi2-api.version>2.0</cdi2-api.version>
<weld.version>3.0.1.Final</weld.version>
<geronimo-config-impl.version>1.1-SNAPSHOT</geronimo-config-impl.version>
<microprofile-config-api.version>1.2</microprofile-config-api.version>
</properties>

<dependencyManagement>
@@ -94,13 +96,13 @@
<dependency>
<groupId>org.eclipse.microprofile.config</groupId>
<artifactId>microprofile-config-api</artifactId>
<version>1.1</version>
<version>${microprofile-config-api.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.geronimo.config</groupId>
<artifactId>geronimo-config-impl</artifactId>
<version>1.0</version>
<version>${geronimo-config-impl.version}</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -35,6 +35,10 @@
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jcdi_2.0_spec</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-annotation_1.3_spec</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-interceptor_1.2_spec</artifactId>
@@ -0,0 +1,61 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.safeguard.api.config;

import javax.annotation.Priority;
import java.time.temporal.ChronoUnit;
import java.util.Comparator;
import java.util.ServiceLoader;
import java.util.SortedSet;
import java.util.TreeSet;

public abstract class ConfigFacade {
private static ConfigFacade INSTANCE;

public abstract boolean getBoolean(String name, boolean defaultValue);
public abstract long getLong(String name, long defaultValue);
public abstract int getInt(String name, int defaultValue);
public abstract double getDouble(String name, double defaultValue);
public abstract ChronoUnit getChronoUnit(String name, ChronoUnit defaultValue);
public abstract Class<? extends Throwable>[] getThrowableClasses(String name, Class<? extends Throwable>[] defaultValue);

public static ConfigFacade getInstance() {
if (INSTANCE == null) {
INSTANCE = load();
}
return INSTANCE;
}

public static void setInstance(ConfigFacade configFacade) {
INSTANCE = configFacade;
}

private static ConfigFacade load() {
ServiceLoader<ConfigFacade> configFacades = ServiceLoader.load(ConfigFacade.class);
SortedSet<ConfigFacade> configFacedSet = new TreeSet<>(Comparator.comparingInt(c -> {
Priority p = c.getClass().getAnnotation(Priority.class);
return p == null ? 1 : p.value();
}));
for(ConfigFacade facade : configFacades) {
configFacedSet.add(facade);
}
return configFacedSet.first();
}
}
@@ -21,8 +21,11 @@

import org.apache.safeguard.api.ExecutionManager;
import org.apache.safeguard.api.bulkhead.BulkheadManager;
import org.apache.safeguard.api.circuitbreaker.CircuitBreakerManager;
import org.apache.safeguard.api.retry.RetryManager;
import org.apache.safeguard.impl.bulkhead.BulkheadManagerImpl;
import org.apache.safeguard.impl.circuitbreaker.FailsafeCircuitBreakerManager;
import org.apache.safeguard.impl.config.MicroprofileAnnotationMapper;
import org.apache.safeguard.impl.executionPlans.ExecutionPlanFactory;
import org.apache.safeguard.impl.retry.FailsafeRetryManager;

@@ -34,17 +37,31 @@

@Vetoed
public class FailsafeExecutionManager implements ExecutionManager {
private BulkheadManagerImpl bulkheadManager;
private FailsafeCircuitBreakerManager circuitBreakerManager;
private FailsafeRetryManager retryManager;
private ExecutionPlanFactory executionPlanFactory;
private final MicroprofileAnnotationMapper mapper;
private final BulkheadManager bulkheadManager;
private final CircuitBreakerManager circuitBreakerManager;
private final RetryManager retryManager;
private final ExecutionPlanFactory executionPlanFactory;

public FailsafeExecutionManager() {
this.circuitBreakerManager = new FailsafeCircuitBreakerManager();
this.retryManager = new FailsafeRetryManager();
this.bulkheadManager = new BulkheadManagerImpl();
this.executionPlanFactory = new ExecutionPlanFactory(this.circuitBreakerManager, this.retryManager,
this.bulkheadManager);
FailsafeCircuitBreakerManager circuitBreakerManager = new FailsafeCircuitBreakerManager();
FailsafeRetryManager retryManager = new FailsafeRetryManager();
BulkheadManagerImpl bulkheadManager = new BulkheadManagerImpl();
this.mapper = MicroprofileAnnotationMapper.getInstance();
this.executionPlanFactory = new ExecutionPlanFactory(circuitBreakerManager, retryManager, bulkheadManager, mapper);
this.circuitBreakerManager = circuitBreakerManager;
this.retryManager = retryManager;
this.bulkheadManager = bulkheadManager;
}

public FailsafeExecutionManager(MicroprofileAnnotationMapper mapper, BulkheadManagerImpl bulkheadManager,
FailsafeCircuitBreakerManager circuitBreakerManager, FailsafeRetryManager retryManager,
ExecutionPlanFactory executionPlanFactory) {
this.mapper = mapper;
this.bulkheadManager = bulkheadManager;
this.circuitBreakerManager = circuitBreakerManager;
this.retryManager = retryManager;
this.executionPlanFactory = executionPlanFactory;
}

public Object execute(InvocationContext invocationContext) {
@@ -70,12 +87,12 @@ public ExecutionPlanFactory getExecutionPlanFactory() {
}

@Override
public FailsafeCircuitBreakerManager getCircuitBreakerManager() {
public CircuitBreakerManager getCircuitBreakerManager() {
return circuitBreakerManager;
}

@Override
public FailsafeRetryManager getRetryManager() {
public RetryManager getRetryManager() {
return retryManager;
}

@@ -0,0 +1,70 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.safeguard.impl.config;

import org.apache.safeguard.api.config.ConfigFacade;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;

import javax.annotation.Priority;
import java.time.temporal.ChronoUnit;

@Priority(1)
public class MicroProfileConfigFacade extends ConfigFacade {
private final Config config;

public MicroProfileConfigFacade() {
this(ConfigProvider.getConfig());
}

public MicroProfileConfigFacade(Config config) {
this.config = config;
}

@Override
public boolean getBoolean(String name, boolean defaultValue) {
return config.getOptionalValue(name, Boolean.class).orElse(defaultValue);
}

@Override
public long getLong(String name, long defaultValue) {
return config.getOptionalValue(name, Long.class).orElse(defaultValue);
}

@Override
public int getInt(String name, int defaultValue) {
return config.getOptionalValue(name, Integer.class).orElse(defaultValue);
}

@Override
public double getDouble(String name, double defaultValue) {
return config.getOptionalValue(name, Double.class).orElse(defaultValue);
}

@Override
public ChronoUnit getChronoUnit(String name, ChronoUnit defaultValue) {
return config.getOptionalValue(name, ChronoUnit.class).orElse(defaultValue);
}

@Override
public Class<? extends Throwable>[] getThrowableClasses(String name, Class<? extends Throwable>[] defaultValue) {
return config.getOptionalValue(name, Class[].class).orElse(defaultValue);
}
}

0 comments on commit 7bff61c

Please sign in to comment.