当前位置: 首页>>代码示例>>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;未经允许,请勿转载。