Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sboikov committed Jan 19, 2015
1 parent 2bbf624 commit eafa114
Show file tree
Hide file tree
Showing 86 changed files with 550 additions and 282 deletions.
6 changes: 3 additions & 3 deletions config/fabric/default-config.xml
Expand Up @@ -40,23 +40,23 @@
<!--
Local cache configuration.
-->
<bean class="org.apache.ignite.cache.GridCacheConfiguration">
<bean class="org.apache.ignite.cache.CacheConfiguration">
<property name="name" value="partitioned"/>
<property name="cacheMode" value="PARTITIONED"/>
</bean>

<!--
Replicated cache configuration.
-->
<bean class="org.apache.ignite.cache.GridCacheConfiguration">
<bean class="org.apache.ignite.cache.CacheConfiguration">
<property name="name" value="replicated"/>
<property name="cacheMode" value="REPLICATED"/>
</bean>

<!--
Partitioned cache configuration.
-->
<bean class="org.apache.ignite.cache.GridCacheConfiguration">
<bean class="org.apache.ignite.cache.CacheConfiguration">
<property name="name" value="local"/>
<property name="cacheMode" value="LOCAL"/>
</bean>
Expand Down
8 changes: 4 additions & 4 deletions config/hadoop/default-config.xml
Expand Up @@ -64,7 +64,7 @@
<!--
Abstract cache configuration for GGFS file data to be used as a template.
-->
<bean id="dataCacheCfgBase" class="org.apache.ignite.cache.GridCacheConfiguration" abstract="true">
<bean id="dataCacheCfgBase" class="org.apache.ignite.cache.CacheConfiguration" abstract="true">
<property name="cacheMode" value="PARTITIONED"/>
<property name="atomicityMode" value="TRANSACTIONAL"/>
<property name="writeSynchronizationMode" value="FULL_SYNC"/>
Expand All @@ -80,7 +80,7 @@
<!--
Abstract cache configuration for GGFS metadata to be used as a template.
-->
<bean id="metaCacheCfgBase" class="org.apache.ignite.cache.GridCacheConfiguration" abstract="true">
<bean id="metaCacheCfgBase" class="org.apache.ignite.cache.CacheConfiguration" abstract="true">
<property name="cacheMode" value="REPLICATED"/>
<property name="atomicityMode" value="TRANSACTIONAL"/>
<property name="writeSynchronizationMode" value="FULL_SYNC"/>
Expand Down Expand Up @@ -135,12 +135,12 @@
<property name="cacheConfiguration">
<list>
<!-- File system metadata cache. -->
<bean class="org.apache.ignite.cache.GridCacheConfiguration" parent="metaCacheCfgBase">
<bean class="org.apache.ignite.cache.CacheConfiguration" parent="metaCacheCfgBase">
<property name="name" value="ggfs-meta"/>
</bean>

<!-- File system files data cache. -->
<bean class="org.apache.ignite.cache.GridCacheConfiguration" parent="dataCacheCfgBase">
<bean class="org.apache.ignite.cache.CacheConfiguration" parent="dataCacheCfgBase">
<property name="name" value="ggfs-data"/>
</bean>
</list>
Expand Down
Expand Up @@ -19,12 +19,14 @@

import org.apache.ignite.*;
import org.apache.ignite.cache.*;
import org.apache.ignite.cache.store.*;
import org.apache.ignite.configuration.*;
import org.gridgain.examples.datagrid.store.dummy.*;
import org.apache.ignite.spi.discovery.tcp.*;
import org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.*;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;

import javax.cache.configuration.*;
import java.util.*;

import static org.gridgain.grid.cache.GridCacheAtomicityMode.*;
Expand All @@ -49,6 +51,7 @@ public static void main(String[] args) throws IgniteCheckedException {
* @return Grid configuration.
* @throws IgniteCheckedException If failed.
*/
@SuppressWarnings("unchecked")
public static IgniteConfiguration configure() throws IgniteCheckedException {
IgniteConfiguration cfg = new IgniteConfiguration();

Expand All @@ -68,10 +71,16 @@ public static IgniteConfiguration configure() throws IgniteCheckedException {
// Set atomicity as transaction, since we are showing transactions in example.
cacheCfg.setAtomicityMode(TRANSACTIONAL);

CacheStore store;

// Uncomment other cache stores to try them.
cacheCfg.setStore(new CacheDummyPersonStore());
// cacheCfg.setStore(new CacheJdbcPersonStore());
// cacheCfg.setStore(new CacheHibernatePersonStore());
store = new CacheDummyPersonStore();
// store = new CacheJdbcPersonStore();
// store = new CacheHibernatePersonStore();

cacheCfg.setCacheStoreFactory(new FactoryBuilder.SingletonFactory(store));
cacheCfg.setReadThrough(true);
cacheCfg.setWriteThrough(true);

cfg.setDiscoverySpi(discoSpi);
cfg.setCacheConfiguration(cacheCfg);
Expand Down
Expand Up @@ -24,6 +24,7 @@
import org.apache.ignite.transactions.*;
import org.gridgain.examples.datagrid.store.*;
import org.gridgain.grid.cache.*;
import org.jetbrains.annotations.*;

import javax.cache.*;
import java.util.*;
Expand Down Expand Up @@ -100,4 +101,14 @@ public class CacheDummyPersonStore extends CacheStoreAdapter<Long, Person> {
}
}
}

/**
* @return Current transaction.
*/
@Nullable
private IgniteTx transaction() {
CacheStoreSession ses = session();

return ses != null ? ses.transaction() : null;
}
}
2 changes: 1 addition & 1 deletion modules/clients/src/test/resources/spring-cache.xml
Expand Up @@ -55,7 +55,7 @@
<property name="cacheConfiguration">
<!--
Specify list of cache configurations here. Any property from
GridCacheConfiguration interface can be configured here.
CacheConfiguration interface can be configured here.
Note that absolutely all configuration properties are optional.
-->
<list>
Expand Down
2 changes: 1 addition & 1 deletion modules/clients/src/test/resources/spring-server-node.xml
Expand Up @@ -107,7 +107,7 @@
<property name="cacheConfiguration">
<!--
Specify list of cache configurations here. Any property from
GridCacheConfiguration interface can be configured here.
CacheConfiguration interface can be configured here.
-->
<list>
<!--
Expand Down
Expand Up @@ -91,7 +91,7 @@
<property name="cacheConfiguration">
<!--
Specify list of cache configurations here. Any property from
GridCacheConfiguration interface can be configured here.
CacheConfiguration interface can be configured here.
-->
<list>
<!--
Expand Down
8 changes: 4 additions & 4 deletions modules/core/src/main/java/org/apache/ignite/IgniteCache.java
Expand Up @@ -226,7 +226,7 @@ public interface IgniteCache<K, V> extends javax.cache.Cache<K, V>, IgniteAsyncS
* that entry will be evicted only if it's not used (not
* participating in any locks or transactions).
* <p>
* If {@link org.apache.ignite.cache.CacheConfiguration#isSwapEnabled()} is set to {@code true} and
* If {@link CacheConfiguration#isSwapEnabled()} is set to {@code true} and
* {@link org.gridgain.grid.cache.GridCacheFlag#SKIP_SWAP} is not enabled, the evicted entry will
* be swapped to offheap, and then to disk.
* <h2 class="header">Cache Flags</h2>
Expand All @@ -246,7 +246,7 @@ public interface IgniteCache<K, V> extends javax.cache.Cache<K, V>, IgniteAsyncS
* This method does not participate in any transactions, however, it will
* peek at transactional value according to the {@link org.gridgain.grid.cache.GridCachePeekMode#SMART} mode
* semantics. If you need to look at global cached value even from within transaction,
* you can use {@link org.gridgain.grid.cache.GridCache#peek(Object, java.util.Collection)} method.
* you can use {@link GridCache#peek(Object, java.util.Collection)} method.
*
* @param key Entry key.
* @return Peeked value.
Expand All @@ -273,7 +273,7 @@ public interface IgniteCache<K, V> extends javax.cache.Cache<K, V>, IgniteAsyncS
* Clears an entry from this cache and swap storage only if the entry
* is not currently locked, and is not participating in a transaction.
* <p>
* If {@link org.apache.ignite.cache.CacheConfiguration#isSwapEnabled()} is set to {@code true} and
* If {@link CacheConfiguration#isSwapEnabled()} is set to {@code true} and
* {@link org.gridgain.grid.cache.GridCacheFlag#SKIP_SWAP} is not enabled, the evicted entries will
* also be cleared from swap.
* <p>
Expand Down Expand Up @@ -477,7 +477,7 @@ public interface IgniteCache<K, V> extends javax.cache.Cache<K, V>, IgniteAsyncS
* </pre>
* <p>
* Note that this method makes sense only if cache is working in portable mode
* ({@link org.apache.ignite.cache.CacheConfiguration#isPortableEnabled()} returns {@code true}. If not,
* ({@link CacheConfiguration#isPortableEnabled()} returns {@code true}. If not,
* this method is no-op and will return current projection.
*
* @return Projection for portable objects.
Expand Down
Expand Up @@ -789,26 +789,8 @@ public void setNearStartSize(int nearStartSize) {
}

/**
* Gets underlying persistent storage for read-through and write-through operations.
* If not provided, cache will not exhibit read-through or write-through behavior.
* Gets factory for underlying persistent storage for read-through and write-through operations.
*
* @return Underlying persistent storage for read-through and write-through operations.
*/
@SuppressWarnings({"unchecked"})
public <K, V> CacheStore<K, V> getStore() {
return null;//(CacheStore<K, V>)store;
}

/**
* Sets persistent storage for cache data.
*
* @param store Persistent cache store.
*/
public <K, V> void setStore(CacheStore<K, V> store) {
//this.store = store;
}

/**
* @return Cache store factory.
*/
@SuppressWarnings("unchecked")
Expand All @@ -817,6 +799,8 @@ public <K, V> void setStore(CacheStore<K, V> store) {
}

/**
* Sets factory fpr persistent storage for cache data.
* @param storeFactory Cache store factory.
*/
@SuppressWarnings("unchecked")
Expand Down
Expand Up @@ -70,7 +70,7 @@
* @param <V> Value type.
* @param <I> Input type.
*/
public abstract class CacheLoadOnlyStoreAdapter<K, V, I> implements CacheStore<K, V> {
public abstract class CacheLoadOnlyStoreAdapter<K, V, I> extends CacheStore<K, V> {
/**
* Default batch size (number of records read with {@link #inputIterator(Object...)}
* and then submitted to internal pool at a time).
Expand Down
Expand Up @@ -17,8 +17,8 @@

package org.apache.ignite.cache.store;

import org.apache.ignite.IgnitePortables;
import org.apache.ignite.cache.CacheConfiguration;
import org.apache.ignite.*;
import org.apache.ignite.cache.*;
import org.apache.ignite.cache.store.jdbc.*;
import org.apache.ignite.lang.*;
import org.apache.ignite.portables.*;
Expand Down Expand Up @@ -121,7 +121,10 @@
* @see IgnitePortables
* @see CacheStoreSession
*/
public interface CacheStore<K, V> extends CacheLoader<K, V>, CacheWriter<K, V> {
public abstract class CacheStore<K, V> implements CacheLoader<K, V>, CacheWriter<K, V> {
/** */
private CacheStoreSession ses;

/**
* Loads all values from underlying persistent storage. Note that keys are not
* passed, so it is up to implementation to figure out what to load. This method
Expand All @@ -141,7 +144,7 @@ public interface CacheStore<K, V> extends CacheLoader<K, V>, CacheWriter<K, V> {
* {@link GridCache#loadCache(org.apache.ignite.lang.IgniteBiPredicate, long, Object...)} method.
* @throws CacheLoaderException If loading failed.
*/
public void loadCache(IgniteBiInClosure<K, V> clo, @Nullable Object... args) throws CacheLoaderException;
public abstract void loadCache(IgniteBiInClosure<K, V> clo, @Nullable Object... args) throws CacheLoaderException;

/**
* Tells store to commit or rollback a transaction depending on the value of the {@code 'commit'}
Expand All @@ -152,5 +155,14 @@ public interface CacheStore<K, V> extends CacheLoader<K, V>, CacheWriter<K, V> {
* may bring cache transaction into {@link IgniteTxState#UNKNOWN} which will
* consequently cause all transacted entries to be invalidated.
*/
public void txEnd(boolean commit) throws CacheWriterException;
public abstract void txEnd(boolean commit) throws CacheWriterException;

/**
* Gets session for current cache operation. Returns {@code null} if store is used with atomic cache.
*
* @return Session for current cache operation.
*/
@Nullable public CacheStoreSession session() {
return ses;
}
}
Expand Up @@ -18,10 +18,7 @@
package org.apache.ignite.cache.store;

import org.apache.ignite.lang.*;
import org.apache.ignite.resources.*;
import org.apache.ignite.transactions.*;
import org.gridgain.grid.cache.*;
import org.jetbrains.annotations.*;

import javax.cache.*;
import java.util.*;
Expand All @@ -36,15 +33,11 @@
* it maybe more preferable to take advantage of database batch update functionality, and therefore
* default adapter implementation may not be the best option.
* <p>
* Note that method {@link #loadCache(org.apache.ignite.lang.IgniteBiInClosure, Object...)} has empty
* Note that method {@link #loadCache(IgniteBiInClosure, Object...)} has empty
* implementation because it is essentially up to the user to invoke it with
* specific arguments.
*/
public abstract class CacheStoreAdapter<K, V> implements CacheStore<K, V> {
/** */
@IgniteCacheSessionResource
private CacheStoreSession ses;

public abstract class CacheStoreAdapter<K, V> extends CacheStore<K, V> {
/**
* Default empty implementation. This method needs to be overridden only if
* {@link GridCache#loadCache(IgniteBiPredicate, long, Object...)} method
Expand Down Expand Up @@ -99,18 +92,4 @@ public abstract class CacheStoreAdapter<K, V> implements CacheStore<K, V> {
@Override public void txEnd(boolean commit) {
// No-op.
}

/**
* @return Current session.
*/
@Nullable protected CacheStoreSession session() {
return ses;
}

/**
* @return Current transaction.
*/
@Nullable protected IgniteTx transaction() {
return ses != null ? ses.transaction() : null;
}
}
Expand Up @@ -33,7 +33,7 @@
/**
* Cache store wrapper that ensures that there will be no more that one thread loading value from underlying store.
*/
public class CacheStoreBalancingWrapper<K, V> implements CacheStore<K, V> {
public class CacheStoreBalancingWrapper<K, V> extends CacheStore<K, V> {
/** */
public static final int DFLT_LOAD_ALL_THRESHOLD = 5;

Expand Down
Expand Up @@ -574,4 +574,13 @@ protected <X> X fromBytes(byte[] bytes) throws IgniteCheckedException {

return marsh.unmarshal(bytes, getClass().getClassLoader());
}

/**
* @return Current transaction.
*/
@Nullable private IgniteTx transaction() {
CacheStoreSession ses = session();

return ses != null ? ses.transaction() : null;
}
}

0 comments on commit eafa114

Please sign in to comment.