Skip to content

Commit

Permalink
IGNITE-45 - WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Goncharuk committed Mar 6, 2015
1 parent a847b8b commit 1cd95ae
Show file tree
Hide file tree
Showing 4 changed files with 347 additions and 335 deletions.
Expand Up @@ -20,14 +20,17 @@
import org.apache.ignite.*;
import org.apache.ignite.cache.*;
import org.apache.ignite.cache.affinity.*;
import org.apache.ignite.cache.affinity.rendezvous.CacheRendezvousAffinityFunction;
import org.apache.ignite.cache.eviction.*;
import org.apache.ignite.cache.store.*;
import org.apache.ignite.internal.processors.cache.*;
import org.apache.ignite.internal.util.typedef.internal.*;
import org.apache.ignite.spi.indexing.*;
import org.jetbrains.annotations.*;

import javax.cache.Cache;
import javax.cache.configuration.*;
import javax.cache.expiry.ExpiryPolicy;
import java.util.*;

/**
Expand Down Expand Up @@ -329,13 +332,13 @@ public CacheConfiguration() {
*
* @param cfg Configuration to copy.
*/
public CacheConfiguration(CompleteConfiguration cfg) {
public CacheConfiguration(CompleteConfiguration<K, V> cfg) {
super(cfg);

if (!(cfg instanceof CacheConfiguration))
return;

CacheConfiguration cc = (CacheConfiguration)cfg;
CacheConfiguration<K, V> cc = (CacheConfiguration<K, V>)cfg;

/*
* NOTE: MAKE SURE TO PRESERVE ALPHABETIC ORDER!
Expand Down Expand Up @@ -392,13 +395,13 @@ public CacheConfiguration(CompleteConfiguration cfg) {
swapEnabled = cc.isSwapEnabled();
tmLookupClsName = cc.getTransactionManagerLookupClassName();
ttl = cc.getDefaultTimeToLive();
typeMeta = cc.getTypeMetadata();
writeBehindBatchSize = cc.getWriteBehindBatchSize();
writeBehindEnabled = cc.isWriteBehindEnabled();
writeBehindFlushFreq = cc.getWriteBehindFlushFrequency();
writeBehindFlushSize = cc.getWriteBehindFlushSize();
writeBehindFlushThreadCnt = cc.getWriteBehindFlushThreadCount();
writeSync = cc.getWriteSynchronizationMode();
typeMeta = cc.getTypeMetadata();
}

/**
Expand Down Expand Up @@ -483,6 +486,20 @@ public void setDistributionMode(CacheDistributionMode distro) {
this.distro = distro;
}

/**
* @return Near enabled flag.
*/
public boolean isNearEnabled() {
return distro == CacheDistributionMode.NEAR_ONLY || distro == CacheDistributionMode.NEAR_PARTITIONED;
}

/**
* @param nearEnabled Near enabled flag.
*/
public void setNearEnabled(boolean nearEnabled) {
distro = nearEnabled ? CacheDistributionMode.NEAR_PARTITIONED : CacheDistributionMode.PARTITIONED_ONLY;
}

/**
* Gets write synchronization mode. This mode controls whether the main
* caller should wait for update on other nodes to complete or not.
Expand Down Expand Up @@ -688,7 +705,7 @@ public void setEvictMaxOverflowRatio(float evictMaxOverflowRatio) {
/**
* Gets eviction filter to specify which entries should not be evicted
* (except explicit evict by calling {@link IgniteCache#localEvict(Collection)}).
* If {@link org.apache.ignite.cache.eviction.CacheEvictionFilter#evictAllowed(javax.cache.Cache.Entry)} method
* If {@link CacheEvictionFilter#evictAllowed(Cache.Entry)} method
* returns {@code false} then eviction policy will not be notified and entry will
* never be evicted.
* <p>
Expand Down Expand Up @@ -718,8 +735,8 @@ public void setEvictionFilter(CacheEvictionFilter<K, V> evictFilter) {
* When not set, default value is {@link #DFLT_EAGER_TTL}.
* <p>
* <b>Note</b> that this flag only matters for entries expiring based on
* {@link javax.cache.expiry.ExpiryPolicy} and should not be confused with entry
* evictions based on configured {@link org.apache.ignite.cache.eviction.CacheEvictionPolicy}.
* {@link ExpiryPolicy} and should not be confused with entry
* evictions based on configured {@link CacheEvictionPolicy}.
*
* @return Flag indicating whether Ignite will eagerly remove expired entries.
*/
Expand Down Expand Up @@ -1107,7 +1124,7 @@ public void setPreloadBatchSize(int preloadBatchSize) {
* swap is disabled which is defined via {@link #DFLT_SWAP_ENABLED} constant.
* <p>
* Note that this flag may be overridden for cache projection created with flag
* {@link org.apache.ignite.internal.processors.cache.CacheFlag#SKIP_SWAP}.
* {@link CacheFlag#SKIP_SWAP}.
*
* @return {@code True} if swap storage is enabled.
*/
Expand Down Expand Up @@ -1343,7 +1360,7 @@ public void setPreloadTimeout(long preloadTimeout) {
* For better efficiency user should usually make sure that new nodes get placed on
* the same place of consistent hash ring as the left nodes, and that nodes are
* restarted before this delay expires. To place nodes on the same place in consistent hash ring,
* use {@link org.apache.ignite.cache.affinity.rendezvous.CacheRendezvousAffinityFunction#setHashIdResolver(CacheAffinityNodeHashResolver)}
* use {@link CacheRendezvousAffinityFunction#setHashIdResolver(CacheAffinityNodeHashResolver)}
* to make sure that a node maps to the same hash ID event if restarted. As an example,
* node IP address and port combination may be used in this case.
* <p>
Expand Down Expand Up @@ -1408,7 +1425,7 @@ public void setPreloadThrottle(long preloadThrottle) {
* on the same node (they will also be backed up on the same nodes as well).
* <p>
* If not provided, then default implementation will be used. The default behavior
* is described in {@link org.apache.ignite.cache.affinity.CacheAffinityKeyMapper} documentation.
* is described in {@link CacheAffinityKeyMapper} documentation.
*
* @return Mapper to use for affinity key mapping.
*/
Expand All @@ -1418,7 +1435,7 @@ public CacheAffinityKeyMapper getAffinityMapper() {

/**
* Sets custom affinity mapper. If not provided, then default implementation will be used. The default behavior is
* described in {@link org.apache.ignite.cache.affinity.CacheAffinityKeyMapper} documentation.
* described in {@link CacheAffinityKeyMapper} documentation.
*
* @param affMapper Affinity mapper.
*/
Expand Down
@@ -0,0 +1,174 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.ignite.configuration;

import org.apache.ignite.*;
import org.apache.ignite.cache.*;
import org.apache.ignite.cache.eviction.*;

import javax.cache.configuration.*;

import static org.apache.ignite.configuration.CacheConfiguration.*;

/**
* Client cache configuration.
*/
public class ClientCacheConfiguration<K, V> extends MutableConfiguration<K, V> {
/** Cache name. */
private String name;

/** Near enabled flag. */
private boolean nearEnabled;

/** Near cache eviction policy. */
private CacheEvictionPolicy nearEvictPlc;

/** Flag indicating whether eviction is synchronized with near nodes. */
private boolean evictNearSync = DFLT_EVICT_NEAR_SYNCHRONIZED;

/** Default near cache start size. */
private int nearStartSize = DFLT_NEAR_START_SIZE;

/**
* Empty constructor.
*/
public ClientCacheConfiguration() {
// No-op.
}

/**
* @param cfg Configuration to copy.
*/
public ClientCacheConfiguration(CompleteConfiguration<K, V> cfg) {
super(cfg);

// Preserve alphabetic order.
if (cfg instanceof CacheConfiguration) {
CacheConfiguration ccfg = (CacheConfiguration)cfg;

evictNearSync = ccfg.isEvictNearSynchronized();
name = ccfg.getName();
nearEnabled = ccfg.isNearEnabled();
nearEvictPlc = ccfg.getNearEvictionPolicy();
nearStartSize = ccfg.getNearStartSize();
}
else if (cfg instanceof ClientCacheConfiguration) {
ClientCacheConfiguration ccfg = (ClientCacheConfiguration)cfg;

evictNearSync = ccfg.isEvictNearSynchronized();
name = ccfg.getName();
nearEnabled = ccfg.isNearEnabled();
nearEvictPlc = ccfg.getNearEvictionPolicy();
nearStartSize = ccfg.getNearStartSize();
}
}

/**
* Gets cache name. The cache can be accessed via {@link Ignite#jcache(String)} method.
*
* @return Cache name.
*/
public String getName() {
return name;
}

/**
* Sets cache name.
*
* @param name Cache name.
*/
public void setName(String name) {
this.name = name;
}

/**
* Gets near enabled flag.
*
* @return Near enabled flag.
*/
public boolean isNearEnabled() {
return nearEnabled;
}

/**
* Sets near enabled flag.
*
* @param nearEnabled Near enabled flag.
*/
public void setNearEnabled(boolean nearEnabled) {
this.nearEnabled = nearEnabled;
}

/**
* @return Near eviction policy.
*/
public CacheEvictionPolicy getNearEvictionPolicy() {
return nearEvictPlc;
}

/**
* @param nearEvictPlc Near eviction policy.
*/
public void setNearEvictionPolicy(CacheEvictionPolicy nearEvictPlc) {
this.nearEvictPlc = nearEvictPlc;
}

/**
* Gets flag indicating whether eviction on primary node is synchronized with
* near nodes where entry is kept. Default value is {@code true}.
* <p>
* Note that in most cases this property should be set to {@code true} to keep
* cache consistency. But there may be the cases when user may use some
* special near eviction policy to have desired control over near cache
* entry set.
*
* @return {@code true} If eviction is synchronized with near nodes in
* partitioned cache, {@code false} if not.
*/
public boolean isEvictNearSynchronized() {
return evictNearSync;
}

/**
* Sets flag indicating whether eviction is synchronized with near nodes.
*
* @param evictNearSync {@code true} if synchronized, {@code false} if not.
*/
public void setEvictNearSynchronized(boolean evictNearSync) {
this.evictNearSync = evictNearSync;
}

/**
* Gets initial cache size for near cache which will be used to pre-create internal
* hash table after start. Default value is defined by {@link CacheConfiguration#DFLT_NEAR_START_SIZE}.
*
* @return Initial near cache size.
*/
public int getNearStartSize() {
return nearStartSize;
}

/**
* Start size for near cache. This property is only used for {@link CacheMode#PARTITIONED} caching mode.
*
* @param nearStartSize Start size for near cache.
*/
public void setNearStartSize(int nearStartSize) {
this.nearStartSize = nearStartSize;
}
}

0 comments on commit 1cd95ae

Please sign in to comment.