Skip to content

Instantly share code, notes, and snippets.

@PointMeAtTheDawn
Created November 5, 2014 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PointMeAtTheDawn/0069e0b32d62aa15fe86 to your computer and use it in GitHub Desktop.
Save PointMeAtTheDawn/0069e0b32d62aa15fe86 to your computer and use it in GitHub Desktop.
import com.riotgames.hermes.caching.core.CacheConfigurationContract;
import com.riotgames.hermes.configuration.annotations.ConfigurationContract;
import com.riotgames.hermes.rfc100.integrator.RFC100ServerConfigurationContract;
import com.riotgames.hermes.server.HermesServerConfigurationContract;
import com.riotgames.hermesextensions.logging.log4j.Log4jConfigurationContract;
import com.riotgames.hermesextensions.metrics.codahale.CodahaleMetricsConfigurationContract;
import com.riotgames.hermesextensions.servicediscovery.discoverous.server.DiscoverousServerIntegratorConfigurationContract;
@ConfigurationContract(appName="blah.MovingAverageService", version="1.0.0",
dependsOn={
HermesServerConfigurationContract.class,
Log4jConfigurationContract.class,
CacheConfigurationContract.class,
RFC100ServerConfigurationContract.class,
DiscoverousServerIntegratorConfigurationContract.class,
CodahaleMetricsConfigurationContract.class})
public class MovingAverageConfigurationContract {
int macPort;
}
import com.riotgames.hermes.caching.core.CachedType;
import com.riotgames.hermes.caching.server.HermesServerSideCacheIntegrator;
import com.riotgames.hermes.configuration.ConfigurationContractProvider;
import com.riotgames.hermes.configuration.providers.StandardConfigurationContractProvider;
import com.riotgames.hermes.configuration.rawproviders.FileRawPropertyProvider;
import com.riotgames.hermes.configuration.rawproviders.RawPropertyProvider;
import com.riotgames.hermes.configuration.rawproviders.SystemPropertyRawProvider;
import com.riotgames.hermes.rfc100.RFC100ControlImpl;
import com.riotgames.hermes.rfc100.RFC100QueryImpl;
import com.riotgames.hermes.rfc100.integrator.RFC100ServerIntegrator;
import com.riotgames.hermes.rfc100.providers.impl.log4j.Log4jLogProvider;
import com.riotgames.hermes.server.netty.HermesNettyServer;
import com.riotgames.hermes.server.netty.HermesNettyServerBuilder;
import com.riotgames.hermesextensions.logging.log4j.Log4jServerIntegrator;
import com.riotgames.hermesextensions.metrics.codahale.CodahaleMetricsProvider;
import com.riotgames.hermesextensions.servicediscovery.discoverous.server.DiscoverousServerIntegrator;
import java.util.ArrayList;
import java.util.List;
// Created by Charlie Roselius on 10/30/2014.
public class MovingAverageServerMain {
public static void main(String args[]) throws Exception {
RawPropertyProvider a[] = processCmdLineArguments();
ConfigurationContractProvider b = makeConfigurationProvider(a);
HermesNettyServer server = wireUp(b);
server.start();
}
public static HermesNettyServer wireUp(ConfigurationContractProvider configurationProvider) throws Exception {
// create the actual server
CachedType cached = new CachedType("PropertySetDTO", 1000);
final HermesServerSideCacheIntegrator cacher = HermesServerSideCacheIntegrator.newIntegrator(
configurationProvider).cachedTypes(new CachedType[] { cached });
DiscoverousServerIntegrator discoverousIntegrator = DiscoverousServerIntegrator
.newIntegrator(configurationProvider);
RFC100ServerIntegrator rfc100Integrator = wireUpRFC100(configurationProvider, discoverousIntegrator);
HermesNettyServerBuilder builder = HermesNettyServerBuilder
.newBuilder(configurationProvider)
.singletons(new MovingAverageService())
.integrators(rfc100Integrator, Log4jServerIntegrator.newIntegrator(configurationProvider),
discoverousIntegrator, cacher);
HermesNettyServer server = builder.build();
return server;
}
/**
* wire up RFC100 integrators
*
*/
private static RFC100ServerIntegrator wireUpRFC100(ConfigurationContractProvider configurationProvider,
DiscoverousServerIntegrator discoverousIntegrator) {
RFC100ControlImpl rfc100Control = new RFC100ControlImpl();
rfc100Control.setConfigurationProvider(configurationProvider);
RFC100QueryImpl rfc100Query = new RFC100QueryImpl();
rfc100Query.setConfigurationProvider(configurationProvider);
CodahaleMetricsProvider metricsProvider = new CodahaleMetricsProvider(configurationProvider);
rfc100Query.setCustomMetricsProvider(metricsProvider);
rfc100Query.setLogProvider(new Log4jLogProvider());
RFC100ServerIntegrator rfc100Integrator = RFC100ServerIntegrator.newIntegrator(configurationProvider)
.rfc100Control(rfc100Control).rfc100Query(rfc100Query);
return rfc100Integrator;
}
/**
* process the cmd line arguments and parse out options
*/
public static RawPropertyProvider[] processCmdLineArguments() {
/*if (args.length == 0) {
//log.error("Usage: configurous log4j.xml(deprecated) <configuration_files>...");
System.exit(-1);
}*/
// The first arg used to be the log4j.xml to use, but now it uses the "std" log4j initialization.
List<RawPropertyProvider> rawProviders = new ArrayList<RawPropertyProvider>();
rawProviders.add(new SystemPropertyRawProvider());
rawProviders.add(new FileRawPropertyProvider("config.properties", 0));
/*for (int lp = 1; lp < args.length; lp++) {
}*/
return rawProviders.toArray(new RawPropertyProvider[0]);
}
public static ConfigurationContractProvider makeConfigurationProvider(RawPropertyProvider... rawProviders) {
return new StandardConfigurationContractProvider(rawProviders);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment