All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hazelcast.client.cache.impl.ClientClusterWideIterator Maven / Gradle / Ivy

/*
 * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved.
 *
 * Licensed 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 com.hazelcast.client.cache.impl;

import com.hazelcast.cache.impl.AbstractClusterWideIterator;
import com.hazelcast.cache.impl.CacheKeyIteratorResult;
import com.hazelcast.client.impl.HazelcastClientInstanceImpl;
import com.hazelcast.client.impl.protocol.ClientMessage;
import com.hazelcast.client.impl.protocol.codec.CacheIterateCodec;
import com.hazelcast.client.spi.ClientContext;
import com.hazelcast.client.spi.impl.ClientInvocation;
import com.hazelcast.client.spi.impl.ClientInvocationFuture;
import com.hazelcast.nio.serialization.Data;
import com.hazelcast.util.ExceptionUtil;

import javax.cache.Cache;
import java.util.Iterator;

/**
 * Client side cluster-wide iterator for {@link com.hazelcast.cache.ICache}.
 * 

* This implementation is used by client implementation of jcache. *

* Note: For more information on the iterator details, see {@link AbstractClusterWideIterator}. * * @param the type of key. * @param the type of value. */ public class ClientClusterWideIterator extends AbstractClusterWideIterator implements Iterator> { private ClientCacheProxy cacheProxy; private ClientContext context; public ClientClusterWideIterator(ClientCacheProxy cacheProxy, ClientContext context) { super(cacheProxy, context.getPartitionService().getPartitionCount()); this.cacheProxy = cacheProxy; this.context = context; advance(); } protected CacheKeyIteratorResult fetch() { ClientMessage request = CacheIterateCodec .encodeRequest(cacheProxy.getNameWithPrefix(), partitionIndex, lastTableIndex, fetchSize); HazelcastClientInstanceImpl client = (HazelcastClientInstanceImpl) context.getHazelcastInstance(); try { ClientInvocation clientInvocation = new ClientInvocation(client, request, partitionIndex); ClientInvocationFuture f = clientInvocation.invoke(); return toObject(CacheIterateCodec.decodeResponse(f.get()).response); } catch (Exception e) { throw ExceptionUtil.rethrow(e); } } @Override protected Data toData(Object obj) { return context.getSerializationService().toData(obj); } @Override protected T toObject(Object data) { return context.getSerializationService().toObject(data); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy