Skip to content

Two simultaneous events fired while changing the property value from JConsole (Only for single property file , for reference file (using @next) , its working fine. #528

@patashish

Description

@patashish

Dear Team,

When i change any property value , I am getting 2 events of same property instead of one event.

firstfile.properties
firstkey1=firstvalue1
firstkey2=firstvalue2
@next=secondfile.properties

secondfile.properties
secondkey1=secondval1

Sample Code:

public class ArchaiusSamplePropFile4JMX {

static {
	System.setProperty("archaius.configurationSource.defaultFileName", "firstfile.properties");

	try {
		ConfigurationManager.loadCascadedPropertiesFromResources("firstfile");
	} catch (IOException e) {
		e.printStackTrace();
	}

}

public void configuration() throws IOException {
	installConfig();
}

private void installConfig() {
	if (!ConfigurationManager.isConfigurationInstalled()) {

		AbstractPollingScheduler scheduler = new FixedDelayPollingScheduler(1000, 1000, true);
		PolledConfigurationSource source = new URLConfigurationSource();
		DynamicConfiguration dynamicConfig = new DynamicConfiguration(source, scheduler);
		ConfigurationManager.install(dynamicConfig);
		// Registering configuration with an MBean and will be accessible for
		// read and update via JConsole
		ConfigJMXManager.registerConfigMbean(dynamicConfig);
		printValue();
	} else {
		System.out.println(".....CONFIGURATION IS ALREADY INSTALLED....");
	}

}

final DynamicStringProperty firstkey1DynamicStringProperty = DynamicPropertyFactory.getInstance()
		.getStringProperty("firstkey1", "defaultValue", new Runnable() {

			public void run() {
				System.out.println("********* firstkey1 PROP UPDATE EVENT***************");
				printValue();
			}
		});

final DynamicStringProperty firstkey2DynamicStringProperty = DynamicPropertyFactory.getInstance()
		.getStringProperty("firstkey2", "defaultValue", new Runnable() {

			public void run() {
				System.out.println("********* firstkey2 PROP UPDATE EVENT ***************");
				printValue();
			}
		});

final DynamicStringProperty secondkey1DynamicStringProperty = DynamicPropertyFactory.getInstance()
		.getStringProperty("secondkey1", "<<<<<NOT LOADED FROM PROP FILE>>>>>>>>>", new Runnable() {

			public void run() {

				System.out.println("********* secondkey1 PROP UPDATE EVENT*************");
				printValue();
			}
		});

private void printValue() {
	StringBuilder sb = new StringBuilder();
	sb.append("\n");
	sb.append("firstkey1:");
	sb.append(firstkey1DynamicStringProperty);
	sb.append("\n");

	sb.append("firstkey2:");
	sb.append(firstkey2DynamicStringProperty);
	sb.append("\n");

	sb.append("secondkey1:");
	sb.append(secondkey1DynamicStringProperty);
	sb.append("\n");

	System.out.println(">>>>>>>>>" + sb.toString());
}

public static void main(String[] args) throws IOException, InterruptedException {

	ArchaiusSamplePropFile4JMX arch = new ArchaiusSamplePropFile4JMX();

	while (true) {
		arch.configuration();
		System.out.println("--waiting --");
		TimeUnit.SECONDS.sleep(10);
		System.out.println("----");
	}

}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions