Search in sources :

Example 1 with WildcardProperties

use of com.mozilla.bagheera.util.WildcardProperties in project bagheera by mozilla-metrics.

the class Bagheera method main.

/**
     * A simple front-end that configures a new server from properties files,
     * waiting until runtime shutdown to clean up.
     */
public static void main(String[] args) throws Exception {
    final int port = Integer.parseInt(System.getProperty("server.port", "8080"));
    final boolean tcpNoDelay = Boolean.parseBoolean(System.getProperty("server.tcpnodelay", "false"));
    // Initalize properties and producer.
    final WildcardProperties props = getDefaultProperties();
    final Properties kafkaProps = getDefaultKafkaProperties();
    final Producer producer = new KafkaProducer(kafkaProps);
    final MetricsManager manager = MetricsManager.getDefaultMetricsManager();
    final BagheeraServerState server = startServer(port, tcpNoDelay, props, producer, getChannelFactory(), Bagheera.class.getName(), manager);
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            server.close();
            server.channelFactory.releaseExternalResources();
        }
    });
}
Also used : KafkaProducer(com.mozilla.bagheera.producer.KafkaProducer) Producer(com.mozilla.bagheera.producer.Producer) KafkaProducer(com.mozilla.bagheera.producer.KafkaProducer) MetricsManager(com.mozilla.bagheera.metrics.MetricsManager) WildcardProperties(com.mozilla.bagheera.util.WildcardProperties) Properties(java.util.Properties) WildcardProperties(com.mozilla.bagheera.util.WildcardProperties)

Example 2 with WildcardProperties

use of com.mozilla.bagheera.util.WildcardProperties in project bagheera by mozilla-metrics.

the class AccessFilterTest method setup.

@Before
public void setup() throws IOException {
    String[] namespaces = new String[] { "foo_*", "bar" };
    WildcardProperties props = new WildcardProperties();
    String propsFileStr = "foo_*.allow.delete.access=false\n" + "foo_*.id.validation=true\n" + "bar.allow.delete.access=true\n" + "bar.id.validation=false";
    InputStream is = new ByteArrayInputStream(propsFileStr.getBytes("UTF-8"));
    props.load(is);
    filter = new AccessFilter(new Validator(namespaces), props);
    remoteAddr = InetSocketAddress.createUnresolved("192.168.1.1", 51723);
    Channel channel = createMock(Channel.class);
    expect(channel.getCloseFuture()).andReturn(new DefaultChannelFuture(channel, false));
    expect(channel.getRemoteAddress()).andReturn(remoteAddr);
    OrderedMemoryAwareThreadPoolExecutor executor = new OrderedMemoryAwareThreadPoolExecutor(10, 0L, 0L);
    final ExecutionHandler handler = new ExecutionHandler(executor, true, true);
    ctx = new FakeChannelHandlerContext(channel, handler);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DefaultChannelFuture(org.jboss.netty.channel.DefaultChannelFuture) WildcardProperties(com.mozilla.bagheera.util.WildcardProperties) Channel(org.jboss.netty.channel.Channel) ExecutionHandler(org.jboss.netty.handler.execution.ExecutionHandler) OrderedMemoryAwareThreadPoolExecutor(org.jboss.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor) Validator(com.mozilla.bagheera.validation.Validator) FakeChannelHandlerContext(org.jboss.netty.channel.FakeChannelHandlerContext) Before(org.junit.Before)

Example 3 with WildcardProperties

use of com.mozilla.bagheera.util.WildcardProperties in project bagheera by mozilla-metrics.

the class Bagheera method getDefaultProperties.

protected static WildcardProperties getDefaultProperties() throws Exception {
    final WildcardProperties props = new WildcardProperties();
    final URL propUrl = Bagheera.class.getResource(PROPERTIES_RESOURCE_NAME);
    if (propUrl == null) {
        throw new IllegalArgumentException("Could not find the properties file: " + PROPERTIES_RESOURCE_NAME);
    }
    final InputStream in = propUrl.openStream();
    try {
        props.load(in);
    } finally {
        in.close();
    }
    return props;
}
Also used : InputStream(java.io.InputStream) WildcardProperties(com.mozilla.bagheera.util.WildcardProperties) URL(java.net.URL)

Aggregations

WildcardProperties (com.mozilla.bagheera.util.WildcardProperties)3 InputStream (java.io.InputStream)2 MetricsManager (com.mozilla.bagheera.metrics.MetricsManager)1 KafkaProducer (com.mozilla.bagheera.producer.KafkaProducer)1 Producer (com.mozilla.bagheera.producer.Producer)1 Validator (com.mozilla.bagheera.validation.Validator)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 URL (java.net.URL)1 Properties (java.util.Properties)1 Channel (org.jboss.netty.channel.Channel)1 DefaultChannelFuture (org.jboss.netty.channel.DefaultChannelFuture)1 FakeChannelHandlerContext (org.jboss.netty.channel.FakeChannelHandlerContext)1 ExecutionHandler (org.jboss.netty.handler.execution.ExecutionHandler)1 OrderedMemoryAwareThreadPoolExecutor (org.jboss.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor)1 Before (org.junit.Before)1