-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #171 from bpitman/master
Create NoOp module
- Loading branch information
Showing
1 changed file
with
100 additions
and
0 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
iep-config/src/main/java/com/netflix/iep/config/DynamicNoOpConfigModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright 2015 Netflix, Inc. | ||
* | ||
* Licensed 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 com.netflix.iep.config; | ||
|
||
import com.google.inject.AbstractModule; | ||
import com.google.inject.Module; | ||
import com.google.inject.Provides; | ||
import com.google.inject.util.Modules; | ||
import com.netflix.archaius.config.PollingDynamicConfig; | ||
import com.netflix.archaius.config.polling.FixedPollingStrategy; | ||
import com.netflix.archaius.config.polling.PollingResponse; | ||
import com.netflix.archaius.config.CompositeConfig; | ||
import com.netflix.archaius.config.MapConfig; | ||
import com.netflix.archaius.guice.ArchaiusModule; | ||
import com.netflix.archaius.inject.ApplicationLayer; | ||
import com.netflix.archaius.inject.RemoteLayer; | ||
import com.netflix.archaius.typesafe.TypesafeConfig; | ||
import com.netflix.iep.platformservice.PlatformServiceModule; | ||
import com.typesafe.config.Config; | ||
import com.typesafe.config.ConfigFactory; | ||
|
||
import javax.inject.Singleton; | ||
import java.util.Properties; | ||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class DynamicNoOpConfigModule extends AbstractModule { | ||
|
||
private final String[] propFiles; | ||
|
||
public DynamicNoOpConfigModule() { | ||
this(null); | ||
} | ||
|
||
public DynamicNoOpConfigModule(String[] propFiles) { | ||
this.propFiles = propFiles; | ||
} | ||
|
||
@Override protected void configure() { | ||
Module m = Modules | ||
.override(new ArchaiusModule()) | ||
.with(new OverrideModule(propFiles)); | ||
install(m); | ||
} | ||
|
||
private static class OverrideModule extends AbstractModule { | ||
|
||
private final String[] propFiles; | ||
|
||
OverrideModule(String[] propFiles) { | ||
this.propFiles = propFiles; | ||
} | ||
|
||
@Override protected void configure() { | ||
bind(Config.class).toInstance(ConfigFactory.load()); | ||
bind(DynamicPropertiesConfiguration.class).asEagerSingleton(); | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
@RemoteLayer | ||
private com.netflix.archaius.Config providesOverrideConfig(Config cfg) throws Exception { | ||
return new PollingDynamicConfig( | ||
new Callable() { | ||
@Override | ||
public PollingResponse call() { | ||
return PollingResponse.noop(); | ||
} | ||
}, | ||
new FixedPollingStrategy(60000, TimeUnit.MILLISECONDS) | ||
); | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
@ApplicationLayer | ||
protected CompositeConfig providesAppConfig(Config cfg) throws Exception { | ||
final Properties props = (propFiles == null) | ||
? ScopedPropertiesLoader.load() | ||
: ScopedPropertiesLoader.load(propFiles); | ||
final CompositeConfig app = new CompositeConfig(); | ||
app.addConfig("scoped", new MapConfig(props)); | ||
app.addConfig("typesafe", new TypesafeConfig(cfg)); | ||
return app; | ||
} | ||
} | ||
} |