blob: 8df8b3b02d644cd91ef95cc98c8376904f094c6a [file] [log] [blame]
<!--
▄▄▄ ██▓███ ▄▄▄ ▄████▄ ██░ ██ ▓█████ ██▓ ▄████ ███▄ █ ██▓▄▄▄█████▓▓█████
▒████▄ ▓██░ ██▒▒████▄ ▒██▀ ▀█ ▓██░ ██▒▓█ ▀ ▓██▒ ██▒ ▀█▒ ██ ▀█ █ ▓██▒▓ ██▒ ▓▒▓█ ▀
▒██ ▀█▄ ▓██░ ██▓▒▒██ ▀█▄ ▒▓█ ▄ ▒██▀▀██░▒███ ▒██▒▒██░▄▄▄░▓██ ▀█ ██▒▒██▒▒ ▓██░ ▒░▒███
░██▄▄▄▄██ ▒██▄█▓▒ ▒░██▄▄▄▄██ ▒▓▓▄ ▄██▒░▓█ ░██ ▒▓█ ▄ ░██░░▓█ ██▓▓██▒ ▐▌██▒░██░░ ▓██▓ ░ ▒▓█ ▄
▓█ ▓██▒▒██▒ ░ ░ ▓█ ▓██▒▒ ▓███▀ ░░▓█▒░██▓░▒████▒ ░██░░▒▓███▀▒▒██░ ▓██░░██░ ▒██▒ ░ ░▒████▒
▒▒ ▓▒█░▒▓▒░ ░ ░ ▒▒ ▓▒█░░ ░▒ ▒ ░ ▒ ░░▒░▒░░ ▒░ ░ ░▓ ░▒ ▒ ░ ▒░ ▒ ▒ ░▓ ▒ ░░ ░░ ▒░ ░
▒ ▒▒ ░░▒ ░ ▒ ▒▒ ░ ░ ▒ ▒ ░▒░ ░ ░ ░ ░ ▒ ░ ░ ░ ░ ░░ ░ ▒░ ▒ ░ ░ ░ ░ ░
░ ▒ ░░ ░ ▒ ░ ░ ░░ ░ ░ ▒ ░░ ░ ░ ░ ░ ░ ▒ ░ ░ ░
░ ░ ░ ░░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░
-->
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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
"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.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="canonical" href="https://ignite.apache.org/features/datastructures.html" />
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<title>Distributed Data Structures - Apache Ignite</title>
<!--#include virtual="/includes/styles.html" -->
<!--#include virtual="/includes/sh.html" -->
</head>
<body>
<!--#include virtual="/includes/header.html" -->
<article>
<header>
<div class="container">
<h1 >Distributed <strong>Data Structures</strong></h1>
</div>
</header>
<div class="container">
<p>
Apache Ignite® allows for most of the data structures from <code>java.util.concurrent</code> framework to be used in a distributed fashion. For example, you can take <code>java.util.concurrent.BlockingDeque</code> and add something to it on one node and poll it from another node. Or have a distributed ID generator, which would guarantee uniqueness of IDs on all nodes.
</p>
<h2>Supported Data Structures:</h2>
<ul class="page-list">
<li><a href="/use-cases/datagrid.html">Concurrent Map (Cache)</a></li>
<li><a href="http://apacheignite.readme.io/docs/queue-and-set" target="docs">Distributed Queues and Sets</a></li>
<li><a href="http://apacheignite.readme.io/docs/atomic-types" target="docs">AtomicLong</a></li>
<li><a href="http://apacheignite.readme.io/docs/atomic-types" target="docs">AtomicReference</a></li>
<li><a href="http://apacheignite.readme.io/docs/id-generator" target="docs">AtomicSequence (ID Generator)</a></li>
<li><a href="http://apacheignite.readme.io/docs/countdownlatch" target="docs">CountDownLatch</a></li>
<li><a href="http://apacheignite.readme.io/docs/executor-service" target="docs">ExecutorService</a></li>
</ul>
<h2>Code Examples:</h2>
<!-- Nav tabs -->
<ul id="datastructure-examples" class="nav nav-tabs">
<li><a class="active" href="#example-queue" aria-controls="home" data-toggle="tab">BlockingQueue</a></li>
<li><a href="#example-set" aria-controls="profile" data-toggle="tab">Set</a></li>
<li><a href="#example-sequence" aria-controls="profile" data-toggle="tab">AtomicSequence</a></li>
<li><a href="#example-long" aria-controls="profile" data-toggle="tab">AtomicLong</a></li>
<li><a href="#example-ref" aria-controls="profile" data-toggle="tab">AtomicReference</a></li>
<li><a href="#example-countdownlatch" aria-controls="profile" data-toggle="tab">CountDownLatch</a></li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane active" id="example-queue">
<pre class="brush:java">
Ignite ignite = Ignition.ignite();
// Non-colocated queue which will be distributed
// across all data nodes.
IgniteQueue&lt;String&gt; queue = ignite.queue("queueName", 20, new CollectionConfiguration());
// Add queue elements.
for (int i = 0; i < 20; i++)
queue.add("Value " + Integer.toString(i));
// Poll queue elements.
for (int i = 0; i < 20; i++)
System.out.println("Polled value: " + queue.poll());
</pre>
</div>
<div class="tab-pane" id="example-set">
<pre class="brush:java">
Ignite ignite = Ignition.ignite();
// Initialize new set.
IgniteSet&lt;String&gt; set = ignite.set("setName", null);
// Add set elements.
for (int i = 0; i < 10; i++)
set.add(Integer.toString(i));
// Iterate over set.
for (String item : set)
System.out.println("Set item: " + item);
</pre>
</div>
<div class="tab-pane" id="example-sequence">
<pre class="brush:java">
Ignite ignite = Ignition.ignite();
// Initialize atomic sequence.
IgniteAtomicSequence seq = ignite.atomicSequence("seqName", 0, true);
for (int i = 0; i < 100; i++)
System.out.println("Next sequence value: " + seq.incrementAndGet());
</pre>
</div>
<div class="tab-pane" id="example-long">
<pre class="brush:java">
Ignite ignite = Ignition.ignite();
// Initialize atomic long.
IgniteAtomicLong atomicLong = ignite.atomicLong("myAtomicLong", 0, true);
for (int i = 0; i < 100; i++)
System.out.println("Incremented value: " + atomicLong.incrementAndGet());
</pre>
</div>
<div class="tab-pane" id="example-ref">
<pre class="brush:java">
Ignite ignite = Ignition.ignite();
String val = "123";
// Initialize distributed atomic reference.
IgniteAtomicReference&lt;String&gt; ref = ignite.atomicReference(refName, val, true);
ref.compareAndSet(val, "456");
</pre>
</div>
<div class="tab-pane" id="example-countdownlatch">
<pre class="brush:java">
Ignite ignite = Ignition.ignite();
// Initialize distributed count down latch.
final IgniteCountDownLatch latch = ignite.countDownLatch(latchName, 10, false, true);
IgniteCompute asyncCompute = ignite.compute().withAsync();
// Asynchronously execute closures on the cluster
// which will simply count down the latch on remote nodes.
for (int i = 0; i < 10; i++)
asyncCompute.run(() -> latch.countDown());
// Wait for all closures to complete.
latch.await();
</pre>
</div>
</div>
<h2>GitHub Examples:</h2>
<p>
Also see <a href="https://github.com/apache/ignite/tree/master/examples/src/main/java/org/apache/ignite/examples/datastructures" target="github">data structure examples</a>
available on GitHub.
</p>
<h2>Data Structure Features</h2>
<table class="table table-bordered table-striped" name="Data Structure Features">
<thead>
<tr>
<th width="35%" class="left">Feature</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="left">Queue and Set</td>
<td>
<p>
Ignite provides an implementation of a fast <b>Distributed Blocking Queue</b> and <b>Distributed Set</b>.
</p>
<div class="page-links">
<a href="https://apacheignite.readme.io/docs/queue-and-set" target="docs">Docs for this feature <i class="fa fa-angle-double-right"></i></a>
</div>
</td>
</tr>
<tr>
<td class="left">Collocated vs. Non-Collocated</td>
<td>
<p>
Queues and Sets can be deployed in <code>collocated</code> or
<span style="white-space: nowrap"><code>non-collocated</code></span> mode. In <i>collocated</i>
mode all the elements of a collection will reside on the same cluster node. This
mode should be used for relatively small collections. In <i>non-collocated</i> mode, the
elements of the collection will be equally distributed within the cluster allowing
to keep very large collections in memory.
</p>
<div class="page-links">
<a href="http://apacheignite.readme.io/docs/queue-and-set" target="docs">Docs for this Feature <i class="fa fa-angle-double-right"></i></a>
</div>
</td>
</tr>
<tr>
<td class="left">Bounded Queues</td>
<td>
<p>
Bounded queues allow users to have queues with predefined maximum size which gives a better
control over the overall cache capacity.
</p>
<div class="page-links">
<a href="http://apacheignite.readme.io/docs/queue-and-set#bounded-queues" target="docs">Docs for this Feature <i class="fa fa-angle-double-right"></i></a>
</div>
</td>
</tr>
<tr>
<td class="left">Atomic Types</td>
<td>
<p>
Ignite supports distributed <b>AtomicLong</b> and <b>AtomicReference</b>.
</p>
<div class="page-links">
<a href="https://apacheignite.readme.io/docs/atomic-types" target="docs">Docs for this feature <i class="fa fa-angle-double-right"></i></a>
</div>
</td>
</tr>
<tr>
<td class="left">CountDownLatch</td>
<td>
<p>
Ignite CountDownLatch allows you to synchronize jobs on all Ignite nodes.
</p>
<div class="page-links">
<a href="https://apacheignite.readme.io/docs/countdownlatch" target="docs">Docs for this feature <i class="fa fa-angle-double-right"></i></a>
</div>
</td>
</tr>
<tr>
<td class="left">Reservation-based ID Generator</td>
<td>
<p>
ID Generator is implemented with <code>AtomicSequence</code>. Whenever you perform
<code>incrementAndGet()</code> (or any other atomic operation) on an atomic sequence,
the data structure reserves ahead a range of values, which are guaranteed to be unique
across the cluster for this sequence instance.
</p>
<div class="page-links">
<a href="http://apacheignite.readme.io/docs/id-generator" target="docs">Docs for this Feature <i class="fa fa-angle-double-right"></i></a>
</div>
</td>
</tr>
<tr>
<td class="left">Semaphore</td>
<td>
<p>
Ignite's distributed semaphore implementation and behavior is similar to <b>java.util.concurrent.Semaphore</b>.
</p>
<div class="page-links">
<a href="https://apacheignite.readme.io/docs/distributed-semaphore" target="docs">Docs for this feature <i class="fa fa-angle-double-right"></i></a>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</article>
<!--#include virtual="/includes/footer.html" -->
<!--#include virtual="/includes/scripts.html" -->
</body>
</html>