Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
patashish opened this issue Nov 10, 2017 · 0 comments

Comments

@patashish
Copy link

patashish commented Nov 10, 2017

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("----");
	}

}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant