Skip to content

Commit

Permalink
New context enums.
Browse files Browse the repository at this point in the history
  • Loading branch information
reevik committed Feb 13, 2016
1 parent b9bdd16 commit c395d07
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public <T> boolean isRegistered(final Class<T> clazz) {


private <T> void validateConfigurationEntity(final Class<T> clazz) {

final Configuration configurationAnnotation = clazz.getAnnotation(Configuration.class);
if (configurationAnnotation == null) {
throw new InvalidConfigurationEntityException("@Configuration annotation is missing.");
Expand All @@ -113,9 +114,9 @@ public <T> Optional<T> load(final Class<T> clazz) {

@Override
public <T> Optional<T> load(Class<T> clazz, Optional<ContextInfo> contextInfo) {

if (isRegistered(clazz)) {
final ConfigurationProvider<T> provider = cache.get(clazz);
return Optional.ofNullable((T) provider.load(clazz, contextInfo));
return Optional.ofNullable((T) cache.get(clazz).load(clazz, contextInfo));
}
return Optional.empty();
}
Expand Down
12 changes: 12 additions & 0 deletions propane-core/src/main/java/io/moo/propane/data/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
*/
package io.moo.propane.data;

import java.util.ArrayList;
import java.util.List;

/**
* @author bagdemir
* @version 1.0
Expand All @@ -36,4 +39,13 @@ public interface Context {
* @return Priority of the context. Lower the priority, better while electing the context infos.
*/
int getPriority();

/**
* Unique context identifier, that used in context id to context instance or
* vice versa
* (de)serialization.
*
* @return
*/
String getContextId();
}
12 changes: 0 additions & 12 deletions propane-core/src/main/java/io/moo/propane/data/ContextInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@
*/
public class ContextInfo {

public enum Regions {
UE1, UW1, UW2, EW1, EC1, APS1, APN1, APS2, APN2, SAE1, US, EU, AP, SA
}

public enum Environments {
DEV, QE, QA, STAGE, PROD
}

public enum Stacks {
A, B, BLUE, GREEN
}

private final List<String> contextIds = Collections.synchronizedList(Lists.newArrayList());


Expand Down
45 changes: 45 additions & 0 deletions propane-core/src/main/java/io/moo/propane/data/Environment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* The MIT License (MIT)
* <p/>
* Copyright (c) 2016 moo.io , Erhan Bagdemir
* <p/>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p/>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p/>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package io.moo.propane.data;

/**
* @author bagdemir
* @since 1.0
* @version 1.0
*/
public enum Environment implements Context {
DEV, QE, QA, STAGE, PROD;


@Override
public int getPriority() {
return 0;
}


@Override
public String getContextId() {
return null;
}
}
22 changes: 8 additions & 14 deletions propane-core/src/main/java/io/moo/propane/data/Region.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,21 @@
* @version 1.0
* @since 1.0
*/
public class Region implements Context {
public enum Region implements Context {

public static int priority = 10;
UE1, UW1, UW2, EW1, EC1, APS1, APN1, APS2, APN2, SAE1, US, EU, AP, SA;

private String region;

public enum Regions {
UE1, UW1, UW2, EW1, EC1, APS1, APN1, APS2, APN2, SAE1, US, EU, AP, SA
}
private int priority = 10;


private Region(final String region) {
this.region = region;
@Override
public int getPriority() {
return priority;
}

public static Region of(String regionName) {
return new Region(regionName);
}

@Override
public int getPriority() {
return priority;
public String getContextId() {
return name();
}
}
44 changes: 44 additions & 0 deletions propane-core/src/main/java/io/moo/propane/data/Stack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* The MIT License (MIT)
* <p/>
* Copyright (c) 2016 moo.io , Erhan Bagdemir
* <p/>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p/>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p/>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package io.moo.propane.data;

/**
* @author bagdemir
* @since 1.0
* @version 1.0
*/
public enum Stack implements Context {
A, B, BLUE, GREEN, ACTIVE, INACTIVE, PUBLIC, PRIVATE;

@Override
public int getPriority() {
return 0;
}


@Override
public String getContextId() {
return null;
}
}

0 comments on commit c395d07

Please sign in to comment.