Skip to content

Commit

Permalink
Ignite-99-2 review
Browse files Browse the repository at this point in the history
  • Loading branch information
Yakov Zhdanov committed Jan 23, 2015
1 parent 885e763 commit 71b2f03
Showing 1 changed file with 15 additions and 9 deletions.
Expand Up @@ -209,8 +209,8 @@ public <K> Map<ClusterNode, Collection<K>> mapKeysToNodes(@Nullable Collection<?
* @param cacheName Cache name. * @param cacheName Cache name.
* @return Cache affinity. * @return Cache affinity.
*/ */
public <K> GridCacheAffinityProxy<K> affinityProxy(String cacheName) { public <K> CacheAffinityProxy<K> affinityProxy(String cacheName) {
return new GridCacheAffinityProxy(cacheName); return new CacheAffinityProxy(cacheName);
} }


/** /**
Expand Down Expand Up @@ -536,30 +536,36 @@ private AffinityAssignmentKey(String cacheName, long topVer) {
/** /**
* Grid cache affinity. * Grid cache affinity.
*/ */
private class GridCacheAffinityProxy<K> implements CacheAffinity<K> { private class CacheAffinityProxy<K> implements CacheAffinity<K> {
/** */
private final String cacheName; private final String cacheName;


/** /**
* @param cacheName Cache name. * @param cacheName Cache name.
*/ */
public GridCacheAffinityProxy(String cacheName) { public CacheAffinityProxy(String cacheName) {
this.cacheName = cacheName; this.cacheName = cacheName;
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
@Override public int partitions() { @Override public int partitions() {
ctx.gateway().readLock();

try { try {
return GridAffinityProcessor.this.affinityCache(cacheName, topologyVersion()).affFunc.partitions(); return affinityCache(cacheName, topologyVersion()).affFunc.partitions();
} }
catch (IgniteCheckedException e) { catch (IgniteCheckedException e) {
throw new IgniteException(e); throw new IgniteException(e);
} }
finally {
ctx.gateway().readUnlock();
}
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
@Override public int partition(K key) { @Override public int partition(K key) {
try { try {
return GridAffinityProcessor.this.affinityCache(cacheName, topologyVersion()).affFunc.partition(key); return affinityCache(cacheName, topologyVersion()).affFunc.partition(key);
} }
catch (IgniteCheckedException e) { catch (IgniteCheckedException e) {
throw new IgniteException(e); throw new IgniteException(e);
Expand Down Expand Up @@ -624,7 +630,7 @@ public GridCacheAffinityProxy(String cacheName) {
try { try {
Collection<Integer> parts = new HashSet<>(); Collection<Integer> parts = new HashSet<>();


AffinityInfo affInfo= GridAffinityProcessor.this.affinityCache(cacheName, topologyVersion()); AffinityInfo affInfo = affinityCache(cacheName, topologyVersion());


for (int partsCnt = affInfo.affFunc.partitions(), part = 0; part < partsCnt; part++) { for (int partsCnt = affInfo.affFunc.partitions(), part = 0; part < partsCnt; part++) {
for (ClusterNode affNode : affInfo.assignment.get(part)) { for (ClusterNode affNode : affInfo.assignment.get(part)) {
Expand Down Expand Up @@ -723,7 +729,7 @@ public GridCacheAffinityProxy(String cacheName) {
* @return Topology version. * @return Topology version.
*/ */
private long topologyVersion() { private long topologyVersion() {
return GridAffinityProcessor.this.ctx.discovery().topologyVersion(); return ctx.discovery().topologyVersion();
} }
} }
} }

0 comments on commit 71b2f03

Please sign in to comment.