com.ctrip.framework.apollo.enums.PropertyChangeType Java Examples
The following examples show how to use
com.ctrip.framework.apollo.enums.PropertyChangeType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractConfigFile.java From apollo with Apache License 2.0 | 5 votes |
@Override public synchronized void onRepositoryChange(String namespace, Properties newProperties) { if (newProperties.equals(m_configProperties.get())) { return; } Properties newConfigProperties = propertiesFactory.getPropertiesInstance(); newConfigProperties.putAll(newProperties); String oldValue = getContent(); update(newProperties); m_sourceType = m_configRepository.getSourceType(); String newValue = getContent(); PropertyChangeType changeType = PropertyChangeType.MODIFIED; if (oldValue == null) { changeType = PropertyChangeType.ADDED; } else if (newValue == null) { changeType = PropertyChangeType.DELETED; } this.fireConfigChange(new ConfigFileChangeEvent(m_namespace, oldValue, newValue, changeType)); Tracer.logEvent("Apollo.Client.ConfigChanges", m_namespace); }
Example #2
Source File: ConfigChange.java From apollo with Apache License 2.0 | 5 votes |
/** * Constructor. * @param namespace the namespace of the key * @param propertyName the key whose value is changed * @param oldValue the value before change * @param newValue the value after change * @param changeType the change type */ public ConfigChange(String namespace, String propertyName, String oldValue, String newValue, PropertyChangeType changeType) { this.namespace = namespace; this.propertyName = propertyName; this.oldValue = oldValue; this.newValue = newValue; this.changeType = changeType; }
Example #3
Source File: ApolloMockServerSpringIntegrationTest.java From apollo with Apache License 2.0 | 5 votes |
@Test @DirtiesContext public void testListenerTriggeredByDel() throws InterruptedException, ExecutionException, TimeoutException { embeddedApollo.deleteProperty(otherNamespace, "key1"); ConfigChangeEvent changeEvent = testBean.futureData.get(5000, TimeUnit.MILLISECONDS); assertEquals(otherNamespace, changeEvent.getNamespace()); assertEquals(PropertyChangeType.DELETED, changeEvent.getChange("key1").getChangeType()); }
Example #4
Source File: ApolloCenterRepository.java From shardingsphere with Apache License 2.0 | 5 votes |
private DataChangedEvent.ChangedType getChangedType(final PropertyChangeType changeType) { switch (changeType) { case ADDED: case MODIFIED: return DataChangedEvent.ChangedType.UPDATED; case DELETED: return DataChangedEvent.ChangedType.DELETED; default: return DataChangedEvent.ChangedType.IGNORED; } }
Example #5
Source File: ApolloConfigWrapperTest.java From shardingsphere with Apache License 2.0 | 5 votes |
@Test public void assertAddChangeListener() throws Exception { final SettableFuture<ConfigChangeEvent> future = SettableFuture.create(); ConfigChangeListener listener = future::set; configWrapper.addChangeListener(listener, Collections.singleton("test.children.2")); embeddedApollo.addOrModifyProperty("orchestration", "test.children.2", "value3"); ConfigChangeEvent changeEvent = future.get(5, TimeUnit.SECONDS); assertTrue(changeEvent.isChanged("test.children.2")); assertThat(changeEvent.getChange("test.children.2").getOldValue(), is("value2")); assertThat(changeEvent.getChange("test.children.2").getNewValue(), is("value3")); assertThat(changeEvent.getChange("test.children.2").getChangeType(), is(PropertyChangeType.MODIFIED)); }
Example #6
Source File: ApolloConfigWrapperTest.java From shardingsphere with Apache License 2.0 | 5 votes |
@Test public void assertAddChangeListenerWithInterestedKeyPrefixes() throws Exception { final SettableFuture<ConfigChangeEvent> future = SettableFuture.create(); ConfigChangeListener listener = future::set; configWrapper.addChangeListener(listener, Collections.singleton("test.children.1"), Collections.singleton("test.children.2")); embeddedApollo.addOrModifyProperty("orchestration", "test.children.2.1", "value4"); ConfigChangeEvent changeEvent = future.get(5, TimeUnit.SECONDS); assertTrue(changeEvent.isChanged("test.children.2.1")); assertThat(changeEvent.getChange("test.children.2.1").getNewValue(), is("value4")); assertThat(changeEvent.getChange("test.children.2.1").getChangeType(), is(PropertyChangeType.ADDED)); }
Example #7
Source File: AbstractConfig.java From apollo with Apache License 2.0 | 4 votes |
List<ConfigChange> calcPropertyChanges(String namespace, Properties previous, Properties current) { if (previous == null) { previous = propertiesFactory.getPropertiesInstance(); } if (current == null) { current = propertiesFactory.getPropertiesInstance(); } Set<String> previousKeys = previous.stringPropertyNames(); Set<String> currentKeys = current.stringPropertyNames(); Set<String> commonKeys = Sets.intersection(previousKeys, currentKeys); Set<String> newKeys = Sets.difference(currentKeys, commonKeys); Set<String> removedKeys = Sets.difference(previousKeys, commonKeys); List<ConfigChange> changes = Lists.newArrayList(); for (String newKey : newKeys) { changes.add(new ConfigChange(namespace, newKey, null, current.getProperty(newKey), PropertyChangeType.ADDED)); } for (String removedKey : removedKeys) { changes.add(new ConfigChange(namespace, removedKey, previous.getProperty(removedKey), null, PropertyChangeType.DELETED)); } for (String commonKey : commonKeys) { String previousValue = previous.getProperty(commonKey); String currentValue = current.getProperty(commonKey); if (Objects.equal(previousValue, currentValue)) { continue; } changes.add(new ConfigChange(namespace, commonKey, previousValue, currentValue, PropertyChangeType.MODIFIED)); } return changes; }
Example #8
Source File: ConfigFileChangeEvent.java From apollo with Apache License 2.0 | 4 votes |
public PropertyChangeType getChangeType() { return changeType; }
Example #9
Source File: ConfigChange.java From apollo with Apache License 2.0 | 4 votes |
public PropertyChangeType getChangeType() { return changeType; }
Example #10
Source File: ConfigChange.java From apollo with Apache License 2.0 | 4 votes |
public void setChangeType(PropertyChangeType changeType) { this.changeType = changeType; }
Example #11
Source File: GatewayPropertiesRefresher.java From apollo-use-cases with Apache License 2.0 | 3 votes |
/*** * 根据changeEvent和定义的pattern匹配key,如果所有对应PropertyChangeType为DELETED则需要清空GatewayProperties里相关集合 * * @param changeEvent * @param pattern * @param existSize * @return boolean * @author ksewen * @date 2019/5/23 2:18 PM */ private boolean checkNeedClear(ConfigChangeEvent changeEvent, String pattern, int existSize) { return changeEvent.changedKeys().stream().filter(key -> key.matches(pattern)) .filter(key -> { ConfigChange change = changeEvent.getChange(key); return PropertyChangeType.DELETED.equals(change.getChangeType()); }).count() == existSize; }
Example #12
Source File: ConfigFileChangeEvent.java From apollo with Apache License 2.0 | 3 votes |
/** * Constructor. * * @param namespace the namespace of the config file change event * @param oldValue the value before change * @param newValue the value after change * @param changeType the change type */ public ConfigFileChangeEvent(String namespace, String oldValue, String newValue, PropertyChangeType changeType) { this.namespace = namespace; this.oldValue = oldValue; this.newValue = newValue; this.changeType = changeType; }