Skip to content

Commit

Permalink
IGNITE-1917: Binary protocol performance optimizations.
Browse files Browse the repository at this point in the history
  • Loading branch information
vozerov-gridgain committed Nov 20, 2015
1 parent 5ea0625 commit 4a1af37
Show file tree
Hide file tree
Showing 37 changed files with 3,788 additions and 2,867 deletions.
Expand Up @@ -102,7 +102,6 @@
import org.apache.ignite.internal.processors.cache.GridCacheUtilityKey; import org.apache.ignite.internal.processors.cache.GridCacheUtilityKey;
import org.apache.ignite.internal.processors.cache.IgniteCacheProxy; import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
import org.apache.ignite.internal.processors.cache.IgniteInternalCache; import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
import org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessor;
import org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl; import org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl;
import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor; import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
import org.apache.ignite.internal.processors.clock.GridClockSyncProcessor; import org.apache.ignite.internal.processors.clock.GridClockSyncProcessor;
Expand Down Expand Up @@ -132,7 +131,7 @@
import org.apache.ignite.internal.processors.session.GridTaskSessionProcessor; import org.apache.ignite.internal.processors.session.GridTaskSessionProcessor;
import org.apache.ignite.internal.processors.task.GridTaskProcessor; import org.apache.ignite.internal.processors.task.GridTaskProcessor;
import org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor; import org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor;
import org.apache.ignite.internal.util.GridEnumCache; import org.apache.ignite.internal.portable.BinaryEnumCache;
import org.apache.ignite.internal.util.GridTimerTask; import org.apache.ignite.internal.util.GridTimerTask;
import org.apache.ignite.internal.util.future.GridFinishedFuture; import org.apache.ignite.internal.util.future.GridFinishedFuture;
import org.apache.ignite.internal.util.future.GridFutureAdapter; import org.apache.ignite.internal.util.future.GridFutureAdapter;
Expand Down Expand Up @@ -1941,7 +1940,7 @@ else if (state == STARTING)
// Clean internal class/classloader caches to avoid stopped contexts held in memory. // Clean internal class/classloader caches to avoid stopped contexts held in memory.
U.clearClassCache(); U.clearClassCache();
MarshallerExclusions.clearCache(); MarshallerExclusions.clearCache();
GridEnumCache.clear(); BinaryEnumCache.clear();


gw.writeLock(); gw.writeLock();


Expand Down
Expand Up @@ -15,36 +15,49 @@
* limitations under the License. * limitations under the License.
*/ */


package org.apache.ignite.internal.util; package org.apache.ignite.internal.portable;


import java.util.concurrent.ConcurrentMap; import org.apache.ignite.binary.BinaryObjectException;
import org.jsr166.ConcurrentHashMap8; import org.jsr166.ConcurrentHashMap8;


import java.util.concurrent.ConcurrentMap;

/** /**
* Cache for enum constants. * Cache for enum constants.
*/ */
public class GridEnumCache { public class BinaryEnumCache {
/** Cache for enum constants. */ /** Cache for enum constants. */
private static final ConcurrentMap<Class<?>, Object[]> ENUM_CACHE = new ConcurrentHashMap8<>(); private static final ConcurrentMap<Class<?>, Object[]> ENUM_CACHE = new ConcurrentHashMap8<>();


/** /**
* Gets enum constants for provided class. * Get value for the given class and ordinal.
* *
* @param cls Class. * @param cls Class.
* @return Enum constants. * @param ord Ordinal.
* @return Value.
* @throws BinaryObjectException In case of invalid ordinal.
*/ */
public static Object[] get(Class<?> cls) { @SuppressWarnings("unchecked")
public static <T> T get(Class<?> cls, int ord) throws BinaryObjectException {
assert cls != null; assert cls != null;


Object[] vals = ENUM_CACHE.get(cls); if (ord >= 0) {
Object[] vals = ENUM_CACHE.get(cls);


if (vals == null) { if (vals == null) {
vals = cls.getEnumConstants(); vals = cls.getEnumConstants();


ENUM_CACHE.putIfAbsent(cls, vals); ENUM_CACHE.putIfAbsent(cls, vals);
} }


return vals; if (ord < vals.length)
return (T) vals[ord];
else
throw new BinaryObjectException("Failed to get enum value for ordinal (do you have correct class " +
"version?) [cls=" + cls.getName() + ", ordinal=" + ord + ", totalValues=" + vals.length + ']');
}
else
return null;
} }


/** /**
Expand Down

0 comments on commit 4a1af37

Please sign in to comment.