Search in sources :

Example 1 with GridTuple3

use of org.apache.ignite.internal.util.lang.GridTuple3 in project ignite by apache.

the class GridTcpMemcachedNioListener method command.

/**
     * Gets command and command attributes from operation code.
     *
     * @param opCode Operation code.
     * @return Command.
     */
@Nullable
private GridTuple3<GridRestCommand, Boolean, Boolean> command(int opCode) {
    GridRestCommand cmd;
    boolean quiet = false;
    boolean retKey = false;
    switch(opCode) {
        case 0x00:
            cmd = CACHE_GET;
            break;
        case 0x01:
            cmd = CACHE_PUT;
            break;
        case 0x02:
            cmd = CACHE_ADD;
            break;
        case 0x03:
            cmd = CACHE_REPLACE;
            break;
        case 0x04:
            cmd = CACHE_REMOVE;
            break;
        case 0x05:
            cmd = ATOMIC_INCREMENT;
            break;
        case 0x06:
            cmd = ATOMIC_DECREMENT;
            break;
        case 0x07:
            cmd = QUIT;
            break;
        case 0x08:
            cmd = CACHE_REMOVE_ALL;
            break;
        case 0x09:
            cmd = CACHE_GET;
            break;
        case 0x0A:
            cmd = NOOP;
            break;
        case 0x0B:
            cmd = VERSION;
            break;
        case 0x0C:
            cmd = CACHE_GET;
            retKey = true;
            break;
        case 0x0D:
            cmd = CACHE_GET;
            retKey = true;
            break;
        case 0x0E:
            cmd = CACHE_APPEND;
            break;
        case 0x0F:
            cmd = CACHE_PREPEND;
            break;
        case 0x10:
            cmd = CACHE_METRICS;
            break;
        case 0x11:
            cmd = CACHE_PUT;
            quiet = true;
            break;
        case 0x12:
            cmd = CACHE_ADD;
            quiet = true;
            break;
        case 0x13:
            cmd = CACHE_REPLACE;
            quiet = true;
            break;
        case 0x14:
            cmd = CACHE_REMOVE;
            quiet = true;
            break;
        case 0x15:
            cmd = ATOMIC_INCREMENT;
            quiet = true;
            break;
        case 0x16:
            cmd = ATOMIC_DECREMENT;
            quiet = true;
            break;
        case 0x17:
            cmd = QUIT;
            quiet = true;
            break;
        case 0x18:
            cmd = CACHE_REMOVE_ALL;
            quiet = true;
            break;
        case 0x19:
            cmd = CACHE_APPEND;
            quiet = true;
            break;
        case 0x1A:
            cmd = CACHE_PREPEND;
            quiet = true;
            break;
        default:
            return null;
    }
    return new GridTuple3<>(cmd, quiet, retKey);
}
Also used : GridRestCommand(org.apache.ignite.internal.processors.rest.GridRestCommand) GridTuple3(org.apache.ignite.internal.util.lang.GridTuple3) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with GridTuple3

use of org.apache.ignite.internal.util.lang.GridTuple3 in project ignite by apache.

the class GridNodeLocalSelfTest method testNodeLocal.

/**
     * Test node-local values operations.
     *
     * @throws Exception If test failed.
     */
public void testNodeLocal() throws Exception {
    Ignite g = G.ignite(getTestIgniteInstanceName());
    String keyStr = "key";
    int keyNum = 1;
    Date keyDate = new Date();
    GridTuple3 key = F.t(keyNum, keyStr, keyDate);
    ConcurrentMap<Object, Object> nl = g.cluster().nodeLocalMap();
    nl.put(keyStr, "Hello world!");
    nl.put(key, 12);
    assert nl.containsKey(keyStr);
    assert nl.containsKey(key);
    assert !nl.containsKey(keyNum);
    assert !nl.containsKey(F.t(keyNum, keyStr));
    assert "Hello world!".equals(nl.get(keyStr));
    assert (Integer) nl.get(key) == 12;
}
Also used : Ignite(org.apache.ignite.Ignite) Date(java.util.Date) GridTuple3(org.apache.ignite.internal.util.lang.GridTuple3)

Example 3 with GridTuple3

use of org.apache.ignite.internal.util.lang.GridTuple3 in project ignite by apache.

the class GridCacheMapEntry method innerUpdateLocal.

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public GridTuple3<Boolean, Object, EntryProcessorResult<Object>> innerUpdateLocal(GridCacheVersion ver, GridCacheOperation op, @Nullable Object writeObj, @Nullable Object[] invokeArgs, boolean writeThrough, boolean readThrough, boolean retval, boolean keepBinary, @Nullable ExpiryPolicy expiryPlc, boolean evt, boolean metrics, @Nullable CacheEntryPredicate[] filter, boolean intercept, @Nullable UUID subjId, String taskName) throws IgniteCheckedException, GridCacheEntryRemovedException {
    assert cctx.isLocal() && cctx.atomic();
    CacheObject old;
    boolean res = true;
    IgniteBiTuple<Boolean, ?> interceptorRes = null;
    EntryProcessorResult<Object> invokeRes = null;
    synchronized (this) {
        boolean internal = isInternal() || !context().userCache();
        Map<UUID, CacheContinuousQueryListener> lsnrCol = cctx.continuousQueries().updateListeners(internal, false);
        boolean needVal = retval || intercept || op == GridCacheOperation.TRANSFORM || !F.isEmpty(filter) || lsnrCol != null;
        checkObsolete();
        CacheDataRow oldRow = null;
        // Load and remove from swap if it is new.
        if (isNew())
            oldRow = unswap(retval, false);
        old = val;
        boolean readFromStore = false;
        Object old0 = null;
        if (readThrough && needVal && old == null && (cctx.readThrough() && (op == GridCacheOperation.TRANSFORM || cctx.loadPreviousValue()))) {
            old0 = readThrough(null, key, false, subjId, taskName);
            old = cctx.toCacheObject(old0);
            long ttl = CU.TTL_ETERNAL;
            long expireTime = CU.EXPIRE_TIME_ETERNAL;
            if (expiryPlc != null && old != null) {
                ttl = CU.toTtl(expiryPlc.getExpiryForCreation());
                if (ttl == CU.TTL_ZERO) {
                    ttl = CU.TTL_MINIMUM;
                    expireTime = CU.expireTimeInPast();
                } else if (ttl == CU.TTL_NOT_CHANGED)
                    ttl = CU.TTL_ETERNAL;
                else
                    expireTime = CU.toExpireTime(ttl);
            }
            // Detach value before index update.
            old = cctx.kernalContext().cacheObjects().prepareForCache(old, cctx);
            if (old != null)
                storeValue(old, expireTime, ver, oldRow);
            else
                removeValue();
            update(old, expireTime, ttl, ver, true);
        }
        // Apply metrics.
        if (metrics && cctx.cache().configuration().isStatisticsEnabled() && needVal) {
            // PutIfAbsent methods mustn't update hit/miss statistics
            if (op != GridCacheOperation.UPDATE || F.isEmpty(filter) || !cctx.putIfAbsentFilter(filter))
                cctx.cache().metrics0().onRead(old != null);
        }
        // Check filter inside of synchronization.
        if (!F.isEmpty(filter)) {
            boolean pass = cctx.isAllLocked(this, filter);
            if (!pass) {
                if (expiryPlc != null && !readFromStore && !cctx.putIfAbsentFilter(filter) && hasValueUnlocked())
                    updateTtl(expiryPlc);
                Object val = retval ? cctx.cacheObjectContext().unwrapBinaryIfNeeded(CU.value(old, cctx, false), keepBinary, false) : null;
                return new T3<>(false, val, null);
            }
        }
        String transformCloClsName = null;
        CacheObject updated;
        Object key0 = null;
        Object updated0 = null;
        // Calculate new value.
        if (op == GridCacheOperation.TRANSFORM) {
            transformCloClsName = EntryProcessorResourceInjectorProxy.unwrap(writeObj).getClass().getName();
            EntryProcessor<Object, Object, ?> entryProcessor = (EntryProcessor<Object, Object, ?>) writeObj;
            assert entryProcessor != null;
            CacheInvokeEntry<Object, Object> entry = new CacheInvokeEntry<>(key, old, version(), keepBinary, this);
            try {
                Object computed = entryProcessor.process(entry, invokeArgs);
                if (entry.modified()) {
                    updated0 = cctx.unwrapTemporary(entry.getValue());
                    updated = cctx.toCacheObject(updated0);
                } else
                    updated = old;
                key0 = entry.key();
                invokeRes = computed != null ? CacheInvokeResult.fromResult(cctx.unwrapTemporary(computed)) : null;
            } catch (Exception e) {
                updated = old;
                invokeRes = CacheInvokeResult.fromError(e);
            }
            if (!entry.modified()) {
                if (expiryPlc != null && !readFromStore && hasValueUnlocked())
                    updateTtl(expiryPlc);
                return new GridTuple3<>(false, null, invokeRes);
            }
        } else
            updated = (CacheObject) writeObj;
        op = updated == null ? GridCacheOperation.DELETE : GridCacheOperation.UPDATE;
        if (intercept) {
            CacheLazyEntry e;
            if (op == GridCacheOperation.UPDATE) {
                updated0 = value(updated0, updated, keepBinary, false);
                e = new CacheLazyEntry(cctx, key, key0, old, old0, keepBinary);
                Object interceptorVal = cctx.config().getInterceptor().onBeforePut(e, updated0);
                if (interceptorVal == null)
                    return new GridTuple3<>(false, cctx.unwrapTemporary(value(old0, old, keepBinary, false)), invokeRes);
                else {
                    updated0 = cctx.unwrapTemporary(interceptorVal);
                    updated = cctx.toCacheObject(updated0);
                }
            } else {
                e = new CacheLazyEntry(cctx, key, key0, old, old0, keepBinary);
                interceptorRes = cctx.config().getInterceptor().onBeforeRemove(e);
                if (cctx.cancelRemove(interceptorRes))
                    return new GridTuple3<>(false, cctx.unwrapTemporary(interceptorRes.get2()), invokeRes);
            }
            key0 = e.key();
            old0 = e.value();
        }
        boolean hadVal = hasValueUnlocked();
        long ttl = CU.TTL_ETERNAL;
        long expireTime = CU.EXPIRE_TIME_ETERNAL;
        if (op == GridCacheOperation.UPDATE) {
            if (expiryPlc != null) {
                ttl = CU.toTtl(hadVal ? expiryPlc.getExpiryForUpdate() : expiryPlc.getExpiryForCreation());
                if (ttl == CU.TTL_NOT_CHANGED) {
                    ttl = ttlExtras();
                    expireTime = expireTimeExtras();
                } else if (ttl != CU.TTL_ZERO)
                    expireTime = CU.toExpireTime(ttl);
            } else {
                ttl = ttlExtras();
                expireTime = expireTimeExtras();
            }
        }
        if (ttl == CU.TTL_ZERO)
            op = GridCacheOperation.DELETE;
        // Try write-through.
        if (op == GridCacheOperation.UPDATE) {
            // Detach value before index update.
            updated = cctx.kernalContext().cacheObjects().prepareForCache(updated, cctx);
            if (writeThrough)
                // Must persist inside synchronization in non-tx mode.
                cctx.store().put(null, key, updated, ver);
            storeValue(updated, expireTime, ver, oldRow);
            assert ttl != CU.TTL_ZERO;
            update(updated, expireTime, ttl, ver, true);
            if (evt) {
                CacheObject evtOld = null;
                if (transformCloClsName != null && cctx.events().isRecordable(EVT_CACHE_OBJECT_READ)) {
                    evtOld = cctx.unwrapTemporary(old);
                    cctx.events().addEvent(partition(), key, cctx.localNodeId(), null, (GridCacheVersion) null, EVT_CACHE_OBJECT_READ, evtOld, evtOld != null || hadVal, evtOld, evtOld != null || hadVal, subjId, transformCloClsName, taskName, keepBinary);
                }
                if (cctx.events().isRecordable(EVT_CACHE_OBJECT_PUT)) {
                    if (evtOld == null)
                        evtOld = cctx.unwrapTemporary(old);
                    cctx.events().addEvent(partition(), key, cctx.localNodeId(), null, (GridCacheVersion) null, EVT_CACHE_OBJECT_PUT, updated, updated != null, evtOld, evtOld != null || hadVal, subjId, null, taskName, keepBinary);
                }
            }
        } else {
            if (writeThrough)
                // Must persist inside synchronization in non-tx mode.
                cctx.store().remove(null, key);
            removeValue();
            update(null, CU.TTL_ETERNAL, CU.EXPIRE_TIME_ETERNAL, ver, true);
            if (evt) {
                CacheObject evtOld = null;
                if (transformCloClsName != null && cctx.events().isRecordable(EVT_CACHE_OBJECT_READ))
                    cctx.events().addEvent(partition(), key, cctx.localNodeId(), null, (GridCacheVersion) null, EVT_CACHE_OBJECT_READ, evtOld, evtOld != null || hadVal, evtOld, evtOld != null || hadVal, subjId, transformCloClsName, taskName, keepBinary);
                if (cctx.events().isRecordable(EVT_CACHE_OBJECT_REMOVED)) {
                    if (evtOld == null)
                        evtOld = cctx.unwrapTemporary(old);
                    cctx.events().addEvent(partition(), key, cctx.localNodeId(), null, (GridCacheVersion) null, EVT_CACHE_OBJECT_REMOVED, null, false, evtOld, evtOld != null || hadVal, subjId, null, taskName, keepBinary);
                }
            }
            res = hadVal;
        }
        if (res)
            updateMetrics(op, metrics);
        if (lsnrCol != null) {
            long updateCntr = nextPartCounter(AffinityTopologyVersion.NONE);
            cctx.continuousQueries().onEntryUpdated(lsnrCol, key, val, old, internal, partition(), true, false, updateCntr, null, AffinityTopologyVersion.NONE);
            onUpdateFinished(updateCntr);
        }
        cctx.dataStructures().onEntryUpdated(key, op == GridCacheOperation.DELETE, keepBinary);
        if (intercept) {
            if (op == GridCacheOperation.UPDATE)
                cctx.config().getInterceptor().onAfterPut(new CacheLazyEntry(cctx, key, key0, updated, updated0, keepBinary, 0L));
            else
                cctx.config().getInterceptor().onAfterRemove(new CacheLazyEntry(cctx, key, key0, old, old0, keepBinary, 0L));
        }
    }
    return new GridTuple3<>(res, cctx.unwrapTemporary(interceptorRes != null ? interceptorRes.get2() : cctx.cacheObjectContext().unwrapBinaryIfNeeded(old, keepBinary, false)), invokeRes);
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.database.CacheDataRow) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) StorageException(org.apache.ignite.internal.pagemem.wal.StorageException) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) GridTuple3(org.apache.ignite.internal.util.lang.GridTuple3) CacheContinuousQueryListener(org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryListener) EntryProcessor(javax.cache.processor.EntryProcessor) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) UUID(java.util.UUID) T3(org.apache.ignite.internal.util.typedef.T3)

Example 4 with GridTuple3

use of org.apache.ignite.internal.util.lang.GridTuple3 in project ignite by apache.

the class GridConfigurationFinder method getConfigFiles.

/**
     * Lists paths to all Ignite configuration files located in given directory with their
     * last modification timestamps.
     *
     * @param dir Directory.
     * @return Collection of configuration files and their last modification timestamps.
     * @throws IOException Thrown in case of any IO error.
     */
private static List<GridTuple3<String, Long, File>> getConfigFiles(File dir) throws IOException {
    assert dir != null;
    LinkedList<GridTuple3<String, Long, File>> lst = listFiles(dir);
    // Sort.
    Collections.sort(lst, new Comparator<GridTuple3<String, Long, File>>() {

        @Override
        public int compare(GridTuple3<String, Long, File> t1, GridTuple3<String, Long, File> t2) {
            String s1 = t1.get1();
            String s2 = t2.get1();
            String q1 = s1.startsWith(Q_PREFIX) ? s1.substring(Q_PREFIX_LEN + 1) : s1;
            String q2 = s2.startsWith(Q_PREFIX) ? s2.substring(Q_PREFIX_LEN + 1) : s2;
            return q1.compareTo(q2);
        }
    });
    File dflt = new File(U.getIgniteHome() + File.separator + DFLT_CFG);
    if (dflt.exists())
        lst.addFirst(F.t(DFLT_CFG, dflt.lastModified(), dflt));
    return lst;
}
Also used : File(java.io.File) GridTuple3(org.apache.ignite.internal.util.lang.GridTuple3)

Example 5 with GridTuple3

use of org.apache.ignite.internal.util.lang.GridTuple3 in project ignite by apache.

the class GridConfigurationFinder method listFiles.

/**
     * Lists paths to all Ignite configuration files located in given directory with their
     * last modification timestamps.
     *
     * NOTE: default configuration path will be skipped.
     *
     * @param dir Directory.
     * @return Collection of configuration files and their last modification timestamps.
     * @throws IOException Thrown in case of any IO error.
     */
private static LinkedList<GridTuple3<String, Long, File>> listFiles(File dir) throws IOException {
    assert dir != null;
    LinkedList<GridTuple3<String, Long, File>> paths = new LinkedList<>();
    String[] configs = dir.list();
    if (configs != null)
        for (String name : configs) {
            File file = new File(dir, name);
            if (file.isDirectory())
                paths.addAll(listFiles(file));
            else if (file.getName().endsWith(".xml")) {
                try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
                    boolean springCfg = false;
                    boolean ggCfg = false;
                    String line;
                    while ((line = reader.readLine()) != null) {
                        if (line.contains("http://www.springframework.org/schema/beans"))
                            springCfg = true;
                        if (line.contains("class=\"org.apache.ignite.configuration.IgniteConfiguration\""))
                            ggCfg = true;
                        if (springCfg && ggCfg)
                            break;
                    }
                    if (springCfg) {
                        String path = file.getAbsolutePath().substring(U.getIgniteHome().length());
                        if (path.startsWith(File.separator))
                            path = path.substring(File.separator.length());
                        if (!path.equals(DFLT_CFG)) {
                            if (!ggCfg)
                                path = Q_PREFIX + ' ' + path;
                            paths.add(F.t(path, file.lastModified(), file));
                        }
                    }
                }
            }
        }
    return paths;
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) LinkedList(java.util.LinkedList) GridTuple3(org.apache.ignite.internal.util.lang.GridTuple3)

Aggregations

GridTuple3 (org.apache.ignite.internal.util.lang.GridTuple3)6 File (java.io.File)3 BufferedReader (java.io.BufferedReader)2 Nullable (org.jetbrains.annotations.Nullable)2 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 UUID (java.util.UUID)1 EntryProcessor (javax.cache.processor.EntryProcessor)1 Ignite (org.apache.ignite.Ignite)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 StorageException (org.apache.ignite.internal.pagemem.wal.StorageException)1 CacheDataRow (org.apache.ignite.internal.processors.cache.database.CacheDataRow)1 CacheContinuousQueryListener (org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryListener)1 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)1 GridRestCommand (org.apache.ignite.internal.processors.rest.GridRestCommand)1 GridClosureException (org.apache.ignite.internal.util.lang.GridClosureException)1