| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| <!-- NewPage --> |
| <html lang="en"> |
| <head> |
| <META NAME="ROBOTS" CONTENT="NOINDEX"> |
| <link rel="canonical" href="https://ignite.apache.org/releases/1.0.0-rc3/javadoc/org/apache/ignite/cache/affinity/CacheAffinityKeyMapped.html" /> |
| <!-- Generated by javadoc (version 1.7.0_21) on Tue Mar 24 10:27:31 MSK 2015 --> |
| <meta http-equiv="Content-Type" content="text/html" charset="UTF-8"> |
| <title>CacheAffinityKeyMapped (Ignite 1.0.0-RC3)</title> |
| <meta name="date" content="2015-03-24"> |
| <link rel="stylesheet" type="text/css" href="../../../../../javadoc.css" title="Style"> |
| <link rel='shortcut icon' href='http://gridgain.com/wp-content/uploads/2014/09/favicon.ico'/> |
| <link type='text/css' rel='stylesheet' href='http://gridgain.com/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/styles/shCore.css'/> |
| <link type='text/css' rel='stylesheet' href='http://gridgain.com/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/styles/shThemeDefault.css'/> |
| <script type='text/javascript' src='http://gridgain.com/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/scripts/shCore.js'></script> |
| <script type='text/javascript' src='http://gridgain.com/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/scripts/shLegacy.js'></script> |
| <script type='text/javascript' src='http://gridgain.com/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/scripts/shBrushJava.js'></script> |
| <script type='text/javascript' src='http://gridgain.com/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/scripts/shBrushPlain.js'></script> |
| <script type='text/javascript' src='http://gridgain.com/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/scripts/shBrushJScript.js'></script> |
| <script type='text/javascript' src='http://gridgain.com/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/scripts/shBrushBash.js'></script> |
| <script type='text/javascript' src='http://gridgain.com/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/scripts/shBrushXml.js'></script> |
| <script type='text/javascript' src='http://gridgain.com/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/scripts/shBrushScala.js'></script> |
| <script type='text/javascript' src='http://gridgain.com/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/scripts/shBrushGroovy.js'></script> |
| |
| <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"><!-- |
| if (location.href.indexOf('is-external=true') == -1) { |
| parent.document.title="CacheAffinityKeyMapped (Ignite 1.0.0-RC3)"; |
| } |
| //--> |
| </script> |
| <noscript> |
| <div>JavaScript is disabled on your browser.</div> |
| </noscript> |
| <!-- ========= START OF TOP NAVBAR ======= --> |
| <div class="topNav"><a name="navbar_top"> |
| <!-- --> |
| </a><a href="#skip-navbar_top" title="Skip navigation links"></a><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/CacheAffinityKeyMapped.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 class="aboutLanguage"><em>Apache Ignite - In-Memory Data Fabric</em></div> |
| </div> |
| <div class="subNav"> |
| <ul class="navList"> |
| <li><a href="../../../../../org/apache/ignite/cache/affinity/CacheAffinityKey.html" title="class in org.apache.ignite.cache.affinity"><span class="strong">Prev Class</span></a></li> |
| <li><a href="../../../../../org/apache/ignite/cache/affinity/CacheAffinityKeyMapper.html" title="interface in org.apache.ignite.cache.affinity"><span class="strong">Next Class</span></a></li> |
| </ul> |
| <ul class="navList"> |
| <li><a href="../../../../../index.html?org/apache/ignite/cache/affinity/CacheAffinityKeyMapped.html" target="_top">Frames</a></li> |
| <li><a href="CacheAffinityKeyMapped.html" target="_top">No Frames</a></li> |
| </ul> |
| <ul class="navList" id="allclasses_navbar_top"> |
| <li><a href="../../../../../allclasses-noframe.html">All 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: </li> |
| <li>Required | </li> |
| <li>Optional</li> |
| </ul> |
| <ul class="subNavList"> |
| <li>Detail: </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 CacheAffinityKeyMapped" class="title">Annotation Type CacheAffinityKeyMapped</h2> |
| </div> |
| <div class="contentContainer"> |
| <div class="description"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <hr> |
| <br> |
| <pre><a href="http://docs.oracle.com/javase/7/docs/api/java/lang/annotation/Documented.html?is-external=true" title="class or interface in java.lang.annotation">@Documented</a> |
| <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/annotation/Retention.html?is-external=true" title="class or interface in java.lang.annotation">@Retention</a>(<a href="http://docs.oracle.com/javase/7/docs/api/java/lang/annotation/Retention.html?is-external=true#value()" title="class or interface in java.lang.annotation">value</a>=<a href="http://docs.oracle.com/javase/7/docs/api/java/lang/annotation/RetentionPolicy.html?is-external=true#RUNTIME" title="class or interface in java.lang.annotation">RUNTIME</a>) |
| <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/annotation/Target.html?is-external=true" title="class or interface in java.lang.annotation">@Target</a>(<a href="http://docs.oracle.com/javase/7/docs/api/java/lang/annotation/Target.html?is-external=true#value()" title="class or interface in java.lang.annotation">value</a>={<a href="http://docs.oracle.com/javase/7/docs/api/java/lang/annotation/ElementType.html?is-external=true#FIELD" title="class or interface in java.lang.annotation">FIELD</a>,<a href="http://docs.oracle.com/javase/7/docs/api/java/lang/annotation/ElementType.html?is-external=true#METHOD" title="class or interface in java.lang.annotation">METHOD</a>}) |
| public @interface <span class="strong">CacheAffinityKeyMapped</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 or a method 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 or method annotated |
| with <code>@CacheAffinityKeyMapped</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/CacheAffinityKeyMapper.html" title="interface in org.apache.ignite.cache.affinity"><code>CacheAffinityKeyMapper</code></a>, which will be used |
| if no explicit affinity mapper is specified in cache configuration, will first look |
| for any field or method annotated with <code>@CacheAffinityKeyMapped</code> annotation. |
| If such field or method 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 or method is found, then the value of this |
| field or method 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>@CacheAffinityKeyMapped</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. |
| @CacheAffinityKeyMapped |
| 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">CacheAffinityKey</h2> |
| For convenience, you can also optionally use <a href="../../../../../org/apache/ignite/cache/affinity/CacheAffinityKey.html" title="class in org.apache.ignite.cache.affinity"><code>CacheAffinityKey</code></a> class. Here is how a |
| <code>PersonKey</code> defined above would look using <a href="../../../../../org/apache/ignite/cache/affinity/CacheAffinityKey.html" title="class in org.apache.ignite.cache.affinity"><code>CacheAffinityKey</code></a>: |
| <pre name="code" class="java"> |
| Object personKey1 = new CacheAffinityKey("myPersonId1", "myCompanyId"); |
| Object personKey2 = new CacheAffinityKey("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>@CacheAffinityKeyMapped</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="http://docs.oracle.com/javase/7/docs/api/java/lang/Runnable.html?is-external=true" title="class or interface in java.lang"><code>Runnable</code></a>, <a href="http://docs.oracle.com/javase/7/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 method or 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. You can also use optional <code>@CacheName</code> |
| annotation whenever non-default cache name needs to be specified. |
| <p> |
| Here is how this annotation can be used to route a job to a node where Person object |
| is cached with ID "1234": |
| <pre name="code" class="java"> |
| G.grid().run(new Runnable() { |
| // This annotation is optional. If omitted, then default |
| // no-name cache will be used. |
| @CacheName |
| private String cacheName = "myCache"; |
| |
| // This annotation specifies that computation should be routed |
| // precisely to the node where key '1234' is cached. |
| @CacheAffinityKeyMapped |
| private String personKey = "1234"; |
| |
| @Override public void run() { |
| // Some computation logic here. |
| ... |
| } |
| }; |
| </pre> |
| The same can be achieved by annotating method instead of field as follows: |
| <pre name="code" class="java"> |
| G.grid().run(new Runnable() { |
| @Override public void run() { |
| // Some computation logic here. |
| ... |
| } |
| |
| // This annotation is optional. If omitted, then default |
| // no-name cache will be used. |
| @CacheName |
| public String cacheName() { |
| return "myCache"; |
| } |
| |
| // This annotation specifies that computation should be routed |
| // precisely to the node where key '1234' is cached. |
| @CacheAffinityKeyMapped |
| public String personKey() { |
| return "1234"; |
| } |
| }; |
| </pre> |
| <p> |
| For more information about cache affinity also see <a href="../../../../../org/apache/ignite/cache/affinity/CacheAffinityKeyMapper.html" title="interface in org.apache.ignite.cache.affinity"><code>CacheAffinityKeyMapper</code></a> and |
| <a href="../../../../../org/apache/ignite/cache/affinity/CacheAffinityFunction.html" title="interface in org.apache.ignite.cache.affinity"><code>CacheAffinityFunction</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="strong">See Also:</span></dt><dd><code>org.apache.ignite.cache.CacheName</code>, |
| <a href="../../../../../org/apache/ignite/cache/affinity/CacheAffinityFunction.html" title="interface in org.apache.ignite.cache.affinity"><code>CacheAffinityFunction</code></a>, |
| <a href="../../../../../org/apache/ignite/cache/affinity/CacheAffinityKeyMapper.html" title="interface in org.apache.ignite.cache.affinity"><code>CacheAffinityKeyMapper</code></a>, |
| <a href="../../../../../org/apache/ignite/cache/affinity/CacheAffinityKey.html" title="class in org.apache.ignite.cache.affinity"><code>CacheAffinityKey</code></a></dd></dl> |
| </li> |
| </ul> |
| </div> |
| </div> |
| <!-- ========= END OF CLASS DATA ========= --> |
| <!-- ======= START OF BOTTOM NAVBAR ====== --> |
| <div class="bottomNav"><a name="navbar_bottom"> |
| <!-- --> |
| </a><a href="#skip-navbar_bottom" title="Skip navigation links"></a><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/CacheAffinityKeyMapped.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 class="aboutLanguage"><em>Apache Ignite - In-Memory Data Fabric</em></div> |
| </div> |
| <div class="subNav"> |
| <ul class="navList"> |
| <li><a href="../../../../../org/apache/ignite/cache/affinity/CacheAffinityKey.html" title="class in org.apache.ignite.cache.affinity"><span class="strong">Prev Class</span></a></li> |
| <li><a href="../../../../../org/apache/ignite/cache/affinity/CacheAffinityKeyMapper.html" title="interface in org.apache.ignite.cache.affinity"><span class="strong">Next Class</span></a></li> |
| </ul> |
| <ul class="navList"> |
| <li><a href="../../../../../index.html?org/apache/ignite/cache/affinity/CacheAffinityKeyMapped.html" target="_top">Frames</a></li> |
| <li><a href="CacheAffinityKeyMapped.html" target="_top">No Frames</a></li> |
| </ul> |
| <ul class="navList" id="allclasses_navbar_bottom"> |
| <li><a href="../../../../../allclasses-noframe.html">All 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: </li> |
| <li>Required | </li> |
| <li>Optional</li> |
| </ul> |
| <ul class="subNavList"> |
| <li>Detail: </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://incubator.apache.org/projects/ignite.html"><nobr>2015 Copyright © 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> <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script> </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>Apache Ignite Fabric</b> </td> <td>: ver. <strong>1.0.0-RC3</strong> </td> </tr> <tr style="padding: 0; margin: 0"> <td> <b>Release Date</b> </td> <td>: March 24 2015 </td> </tr> </tbody> </table> </td> </tr> </table></small></p> |
| <!--FOOTER--><script type='text/javascript'>SyntaxHighlighter.all();dp.SyntaxHighlighter.HighlightAll('code');</script> |
| </body> |
| |
| </html> |