private static boolean isCacheEmpty(Message message) { boolean emptyCache = true; if (message.hasCache()) { ConcurrentMap<String, IoBufferEx> cache = message.getCache(); emptyCache = cache.isEmpty(); } return emptyCache; }
private static boolean isCacheEmpty(Message message) { boolean emptyCache = true; if (message.hasCache()) { ConcurrentMap<String, IoBufferEx> cache = message.getCache(); emptyCache = cache.isEmpty(); } return emptyCache; } }
protected final <T extends Message> IoBufferEx encode(String cacheKey, MessageEncoder<T> encoder, T message, IoBufferAllocatorEx<?> allocator, int flags) { ConcurrentMap<String, IoBufferEx> cache = message.getCache(); // if cache is not initialized, throw exception (caller should guard) if (cache == null) { throw new IllegalStateException("Cache not initialized"); } // lookup existing cached encoding entry IoBufferEx cachedBuffer = cache.get(cacheKey); if (cachedBuffer == null) { // when cachedBuffer is null, perform encode, then cache the result // with standard atomic race condition awareness (put-if-absent) if ((flags & FLAG_ZERO_COPY) != 0) { if (!cache.isEmpty()) { flags &= ~FLAG_ZERO_COPY; } } IoBufferEx newCachedBuffer = encoder.encode(allocator, message, flags); if (newCachedBuffer instanceof MessageBuffer<?>) { MessageBuffer<?> cacheableBuffer = (MessageBuffer<?>) newCachedBuffer; cacheableBuffer.setAutoCache(true); } cachedBuffer = cache.putIfAbsent(cacheKey, newCachedBuffer); if (cachedBuffer == null) { cachedBuffer = newCachedBuffer; } } return cachedBuffer; }
String nextProtocol = BridgeSession.LOCAL_ADDRESS.get(session).getOption(ResourceAddress.NEXT_PROTOCOL); if (message.hasCache()) { IoBufferEx cachedProtocolBuffer = message.getCache().get(nextProtocol); if (cachedProtocolBuffer != null) { if(cachedProtocolBuffer.capacity()==0) {