我想寫我自己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
親切,如果你滿意接受的答案。謝謝 –