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

The following examples show how to use io.openmessaging.KeyValue#getString() . 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: V4PullConsumer.java    From coding-snippets with MIT License 6 votes vote down vote up
public V4PullConsumer(KeyValue properties) {
	this.properties = properties;
	/**
	 * 暂未考虑同步问题。现在测试例使用反射,没有并发,所以测试问题没发现问题。
	 * files为null代表是新的测试例,为避免本次测试影响下次需要初始化各个属性。
	 */
	if (files == null) {
		String path = properties.getString("STORE_PATH");
		files = new File(path).listFiles();
		fileNum = files.length;
		index = new AtomicInteger(0);
		finshed = new AtomicInteger(0);
		latch = new CountDownLatch(fileNum);
		data = new HashMap<String, List<BytesMessage>>(170);
		listOffset = new HashMap<String, AtomicInteger>(170);
	}
}
 
Example 2
Source File: Config.java    From openmessaging-connect-odar with Apache License 2.0 5 votes vote down vote up
private void properties2Object(final KeyValue p, final Object object) {

        Method[] methods = object.getClass().getMethods();
        for (Method method : methods) {
            String mn = method.getName();
            if (mn.startsWith("set")) {
                try {
                    String tmp = mn.substring(4);
                    String first = mn.substring(3, 4);

                    String key = first.toLowerCase() + tmp;
                    String property = p.getString(key);
                    if (property != null) {
                        Class<?>[] pt = method.getParameterTypes();
                        if (pt != null && pt.length > 0) {
                            String cn = pt[0].getSimpleName();
                            Object arg;
                            if (cn.equals("int") || cn.equals("Integer")) {
                                arg = Integer.parseInt(property);
                            } else if (cn.equals("long") || cn.equals("Long")) {
                                arg = Long.parseLong(property);
                            } else if (cn.equals("double") || cn.equals("Double")) {
                                arg = Double.parseDouble(property);
                            } else if (cn.equals("boolean") || cn.equals("Boolean")) {
                                arg = Boolean.parseBoolean(property);
                            } else if (cn.equals("float") || cn.equals("Float")) {
                                arg = Float.parseFloat(property);
                            } else if (cn.equals("String")) {
                                arg = property;
                            } else {
                                continue;
                            }
                            method.invoke(object, arg);
                        }
                    }
                } catch (Throwable ignored) {
                }
            }
        }
    }
 
Example 3
Source File: V7Producer.java    From coding-snippets with MIT License 5 votes vote down vote up
/**
 * 初始化对象时,初始化io。并一直持有ObjectOutputStream oos。
 * @param properties
 */
public V7Producer(KeyValue properties) {

    producerId = count++;
    //对于所有线程只需要初始化一次
    if(data == null){
        this.properties = properties;
        path = properties.getString("STORE_PATH");
        data = new HashMap<String, HashMap<Integer, List<DefaultBytesMessage>>>(256);
    }

}
 
Example 4
Source File: V7ProducerList.java    From coding-snippets with MIT License 5 votes vote down vote up
/**
 * 初始化对象时,初始化io。并一直持有ObjectOutputStream oos。
 * @param properties
 */
public V7ProducerList(KeyValue properties) {

    producerId = count++;
    //对于所有线程只需要初始化一次
    if(data == null){
        this.properties = properties;
        path = properties.getString("STORE_PATH");
        data = new HashMap<String, HashMap<Integer, List<DefaultBytesMessageList>>>(256);
    }

}
 
Example 5
Source File: V1PullConsumer.java    From coding-snippets with MIT License 5 votes vote down vote up
public V1PullConsumer(KeyValue properties) {
    this.properties = properties;
    /**
     * 暂未考虑同步问题。现在测试例使用反射,没有并发,所以测试问题没发现问题。
     * files为null代表是新的测试例,为避免本次测试影响下次需要初始化各个属性。
     */
    if(files == null){
    	String path = properties.getString("STORE_PATH");
        files = new File(path).listFiles();
        fileNum = files.length;
        index = new AtomicInteger(0);
        finshed = new AtomicInteger(0);
        data = new HashMap<String, List<BytesMessage>>(170);
    }
}
 
Example 6
Source File: DefaultProducer.java    From coding-snippets with MIT License 5 votes vote down vote up
/**
 * 初始化对象时,初始化io。并一直持有ObjectOutputStream oos。
 * @param properties
 */
public DefaultProducer(KeyValue properties) {

    producerId = count++;
    //对于所有线程只需要初始化一次
    if(data == null){
        this.properties = properties;
        path = properties.getString("STORE_PATH");
        data = new HashMap<String, HashMap<Integer, List<DefaultBytesMessage>>>(256);
    }

}
 
Example 7
Source File: V6ProducerUseBuilder.java    From coding-snippets with MIT License 5 votes vote down vote up
/**
 * 初始化对象时,初始化io。并一直持有ObjectOutputStream oos。
 * @param properties
 */
public V6ProducerUseBuilder(KeyValue properties) {

    producerId = count++;
    //对于所有线程只需要初始化一次
    if(data == null){
        this.properties = properties;
        path = properties.getString("STORE_PATH");
        data = new HashMap<String, HashMap<Integer, List<DefaultBytesMessage>>>(256);
    }

}
 
Example 8
Source File: V6ProducerTh.java    From coding-snippets with MIT License 5 votes vote down vote up
/**
 * 初始化对象时,初始化io。并一直持有ObjectOutputStream oos。
 * @param properties
 */
public V6ProducerTh(KeyValue properties) {

    producerId = count++;
    //对于所有线程只需要初始化一次
    if(data == null){
        this.properties = properties;
        path = properties.getString("STORE_PATH");
        data = new HashMap<String, HashMap<Integer, List<DefaultBytesMessage>>>(256);
    }

}
 
Example 9
Source File: V6ProducerNoStr.java    From coding-snippets with MIT License 5 votes vote down vote up
/**
 * 初始化对象时,初始化io。并一直持有ObjectOutputStream oos。
 * @param properties
 */
public V6ProducerNoStr(KeyValue properties) {

    producerId = count++;
    //对于所有线程只需要初始化一次
    if(data == null){
        this.properties = properties;
        path = properties.getString("STORE_PATH");
        data = new HashMap<String, HashMap<Integer, List<DefaultBytesMessageProducer2>>>(256);
    }

}
 
Example 10
Source File: V6Producer.java    From coding-snippets with MIT License 5 votes vote down vote up
/**
 * 初始化对象时,初始化io。并一直持有ObjectOutputStream oos。
 * @param properties
 */
public V6Producer(KeyValue properties) {

    producerId = count++;
    //对于所有线程只需要初始化一次
    if(data == null){
        this.properties = properties;
        path = properties.getString("STORE_PATH");
        data = new HashMap<String, HashMap<Integer, List<DefaultBytesMessage>>>(256);
    }

}
 
Example 11
Source File: V2PullConsumer.java    From coding-snippets with MIT License 5 votes vote down vote up
public V2PullConsumer(KeyValue properties) {
	this.properties = properties;
	/**
	 * 暂未考虑同步问题。现在测试例使用反射,没有并发,所以测试问题没发现问题。
	 * files为null代表是新的测试例,为避免本次测试影响下次需要初始化各个属性。
	 */
	if (files == null) {
		String path = properties.getString("STORE_PATH");
		files = new File(path).listFiles();
		fileNum = files.length;
		index = new AtomicInteger(0);
		finshed = new AtomicInteger(0);
		data = new HashMap<String, List<BytesMessage>>(170);
	}
}
 
Example 12
Source File: ProducerService.java    From coding-snippets with MIT License 5 votes vote down vote up
public static ProducerService getInstance(KeyValue keyValue) {
    if (instance == null) {
        String storePath = keyValue.getString("STORE_PATH");
        synchronized (ProducerService.class) {
            if (instance == null) {
                if (!storePath.endsWith("/")) {
                    storePath += "/";
                }
                instance = new ProducerService(storePath);
            }
        }
    }
    instance.waitCount.addAndGet(1);
    return instance;
}
 
Example 13
Source File: ConsumerService.java    From coding-snippets with MIT License 5 votes vote down vote up
public static ConsumerService getInstance(KeyValue keyValue) {
    if (instance == null) {
        String storePath = keyValue.getString("STORE_PATH");
        synchronized (ConsumerService.class) {
            if (instance == null) {
                if (!storePath.endsWith("/")) {
                    storePath += "/";
                }
                instance = new ConsumerService(storePath);
            }
        }
    }
    return instance;
}
 
Example 14
Source File: KeyValueHelper.java    From joyqueue with Apache License 2.0 4 votes vote down vote up
public static String getString(KeyValue keyValue, String key, String defaultValue) {
    if (!keyValue.containsKey(key)) {
        return defaultValue;
    }
    return keyValue.getString(key);
}
 
Example 15
Source File: DefaultPullConsumer.java    From OpenMessageShaping with MIT License 4 votes vote down vote up
public DefaultPullConsumer(KeyValue properties) {
    this.properties = properties;
    this.naiveDataReader = new NaiveDataReader(properties.getString("STORE_PATH"));
}
 
Example 16
Source File: MessagingAccessPointAdapter.java    From openmessaging-java with Apache License 2.0 4 votes vote down vote up
private static String parseDriverImpl(String driverType, KeyValue attributes) {
    if (attributes.containsKey(OMSBuiltinKeys.DRIVER_IMPL)) {
        return attributes.getString(OMSBuiltinKeys.DRIVER_IMPL);
    }
    return "io.openmessaging." + driverType + ".MessagingAccessPointImpl";
}