當前位置: 首頁>>代碼示例>>Java>>正文


Java ConfigChangeEvent類代碼示例

本文整理匯總了Java中com.ctrip.framework.apollo.model.ConfigChangeEvent的典型用法代碼示例。如果您正苦於以下問題:Java ConfigChangeEvent類的具體用法?Java ConfigChangeEvent怎麽用?Java ConfigChangeEvent使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ConfigChangeEvent類屬於com.ctrip.framework.apollo.model包,在下文中一共展示了ConfigChangeEvent類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: fireConfigChange

import com.ctrip.framework.apollo.model.ConfigChangeEvent; //導入依賴的package包/類
protected void fireConfigChange(final ConfigChangeEvent changeEvent) {
  for (final ConfigChangeListener listener : m_listeners) {
    m_executorService.submit(new Runnable() {
      @Override
      public void run() {
        String listenerName = listener.getClass().getName();
        Transaction transaction = Tracer.newTransaction("Apollo.ConfigChangeListener", listenerName);
        try {
          listener.onChange(changeEvent);
          transaction.setStatus(Transaction.SUCCESS);
        } catch (Throwable ex) {
          transaction.setStatus(ex);
          Tracer.logError(ex);
          logger.error("Failed to invoke config change listener {}", listenerName, ex);
        } finally {
          transaction.complete();
        }
      }
    });
  }
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:22,代碼來源:AbstractConfig.java

示例2: onRepositoryChange

import com.ctrip.framework.apollo.model.ConfigChangeEvent; //導入依賴的package包/類
@Override
public synchronized void onRepositoryChange(String namespace, Properties newProperties) {
  if (newProperties.equals(m_configProperties)) {
    return;
  }
  Properties newConfigProperties = new Properties();
  newConfigProperties.putAll(newProperties);

  List<ConfigChange>
      changes =
      calcPropertyChanges(namespace, m_configProperties, newConfigProperties);
  Map<String, ConfigChange> changeMap = Maps.uniqueIndex(changes,
      new Function<ConfigChange, String>() {
        @Override
        public String apply(ConfigChange input) {
          return input.getPropertyName();
        }
      });

  m_configProperties = newConfigProperties;
  clearConfigCache();

  this.fireConfigChange(new ConfigChangeEvent(m_namespace, changeMap));

  Tracer.logEvent("Apollo.Client.ConfigChanges", m_namespace);
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:27,代碼來源:SimpleConfig.java

示例3: onRepositoryChange

import com.ctrip.framework.apollo.model.ConfigChangeEvent; //導入依賴的package包/類
@Override
public synchronized void onRepositoryChange(String namespace, Properties newProperties) {
  if (newProperties.equals(m_configProperties.get())) {
    return;
  }
  Properties newConfigProperties = new Properties();
  newConfigProperties.putAll(newProperties);

  Map<String, ConfigChange> actualChanges = updateAndCalcConfigChanges(newConfigProperties);

  //check double checked result
  if (actualChanges.isEmpty()) {
    return;
  }

  this.fireConfigChange(new ConfigChangeEvent(m_namespace, actualChanges));

  Tracer.logEvent("Apollo.Client.ConfigChanges", m_namespace);
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:20,代碼來源:DefaultConfig.java

示例4: SimpleApolloConfigDemo

import com.ctrip.framework.apollo.model.ConfigChangeEvent; //導入依賴的package包/類
public SimpleApolloConfigDemo() {
  ConfigChangeListener changeListener = new ConfigChangeListener() {
    @Override
    public void onChange(ConfigChangeEvent changeEvent) {
      logger.info("Changes for namespace {}", changeEvent.getNamespace());
      for (String key : changeEvent.changedKeys()) {
        ConfigChange change = changeEvent.getChange(key);
        logger.info("Change - key: {}, oldValue: {}, newValue: {}, changeType: {}",
            change.getPropertyName(), change.getOldValue(), change.getNewValue(),
            change.getChangeType());
      }
    }
  };
  config = ConfigService.getAppConfig();
  config.addChangeListener(changeListener);
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:17,代碼來源:SimpleApolloConfigDemo.java

示例5: processMethods

import com.ctrip.framework.apollo.model.ConfigChangeEvent; //導入依賴的package包/類
private void processMethods(final Object bean, Method[] declaredMethods) {
  for (final Method method : declaredMethods) {
    ApolloConfigChangeListener annotation = AnnotationUtils.findAnnotation(method, ApolloConfigChangeListener.class);
    if (annotation == null) {
      continue;
    }

    Class<?>[] parameterTypes = method.getParameterTypes();
    Preconditions.checkArgument(parameterTypes.length == 1,
        "Invalid number of parameters: %s for method: %s, should be 1", parameterTypes.length, method);
    Preconditions.checkArgument(ConfigChangeEvent.class.isAssignableFrom(parameterTypes[0]),
        "Invalid parameter type: %s for method: %s, should be ConfigChangeEvent", parameterTypes[0], method);

    ReflectionUtils.makeAccessible(method);
    String[] namespaces = annotation.value();
    for (String namespace : namespaces) {
      Config config = ConfigService.getConfig(namespace);

      config.addChangeListener(new ConfigChangeListener() {
        @Override
        public void onChange(ConfigChangeEvent changeEvent) {
          ReflectionUtils.invokeMethod(method, bean, changeEvent);
        }
      });
    }
  }
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:28,代碼來源:ApolloAnnotationProcessor.java

示例6: testLongPollRefresh

import com.ctrip.framework.apollo.model.ConfigChangeEvent; //導入依賴的package包/類
@Test
public void testLongPollRefresh() throws Exception {
  final String someKey = "someKey";
  final String someValue = "someValue";
  final String anotherValue = "anotherValue";
  long someNotificationId = 1;

  long pollTimeoutInMS = 50;
  Map<String, String> configurations = Maps.newHashMap();
  configurations.put(someKey, someValue);
  ApolloConfig apolloConfig = assembleApolloConfig(configurations);
  ContextHandler configHandler = mockConfigServerHandler(HttpServletResponse.SC_OK, apolloConfig);
  ContextHandler pollHandler =
      mockPollNotificationHandler(pollTimeoutInMS, HttpServletResponse.SC_OK,
          Lists.newArrayList(
              new ApolloConfigNotification(apolloConfig.getNamespaceName(), someNotificationId)),
          false);

  startServerWithHandlers(configHandler, pollHandler);

  Config config = ConfigService.getAppConfig();
  assertEquals(someValue, config.getProperty(someKey, null));

  final SettableFuture<Boolean> longPollFinished = SettableFuture.create();

  config.addChangeListener(new ConfigChangeListener() {
    @Override
    public void onChange(ConfigChangeEvent changeEvent) {
      longPollFinished.set(true);
    }
  });

  apolloConfig.getConfigurations().put(someKey, anotherValue);

  longPollFinished.get(pollTimeoutInMS * 20, TimeUnit.MILLISECONDS);

  assertEquals(anotherValue, config.getProperty(someKey, null));
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:39,代碼來源:ConfigIntegrationTest.java

示例7: onChange

import com.ctrip.framework.apollo.model.ConfigChangeEvent; //導入依賴的package包/類
@ApolloConfigChangeListener
private void onChange(ConfigChangeEvent changeEvent) {
  if (changeEvent.isChanged("timeout")) {
    logger.info("Manually refreshing xmlBean.timeout");
    xmlBean.setTimeout(config.getIntProperty("timeout", xmlBean.getTimeout()));
  }

  if (changeEvent.isChanged("batch")) {
    logger.info("Manually refreshing xmlBean.batch");
    xmlBean.setBatch(config.getIntProperty("batch", xmlBean.getBatch()));
  }
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:13,代碼來源:ManualRefreshUtil.java

示例8: onChange

import com.ctrip.framework.apollo.model.ConfigChangeEvent; //導入依賴的package包/類
@ApolloConfigChangeListener({"application", "FX.apollo"})
private void onChange(ConfigChangeEvent changeEvent) {
  if (changeEvent.isChanged("timeout") || changeEvent.isChanged("batch")) {
    logger.info("before refresh {}", annotatedBean.toString());
    //could also call refreshScope.refreshAll();
    refreshScope.refresh("annotatedBean");
    logger.info("after refresh {}", annotatedBean.toString());
  }
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:10,代碼來源:ApolloRefreshConfig.java

示例9: someChangeHandler

import com.ctrip.framework.apollo.model.ConfigChangeEvent; //導入依賴的package包/類
@ApolloConfigChangeListener("application")
private void someChangeHandler(ConfigChangeEvent changeEvent) {
  logger.info("[someChangeHandler]Changes for namespace {}", changeEvent.getNamespace());
  for (String key : changeEvent.changedKeys()) {
    ConfigChange change = changeEvent.getChange(key);
    logger.info("[someChangeHandler]Change - key: {}, oldValue: {}, newValue: {}, changeType: {}",
        change.getPropertyName(), change.getOldValue(), change.getNewValue(),
        change.getChangeType());
  }
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:11,代碼來源:XmlBean.java

示例10: anotherChangeHandler

import com.ctrip.framework.apollo.model.ConfigChangeEvent; //導入依賴的package包/類
@ApolloConfigChangeListener({"application", "FX.apollo"})
private void anotherChangeHandler(ConfigChangeEvent changeEvent) {
  logger.info("[anotherChangeHandler]Changes for namespace {}", changeEvent.getNamespace());
  for (String key : changeEvent.changedKeys()) {
    ConfigChange change = changeEvent.getChange(key);
    logger.info("[anotherChangeHandler]Change - key: {}, oldValue: {}, newValue: {}, changeType: {}",
        change.getPropertyName(), change.getOldValue(), change.getNewValue(),
        change.getChangeType());
  }
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:11,代碼來源:XmlBean.java

示例11: someChangeHandler

import com.ctrip.framework.apollo.model.ConfigChangeEvent; //導入依賴的package包/類
@ApolloConfigChangeListener("application")
private void someChangeHandler(ConfigChangeEvent changeEvent) {
  logger.info("[someChangeHandler]Changes for namespace {}", changeEvent.getNamespace());
  if (changeEvent.isChanged("timeout")) {
    refreshTimeout();
  }
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:8,代碼來源:AnnotatedBean.java

示例12: onChange1

import com.ctrip.framework.apollo.model.ConfigChangeEvent; //導入依賴的package包/類
@ApolloConfigChangeListener
private void onChange1(ConfigChangeEvent changeEvent) {
  this.changeEvent1 = changeEvent;
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:5,代碼來源:XMLConfigAnnotationTest.java

示例13: onChange2

import com.ctrip.framework.apollo.model.ConfigChangeEvent; //導入依賴的package包/類
@ApolloConfigChangeListener(ConfigConsts.NAMESPACE_APPLICATION)
private void onChange2(ConfigChangeEvent changeEvent) {
  this.changeEvent2 = changeEvent;
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:5,代碼來源:XMLConfigAnnotationTest.java

示例14: onChange3

import com.ctrip.framework.apollo.model.ConfigChangeEvent; //導入依賴的package包/類
@ApolloConfigChangeListener({ConfigConsts.NAMESPACE_APPLICATION, FX_APOLLO_NAMESPACE})
private void onChange3(ConfigChangeEvent changeEvent) {
  this.changeEvent3 = changeEvent;
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:5,代碼來源:XMLConfigAnnotationTest.java

示例15: getChangeEvent1

import com.ctrip.framework.apollo.model.ConfigChangeEvent; //導入依賴的package包/類
public ConfigChangeEvent getChangeEvent1() {
  return changeEvent1;
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:4,代碼來源:XMLConfigAnnotationTest.java


注:本文中的com.ctrip.framework.apollo.model.ConfigChangeEvent類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。