Tabnine Logo
IgniteInternalCache
Code IndexAdd Tabnine to your IDE (free)

How to use
IgniteInternalCache
in
org.apache.ignite.internal.processors.cache

Best Java code snippets using org.apache.ignite.internal.processors.cache.IgniteInternalCache (Showing top 20 results out of 315)

origin: apache/ignite

  @Override public Void call() throws Exception {
    try (GridNearTxLocal tx = CU.txStartInternal(ctx, cacheView, PESSIMISTIC, REPEATABLE_READ)) {
      GridCacheAtomicReferenceValue<T> ref = cacheView.get(key);
      if (ref == null)
        throw new IgniteException("Failed to find atomic reference with given name: " + name);
      cacheView.put(key, new GridCacheAtomicReferenceValue<>(val));
      tx.commit();
    }
    return null;
  }
});
origin: apache/ignite

/** {@inheritDoc} */
@Override public Affinity affinity() {
  return delegate.get().affinity();
}
origin: apache/ignite

/** {@inheritDoc} */
@Override public CacheConfiguration configuration() {
  return delegate.configuration();
}
origin: apache/ignite

/** {@inheritDoc} */
@Override public boolean containsKey(K key) {
  IgniteInternalCache<K, V> delegate = getDelegateSafe();
  if (isAsync()) {
    setFuture(delegate.containsKeyAsync(key));
    return false;
  }
  else
    return delegate.containsKey(key);
}
origin: apache/ignite

/** {@inheritDoc} */
@Nullable @Override public V getAndPutIfAbsent(K key, V val) throws CacheException {
  IgniteInternalCache<K, V> delegate = getDelegateSafe();
  try {
    if (isAsync()) {
      setFuture(delegate.getAndPutIfAbsentAsync(key, val));
      return null;
    }
    else
      return delegate.getAndPutIfAbsent(key, val);
  }
  catch (IgniteCheckedException | IgniteException e) {
    throw cacheException(e);
  }
}
origin: apache/ignite

/**
 * Success if explicit tx doesn't fail.
 *
 * @param cache Cache instance.
 * @throws Exception If failed.
 */
protected void checkStartTxSuccess(final IgniteInternalCache<Object, Object> cache) throws Exception {
  try (final GridNearTxLocal tx = CU.txStartInternal(cache.context(), cache, PESSIMISTIC, REPEATABLE_READ)) {
    assert tx != null;
    sleepForTxFailure();
    cache.put("key", "val");
    tx.commit();
  }
  assert cache.containsKey("key");
  cache.clear();
}
origin: apache/ignite

/**
 * Fill cache.
 *
 * @throws IgniteCheckedException if failed.
 */
private static Set<Integer> populateCache(IgniteEx ignite, boolean loc, int cnt,
  IgnitePredicate<Integer> expectedEntryFilter) throws IgniteCheckedException {
  IgniteInternalCache<Integer, Person> cache = ignite.cachex(PERSON_CACHE);
  assertNotNull(cache);
  Random rand = new Random();
  HashSet<Integer> exp = new HashSet<>();
  Affinity<Integer> aff = cache.affinity();
  ClusterNode localNode = cache.context().localNode();
  for (int i = 0; i < cnt; i++) {
    int val = rand.nextInt(cnt);
    cache.put(val, new Person(String.valueOf(val), val));
    if (expectedEntryFilter.apply(val) && (!loc || aff.isPrimary(localNode, val)))
      exp.add(val);
  }
  return exp;
}
origin: apache/ignite

/**
 * @throws Exception If failed.
 */
@Test
public void testSystemTxInsideUserTx() throws Exception {
  Assume.assumeFalse("https://issues.apache.org/jira/browse/IGNITE-10473", MvccFeatureChecker.forcedMvcc());
  IgniteKernal ignite = (IgniteKernal)grid(0);
  IgniteCache<Object, Object> jcache = ignite.cache(DEFAULT_CACHE_NAME);
  try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
    jcache.get("1");
    jcache.put("1", "11");
    IgniteInternalCache<Object, Object> utilityCache = ignite.context().cache().utilityCache();
    utilityCache.getAndPutIfAbsent("2", "2");
    try (GridNearTxLocal itx = utilityCache.txStartEx(PESSIMISTIC, REPEATABLE_READ)) {
      assertEquals(null, utilityCache.get("1"));
      assertEquals("2", utilityCache.get("2"));
      assertEquals(null, utilityCache.get("3"));
      utilityCache.getAndPut("3", "3");
      itx.commit();
    }
    jcache.put("2", "22");
    tx.commit();
  }
  checkTransactionsCommitted();
  checkEntries(DEFAULT_CACHE_NAME, "1", "11", "2", "22", "3", null);
  checkEntries(CU.UTILITY_CACHE_NAME, "1", null, "2", "2", "3", "3");
}
origin: apache/ignite

  @Override public Object call() throws Exception {
    qryProc.querySqlFields(cache.context(), qry, null, false, true);
    return null;
  }
}, IgniteSQLException.class, "Multiple statements queries are not supported");
origin: apache/ignite

  /** {@inheritDoc} */
  @Override protected void operation(int key) throws Exception {
    cache.get(key);
  }
}
origin: apache/ignite

((IgniteKernal)grid(0)).getCache(cacheName).getAndPut(new GridCacheInternalKeyImpl("LONG", ""), new GridCacheAtomicLongValue(0));
  ((IgniteKernal)grid(0)).getCache(intCache.getName()).context().queries().sqlMetadata();
((IgniteKernal)grid(0)).getCache(intCache.getName()).remove(new GridCacheInternalKeyImpl("LONG", ""));
origin: apache/ignite

/**
 * Must be called when the grid is up.
 */
private List<Path> getIndexBinPaths() {
  return G.allGrids().stream()
    .map(grid -> (IgniteEx) grid)
    .map(grid -> {
      IgniteInternalCache<Object, Object> cachex = grid.cachex(DEFAULT_CACHE_NAME);
      assertNotNull(cachex);
      FilePageStoreManager pageStoreMgr = (FilePageStoreManager) cachex.context().shared().pageStore();
      assertNotNull(pageStoreMgr);
      File cacheWorkDir = pageStoreMgr.cacheWorkDir(cachex.configuration());
      return cacheWorkDir.toPath().resolve("index.bin");
    })
    .collect(Collectors.toList());
}
origin: apache/ignite

/**
 * Saves task name metadata to utility cache.
 *
 * @param taskName Task name.
 * @throws IgniteCheckedException If failed.
 */
private void saveTaskMetadata(String taskName) throws IgniteCheckedException {
  if (ctx.isDaemon())
    return;
  assert ctx.security().enabled();
  int nameHash = taskName.hashCode();
  // 0 is reserved for no task.
  if (nameHash == 0)
    nameHash = 1;
  GridTaskNameHashKey key = new GridTaskNameHashKey(nameHash);
  IgniteInternalCache<GridTaskNameHashKey, String> tasksMetaCache = taskMetaCache();
  String existingName = tasksMetaCache.get(key);
  if (existingName == null)
    existingName = tasksMetaCache.getAndPutIfAbsent(key, taskName);
  if (existingName != null && !F.eq(existingName, taskName))
    throw new IgniteCheckedException("Task name hash collision for security-enabled node " +
      "[taskName=" + taskName +
      ", existing taskName=" + existingName + ']');
}
origin: apache/ignite

hdr = new GridCacheQueueHeader(IgniteUuid.randomUuid(), cap, colloc, 0, 0, null);
GridCacheQueueHeader old = queueHdrView.withNoRetries().getAndPutIfAbsent(key, hdr);
hdr = queueHdrView.get(key);
origin: apache/ignite

/** {@inheritDoc} */
@Nullable @Override public EntryProcessorResult invoke(
  @Nullable AffinityTopologyVersion topVer,
  Object key,
  EntryProcessor entryProcessor,
  Object... args
) throws IgniteCheckedException {
  return delegate.get().invoke(topVer, key, entryProcessor, args);
}
origin: apache/ignite

/**
 * Generates next affinity key for local node based on current topology. If previous affinity key maps
 * on local node, return previous affinity key to prevent unnecessary file map growth.
 *
 * @param prevAffKey Affinity key of previous block.
 * @return Affinity key.
 */
@SuppressWarnings("ConstantConditions")
public IgniteUuid nextAffinityKey(@Nullable IgniteUuid prevAffKey) {
  // Do not generate affinity key for non-affinity nodes.
  if (!dataCache.context().affinityNode())
    return null;
  UUID nodeId = igfsCtx.kernalContext().localNodeId();
  if (prevAffKey != null && dataCache.affinity().mapKeyToNode(prevAffKey).isLocal())
    return prevAffKey;
  while (true) {
    IgniteUuid key = new IgniteUuid(nodeId, affKeyGen.getAndIncrement());
    if (dataCache.affinity().mapKeyToNode(key).isLocal())
      return key;
  }
}
origin: apache/ignite

/** {@inheritDoc} */
@Override public IgniteInternalFuture<EntryProcessorResult> invokeAsync(
  Object key,
  EntryProcessor entryProcessor,
  Object... args
) {
  return delegate.get().invokeAsync(keyTransformer.transform(key), entryProcessor, args);
}
origin: apache/ignite

if (separated && (cache == null || !cache.containsKey(new GridCacheSetHeaderKey(dsName)))) {
  cacheName += "#" + dsType.name() + "_" + dsName;
  IgnitePredicate<ClusterNode> cacheNodeFilter = cache.context().group().nodeFilter();
origin: apache/ignite

/** {@inheritDoc} */
@Override public boolean containsKeys(Collection keys) {
  return delegate.get().containsKey(transform(keys));
}
origin: apache/ignite

  @Override public GridRestResponse applyx(IgniteInternalFuture<?> f) throws IgniteCheckedException {
    GridCacheRestResponse resp = new GridCacheRestResponse();
    resp.setResponse(f.get());
    if (key != null)
      resp.setAffinityNodeId(c.cache().affinity().mapKeyToNode(key).id().toString());
    return resp;
  }
};
org.apache.ignite.internal.processors.cacheIgniteInternalCache

Javadoc

This interface provides a rich API for working with distributed caches. It includes the following main functionality:
  • Various 'get(..)' methods to synchronously or asynchronously get values from cache. All 'get(..)' methods are transactional and will participate in an ongoing transaction if there is one.
  • Various 'put(..)', 'putIfAbsent(..)', and 'replace(..)' methods to synchronously or asynchronously put single or multiple entries into cache. All these methods are transactional and will participate in an ongoing transaction if there is one.
  • Various 'remove(..)' methods to synchronously or asynchronously remove single or multiple keys from cache. All 'remove(..)' methods are transactional and will participate in an ongoing transaction if there is one.
  • Various 'contains(..)' method to check if cache contains certain keys or values locally.
  • Various 'forEach(..)', 'forAny(..)', and 'reduce(..)' methods to visit every local cache entry within this projection.
  • Various flagsOn(..)', 'flagsOff(..)', and 'projection(..)' methods to set specific flags and filters on a cache projection.
  • Methods like 'keySet(..)', 'values(..)', and 'entrySet(..)' to provide views on cache keys, values, and entries.
  • Various 'peek(..)' methods to peek at values in global or transactional memory, swap storage, or persistent storage.
  • Various 'reload(..)' methods to reload latest values from persistent storage.
  • Various 'promote(..)' methods to load specified keys from swap storage into global cache memory.
  • Various 'lock(..)', 'unlock(..)', and 'isLocked(..)' methods to acquire, release, and check on distributed locks on a single or multiple keys in cache. All locking methods are not transactional and will not enlist keys into ongoing transaction, if any.
  • Various 'clear(..)' methods to clear elements from cache, and optionally from swap storage. All 'clear(..)' methods are not transactional and will not enlist cleared keys into ongoing transaction, if any.
  • Various 'evict(..)' methods to evict elements from cache, and optionally store them in underlying swap storage for later access. All 'evict(..)' methods are not transactional and will not enlist evicted keys into ongoing transaction, if any.
  • Various 'txStart(..)' methods to perform various cache operations within a transaction (see Transaction for more information).
  • Various 'gridProjection(..)' methods which provide ClusterGroup only for nodes on which given keys reside. All 'gridProjection(..)' methods are not transactional and will not enlist keys into ongoing transaction.
Extended Put And Remove Methods All methods that end with 'x' provide the same functionality as their sibling methods that don't end with 'x', however instead of returning a previous value they return a boolean flag indicating whether operation succeeded or not. Returning a previous value may involve a network trip or a persistent store lookup and should be avoided whenever not needed. Predicate Filters All filters passed into methods on this API are checked atomically. In other words the value returned by the methods is guaranteed to be consistent with the filters passed in. Note that filters are optional, and if not passed in, then methods will still work as is without filter validation. Transactions Cache API supports distributed transactions. All 'get(..)', 'put(..)', 'replace(..)', and 'remove(..)' operations are transactional and will participate in an ongoing transaction, if any. Other methods like 'peek(..)' or various 'contains(..)' methods may be transaction-aware, i.e. check in-transaction entries first, but will not affect the current state of transaction. See Transaction documentation for more information about transactions. Group Locking Group Locking is a feature where instead of acquiring individual locks, Ignite will lock multiple keys with one lock to save on locking overhead. There are 2 types of Group Locking: affinity-based, and partitioned-based.

With affinity-based-group-locking the keys are grouped by affinity-key. This means that only keys with identical affinity-key (see AffinityKeyMapped) can participate in the transaction, and only one lock on the affinity-key will be acquired for the whole transaction. Affinity-group-locked transactions are started via txStartAffinity(Object, TransactionConcurrency, TransactionIsolation, long, int) method.

With partition-based-group-locking the keys are grouped by partition ID. This means that only keys belonging to identical partition (see Affinity#partition(Object)) can participate in the transaction, and only one lock on the whole partition will be acquired for the whole transaction. Partition-group-locked transactions are started via txStartPartition(int, TransactionConcurrency, TransactionIsolation, long, int) method.

Group locking should always be used for transactions whenever possible. If your requirements fit either affinity-based or partition-based scenarios outlined above then group-locking can significantly improve performance of your application, often by an order of magnitude.

Null Keys or Values Neither null keys or values are allowed to be stored in cache. If a null value happens to be in cache (e.g. after invalidation or remove), then cache will treat this case as there is no value at all. Peer Class Loading If peer-class-loading is enabled, all classes passed into cache API will be automatically deployed to any participating grid nodes. However, in case of redeployment, caches will be cleared and all entries will be removed. This behavior is useful during development, but should not be used in production. Binary Objects If an object is defined as binary Ignite cache will automatically store it in binary (i.e. binary) format. User can choose to work either with the binary format or with the deserialized form (assuming that class definitions are present in the classpath). By default, cache works with deserialized form (example shows the case when Integer is used as a key for a binary object):
 
IgniteInternalCache prj = Ignition.grid().cache(null); 
// Value will be serialized and stored in cache in binary format. 
prj.put(1, new Value()); 
// Value will be deserialized since it's stored in binary format. 
Value val = prj.get(1); 
You won't be able to work with deserialized form if class definition for the Value is not on classpath. Even if you have the class definition, you should always avoid full deserialization if it's not needed for performance reasons. To work with binary format directly you should create special projection using #keepBinary() method:
 
IgniteInternalCache prj = Ignition.grid().cache(null).keepBinary(); 
// Value is not deserialized and returned in binary format. 
GridBinaryObject po = prj.get(1); 
See #keepBinary() method JavaDoc for more details.

Most used methods

  • context
  • get
    Retrieves value mapped to the specified key from cache. Value will only be returned if its entry pas
  • affinity
    Gets affinity service to provide information about data partitioning and distribution.
  • configuration
    Gets configuration bean for this cache.
  • containsKey
  • getAndPut
    Stores given key-value pair in cache. If filters are provided, then entries will be stored in cache
  • getAndPutIfAbsent
    Stores given key-value pair in cache only if cache had no previous mapping for it. If cache previous
  • invoke
  • invokeAsync
  • put
    Stores given key-value pair in cache. If filters are provided, then entries will be stored in cache
  • size
  • cache
    Gets base cache for this projection.
  • size,
  • cache,
  • clear,
  • clearLocallyAll,
  • isEmpty,
  • isIgfsDataCache,
  • keySet,
  • localEntries,
  • localPeek,
  • lock

Popular in Java

  • Running tasks concurrently on multiple threads
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • putExtra (Intent)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • FileReader (java.io)
    A specialized Reader that reads from a file in the file system. All read requests made by calling me
  • RandomAccessFile (java.io)
    Allows reading from and writing to a file in a random-access manner. This is different from the uni-
  • ResultSet (java.sql)
    An interface for an object which represents a database table entry, returned as the result of the qu
  • BitSet (java.util)
    The BitSet class implements abit array [http://en.wikipedia.org/wiki/Bit_array]. Each element is eit
  • Filter (javax.servlet)
    A filter is an object that performs filtering tasks on either the request to a resource (a servlet o
  • JTable (javax.swing)
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now