Search in sources :

Example 1 with MapStoreWrapper

use of com.hazelcast.map.impl.MapStoreWrapper in project hazelcast by hazelcast.

the class BasicMapStoreContext method callLifecycleSupportInit.

private static void callLifecycleSupportInit(MapStoreContext mapStoreContext) {
    final MapStoreWrapper mapStoreWrapper = mapStoreContext.getMapStoreWrapper();
    final MapServiceContext mapServiceContext = mapStoreContext.getMapServiceContext();
    final NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
    final HazelcastInstance hazelcastInstance = nodeEngine.getHazelcastInstance();
    final MapStoreConfig mapStoreConfig = mapStoreContext.getMapStoreConfig();
    final Properties properties = mapStoreConfig.getProperties();
    final String mapName = mapStoreContext.getMapName();
    mapStoreWrapper.init(hazelcastInstance, properties, mapName);
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) MapStoreWrapper(com.hazelcast.map.impl.MapStoreWrapper) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Properties(java.util.Properties) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 2 with MapStoreWrapper

use of com.hazelcast.map.impl.MapStoreWrapper in project hazelcast by hazelcast.

the class BasicMapStoreContext method create.

static MapStoreContext create(MapContainer mapContainer) {
    final BasicMapStoreContext context = new BasicMapStoreContext();
    final String mapName = mapContainer.getName();
    final MapServiceContext mapServiceContext = mapContainer.getMapServiceContext();
    final NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
    final PartitioningStrategy partitioningStrategy = mapContainer.getPartitioningStrategy();
    final MapConfig mapConfig = mapContainer.getMapConfig();
    final MapStoreConfig mapStoreConfig = mapConfig.getMapStoreConfig();
    final ClassLoader configClassLoader = nodeEngine.getConfigClassLoader();
    // create store.
    final Object store = createStore(mapName, mapStoreConfig, configClassLoader);
    final MapStoreWrapper storeWrapper = new MapStoreWrapper(mapName, store);
    storeWrapper.instrument(nodeEngine);
    setStoreImplToWritableMapStoreConfig(nodeEngine, mapName, store);
    context.setMapName(mapName);
    context.setMapStoreConfig(mapStoreConfig);
    context.setPartitioningStrategy(partitioningStrategy);
    context.setMapServiceContext(mapServiceContext);
    context.setStoreWrapper(storeWrapper);
    final MapStoreManager mapStoreManager = createMapStoreManager(context);
    context.setMapStoreManager(mapStoreManager);
    // todo this is user code. it may also block map store creation.
    callLifecycleSupportInit(context);
    return context;
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) MapStoreWrapper(com.hazelcast.map.impl.MapStoreWrapper) PartitioningStrategy(com.hazelcast.core.PartitioningStrategy) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 3 with MapStoreWrapper

use of com.hazelcast.map.impl.MapStoreWrapper in project hazelcast by hazelcast.

the class MapDataStores method createWriteThroughStore.

/**
     * Creates a write through data store.
     *
     * @param mapStoreContext context for map store operations.
     * @param <K>             type of key to store.
     * @param <V>             type of value to store.
     * @return new write through store manager.
     */
public static <K, V> MapDataStore<K, V> createWriteThroughStore(MapStoreContext mapStoreContext) {
    final MapStoreWrapper store = mapStoreContext.getMapStoreWrapper();
    final MapServiceContext mapServiceContext = mapStoreContext.getMapServiceContext();
    final NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
    final SerializationService serializationService = nodeEngine.getSerializationService();
    return (MapDataStore<K, V>) new WriteThroughStore(store, serializationService);
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) MapStoreWrapper(com.hazelcast.map.impl.MapStoreWrapper) WriteThroughStore(com.hazelcast.map.impl.mapstore.writethrough.WriteThroughStore) SerializationService(com.hazelcast.spi.serialization.SerializationService) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 4 with MapStoreWrapper

use of com.hazelcast.map.impl.MapStoreWrapper in project hazelcast by hazelcast.

the class MapStoreTest method testReadingConfiguration.

@Test(timeout = 120000)
public void testReadingConfiguration() throws Exception {
    String mapName = "mapstore-test";
    InputStream is = getClass().getResourceAsStream("/com/hazelcast/config/hazelcast-mapstore-config.xml");
    XmlConfigBuilder builder = new XmlConfigBuilder(is);
    Config config = builder.build();
    HazelcastInstance hz = createHazelcastInstance(config);
    MapProxyImpl map = (MapProxyImpl) hz.getMap(mapName);
    MapService mapService = (MapService) map.getService();
    MapContainer mapContainer = mapService.getMapServiceContext().getMapContainer(mapName);
    MapStoreWrapper mapStoreWrapper = mapContainer.getMapStoreContext().getMapStoreWrapper();
    Iterator keys = mapStoreWrapper.loadAllKeys().iterator();
    final Set<String> loadedKeySet = loadedKeySet(keys);
    final Set<String> expectedKeySet = expectedKeySet();
    assertEquals(expectedKeySet, loadedKeySet);
    assertEquals("true", mapStoreWrapper.load("my-prop-1"));
    assertEquals("foo", mapStoreWrapper.load("my-prop-2"));
}
Also used : MapStoreWrapper(com.hazelcast.map.impl.MapStoreWrapper) XmlConfigBuilder(com.hazelcast.config.XmlConfigBuilder) HazelcastInstance(com.hazelcast.core.HazelcastInstance) InputStream(java.io.InputStream) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) GroupConfig(com.hazelcast.config.GroupConfig) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) Iterator(java.util.Iterator) MapService(com.hazelcast.map.impl.MapService) MapContainer(com.hazelcast.map.impl.MapContainer) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

MapStoreWrapper (com.hazelcast.map.impl.MapStoreWrapper)4 MapStoreConfig (com.hazelcast.config.MapStoreConfig)3 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)3 NodeEngine (com.hazelcast.spi.NodeEngine)3 MapConfig (com.hazelcast.config.MapConfig)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 Config (com.hazelcast.config.Config)1 GroupConfig (com.hazelcast.config.GroupConfig)1 XmlConfigBuilder (com.hazelcast.config.XmlConfigBuilder)1 PartitioningStrategy (com.hazelcast.core.PartitioningStrategy)1 MapContainer (com.hazelcast.map.impl.MapContainer)1 MapService (com.hazelcast.map.impl.MapService)1 WriteThroughStore (com.hazelcast.map.impl.mapstore.writethrough.WriteThroughStore)1 MapProxyImpl (com.hazelcast.map.impl.proxy.MapProxyImpl)1 SerializationService (com.hazelcast.spi.serialization.SerializationService)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 InputStream (java.io.InputStream)1 Iterator (java.util.Iterator)1 Properties (java.util.Properties)1