Cassandra 将参数传递给Hazelcast MapStore
我想写我自己的Cassandra 将参数传递给Hazelcast MapStore,cassandra,parameter-passing,hazelcast,Cassandra,Parameter Passing,Hazelcast,我想写我自己的MapStore,它将访问Cassandra 我希望能够传递参数,比如Cassandra的地址,假设我可以使用构造函数,我该怎么做呢 我正在使用Dropwizard,特别是Dropwizard cassandra库。Hazelcast提供了从Hazelcast.xml内部将属性(配置)传递到MapStore实现的选项。不幸的是,您是对的,文档中没有示例说明如何做到这一点,但下面是指向XSD模式的链接: 对于文档示例,我将信息传递给我们的文档团队以添加一个:)Hazelcast提供了
MapStore
,它将访问Cassandra
我希望能够传递参数,比如Cassandra的地址,假设我可以使用构造函数,我该怎么做呢
我正在使用
Dropwizard
,特别是Dropwizard cassandra
库。Hazelcast提供了从Hazelcast.xml
内部将属性(配置)传递到MapStore
实现的选项。不幸的是,您是对的,文档中没有示例说明如何做到这一点,但下面是指向XSD模式的链接:
对于文档示例,我将信息传递给我们的文档团队以添加一个:)Hazelcast提供了从
Hazelcast.xml
内部将属性(配置)传递到MapStore
实现的选项。不幸的是,您是对的,文档中没有示例说明如何做到这一点,但下面是指向XSD模式的链接:
对于文档示例,我将信息传递给我们的文档团队以添加一个:)@danieln
@noctarius展示了在hazelcast.xml
中指定属性的声明方式
但是MapLoader
没有将此属性注入实例的方法
为此,您需要实现MapLoaderLifeCyclesSupport
接口。
属性将被注入到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();
}
公共接口MapLoaderLifeCyclesSupport{
/**
*初始化此MapLoader实现。Hazelcast将调用
*此方法在地图首次用于
*HazelcastInstance.实现可以
*初始化实施过程所需的资源
*mapLoader,例如读取配置文件和/或创建
*数据库连接。对映射的引用,而不是
*此{@code MapLoader}已配置,可从
*{@code hazelcastInstance}在该方法的实现中。
*
*在加入集群的成员上,此方法在终结期间执行
*因此,应注意遵守
*{@link com.hazelcast.spi.PostJoinAwareService#getPostJoinOperation()}的规则。
*如果实现执行的操作可能会等待锁或其他
*阻塞(例如等待网络操作),这可能导致超时和
*阻止新成员加入群集。如果阻止操作
*初始化{@代码MAPADADER }所需的,考虑推迟它们
*使用惰性初始化方案。
*
*
*@param hazelcastInstance此mapLoader的hazelcastInstance。
*@param属性为此mapStore设置。请参阅MapStoreConfig
*@param mapName映射的名称。
*/
void init(HazelcastInstance HazelcastInstance,属性属性,字符串映射名);
/**
*Hazelcast将在关闭前调用此方法。
*可以重写此方法以清理资源
*由此映射加载器实现持有,例如关闭
*数据库连接等。
*/
无效销毁();
}
我们没有Cassandra的例子,但我们有Mongo的例子供您使用。此示例演示了将属性传递给加载程序的方法
此外,如果您愿意提供一个例子,我们也很乐意接受卡桑德拉的例子
如果您有任何问题,请在下面的评论中告诉我
多谢各位
维克@danieln
@noctarius展示了在hazelcast.xml
中指定属性的声明方式
但是MapLoader
没有将此属性注入实例的方法
为此,您需要实现MapLoaderLifeCyclesSupport
接口。
属性将被注入到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();
}
公共接口MapLoaderLifeCyclesSupport{
/**
*初始化此MapLoader实现。Hazelcast将调用
*此方法在地图首次用于
*HazelcastInstance.实现可以
*初始化实施过程所需的资源
*mapLoader,例如读取配置文件和/或创建
*数据库连接。对映射的引用,而不是
*此{@code MapLoader}已配置,可从
*{@code hazelcastInstance}在该方法的实现中。
*
*在加入集群的成员上,此方法在终结期间执行
*因此,应注意遵守
*{@link com.hazelcast.spi.PostJoinAwareService#getPostJoinOperation()}的规则。
*如果实现执行的操作可能会等待锁或其他
*阻塞(例如等待网络操作),这可能导致超时和
*阻止新成员加入群集。如果阻止操作
*初始化{@代码MAPADADER }所需的,考虑推迟它们
*使用惰性初始化方案。
*
*
*@param hazelcastInstance此mapLoader的hazelcastInstance。
*@param属性为此mapStore设置。请参阅MapStoreConfig
*@param mapName映射的名称。
*/
void init(HazelcastInstance HazelcastInstance,属性属性,字符串映射名);
/**
*Hazelcast将在关闭前调用此方法。
*可以重写此方法以清理资源
*由此映射加载器实现持有,例如关闭
*数据库连接等。
*/
无效销毁();
}
我们没有Cassandra的例子,但我们有Mongo的例子供您使用。此示例演示了将属性传递给加载程序的方法
此外,如果您愿意提供一个例子,我们也很乐意接受卡桑德拉的例子
如果您有任何问题,请在下面的评论中告诉我
多谢各位
Vik亲爱的danieln,请检查我的答案,如果对您有效,请标记它已解决。谢谢你我最终做的是实现