Search in sources :

Example 11 with DynamicProperty

use of com.netflix.config.DynamicProperty in project java-chassis by ServiceComb.

the class ProviderQpsControllerManager method initConfig.

private void initConfig(String key) {
    if (watchedKeySet.contains(key)) {
        return;
    }
    watchedKeySet.add(key);
    String configKey = Config.PROVIDER_LIMIT_KEY_PREFIX + key;
    DynamicProperty property = DynamicProperty.getInstance(configKey);
    initQpsLimit(key, getIntegerLimitProperty(property));
    property.addCallback(() -> {
        updateQpsLimit(key, getIntegerLimitProperty(property));
        QpsController qpsController = findReference(key);
        objMap.put(key, qpsController);
    });
}
Also used : DynamicProperty(com.netflix.config.DynamicProperty)

Example 12 with DynamicProperty

use of com.netflix.config.DynamicProperty in project java-chassis by ServiceComb.

the class TestPriorityPropertyManager method testConfigurationsAreGCCollected.

@Test
public void testConfigurationsAreGCCollected() {
    long timeBegin = System.currentTimeMillis();
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            TestConfigObjectFactory.ConfigWithAnnotation configConfigObject = priorityPropertyManager.createConfigObject(TestConfigObjectFactory.ConfigWithAnnotation.class);
            Assert.assertEquals("abc", configConfigObject.strDef);
            PriorityProperty<Long> configPriorityProperty = propertyFactory.getOrCreate(Long.class, -1L, -2L, keys);
            Assert.assertEquals(-2L, (long) configPriorityProperty.getValue());
        }
    }
    waitKeyForGC(priorityPropertyManager);
    Assert.assertTrue(priorityPropertyManager.getConfigObjectMap().isEmpty());
    for (DynamicProperty property : ConfigUtil.getAllDynamicProperties().values()) {
        Assert.assertTrue(ConfigUtil.getCallbacks(property).isEmpty());
    }
    System.out.println("Token : " + (System.currentTimeMillis() - timeBegin));
}
Also used : DynamicProperty(com.netflix.config.DynamicProperty) TestConfigObjectFactory(org.apache.servicecomb.config.inject.TestConfigObjectFactory) Test(org.junit.jupiter.api.Test)

Example 13 with DynamicProperty

use of com.netflix.config.DynamicProperty in project java-chassis by ServiceComb.

the class InspectorImpl method dynamicProperties.

@Path("/dynamicProperties")
@GET
public List<DynamicPropertyView> dynamicProperties() {
    List<DynamicPropertyView> views = new ArrayList<>();
    for (DynamicProperty property : ConfigUtil.getAllDynamicProperties().values()) {
        views.add(createDynamicPropertyView(property));
    }
    // show more callback first, because maybe there is memory leak problem
    // show recently changed second
    // and sort by key
    views.sort(Comparator.comparing(DynamicPropertyView::getCallbackCount).thenComparing(DynamicPropertyView::getChangedTime).reversed().thenComparing(DynamicPropertyView::getKey));
    return views;
}
Also used : DynamicProperty(com.netflix.config.DynamicProperty) DynamicPropertyView(org.apache.servicecomb.inspector.internal.model.DynamicPropertyView) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 14 with DynamicProperty

use of com.netflix.config.DynamicProperty in project java-chassis by ServiceComb.

the class InspectorImpl method createPriorityPropertyView.

private PriorityPropertyView createPriorityPropertyView(PriorityProperty<?> priorityProperty) {
    PriorityPropertyView view = new PriorityPropertyView();
    view.setDynamicProperties(new ArrayList<>());
    for (DynamicProperty property : priorityProperty.getProperties()) {
        view.getDynamicProperties().add(createDynamicPropertyView(property));
    }
    view.setDefaultValue(String.valueOf(priorityProperty.getDefaultValue()));
    view.setValue(String.valueOf(priorityProperty.getValue()));
    return view;
}
Also used : DynamicProperty(com.netflix.config.DynamicProperty) PriorityPropertyView(org.apache.servicecomb.inspector.internal.model.PriorityPropertyView)

Example 15 with DynamicProperty

use of com.netflix.config.DynamicProperty in project java-chassis by ServiceComb.

the class QpsControllerManager method initGlobalQpsController.

private void initGlobalQpsController() {
    DynamicProperty globalLimitProperty = DynamicProperty.getInstance(globalLimitKey);
    DynamicProperty globalBucketProperty = DynamicProperty.getInstance(globalBucketKey);
    DynamicProperty globalStrategyProperty = DynamicProperty.getInstance(Config.STRATEGY_KEY);
    globalQpsStrategy = chooseStrategy(globalLimitKey, globalLimitProperty.getLong((long) Integer.MAX_VALUE), globalBucketProperty.getLong(), globalStrategyProperty.getString());
    globalStrategyProperty.addCallback(() -> {
        globalQpsStrategy = chooseStrategy(globalLimitKey, globalLimitProperty.getLong((long) Integer.MAX_VALUE), globalBucketProperty.getLong(), globalStrategyProperty.getString());
        LOGGER.info("Global flow control strategy update, value = [{}]", globalStrategyProperty.getString());
    });
    globalLimitProperty.addCallback(() -> {
        globalQpsStrategy.setQpsLimit(globalLimitProperty.getLong((long) Integer.MAX_VALUE));
        LOGGER.info("Global qps limit update, value = [{}]", globalLimitProperty.getLong());
    });
    globalBucketProperty.addCallback(() -> {
        globalQpsStrategy.setBucketLimit(globalBucketProperty.getLong());
        LOGGER.info("Global bucket limit update, value = [{}]", globalBucketProperty.getLong());
    });
}
Also used : DynamicProperty(com.netflix.config.DynamicProperty)

Aggregations

DynamicProperty (com.netflix.config.DynamicProperty)17 ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 TestConfigObjectFactory (org.apache.servicecomb.config.inject.TestConfigObjectFactory)2 DynamicPropertyView (org.apache.servicecomb.inspector.internal.model.DynamicPropertyView)2 PriorityPropertyView (org.apache.servicecomb.inspector.internal.model.PriorityPropertyView)2 AbstractQpsStrategy (org.apache.servicecomb.qps.strategy.AbstractQpsStrategy)2 Test (org.junit.Test)2 Test (org.junit.jupiter.api.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2