Java Code Examples for io.openmessaging.KeyValue#keySet()

The following examples show how to use io.openmessaging.KeyValue#keySet() . 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: BeanUtils.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public static <T> T populate(final KeyValue properties, final T obj) {
    Class<?> clazz = obj.getClass();
    try {

        final Set<String> keySet = properties.keySet();
        for (String key : keySet) {
            String[] keyGroup = key.split("\\.");
            for (int i = 0; i < keyGroup.length; i++) {
                keyGroup[i] = keyGroup[i].toLowerCase();
                keyGroup[i] = StringUtils.capitalize(keyGroup[i]);
            }
            String beanFieldNameWithCapitalization = StringUtils.join(keyGroup);
            try {
                setProperties(clazz, obj, "set" + beanFieldNameWithCapitalization, properties.getString(key));
            } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {
                //ignored...
            }
        }
    } catch (RuntimeException e) {
        log.warn("Error occurs !", e);
    }
    return obj;
}
 
Example 2
Source File: BeanUtils.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
public static <T> T populate(final KeyValue properties, final T obj) {
    Class<?> clazz = obj.getClass();
    try {

        final Set<String> keySet = properties.keySet();
        for (String key : keySet) {
            String[] keyGroup = key.split("[\\._]");
            for (int i = 0; i < keyGroup.length; i++) {
                keyGroup[i] = keyGroup[i].toLowerCase();
                keyGroup[i] = StringUtils.capitalize(keyGroup[i]);
            }
            String beanFieldNameWithCapitalization = StringUtils.join(keyGroup);
            try {
                setProperties(clazz, obj, "set" + beanFieldNameWithCapitalization, properties.getString(key));
            } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {
                //ignored...
            }
        }
    } catch (RuntimeException e) {
        log.warn("Error occurs !", e);
    }
    return obj;
}
 
Example 3
Source File: BeanUtils.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
public static <T> T populate(final KeyValue properties, final T obj) {
    Class<?> clazz = obj.getClass();
    try {

        final Set<String> keySet = properties.keySet();
        for (String key : keySet) {
            String[] keyGroup = key.split("[\\._]");
            for (int i = 0; i < keyGroup.length; i++) {
                keyGroup[i] = keyGroup[i].toLowerCase();
                keyGroup[i] = StringUtils.capitalize(keyGroup[i]);
            }
            String beanFieldNameWithCapitalization = StringUtils.join(keyGroup);
            try {
                setProperties(clazz, obj, "set" + beanFieldNameWithCapitalization, properties.getString(key));
            } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {
                //ignored...
            }
        }
    } catch (RuntimeException e) {
        log.warn("Error occurs !", e);
    }
    return obj;
}
 
Example 4
Source File: BeanUtils.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public static <T> T populate(final KeyValue properties, final T obj) {
    Class<?> clazz = obj.getClass();
    try {

        final Set<String> keySet = properties.keySet();
        for (String key : keySet) {
            String[] keyGroup = key.split("\\.");
            for (int i = 0; i < keyGroup.length; i++) {
                keyGroup[i] = keyGroup[i].toLowerCase();
                keyGroup[i] = StringUtils.capitalize(keyGroup[i]);
            }
            String beanFieldNameWithCapitalization = StringUtils.join(keyGroup);
            try {
                setProperties(clazz, obj, "set" + beanFieldNameWithCapitalization, properties.getString(key));
            } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {
                //ignored...
            }
        }
    } catch (RuntimeException e) {
        log.warn("Error occurs !", e);
    }
    return obj;
}
 
Example 5
Source File: BeanUtils.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
public static <T> T populate(final KeyValue properties, final T obj) {
    Class<?> clazz = obj.getClass();
    try {

        final Set<String> keySet = properties.keySet();
        for (String key : keySet) {
            String[] keyGroup = key.split("\\.");
            for (int i = 0; i < keyGroup.length; i++) {
                keyGroup[i] = keyGroup[i].toLowerCase();
                keyGroup[i] = StringUtils.capitalize(keyGroup[i]);
            }
            String beanFieldNameWithCapitalization = StringUtils.join(keyGroup);
            try {
                setProperties(clazz, obj, "set" + beanFieldNameWithCapitalization, properties.getString(key));
            } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {
                //ignored...
            }
        }
    } catch (RuntimeException e) {
        log.warn("Error occurs !", e);
    }
    return obj;
}
 
Example 6
Source File: BeanUtils.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public static <T> T populate(final KeyValue properties, final T obj) {
    Class<?> clazz = obj.getClass();
    try {

        final Set<String> keySet = properties.keySet();
        for (String key : keySet) {
            String[] keyGroup = key.split("[\\._]");
            for (int i = 0; i < keyGroup.length; i++) {
                keyGroup[i] = keyGroup[i].toLowerCase();
                keyGroup[i] = StringUtils.capitalize(keyGroup[i]);
            }
            String beanFieldNameWithCapitalization = StringUtils.join(keyGroup);
            try {
                setProperties(clazz, obj, "set" + beanFieldNameWithCapitalization, properties.getString(key));
            } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {
                //ignored...
            }
        }
    } catch (RuntimeException e) {
        log.warn("Error occurs !", e);
    }
    return obj;
}
 
Example 7
Source File: OMSUtil.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public static KeyValue buildKeyValue(KeyValue... keyValues) {
    KeyValue keyValue = OMS.newKeyValue();
    for (KeyValue properties : keyValues) {
        for (String key : properties.keySet()) {
            keyValue.put(key, properties.getString(key));
        }
    }
    return keyValue;
}
 
Example 8
Source File: OMSUtil.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public static KeyValue buildKeyValue(KeyValue... keyValues) {
    KeyValue keyValue = OMS.newKeyValue();
    for (KeyValue properties : keyValues) {
        for (String key : properties.keySet()) {
            keyValue.put(key, properties.getString(key));
        }
    }
    return keyValue;
}
 
Example 9
Source File: OMSUtil.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
public static KeyValue buildKeyValue(KeyValue... keyValues) {
    KeyValue keyValue = OMS.newKeyValue();
    for (KeyValue properties : keyValues) {
        for (String key : properties.keySet()) {
            keyValue.put(key, properties.getString(key));
        }
    }
    return keyValue;
}
 
Example 10
Source File: ConnectKeyValueTest.java    From openmessaging-connect-runtime with Apache License 2.0 5 votes vote down vote up
@Test
public void testKeyValueOperations(){

    KeyValue keyValue = new ConnectKeyValue();
    keyValue.put("StringKey", "StringValue");
    keyValue.put("IntegerKey", 0);
    keyValue.put("LongKey", 1L);
    keyValue.put("DoubleKey", 5.2);

    assertEquals("StringValue", keyValue.getString("StringKey"));
    assertEquals(0, keyValue.getInt("IntegerKey"));
    assertEquals(1L, keyValue.getLong("LongKey"));
    assertEquals(5.2, keyValue.getDouble("DoubleKey"), 0.0);

    assertEquals("StringValue1", keyValue.getString("StringKey1", "StringValue1"));
    assertEquals(2, keyValue.getInt("IntegerKey1", 2));
    assertEquals(2L, keyValue.getLong("LongKey1", 2L));
    assertEquals(5.0, keyValue.getDouble("DoubleKey1", 5.0), 0.0);

    Set<String> keySet = keyValue.keySet();
    Set<String> compareKeySet = new HashSet<>();
    compareKeySet.add("StringKey");
    compareKeySet.add("IntegerKey");
    compareKeySet.add("LongKey");
    compareKeySet.add("DoubleKey");

    assertEquals(keySet, compareKeySet);

    assertTrue(keyValue.containsKey("StringKey"));
    assertTrue(keyValue.containsKey("IntegerKey"));
    assertTrue(keyValue.containsKey("LongKey"));
    assertTrue(keyValue.containsKey("DoubleKey"));

}
 
Example 11
Source File: SimpleBinarySerializer.java    From coding-snippets with MIT License 5 votes vote down vote up
private void write(ByteBuffer buffer, KeyValue keyValue) throws BufferOverflowException {
    if (keyValue == null) {
        buffer.putInt(0);
        return;
    }
    Set<String> keySet = keyValue.keySet();
    buffer.putInt(keySet.size());
    for (String key : keySet) {
        write(buffer, key);
        // TODO: only support String currently
        write(buffer, keyValue.getString(key));
    }
}
 
Example 12
Source File: OMSUtil.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public static KeyValue buildKeyValue(KeyValue... keyValues) {
    KeyValue keyValue = OMS.newKeyValue();
    for (KeyValue properties : keyValues) {
        for (String key : properties.keySet()) {
            keyValue.put(key, properties.getString(key));
        }
    }
    return keyValue;
}
 
Example 13
Source File: OMSUtil.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
public static KeyValue buildKeyValue(KeyValue... keyValues) {
    KeyValue keyValue = OMS.newKeyValue();
    for (KeyValue properties : keyValues) {
        for (String key : properties.keySet()) {
            keyValue.put(key, properties.getString(key));
        }
    }
    return keyValue;
}
 
Example 14
Source File: OMSUtil.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public static KeyValue buildKeyValue(KeyValue... keyValues) {
    KeyValue keyValue = OMS.newKeyValue();
    for (KeyValue properties : keyValues) {
        for (String key : properties.keySet()) {
            keyValue.put(key, properties.getString(key));
        }
    }
    return keyValue;
}
 
Example 15
Source File: ConfigManagementServiceImpl.java    From openmessaging-connect-runtime with Apache License 2.0 4 votes vote down vote up
@Override
public String putConnectorConfig(String connectorName, ConnectKeyValue configs) throws Exception {

    ConnectKeyValue exist = connectorKeyValueStore.get(connectorName);
    if (null != exist) {
        Long updateTimestamp = exist.getLong(RuntimeConfigDefine.UPDATE_TIMESATMP);
        if (null != updateTimestamp) {
            configs.put(RuntimeConfigDefine.UPDATE_TIMESATMP, updateTimestamp);
        }
    }
    if(configs.equals(exist)){
        return "Connector with same config already exist.";
    }

    Long currentTimestamp = System.currentTimeMillis();
    configs.put(RuntimeConfigDefine.UPDATE_TIMESATMP, currentTimestamp);
    for(String requireConfig : RuntimeConfigDefine.REQUEST_CONFIG){
        if(!configs.containsKey(requireConfig)){
            return "Request config key: " + requireConfig;
        }
    }

    String className = configs.getString(RuntimeConfigDefine.CONNECTOR_CLASS);
    Class clazz = Class.forName(className);
    Connector connector = (Connector) clazz.newInstance();

    String errorMessage = connector.verifyAndSetConfig(configs);
    if(errorMessage != null && errorMessage.length() > 0){
        return errorMessage;
    }

    connector.start();
    connectorKeyValueStore.put(connectorName, configs);
    List<KeyValue> taskConfigs = connector.taskConfigs();
    List<ConnectKeyValue> converterdConfigs = new ArrayList<>();
    for(KeyValue keyValue : taskConfigs){
        ConnectKeyValue newKeyValue = new ConnectKeyValue();
        for(String key : keyValue.keySet()){
            newKeyValue.put(key, keyValue.getString(key));
        }
        newKeyValue.put(RuntimeConfigDefine.TASK_CLASS, connector.taskClass().getName());
        newKeyValue.put(RuntimeConfigDefine.OMS_DRIVER_URL, configs.getString(RuntimeConfigDefine.OMS_DRIVER_URL));
        newKeyValue.put(RuntimeConfigDefine.UPDATE_TIMESATMP, currentTimestamp);
        converterdConfigs.add(newKeyValue);
    }
    putTaskConfigs(connectorName, converterdConfigs);
    connector.stop();
    sendSynchronizeConfig();

    triggerListener();
    return "";
}