blob: cef6b2e6de919f255d5755ad9c6c2a6168e4775d [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="en">
<head>
<!-- Yandex.Metrika counter -->
<script type="text/javascript" >
(function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
m[i].l=1*new Date();k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)})
(window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym");
ym(72949126, "init", {
clickmap:true,
trackLinks:true,
accurateTrackBounce:true,
webvisor:true
});
</script>
<noscript><div><img src="https://mc.yandex.ru/watch/72949126" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
<!-- /Yandex.Metrika counter -->
<script type='text/javascript'>
window.__lo_site_id = 284467;
(function() {
var wa = document.createElement('script'); wa.type = 'text/javascript'; wa.async = true;
wa.src = 'https://d10lpsik1i8c69.cloudfront.net/w.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(wa, s);
})();
</script>
<link rel="canonical" href="https://ignite.apache.org/releases/latest/javadoc/org/apache/ignite/cache/affinity/AffinityKeyMapped.html" />
<!-- Generated by javadoc (1.8.0_261) on Wed Dec 09 14:33:09 MSK 2020 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>AffinityKeyMapped (Ignite 2.9.1)</title>
<meta name="date" content="2020-12-09">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
<link rel='shortcut icon' href='https://ignite.apache.org/favicon.ico'/>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-61232409-1', 'auto');
ga('send', 'pageview');
</script></head>
<body>
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="AffinityKeyMapped (Ignite 2.9.1)";
}
}
catch(err) {
}
//-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar.top">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.top.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="class-use/AffinityKeyMapped.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../org/apache/ignite/cache/affinity/AffinityKey.html" title="class in org.apache.ignite.cache.affinity"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li><a href="../../../../../org/apache/ignite/cache/affinity/AffinityKeyMapper.html" title="interface in org.apache.ignite.cache.affinity"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../index.html?org/apache/ignite/cache/affinity/AffinityKeyMapped.html" target="_top">Frames</a></li>
<li><a href="AffinityKeyMapped.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../../allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_top");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Required&nbsp;|&nbsp;</li>
<li>Optional</li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Element</li>
</ul>
</div>
<a name="skip.navbar.top">
<!-- -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="subTitle">org.apache.ignite.cache.affinity</div>
<h2 title="Annotation Type AffinityKeyMapped" class="title">Annotation Type AffinityKeyMapped</h2>
</div>
<div class="contentContainer">
<div class="description">
<ul class="blockList">
<li class="blockList">
<hr>
<br>
<pre><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/annotation/Documented.html?is-external=true" title="class or interface in java.lang.annotation">@Documented</a>
<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/annotation/Retention.html?is-external=true" title="class or interface in java.lang.annotation">@Retention</a>(<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/annotation/Retention.html?is-external=true#value--" title="class or interface in java.lang.annotation">value</a>=<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/annotation/RetentionPolicy.html?is-external=true#RUNTIME" title="class or interface in java.lang.annotation">RUNTIME</a>)
<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/annotation/Target.html?is-external=true" title="class or interface in java.lang.annotation">@Target</a>(<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/annotation/Target.html?is-external=true#value--" title="class or interface in java.lang.annotation">value</a>=<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/annotation/ElementType.html?is-external=true#FIELD" title="class or interface in java.lang.annotation">FIELD</a>)
public @interface <span class="memberNameLabel">AffinityKeyMapped</span></pre>
<div class="block">Optional annotation to specify custom key-to-node affinity. Affinity key is a key
which will be used to determine a node on which given cache key will be stored. This
annotation allows to mark a field in the cache key object that will be
used as an affinity key (instead of the entire cache key object that is used for
affinity by default). Note that a class can have only one field annotated
with <code>@AffinityKeyMapped</code> annotation.
<p>
One of the major use cases for this annotation is the routing of grid computations
to the nodes where the data for this computation is cached, the concept
otherwise known as <code>Collocation Of Computations And Data</code>.
<p>
<h1 class="header">Mapping Cache Keys</h1>
The default implementation of <a href="../../../../../org/apache/ignite/cache/affinity/AffinityKeyMapper.html" title="interface in org.apache.ignite.cache.affinity"><code>AffinityKeyMapper</code></a>, which will be used
if no explicit affinity mapper is specified in cache configuration, will first look
for any field annotated with <code>@AffinityKeyMapped</code> annotation.
If such field is not found, then the cache key itself will be used for
key-to-node affinity (this means that all objects with the same cache key will always
be routed to the same node). If such field is found, then the value of this
field will be used for key-to-node affinity. This allows to specify alternate
affinity key, other than the cache key itself, whenever needed.
<p>
For example, if a <code>Person</code> object is always accessed together with a <code>Company</code> object
for which this person is an employee, then for better performance and scalability it makes sense to
collocate <code>Person</code> objects together with their <code>Company</code> object when storing them in
cache. To achieve that, cache key used to cache <code>Person</code> objects should have a field or method
annotated with <code>@AffinityKeyMapped</code> annotation, which will provide the value of
the company key for which that person works, like so:
<pre name="code" class="java">
public class PersonKey {
// Person ID used to identify a person.
private String personId;
// Company ID which will be used for affinity.
&#64;AffinityKeyMapped
private String companyId;
...
}
...
// Instantiate person keys.
Object personKey1 = new PersonKey("myPersonId1", "myCompanyId");
Object personKey2 = new PersonKey("myPersonId2", "myCompanyId");
// Both, the company and the person objects will be cached on the same node.
cache.put("myCompanyId", new Company(..));
cache.put(personKey1, new Person(..));
cache.put(personKey2, new Person(..));
</pre>
<p>
<h2 class="header">AffinityKey</h2>
For convenience, you can also optionally use <a href="../../../../../org/apache/ignite/cache/affinity/AffinityKey.html" title="class in org.apache.ignite.cache.affinity"><code>AffinityKey</code></a> class. Here is how a
<code>PersonKey</code> defined above would look using <a href="../../../../../org/apache/ignite/cache/affinity/AffinityKey.html" title="class in org.apache.ignite.cache.affinity"><code>AffinityKey</code></a>:
<pre name="code" class="java">
Object personKey1 = new AffinityKey("myPersonId1", "myCompanyId");
Object personKey2 = new AffinityKey("myPersonId2", "myCompanyId");
// Both, the company and the person objects will be cached on the same node.
cache.put(myCompanyId, new Company(..));
cache.put(personKey1, new Person(..));
cache.put(personKey2, new Person(..));
</pre>
<p>
<h1 class="header">Collocating Computations And Data</h1>
It is also possible to route computations to the nodes where the data is cached. This concept
is otherwise known as <code>Collocation Of Computations And Data</code>. In this case,
<code>@AffinityKeyMapped</code> annotation allows to specify a routing affinity key for a
<a href="../../../../../org/apache/ignite/compute/ComputeJob.html" title="interface in org.apache.ignite.compute"><code>ComputeJob</code></a> or any other grid computation, such as <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Runnable.html?is-external=true" title="class or interface in java.lang"><code>Runnable</code></a>,
<a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Callable.html?is-external=true" title="class or interface in java.util.concurrent"><code>Callable</code></a>, or <a href="../../../../../org/apache/ignite/lang/IgniteClosure.html" title="interface in org.apache.ignite.lang"><code>IgniteClosure</code></a>. It should be attached to a field
that provides affinity key for the computation. Only one annotation per class is allowed.
Whenever such annotation is detected, then <a href="../../../../../org/apache/ignite/spi/loadbalancing/LoadBalancingSpi.html" title="interface in org.apache.ignite.spi.loadbalancing"><code>LoadBalancingSpi</code></a>
will be bypassed, and computation will be routed to the grid node where the specified affinity key is cached.
<p>
For more information about cache affinity also see <a href="../../../../../org/apache/ignite/cache/affinity/AffinityKeyMapper.html" title="interface in org.apache.ignite.cache.affinity"><code>AffinityKeyMapper</code></a> and
<a href="../../../../../org/apache/ignite/cache/affinity/AffinityFunction.html" title="interface in org.apache.ignite.cache.affinity"><code>AffinityFunction</code></a> documentation.
Affinity for a key can be found from any node, regardless of whether it has cache started
or not. If cache is not started, affinity function will be fetched from the remote node
which does have the cache running.</div>
<dl>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../../../../../org/apache/ignite/cache/affinity/AffinityFunction.html" title="interface in org.apache.ignite.cache.affinity"><code>AffinityFunction</code></a>,
<a href="../../../../../org/apache/ignite/cache/affinity/AffinityKeyMapper.html" title="interface in org.apache.ignite.cache.affinity"><code>AffinityKeyMapper</code></a>,
<a href="../../../../../org/apache/ignite/cache/affinity/AffinityKey.html" title="class in org.apache.ignite.cache.affinity"><code>AffinityKey</code></a></dd>
</dl>
</li>
</ul>
</div>
</div>
<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar.bottom">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.bottom.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="class-use/AffinityKeyMapped.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../org/apache/ignite/cache/affinity/AffinityKey.html" title="class in org.apache.ignite.cache.affinity"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li><a href="../../../../../org/apache/ignite/cache/affinity/AffinityKeyMapper.html" title="interface in org.apache.ignite.cache.affinity"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../index.html?org/apache/ignite/cache/affinity/AffinityKeyMapped.html" target="_top">Frames</a></li>
<li><a href="AffinityKeyMapped.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../../allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_bottom");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Required&nbsp;|&nbsp;</li>
<li>Optional</li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Element</li>
</ul>
</div>
<a name="skip.navbar.bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<p class="legalCopy"><small><table width="100%" border="0" cellspacing=0 cellpadding=0 style="padding: 5px"> <tr> <td> <table style="padding-left: 0; margin: 0"> <tbody style="padding: 0; margin: 0"> <tr style="padding: 0; margin: 0"> <td> <a target=_blank href="https://ignite.apache.org"><nobr>2020 Copyright &#169; Apache Software Foundation</nobr></a> </td> </tr> </tbody> </table> </td> <td width="100%" align="right" valign="center"> <a href="https://twitter.com/ApacheIgnite" class="twitter-follow-button" data-show-count="false" data-size="large">Follow @ApacheIgnite</a> </td> </tr> <tr> <td colspan="2" valign="top" align="left"> <table style="padding-left: 0; margin: 0"> <tbody style="padding: 0; margin: 0"> <tr style="padding: 0; margin: 0"> <td> <b>Ignite Database and Caching Platform</b> </td> <td>:&nbsp;&nbsp; ver. <strong>2.9.1</strong> </td> </tr> <tr style="padding: 0; margin: 0"> <td> <b>Release Date</b> </td> <td>:&nbsp;&nbsp; December 9 2020 </td> </tr> </tbody> </table> </td> </tr> </table></small></p>
</body>
</html>