Search in sources :

Example 1 with StaticPropertiesConfigurationFactory

use of io.mantisrx.server.master.client.config.StaticPropertiesConfigurationFactory in project mantis by Netflix.

the class TestGetMasterMonitor method main.

public static void main(String[] args) {
    try {
        Args.parse(TestGetMasterMonitor.class, args);
    } catch (IllegalArgumentException e) {
        Args.usage(TestGetMasterMonitor.class);
        System.exit(1);
    }
    Properties properties = new Properties();
    System.out.println("propfile=" + propFile);
    try (InputStream inputStream = new FileInputStream(propFile)) {
        properties.load(inputStream);
    } catch (IOException e) {
        e.printStackTrace();
    }
    final AtomicInteger counter = new AtomicInteger();
    final CountDownLatch latch = new CountDownLatch(5);
    StaticPropertiesConfigurationFactory configurationFactory = new StaticPropertiesConfigurationFactory(properties);
    CoreConfiguration config = configurationFactory.getConfig();
    final CuratorService curatorService = new CuratorService(config, null);
    MasterMonitor masterMonitor = curatorService.getMasterMonitor();
    masterMonitor.getMasterObservable().filter(new Func1<MasterDescription, Boolean>() {

        @Override
        public Boolean call(MasterDescription masterDescription) {
            return masterDescription != null;
        }
    }).doOnNext(new Action1<MasterDescription>() {

        @Override
        public void call(MasterDescription masterDescription) {
            System.out.println(counter.incrementAndGet() + ": Got new master: " + masterDescription.toString());
            latch.countDown();
        }
    }).subscribe();
    curatorService.start();
    try {
        latch.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : MasterDescription(io.mantisrx.server.core.master.MasterDescription) Action1(rx.functions.Action1) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) CoreConfiguration(io.mantisrx.server.core.CoreConfiguration) Properties(java.util.Properties) CountDownLatch(java.util.concurrent.CountDownLatch) FileInputStream(java.io.FileInputStream) StaticPropertiesConfigurationFactory(io.mantisrx.server.master.client.config.StaticPropertiesConfigurationFactory) MasterMonitor(io.mantisrx.server.core.master.MasterMonitor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CuratorService(io.mantisrx.server.core.zookeeper.CuratorService)

Aggregations

CoreConfiguration (io.mantisrx.server.core.CoreConfiguration)1 MasterDescription (io.mantisrx.server.core.master.MasterDescription)1 MasterMonitor (io.mantisrx.server.core.master.MasterMonitor)1 CuratorService (io.mantisrx.server.core.zookeeper.CuratorService)1 StaticPropertiesConfigurationFactory (io.mantisrx.server.master.client.config.StaticPropertiesConfigurationFactory)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Properties (java.util.Properties)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Action1 (rx.functions.Action1)1