/** * Returns an iterator for iterating entries in the {@code partitionId}. If {@code prefetchValues} is * {@code true}, all values will be sent along with the keys and no additional data will be fetched when * iterating. If {@code false}, the values will be fetched when iterating the entries. * <p> * The values are not fetched one-by-one but rather in batches. * You may control the size of the batch by changing the {@code fetchSize} parameter. * A too small {@code fetchSize} can affect performance since more data will have to be sent to and from the partition owner. * A too high {@code fetchSize} means that more data will be sent which can block other operations from being sent, * including internal operations. * The underlying implementation may send more values in one batch than {@code fetchSize} if it needs to get to * a "safepoint" to later resume iteration. * <p> * <b>NOTE</b> * Iterating the map should be done only when the {@link IMap} is not being * mutated and the cluster is stable (there are no migrations or membership changes). * In other cases, the iterator may not return some entries or may return an entry twice. * * @param fetchSize the size of the batches which will be sent when iterating the data * @param partitionId the partition ID which is being iterated * @return the iterator for the projected entries */ public Iterator<Entry<K, V>> iterator(int fetchSize, int partitionId, boolean prefetchValues) { return new ClientMapPartitionIterator<K, V>(this, getContext(), fetchSize, partitionId, prefetchValues); }
/** * Returns an iterator for iterating entries in the {@code partitionId}. If {@code prefetchValues} is * {@code true}, all values will be sent along with the keys and no additional data will be fetched when * iterating. If {@code false}, the values will be fetched when iterating the entries. * <p> * The values are not fetched one-by-one but rather in batches. * You may control the size of the batch by changing the {@code fetchSize} parameter. * A too small {@code fetchSize} can affect performance since more data will have to be sent to and from the partition owner. * A too high {@code fetchSize} means that more data will be sent which can block other operations from being sent, * including internal operations. * The underlying implementation may send more values in one batch than {@code fetchSize} if it needs to get to * a "safepoint" to later resume iteration. * <p> * <b>NOTE</b> * Iterating the map should be done only when the {@link IMap} is not being * mutated and the cluster is stable (there are no migrations or membership changes). * In other cases, the iterator may not return some entries or may return an entry twice. * * @param fetchSize the size of the batches which will be sent when iterating the data * @param partitionId the partition ID which is being iterated * @return the iterator for the projected entries */ public Iterator<Entry<K, V>> iterator(int fetchSize, int partitionId, boolean prefetchValues) { return new ClientMapPartitionIterator<K, V>(this, getContext(), fetchSize, partitionId, prefetchValues); }
protected void fillPartitionToKeyData(Set<K> keys, Map<Integer, List<Data>> partitionToKeyData, Map<Object, Data> keyMap, Map<Data, Object> reverseKeyMap) { ClientPartitionService partitionService = getContext().getPartitionService(); for (K key : keys) { Data keyData = toData(key); int partitionId = partitionService.getPartitionId(keyData); List<Data> keyList = partitionToKeyData.get(partitionId); if (keyList == null) { keyList = new ArrayList<Data>(); partitionToKeyData.put(partitionId, keyList); } keyList.add(keyData); if (keyMap != null) { keyMap.put(key, keyData); } if (reverseKeyMap != null) { reverseKeyMap.put(keyData, key); } } }
protected void fillPartitionToKeyData(Set<K> keys, Map<Integer, List<Data>> partitionToKeyData, Map<Object, Data> keyMap, Map<Data, Object> reverseKeyMap) { ClientPartitionService partitionService = getContext().getPartitionService(); for (K key : keys) { Data keyData = toData(key); int partitionId = partitionService.getPartitionId(keyData); List<Data> keyList = partitionToKeyData.get(partitionId); if (keyList == null) { keyList = new ArrayList<Data>(); partitionToKeyData.put(partitionId, keyList); } keyList.add(keyData); if (keyMap != null) { keyMap.put(key, keyData); } if (reverseKeyMap != null) { reverseKeyMap.put(keyData, key); } } }
@Override public void putAll(Map<? extends K, ? extends V> map) { ClientPartitionService partitionService = getContext().getPartitionService(); int partitionCount = partitionService.getPartitionCount(); Map<Integer, List<Map.Entry<Data, Data>>> entryMap = new HashMap<Integer, List<Map.Entry<Data, Data>>>(partitionCount); for (Entry<? extends K, ? extends V> entry : map.entrySet()) { checkNotNull(entry.getKey(), NULL_KEY_IS_NOT_ALLOWED); checkNotNull(entry.getValue(), NULL_VALUE_IS_NOT_ALLOWED); Data keyData = toData(entry.getKey()); int partitionId = partitionService.getPartitionId(keyData); List<Map.Entry<Data, Data>> partition = entryMap.get(partitionId); if (partition == null) { partition = new ArrayList<Map.Entry<Data, Data>>(); entryMap.put(partitionId, partition); } partition.add(new AbstractMap.SimpleEntry<Data, Data>(keyData, toData(entry.getValue()))); } putAllInternal(map, entryMap); }
@Override public void putAll(Map<? extends K, ? extends V> map) { ClientPartitionService partitionService = getContext().getPartitionService(); int partitionCount = partitionService.getPartitionCount(); Map<Integer, List<Map.Entry<Data, Data>>> entryMap = new HashMap<Integer, List<Map.Entry<Data, Data>>>(partitionCount); for (Entry<? extends K, ? extends V> entry : map.entrySet()) { checkNotNull(entry.getKey(), NULL_KEY_IS_NOT_ALLOWED); checkNotNull(entry.getValue(), NULL_VALUE_IS_NOT_ALLOWED); Data keyData = toData(entry.getKey()); int partitionId = partitionService.getPartitionId(keyData); List<Map.Entry<Data, Data>> partition = entryMap.get(partitionId); if (partition == null) { partition = new ArrayList<Map.Entry<Data, Data>>(); entryMap.put(partitionId, partition); } partition.add(new AbstractMap.SimpleEntry<Data, Data>(keyData, toData(entry.getValue()))); } putAllInternal(map, entryMap); }
@Override public Set<Entry<K, V>> entrySet() { ClientMessage request = MapEntrySetCodec.encodeRequest(name); ClientMessage response = invoke(request); MapEntrySetCodec.ResponseParameters resultParameters = MapEntrySetCodec.decodeResponse(response); InflatableSet.Builder<Entry<K, V>> setBuilder = InflatableSet.newBuilder(resultParameters.response.size()); InternalSerializationService serializationService = getContext().getSerializationService(); for (Entry<Data, Data> row : resultParameters.response) { LazyMapEntry<K, V> entry = new LazyMapEntry<K, V>(row.getKey(), row.getValue(), serializationService); setBuilder.add(entry); } return setBuilder.build(); }
@Override public Set<Entry<K, V>> entrySet() { ClientMessage request = MapEntrySetCodec.encodeRequest(name); ClientMessage response = invoke(request); MapEntrySetCodec.ResponseParameters resultParameters = MapEntrySetCodec.decodeResponse(response); InflatableSet.Builder<Entry<K, V>> setBuilder = InflatableSet.newBuilder(resultParameters.response.size()); InternalSerializationService serializationService = ((InternalSerializationService) getContext() .getSerializationService()); for (Entry<Data, Data> row : resultParameters.response) { LazyMapEntry<K, V> entry = new LazyMapEntry<K, V>(row.getKey(), row.getValue(), serializationService); setBuilder.add(entry); } return setBuilder.build(); }
private <T> T invoke(ClientMessage clientMessage, Object key, long invocationTimeoutSeconds) { final int partitionId = getContext().getPartitionService().getPartitionId(key); try { ClientInvocation clientInvocation = new ClientInvocation(getClient(), clientMessage, getName(), partitionId); clientInvocation.setInvocationTimeoutMillis(invocationTimeoutSeconds); final Future future = clientInvocation.invoke(); return (T) future.get(); } catch (Exception e) { throw rethrow(e); } }
@Override protected void onInitialize() { super.onInitialize(); lockReferenceIdGenerator = getClient().getLockReferenceIdGenerator(); queryCacheContext = getContext().getQueryCacheContext(); eventJournalReadResponseDecoder = new ClientMessageDecoder() { @Override public ReadResultSet<?> decodeClientMessage(ClientMessage message) { final MapEventJournalReadCodec.ResponseParameters params = MapEventJournalReadCodec.decodeResponse(message); final PortableReadResultSet<?> resultSet = new PortableReadResultSet<Object>( params.readCount, params.items, params.itemSeqs, params.nextSeqExist ? params.nextSeq : ReadResultSet.SEQUENCE_UNAVAILABLE); resultSet.setSerializationService(getSerializationService()); return resultSet; } }; eventJournalSubscribeResponseDecoder = new ClientMessageDecoder() { @Override public EventJournalInitialSubscriberState decodeClientMessage(ClientMessage message) { final ResponseParameters resp = MapEventJournalSubscribeCodec.decodeResponse(message); return new EventJournalInitialSubscriberState(resp.oldestSequence, resp.newestSequence); } }; }
private ClientInvocationFuture invokeOnKeyOwner(ClientMessage request, Data keyData) { int partitionId = getContext().getPartitionService().getPartitionId(keyData); ClientInvocation clientInvocation = new ClientInvocation(getClient(), request, getName(), partitionId); return clientInvocation.invoke(); }
private <T> T invoke(ClientMessage clientMessage, Object key, long invocationTimeoutSeconds) { final int partitionId = getContext().getPartitionService().getPartitionId(key); try { ClientInvocation clientInvocation = new ClientInvocation(getClient(), clientMessage, getName(), partitionId); clientInvocation.setInvocationTimeoutMillis(invocationTimeoutSeconds); final Future future = clientInvocation.invoke(); return (T) future.get(); } catch (Exception e) { throw rethrow(e); } }
@Override protected void onInitialize() { super.onInitialize(); lockReferenceIdGenerator = getClient().getLockReferenceIdGenerator(); queryCacheContext = getContext().getQueryCacheContext(); eventJournalReadResponseDecoder = new ClientMessageDecoder() { @Override public ReadResultSet<?> decodeClientMessage(ClientMessage message) { final MapEventJournalReadCodec.ResponseParameters params = MapEventJournalReadCodec.decodeResponse(message); final PortableReadResultSet<?> resultSet = new PortableReadResultSet<Object>( params.readCount, params.items, params.itemSeqs, params.nextSeqExist ? params.nextSeq : ReadResultSet.SEQUENCE_UNAVAILABLE); resultSet.setSerializationService(getSerializationService()); return resultSet; } }; eventJournalSubscribeResponseDecoder = new ClientMessageDecoder() { @Override public EventJournalInitialSubscriberState decodeClientMessage(ClientMessage message) { final ResponseParameters resp = MapEventJournalSubscribeCodec.decodeResponse(message); return new EventJournalInitialSubscriberState(resp.oldestSequence, resp.newestSequence); } }; }
@Override public Set<Entry<K, V>> entrySet(Predicate predicate) { if (containsPagingPredicate(predicate)) { return entrySetWithPagingPredicate(predicate); } ClientMessage request = MapEntriesWithPredicateCodec.encodeRequest(name, toData(predicate)); ClientMessage response = invokeWithPredicate(request, predicate); MapEntriesWithPredicateCodec.ResponseParameters resultParameters = MapEntriesWithPredicateCodec.decodeResponse(response); InflatableSet.Builder<Entry<K, V>> setBuilder = InflatableSet.newBuilder(resultParameters.response.size()); InternalSerializationService serializationService = getContext().getSerializationService(); for (Entry<Data, Data> row : resultParameters.response) { LazyMapEntry<K, V> entry = new LazyMapEntry<K, V>(row.getKey(), row.getValue(), serializationService); setBuilder.add(entry); } return setBuilder.build(); }
private ClientInvocationFuture invokeOnKeyOwner(ClientMessage request, Data keyData) { int partitionId = getContext().getPartitionService().getPartitionId(keyData); ClientInvocation clientInvocation = new ClientInvocation(getClient(), request, getName(), partitionId); return clientInvocation.invoke(); }
@Override public Set<Entry<K, V>> entrySet(Predicate predicate) { if (containsPagingPredicate(predicate)) { return entrySetWithPagingPredicate(predicate); } ClientMessage request = MapEntriesWithPredicateCodec.encodeRequest(name, toData(predicate)); ClientMessage response = invokeWithPredicate(request, predicate); MapEntriesWithPredicateCodec.ResponseParameters resultParameters = MapEntriesWithPredicateCodec.decodeResponse(response); InflatableSet.Builder<Entry<K, V>> setBuilder = InflatableSet.newBuilder(resultParameters.response.size()); InternalSerializationService serializationService = ((InternalSerializationService) getContext() .getSerializationService()); for (Entry<Data, Data> row : resultParameters.response) { LazyMapEntry<K, V> entry = new LazyMapEntry<K, V>(row.getKey(), row.getValue(), serializationService); setBuilder.add(entry); } return setBuilder.build(); }
checkNotNull(predicate, NULL_PREDICATE_IS_NOT_ALLOWED); checkNotPagingPredicate(predicate, "iterator"); return new ClientMapQueryPartitionIterator<K, V, R>(this, getContext(), fetchSize, partitionId, predicate, projection);
checkNotNull(predicate, NULL_PREDICATE_IS_NOT_ALLOWED); checkNotPagingPredicate(predicate, "iterator"); return new ClientMapQueryPartitionIterator<K, V, R>(this, getContext(), fetchSize, partitionId, predicate, projection);