Code example for Properties

Methods: load

0
        // start master 
        this.master = this.startEnhanceBroker("samsa_server1", true, true, this.getMasterProperties());
        try { 
            this.createProducer();
            this.producer.publish(this.topic);
            final byte[] data = "testOneMasterOneSlaveOneProducerOneConsumer".getBytes();
            this.sendMessage(100, data, this.topic);
            final String group = "GregorMasterSlaveTest";
            this.createConsumer(group);
            this.subscribe(this.topic, 1024 * 1024, 100);
        } 
        finally { 
            this.producer.shutdown();
            this.consumer.shutdown();
        } 
    } 
 
 
    @Test 
    public void testOneMasterOneSlaveNProducerNConsumer() throws Exception { 
        // start slave 
        this.slave = this.startEnhanceBroker("gregor_server1", true, true, this.getSlaveProperties());
        // start master 
        this.master = this.startEnhanceBroker("samsa_server1", true, true, this.getMasterProperties());
        try { 
            this.create_nProducer(10);
            this.sendMessage_nProducer(100, "testOneMasterOneSlaveNProducerNConsumer", this.topic, 10);
            this.subscribe_nConsumer(this.topic, 1024 * 1024, 100, 10, 10);
            // this.subscribe(this.topic, 1024 * 1024, 100); 
        } 
        finally { 
            Utils.shutdown(this.producerList);
            Utils.shutdown(this.consumerList);
        } 
    } 
 
 
    @Test 
    public void testSlaveAsMaster() throws Exception { 
        // ÏÈ·¢ËÍ100ÌõÏûÏ¢µ½masterºÍslave 
        // start slave 
        this.testOneMasterOneSlaveOneProducerOneConsumer();
        try { 
            this.stopMasterSlave();
            this.queue.clear();
            Thread.sleep(5000);
            // È»ºóslave×÷ΪmasterÆô¶¯£¬master×÷ΪslaveÆô¶¯£¬ÔÙ·¢ËÍ100Ìõ 
            this.slave = this.startEnhanceBroker("samsa_server1", false, false, this.getSlaveProperties());
            final Map<String, Properties> masterProperties = this.getMasterProperties();
            // ÏÖÔÚslaveÊÇ8123¶Ë¿Ú 
            masterProperties.get("samsa").put("slave", "localhost:8123");
            this.master = this.startEnhanceBroker("gregor_server1", false, false, masterProperties);
            // µÈ´ýproducerºÍconsumerÖØÁ¬ 
            Thread.sleep(2000);
            final byte[] data = "testSlaveAsMaster".getBytes();
            this.createProducer();
            this.producer.publish(this.topic);
            this.sendMessage(100, data, this.topic);
            final String group = "GregorMasterSlaveTest";
            this.createConsumer(group);
            this.subscribe(this.topic, 1024 * 1024, 100);
 
        } 
        finally { 
            Utils.shutdown(this.producer);
            Utils.shutdown(this.consumer);
            Utils.shutdown(this.producerList);
            Utils.shutdown(this.consumerList);
        } 
    } 
 
 
    protected EnhancedBroker startEnhanceBroker(final String name, final boolean isClearConsumerInfo,
            final boolean isClearMsg, final Map<String, Properties> pluginsInfo) throws Exception {
        final MetaConfig metaConfig = this.metaConfig(name);
        metaConfig.setDashboardHttpPort(metaConfig.getServerPort() - 80);
        if (isClearMsg) {
            Utils.clearDataDir(metaConfig);
        } 
        final EnhancedBroker broker = new EnhancedBroker(metaConfig, pluginsInfo);
        if (isClearConsumerInfo) {
            Utils.clearConsumerInfoInZk(broker.getBroker().getBrokerZooKeeper().getZkClient(), broker.getBroker()
                .getBrokerZooKeeper().getMetaZookeeper()); 
        } 
        broker.start();
        // this.slaveBrokers.add(broker); 
        return broker;
    } 
 
 
    private Map<String, Properties> getSlaveProperties() throws IOException {
        final Map<String, Properties> ret = new HashMap<String, Properties>();
        final Properties properties =
                com.taobao.metamorphosis.utils.Utils.getResourceAsProperties("gregor_slave.properties", "GBK"); 
        ret.put("gregor", properties);
        return ret;
    } 
 
 
    private Map<String, Properties> getMasterProperties() throws IOException {