我想写我自己MapStore
将访问卡桑德拉。传递参数给Hazelcast MapStore
我想能够传递参数如卡桑德拉的地址,我怎么能做到这一点,假设我可以使用构造函数。
我使用的是Dropwizard
,特别是dropwizard-cassandra
库。
我想写我自己MapStore
将访问卡桑德拉。传递参数给Hazelcast MapStore
我想能够传递参数如卡桑德拉的地址,我怎么能做到这一点,假设我可以使用构造函数。
我使用的是Dropwizard
,特别是dropwizard-cassandra
库。
Hazelcast提供了将属性(配置)从hazelcast.xml
内部传递到MapStore
实现的选项。不幸的是,你是对的,所以存在显示了如何做到这一点的文档没有例子,但这里的链接到XSD架构:https://github.com/hazelcast/hazelcast/blob/master/hazelcast/src/main/resources/hazelcast-config-3.7.xsd#L1731
对于文档的例子,我传递信息到我们的文档团队添加一个:)
@danieln
@noctarius显示,hazelcast.xml
指定属性的声明方式。
但MapLoader
没有办法将该属性注入到实例中。
要做到这一点,您需要实现MapLoaderLifecycleSupport
接口。 属性将我注入init()
方法
public interface MapLoaderLifecycleSupport {
/**
* Initializes this MapLoader implementation. Hazelcast will call
* this method when the map is first used on the
* HazelcastInstance. Implementation can
* initialize required resources for the implementing
* mapLoader, such as reading a config file and/or creating a
* database connection. References to maps, other than the one on which
* this {@code MapLoader} is configured, can be obtained from the
* {@code hazelcastInstance} in this method's implementation.
* <p>
* On members joining a cluster, this method is executed during finalization
* of the join operation, therefore care should be taken to adhere to the
* rules for {@link com.hazelcast.spi.PostJoinAwareService#getPostJoinOperation()}.
* If the implementation executes operations which may wait on locks or otherwise
* block (e.g. waiting for network operations), this may result in a time-out and
* obstruct the new member from joining the cluster. If blocking operations are
* required for initialization of the {@code MapLoader}, consider deferring them
* with a lazy initialization scheme.
* </p>
*
* @param hazelcastInstance HazelcastInstance of this mapLoader.
* @param properties Properties set for this mapStore. see MapStoreConfig
* @param mapName name of the map.
*/
void init(HazelcastInstance hazelcastInstance, Properties properties, String mapName);
/**
* Hazelcast will call this method before shutting down.
* This method can be overridden to clean up the resources
* held by this map loader implementation, such as closing the
* database connections, etc.
*/
void destroy();
}
我们没有卡桑德拉的例子,但我们确实有在您的处置蒙戈例如here。本实施例说明使属性,以装载机的方法。
此外,我们很乐意接受卡桑德拉的例子为hazelcast-code-samples,如果您愿意捐助一个。
如果您有任何问题,请在下面的评论中告诉我。
谢谢
维克
哦很好的补充,谢谢:) – noctarius
亲爱danieln,请查看我的回答并标记它解决它是否适合你。谢谢 –
我最终做的是实现''MapStoreFactory'',所以我可以传递参数到''MapStore''构造函数,如下所示: ''mapStoreConfig.setFactoryImplementation((MapStoreFactory)( MAPNAME,属性) - > {如果(mapName.equals( “X”)){返回mapStore;}返回NULL;}); '' –
danieln
亲切,如果你满意接受的答案。谢谢 –