Package com.hazelcast.map.impl

Examples of com.hazelcast.map.impl.MapServiceContext


        checkTransactionState();
        TxnValueWrapper wrapper = txMap.get(key);
        boolean haveTxnPast = wrapper != null;

        MapService service = getService();
        final MapServiceContext mapServiceContext = service.getMapServiceContext();
        if (haveTxnPast) {
            if (wrapper.type == TxnValueWrapper.Type.REMOVED) {
                return null;
            }
            putInternal(mapServiceContext.toData(key, partitionStrategy), mapServiceContext.toData(value));
            txMap.put(key, new TxnValueWrapper(value, TxnValueWrapper.Type.UPDATED));
            return wrapper.value;
        } else {
            Data oldValue = replaceInternal(mapServiceContext.toData(key, partitionStrategy), mapServiceContext.toData(value));
            if (oldValue != null) {
                txMap.put(key, new TxnValueWrapper(value, TxnValueWrapper.Type.UPDATED));
            }
            return mapServiceContext.toObject(oldValue);
        }
    }
View Full Code Here


        checkTransactionState();
        TxnValueWrapper wrapper = txMap.get(key);
        boolean haveTxnPast = wrapper != null;

        MapService service = getService();
        final MapServiceContext mapServiceContext = service.getMapServiceContext();
        if (haveTxnPast) {
            if (!wrapper.value.equals(oldValue)) {
                return false;
            }
            putInternal(mapServiceContext.toData(key, partitionStrategy), mapServiceContext.toData(newValue));
            txMap.put(key, new TxnValueWrapper(wrapper.value, TxnValueWrapper.Type.UPDATED));
            return true;
        } else {
            boolean success = replaceIfSameInternal(mapServiceContext.toData(key),
                    mapServiceContext.toData(oldValue), mapServiceContext.toData(newValue));
            if (success) {
                txMap.put(key, new TxnValueWrapper(newValue, TxnValueWrapper.Type.UPDATED));
            }
            return success;
        }
View Full Code Here

    public boolean remove(Object key, Object value) {
        checkTransactionState();
        TxnValueWrapper wrapper = txMap.get(key);

        MapService service = getService();
        final MapServiceContext mapServiceContext = service.getMapServiceContext();
        if (wrapper != null && !mapServiceContext.compare(name, wrapper.value, value)) {
            return false;
        }
        boolean removed = removeIfSameInternal(mapServiceContext.toData(key, partitionStrategy), value);
        if (removed) {
            txMap.put(key, new TxnValueWrapper(value, TxnValueWrapper.Type.REMOVED));
        }
        return removed;
    }
View Full Code Here

    }

    public Object remove(Object key) {
        checkTransactionState();
        MapService service = getService();
        final MapServiceContext mapServiceContext = service.getMapServiceContext();
        final Object valueBeforeTxn
                = mapServiceContext.toObject(removeInternal(mapServiceContext.toData(key, partitionStrategy)));
        TxnValueWrapper wrapper = null;
        if (valueBeforeTxn != null || txMap.containsKey(key)) {
            wrapper = txMap.put(key, new TxnValueWrapper(valueBeforeTxn, TxnValueWrapper.Type.REMOVED));
        }
        return wrapper == null ? valueBeforeTxn : checkIfRemoved(wrapper);
View Full Code Here

    }

    public void delete(Object key) {
        checkTransactionState();
        MapService service = getService();
        final MapServiceContext mapServiceContext = service.getMapServiceContext();
        Data data = removeInternal(mapServiceContext.toData(key, partitionStrategy));
        if (data != null || txMap.containsKey(key)) {
            txMap.put(key, new TxnValueWrapper(mapServiceContext.toObject(data), TxnValueWrapper.Type.REMOVED));
        }
    }
View Full Code Here

    public Set<Object> keySet() {
        checkTransactionState();
        final Set<Data> keySet = keySetInternal();
        final Set<Object> keys = new HashSet<Object>(keySet.size());
        final MapService service = getService();
        final MapServiceContext mapServiceContext = service.getMapServiceContext();
        // convert Data to Object
        for (final Data data : keySet) {
            keys.add(mapServiceContext.toObject(data));
        }

        for (final Map.Entry<Object, TxnValueWrapper> entry : txMap.entrySet()) {
            if (TxnValueWrapper.Type.NEW.equals(entry.getValue().type)) {
                keys.add(entry.getKey());
View Full Code Here

        }
        if (predicate instanceof PagingPredicate) {
            throw new NullPointerException("Paging is not supported for Transactional queries!");
        }
        final MapService service = getService();
        final MapServiceContext mapServiceContext = service.getMapServiceContext();
        final QueryResultSet queryResultSet = (QueryResultSet) queryInternal(predicate, IterationType.KEY, false);
        //todo: Can't we just use the original set?
        final Set<Object> keySet = new HashSet<Object>(queryResultSet);

        for (final Map.Entry<Object, TxnValueWrapper> entry : txMap.entrySet()) {
            if (!TxnValueWrapper.Type.REMOVED.equals(entry.getValue().type)) {
                final Object value = entry.getValue().value instanceof Data
                        ? mapServiceContext.toObject(entry.getValue().value) : entry.getValue().value;

                final SerializationService ss = getNodeEngine().getSerializationService();
                final QueryEntry queryEntry =
                        new QueryEntry(ss, mapServiceContext.toData(entry.getKey()), entry.getKey(), value);
                // apply predicate on txMap.
                if (predicate.apply(queryEntry)) {
                    keySet.add(entry.getKey());
                }
            } else {
View Full Code Here

    public Collection<Object> values() {
        checkTransactionState();
        final List<Map.Entry<Data, Data>> entries = getEntries();
        final MapService service = getService();
        final MapServiceContext mapServiceContext = service.getMapServiceContext();
        final Collection<Object> values = new ArrayList<Object>(entries.size());
        final Set<Object> keyWontBeIncluded = new HashSet<Object>();

        for (final Map.Entry<Object, TxnValueWrapper> entry : txMap.entrySet()) {
            final boolean isRemoved = TxnValueWrapper.Type.REMOVED.equals(entry.getValue().type);
            final boolean isUpdated = TxnValueWrapper.Type.UPDATED.equals(entry.getValue().type);

            Object objectKey = entry.getKey();
            if (isRemoved) {
                keyWontBeIncluded.add(objectKey);
            } else {
                if (isUpdated) {
                    keyWontBeIncluded.add(objectKey);
                }
                Object entryValue = entry.getValue().value;
                values.add(entryValue);
            }
        }
        Iterator<Map.Entry<Data, Data>> iterator = entries.iterator();
        while (iterator.hasNext()) {
            final Map.Entry entry = iterator.next();
            Object key = mapServiceContext.toObject(entry.getKey());
            if (keyWontBeIncluded.contains(key)) {
                continue;
            }
            Object value = mapServiceContext.toObject(entry.getValue());
            values.add(value);
        }
        return values;
    }
View Full Code Here

        }
        if (predicate instanceof PagingPredicate) {
            throw new IllegalArgumentException("Paging is not supported for Transactional queries");
        }
        final MapService service = getService();
        final MapServiceContext mapServiceContext = service.getMapServiceContext();
        final QueryResultSet queryResultSet = (QueryResultSet) queryInternal(predicate, IterationType.ENTRY, false);
        //todo: Can't we just use the original set?
        final Set<Object> valueSet = new HashSet<Object>();
        final Set<Object> keyWontBeIncluded = new HashSet<Object>();

        // iterate over the txMap and see if the values are updated or removed.
        for (final Map.Entry<Object, TxnValueWrapper> entry : txMap.entrySet()) {
            final boolean isRemoved = TxnValueWrapper.Type.REMOVED.equals(entry.getValue().type);
            final boolean isUpdated = TxnValueWrapper.Type.UPDATED.equals(entry.getValue().type);

            Object objectKey = entry.getKey();
            if (isRemoved) {
                keyWontBeIncluded.add(objectKey);
            } else {
                if (isUpdated) {
                    keyWontBeIncluded.add(objectKey);
                }
                Object entryValue = entry.getValue().value;
                final Object objectValue = entryValue instanceof Data
                        ? mapServiceContext.toObject(entryValue) : entryValue;
                Data dataKey = mapServiceContext.toData(objectKey);
                final SerializationService serializationService = getNodeEngine().getSerializationService();
                final QueryEntry queryEntry = new QueryEntry(serializationService, dataKey, objectKey, objectValue);
                if (predicate.apply(queryEntry)) {
                    valueSet.add(entryValue);
                }
View Full Code Here

        }
    }

    @Override
    public void run() {
        final MapServiceContext mapServiceContext = mapService.getMapServiceContext();
        final EventService eventService = getNodeEngine().getEventService();
        recordStore.unlock(dataKey, ownerUuid, threadId);
        Record record = recordStore.getRecordOrNull(dataKey);
        if (record == null || version == record.getVersion()) {
            if (eventService.hasEventRegistration(MapService.SERVICE_NAME, getName())) {
                dataOldValue = record == null ? null : mapServiceContext.toData(record.getValue());
            }
            eventType = record == null ? EntryEventType.ADDED : EntryEventType.UPDATED;
            recordStore.set(dataKey, dataValue, ttl);
            shouldBackup = true;
        }
View Full Code Here

TOP

Related Classes of com.hazelcast.map.impl.MapServiceContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.