<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4256227498919592379</id><updated>2024-09-22T20:48:24.702-04:00</updated><category term="Java"/><category term="Tricks"/><category term="Functional"/><category term="Hadoop"/><category term="Java 8"/><category term="YARN"/><category term="Reflection"/><category term="Scala and Spring"/><category term="Tez"/><category term="CliffsNotes"/><category term="FactoryBean"/><category term="JMX"/><category term="Mesos"/><category term="Spring Integration"/><category term="Spring and Scala"/><category term="pipes-and-filters"/><category term="reactive"/><category term="reactor"/><title type='text'>Random Tech Rants</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://olegzk.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://olegzk.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Oleg Zhurakousky</name><uri>http://www.blogger.com/profile/11081810519614445288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTWgr8OLMee67w9QBxLvwmcgUWEFuY_6A6jTgtHjWSvbLTcHQoHObrYyayybK92RVXqBxrhj2TWjIolZxaOMYBhK-RKOmXQASDCf1UJFc8bfdp7hKhTdLPgsPEPUGPfyw/s220/Oleg-Prove.jpeg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>18</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4256227498919592379.post-3968623449507915655</id><published>2019-07-18T12:55:00.000-04:00</published><updated>2019-07-18T12:57:52.802-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="reactive"/><category scheme="http://www.blogger.com/atom/ns#" term="reactor"/><title type='text'>UnicastProcessor sample</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
UnicastProcessor&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #0000c0; font-family: &amp;quot;menlo&amp;quot;; font-size: 12px;&quot;&gt;UnicastProcessor hotSource = UnicastProcessor.create()&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0000c0; font-family: &amp;quot;menlo&amp;quot;; font-size: 12px;&quot;&gt;hotSource.subscribe(System.out::println)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0000c0; font-family: &amp;quot;menlo&amp;quot;; font-size: 12px;&quot;&gt;hotSource.onNext(&quot;foo&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0000c0; font-family: &amp;quot;menlo&amp;quot;; font-size: 12px;&quot;&gt;hotSource.onNext(&quot;bar&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #0000c0; font-family: &amp;quot;menlo&amp;quot;; font-size: 12px;&quot;&gt;. . .&lt;/span&gt;&lt;br /&gt;
&lt;style type=&quot;text/css&quot;&gt;
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Menlo}
&lt;/style&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://olegzk.blogspot.com/feeds/3968623449507915655/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4256227498919592379/3968623449507915655' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/3968623449507915655'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/3968623449507915655'/><link rel='alternate' type='text/html' href='http://olegzk.blogspot.com/2019/07/unicastprocessor-unicastprocessor.html' title='UnicastProcessor sample'/><author><name>Oleg Zhurakousky</name><uri>http://www.blogger.com/profile/11081810519614445288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTWgr8OLMee67w9QBxLvwmcgUWEFuY_6A6jTgtHjWSvbLTcHQoHObrYyayybK92RVXqBxrhj2TWjIolZxaOMYBhK-RKOmXQASDCf1UJFc8bfdp7hKhTdLPgsPEPUGPfyw/s220/Oleg-Prove.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4256227498919592379.post-5053491820903060137</id><published>2016-12-01T18:13:00.000-05:00</published><updated>2016-12-01T18:36:56.258-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Tricks"/><title type='text'>Optimized character search in String</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Problem:&lt;br /&gt;
You have a large string (string A) and another string (string B) and you want to find out if all characters of string B are present in string A. The problem is not complex through a basic loop and ‘contains’ call, but could be made more optimal by splitting both strings.
Why splitting is important? By splitting string A you creating a potential to discover that all character in string B are present in split from String A and you can break off the loop and return true. If not you concatenate first split with the second one and repeat. The bottom line is that you only have to look through the whole string if you can’t find a match until the last split. 
Splitting string B is also important since if a split from string B was matched to a string A, you no longer have to include it in your matching logic.
&lt;br /&gt;
&lt;hr /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-size: x-small;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot; style=&quot;font-size: x-small;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;nbsp;CharSearchInString {&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s1&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;void&lt;/span&gt; main(String[] &lt;span class=&quot;s2&quot;&gt;args&lt;/span&gt;) {&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p4&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; String[] &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;driverStrings&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; = &lt;/span&gt;&quot;java.util.concurrent.atomic.AtomicInteger&quot;&lt;span class=&quot;s3&quot;&gt;.split(&lt;/span&gt;&quot;(?&amp;lt;=\\G.{4})&quot;&lt;span class=&quot;s3&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;String[] comparableStrings = &quot;avrutcimIr&quot;.split(&quot;(?&amp;lt;=\\G.{3})&quot;);&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;// should return true as all characters in &#39;comparableStrings&#39; are&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;// present in &#39;driverStrings&#39;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.&lt;span class=&quot;s5&quot;&gt;out&lt;/span&gt;.println(performCompare(&lt;span class=&quot;s2&quot;&gt;driverStrings&lt;/span&gt;, &lt;span class=&quot;s2&quot;&gt;comparableStrings&lt;/span&gt;));&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s6&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p5&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; *&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p5&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; */&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s1&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;boolean&lt;/span&gt; performCompare(String[] &lt;span class=&quot;s2&quot;&gt;driverStrings&lt;/span&gt;, String[] &lt;span class=&quot;s2&quot;&gt;comparableStrings&lt;/span&gt;) {&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s1&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;csCount&lt;/span&gt; = 0;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; String &lt;span class=&quot;s2&quot;&gt;driverString&lt;/span&gt; = &lt;span class=&quot;s4&quot;&gt;&quot;&quot;&lt;/span&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p6&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;dsCount&lt;span class=&quot;s3&quot;&gt; = 0; &lt;/span&gt;dsCount&lt;span class=&quot;s3&quot;&gt; &amp;lt; &lt;/span&gt;driverStrings&lt;span class=&quot;s3&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;;) {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; innerLoop:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s1&quot;&gt;for&lt;/span&gt; (; &lt;span class=&quot;s2&quot;&gt;csCount&lt;/span&gt; &amp;lt; &lt;span class=&quot;s2&quot;&gt;comparableStrings&lt;/span&gt;.&lt;span class=&quot;s5&quot;&gt;length&lt;/span&gt;;) {&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p6&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; String &lt;/span&gt;comparableString&lt;span class=&quot;s3&quot;&gt; = &lt;/span&gt;comparableStrings&lt;span class=&quot;s3&quot;&gt;[&lt;/span&gt;csCount&lt;span class=&quot;s3&quot;&gt;];&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s1&quot;&gt;if&lt;/span&gt; (compares(&lt;span class=&quot;s2&quot;&gt;driverString&lt;/span&gt;, &lt;span class=&quot;s2&quot;&gt;comparableString&lt;/span&gt;)) {&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s2&quot;&gt;csCount&lt;/span&gt;++;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } &lt;span class=&quot;s1&quot;&gt;else&lt;/span&gt; {&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p6&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;driverString&lt;span class=&quot;s3&quot;&gt; += &lt;/span&gt;driverStrings&lt;span class=&quot;s3&quot;&gt;[&lt;/span&gt;dsCount&lt;span class=&quot;s3&quot;&gt;];&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s2&quot;&gt;dsCount&lt;/span&gt;++;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s1&quot;&gt;break&lt;/span&gt; innerLoop;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p6&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; (&lt;/span&gt;csCount&lt;span class=&quot;s3&quot;&gt; == &lt;/span&gt;comparableStrings&lt;span class=&quot;s3&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s1&quot;&gt;break&lt;/span&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;// will return true if all strings in &#39;comparableStrings&#39; were matched&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p3&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;// to at least one string in &#39;driverStrings&#39;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p6&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;csCount&lt;span class=&quot;s3&quot;&gt; == &lt;/span&gt;comparableStrings&lt;span class=&quot;s3&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s5&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;s6&quot; style=&quot;font-size: x-small;&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;p5&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; *&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p5&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; */&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;s1&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;boolean&lt;/span&gt; compares(String &lt;span class=&quot;s2&quot;&gt;a&lt;/span&gt;, String &lt;span class=&quot;s2&quot;&gt;b&lt;/span&gt;) {&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s1&quot;&gt;byte&lt;/span&gt;[] &lt;span class=&quot;s2&quot;&gt;bArray&lt;/span&gt; = &lt;span class=&quot;s2&quot;&gt;b&lt;/span&gt;.getBytes();&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s1&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;s1&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;i&lt;/span&gt; = 0; &lt;span class=&quot;s2&quot;&gt;i&lt;/span&gt; &amp;lt; &lt;span class=&quot;s2&quot;&gt;bArray&lt;/span&gt;.&lt;span class=&quot;s5&quot;&gt;length&lt;/span&gt;; &lt;span class=&quot;s2&quot;&gt;i&lt;/span&gt;++) {&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s1&quot;&gt;byte&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;x&lt;/span&gt; = &lt;span class=&quot;s2&quot;&gt;bArray&lt;/span&gt;[&lt;span class=&quot;s2&quot;&gt;i&lt;/span&gt;];&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s1&quot;&gt;if&lt;/span&gt; (!&lt;span class=&quot;s2&quot;&gt;a&lt;/span&gt;.contains((&lt;span class=&quot;s1&quot;&gt;char&lt;/span&gt;) &lt;span class=&quot;s2&quot;&gt;x&lt;/span&gt; + &lt;span class=&quot;s4&quot;&gt;&quot;&quot;&lt;/span&gt;)) {&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;false&lt;/span&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;s1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;true&lt;/span&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;style type=&quot;text/css&quot;&gt;
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #4e9072}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #3933ff}
p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #4f76cb}
p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #7e504f}
span.s1 {color: #931a68}
span.s2 {color: #7e504f}
span.s3 {color: #000000}
span.s4 {color: #3933ff}
span.s5 {color: #0326cc}
span.s6 {color: #4f76cb}
span.s7 {text-decoration: underline}
&lt;/style&gt;

&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr /&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://olegzk.blogspot.com/feeds/5053491820903060137/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4256227498919592379/5053491820903060137' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/5053491820903060137'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/5053491820903060137'/><link rel='alternate' type='text/html' href='http://olegzk.blogspot.com/2016/12/public-class-public-static-void.html' title='Optimized character search in String'/><author><name>Oleg Zhurakousky</name><uri>http://www.blogger.com/profile/11081810519614445288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTWgr8OLMee67w9QBxLvwmcgUWEFuY_6A6jTgtHjWSvbLTcHQoHObrYyayybK92RVXqBxrhj2TWjIolZxaOMYBhK-RKOmXQASDCf1UJFc8bfdp7hKhTdLPgsPEPUGPfyw/s220/Oleg-Prove.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4256227498919592379.post-7393819429695604782</id><published>2016-06-09T12:09:00.000-04:00</published><updated>2016-12-01T18:31:09.189-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Reflection"/><title type='text'>Set static final via java Reflection</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;hr /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&lt;span class=&quot;s1&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;void&lt;/span&gt; setFinalField(Field &lt;span class=&quot;s2&quot;&gt;field&lt;/span&gt;, Object &lt;span class=&quot;s2&quot;&gt;newValue&lt;/span&gt;) &lt;span class=&quot;s1&quot;&gt;throws&lt;/span&gt; Exception {&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;span class=&quot;s2&quot;&gt;field&lt;/span&gt;.setAccessible(&lt;span class=&quot;s1&quot;&gt;true&lt;/span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;Field &lt;span class=&quot;s2&quot;&gt;modifiersField&lt;/span&gt; = Field.&lt;span class=&quot;s1&quot;&gt;class&lt;/span&gt;.getDeclaredField(&lt;span class=&quot;s3&quot;&gt;&quot;modifiers&quot;&lt;/span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;span class=&quot;s2&quot;&gt;modifiersField&lt;/span&gt;.setAccessible(&lt;span class=&quot;s1&quot;&gt;true&lt;/span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;span class=&quot;s2&quot;&gt;modifiersField&lt;/span&gt;.setInt(&lt;span class=&quot;s2&quot;&gt;field&lt;/span&gt;, &lt;span class=&quot;s2&quot;&gt;field&lt;/span&gt;.getModifiers() &amp;amp; ~Modifier.&lt;span class=&quot;s4&quot;&gt;FINAL&lt;/span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;span class=&quot;s2&quot;&gt;field&lt;/span&gt;.set(&lt;span class=&quot;s1&quot;&gt;null&lt;/span&gt;, &lt;span class=&quot;s2&quot;&gt;newValue&lt;/span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: x-small;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr /&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://olegzk.blogspot.com/feeds/7393819429695604782/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4256227498919592379/7393819429695604782' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/7393819429695604782'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/7393819429695604782'/><link rel='alternate' type='text/html' href='http://olegzk.blogspot.com/2016/06/set-static-final-via-java-reflection.html' title='Set static final via java Reflection'/><author><name>Oleg Zhurakousky</name><uri>http://www.blogger.com/profile/11081810519614445288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTWgr8OLMee67w9QBxLvwmcgUWEFuY_6A6jTgtHjWSvbLTcHQoHObrYyayybK92RVXqBxrhj2TWjIolZxaOMYBhK-RKOmXQASDCf1UJFc8bfdp7hKhTdLPgsPEPUGPfyw/s220/Oleg-Prove.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4256227498919592379.post-4916470553733470010</id><published>2015-03-14T09:30:00.001-04:00</published><updated>2015-03-14T09:30:09.521-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><title type='text'>Getting stack trace without raising exception</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;hr /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Thread.currentThread().getStackTrace()
&lt;/span&gt;&lt;br /&gt;
&lt;hr /&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://olegzk.blogspot.com/feeds/4916470553733470010/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4256227498919592379/4916470553733470010' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/4916470553733470010'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/4916470553733470010'/><link rel='alternate' type='text/html' href='http://olegzk.blogspot.com/2015/03/getting-stack-trace-without-raising.html' title='Getting stack trace without raising exception'/><author><name>Oleg Zhurakousky</name><uri>http://www.blogger.com/profile/11081810519614445288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTWgr8OLMee67w9QBxLvwmcgUWEFuY_6A6jTgtHjWSvbLTcHQoHObrYyayybK92RVXqBxrhj2TWjIolZxaOMYBhK-RKOmXQASDCf1UJFc8bfdp7hKhTdLPgsPEPUGPfyw/s220/Oleg-Prove.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4256227498919592379.post-4806612849302153523</id><published>2015-02-28T11:28:00.001-05:00</published><updated>2015-02-28T11:28:54.142-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Functional"/><category scheme="http://www.blogger.com/atom/ns#" term="Java 8"/><category scheme="http://www.blogger.com/atom/ns#" term="Tricks"/><title type='text'>Make Java 8 Lambdas Serializable (type intersection)</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;hr /&gt;
Java 8 introduces type intersection allowing object to be cast to an intersection of types
&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;span class=&quot;s1&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;TypeIntersectionSample&lt;/span&gt; {&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; public&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;void&lt;/span&gt; main(String... &lt;span class=&quot;s3&quot;&gt;arg&lt;/span&gt;) {&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Serializable &lt;span class=&quot;s3&quot;&gt;bser&lt;/span&gt; = toSerializable(Integer::sum);&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; public&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;static&lt;/span&gt;&amp;nbsp;&amp;lt;T &lt;span class=&quot;s1&quot;&gt;extends&lt;/span&gt; BinaryOperator&amp;lt;Integer&amp;gt; &amp;amp; Serializable&amp;gt; T toSerializable(T &lt;span class=&quot;s3&quot;&gt;bo&lt;/span&gt;) {&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return&lt;/span&gt; (T) &lt;span class=&quot;s3&quot;&gt;bo&lt;/span&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://olegzk.blogspot.com/feeds/4806612849302153523/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4256227498919592379/4806612849302153523' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/4806612849302153523'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/4806612849302153523'/><link rel='alternate' type='text/html' href='http://olegzk.blogspot.com/2015/02/make-java-8-lambdas-serializable-type.html' title='Make Java 8 Lambdas Serializable (type intersection)'/><author><name>Oleg Zhurakousky</name><uri>http://www.blogger.com/profile/11081810519614445288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTWgr8OLMee67w9QBxLvwmcgUWEFuY_6A6jTgtHjWSvbLTcHQoHObrYyayybK92RVXqBxrhj2TWjIolZxaOMYBhK-RKOmXQASDCf1UJFc8bfdp7hKhTdLPgsPEPUGPfyw/s220/Oleg-Prove.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4256227498919592379.post-4525673867999360664</id><published>2015-02-09T15:49:00.002-05:00</published><updated>2015-02-09T15:49:23.043-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Functional"/><category scheme="http://www.blogger.com/atom/ns#" term="Java 8"/><title type='text'>ThreadLocal with Java 8</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;hr /&gt;
There is a new factory method in ThreadLocal allowing you to create and set initial value all at he same time via lambda expression.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;ThreadLocal&lt;string&gt; &lt;span class=&quot;s1&quot;&gt;tl&lt;/span&gt; = ThreadLocal.withInitial(() -&amp;gt; &lt;span class=&quot;s2&quot;&gt;&quot;Hello&quot;&lt;/span&gt;);&lt;/string&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
The rest is the same as before with regard to &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;set(..)/get()&lt;/span&gt;.&lt;/div&gt;
&lt;hr /&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://olegzk.blogspot.com/feeds/4525673867999360664/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4256227498919592379/4525673867999360664' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/4525673867999360664'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/4525673867999360664'/><link rel='alternate' type='text/html' href='http://olegzk.blogspot.com/2015/02/threadlocal-with-java-8_9.html' title='ThreadLocal with Java 8'/><author><name>Oleg Zhurakousky</name><uri>http://www.blogger.com/profile/11081810519614445288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTWgr8OLMee67w9QBxLvwmcgUWEFuY_6A6jTgtHjWSvbLTcHQoHObrYyayybK92RVXqBxrhj2TWjIolZxaOMYBhK-RKOmXQASDCf1UJFc8bfdp7hKhTdLPgsPEPUGPfyw/s220/Oleg-Prove.jpeg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4256227498919592379.post-1977169522546984003</id><published>2015-01-23T15:36:00.003-05:00</published><updated>2015-01-23T15:42:25.882-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="JMX"/><category scheme="http://www.blogger.com/atom/ns#" term="Tricks"/><title type='text'>Accessing JVM&#39;s memory info</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;hr /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Simply use&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;MemoryMXBean&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;MemoryUsage heapUsage =&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;memoryBean&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;.getHeapMemoryUsage();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;MemoryUsage nonHeapUsage =&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;memoryBean&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;.getNonHeapMemoryUsage();&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
Then simply interrogate instance of&amp;nbsp;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;MemoryUsage&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;long usedMemory =&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;heapUsage&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;.getUsed();&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;long maxMemory =&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;heapUsage&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;.getMax();&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;long initMemory =&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;heapUsage&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;.getInit();&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;long maxMemory =&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;heapUsage&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;.getMax();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
The same goes for non heap&amp;nbsp;&lt;/div&gt;
&lt;hr /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://olegzk.blogspot.com/feeds/1977169522546984003/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4256227498919592379/1977169522546984003' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/1977169522546984003'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/1977169522546984003'/><link rel='alternate' type='text/html' href='http://olegzk.blogspot.com/2015/01/accessing-jvms-memory-info.html' title='Accessing JVM&#39;s memory info'/><author><name>Oleg Zhurakousky</name><uri>http://www.blogger.com/profile/11081810519614445288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTWgr8OLMee67w9QBxLvwmcgUWEFuY_6A6jTgtHjWSvbLTcHQoHObrYyayybK92RVXqBxrhj2TWjIolZxaOMYBhK-RKOmXQASDCf1UJFc8bfdp7hKhTdLPgsPEPUGPfyw/s220/Oleg-Prove.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4256227498919592379.post-786518379911633888</id><published>2015-01-22T11:44:00.001-05:00</published><updated>2015-01-22T15:52:57.629-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="CliffsNotes"/><category scheme="http://www.blogger.com/atom/ns#" term="Hadoop"/><category scheme="http://www.blogger.com/atom/ns#" term="Mesos"/><category scheme="http://www.blogger.com/atom/ns#" term="Tez"/><category scheme="http://www.blogger.com/atom/ns#" term="YARN"/><title type='text'>Messos (Cliffs Notes)</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;hr/&gt;
&lt;b&gt;What is it?&lt;/b&gt;&lt;br /&gt;

Mesos is an independent &lt;i&gt;cluster platform&lt;/i&gt; which hosts &lt;i&gt;cluster computing frameworks&lt;/i&gt;.&lt;br /&gt;
Giving the fact that cluster platform&#39;s main responsibility to manage cluster resources a good example of similar architecture in Hadoop would be YARN and Tez, where YARN is native Hadoop &lt;i&gt;cluster platform&lt;/i&gt; with Tez being domain-specific (domain being DAG) &lt;i&gt;cluster computing framework&lt;/i&gt; hosted by YARN. This allows not only multi-framework hosting but also multi-instances and/or versions of the same framework hosted in the same shared cluster.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Architecture&lt;/b&gt;&lt;br /&gt;
&lt;i&gt;Mesos&lt;/i&gt; - Consists of Master and Slave nodes with allocation modules hosted by Master&lt;br /&gt;
&lt;i&gt;Framework&lt;/i&gt; - Consists of Scheduler and Executor processes launched on every node (to execute framework&#39;s tasks)&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Scheduling&amp;nbsp;and data locality&lt;/b&gt;&lt;br /&gt;
Mesos introduces the concept of &lt;i&gt;decentralized scheduler&lt;/i&gt;. The arguments for that are:&lt;br /&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;the need for expressive API to support all the frameworks (known and un-known)&lt;/li&gt;
&lt;li&gt;new frameworks may already come with its own scheduling mechanism, so refactoring it into centralized would not be feasible&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
So Mesos delegates scheduling to the frameworks themselves via &lt;b&gt;&lt;i&gt;resource offers&lt;/i&gt;&lt;/b&gt;. Mesos offers resources to frameworks based on &lt;i&gt;organizational policies&lt;/i&gt; (e.g., fair, priority etc), while the framework itself decides to accept/reject or how much of resources to accept.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Slave reports resource availability to the Master -&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Master(4 cpu and 8Gb on this slave) via allocation policy module -&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Framework&#39;s scheduler (takes 2 CPU, 2GB mem, on this slave or rehect) -&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Master(OK, and launches the tasks on such slave)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
Unused resources are offered to other frameworks and the overall process repeats upon completion of tasks.&lt;br /&gt;
&lt;br /&gt;
This is one of the mechanism frameworks utilize to achieve &lt;i&gt;&lt;b&gt;data locality&lt;/b&gt;&lt;/i&gt; - by accepting and/or rejecting resource offers from slaves based on data proximity.&lt;br /&gt;
&lt;br /&gt;
So the main design philosophy for Mesos - define a minimal interface that enables efficient resource sharing across frameworks, and otherwise push control of task scheduling and execution to the frameworks.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Allocation module&lt;/b&gt;&lt;br /&gt;
Based on assumption that task have a short life span which means it can reallocate resources as quick as tasks complete. However in a cases of long-running tasks Mesos can revoke (kill) tasks by killing task itself and/or killing executor if task does not respond. It&#39;s all in implementation detail of allocation module policies.&lt;br /&gt;
While MR based frameworks can easily live with re-allocated/killed tasks, MPI-style frameworks can&#39;t, so allocation modules can expose &lt;b&gt;&lt;i&gt;guaranteed allocation&amp;nbsp;&lt;/i&gt;&lt;/b&gt;to each framework - basically a set of resources permanently taken by the framework.&lt;br /&gt;
&lt;br /&gt;
Since resource acceptance is based on &lt;i&gt;accept&lt;/i&gt; or &lt;i&gt;reject&lt;/i&gt; mechanism, rejection in itself may introduce an unnecessary chatter especially for cases where certain slaves would always reject a particular scheduling request. Mesos allows such chatter to be further reduced by providing &lt;i&gt;&lt;b&gt;allocation&amp;nbsp;&lt;/b&gt;&lt;/i&gt;&lt;b&gt;&lt;i&gt;filters&lt;/i&gt;&lt;/b&gt; to the master essentially allowing resource offer not to go out to a particular slave if it does not pass a filter criteria&lt;br /&gt;
&lt;br /&gt;
Resource offers will be rescinded if a framework does not respond timely to resource offer, thus allowing such resources to be re-offered to other frameworks.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Performance Isolation&lt;/b&gt;&lt;br /&gt;
Performance isolation achieved via native mechanisms (e.g., Linux containers, etc.)&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Master fault tolerance (hot stand-by)&lt;/b&gt;&lt;br /&gt;
Master has few standby nodes. In a case of master failure ZooKeeper will select a new master from the list. Since all (hot and standby) masters receive events from the cluster, a new master will be able to reconstruct its latest state from these events.&lt;br /&gt;
&lt;br /&gt;
&lt;hr/&gt;
&lt;b&gt;Opinion:&lt;/b&gt;&lt;br /&gt;
Mesos may have its benefits in heterogeneous clusters often seen in small/medium sized businesses where maintaining a domain specific cluster is not cost efficient due to low load and high idle scenarios, so a single cluster platform can host multiple cluster computing frameworks sharing resources between them, thus limiting the idle time.&lt;br /&gt;
However, in large scale high load data clusters (e.g., Hadoop) having a native cluster platform such as YARN is more beneficial based on a simple premise that specialized solutions are generally better then generalized.&lt;br /&gt;
&lt;i&gt;&lt;u&gt;Having said that, YARN is perfectly capable of hosting cluster computation frameworks which may have nothing to do with Hadoop all together, thus allowing Hadoop/YARN cluster to be used as heterogeneous cluster compute platform.&lt;/u&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Missrepresentation&lt;/b&gt;:&lt;br /&gt;
In Mesos Architecture white paper (&lt;a href=&quot;http://mesos.berkeley.edu/mesos_tech_report.pdf&quot;&gt;http://mesos.berkeley.edu/mesos_tech_report.pdf&lt;/a&gt;). In Page 2 Section 2 it talks about an example of what needs to happen to data sitting in Hadoop after MR processing if such data needs to be integrated with MPI. It talks about requirement for spinning up a new MPI cluster and moving terrabytes of data from Hadoop cluster while making the argument that MPI could be just another compute framework hosted in the same cluster.&lt;br /&gt;
That is actually &lt;i&gt;&lt;b&gt;not true&lt;/b&gt;&lt;/i&gt; and these capabilities existed in Hadoop even before YARN/Tez, since MPI concepts could always be implemented as part of your MR job (although I&#39;d admit it was not simple). However with YARN and Tez it is relatively simple. In fact Tez is being more flexible when it comes to this sort of requirements since it is a low-level DAG framework comprised of simple Vertexes &quot;processors&quot; (filters) connected by Edges (pipes) as in standard &lt;a href=&quot;http://www.eaipatterns.com/PipesAndFilters.html&quot;&gt;pipes-and-filters&lt;/a&gt; architecture.&lt;br /&gt;
&lt;br /&gt;
&lt;hr/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://olegzk.blogspot.com/feeds/786518379911633888/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4256227498919592379/786518379911633888' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/786518379911633888'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/786518379911633888'/><link rel='alternate' type='text/html' href='http://olegzk.blogspot.com/2015/01/messos-cliffs-notes.html' title='Messos (Cliffs Notes)'/><author><name>Oleg Zhurakousky</name><uri>http://www.blogger.com/profile/11081810519614445288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTWgr8OLMee67w9QBxLvwmcgUWEFuY_6A6jTgtHjWSvbLTcHQoHObrYyayybK92RVXqBxrhj2TWjIolZxaOMYBhK-RKOmXQASDCf1UJFc8bfdp7hKhTdLPgsPEPUGPfyw/s220/Oleg-Prove.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4256227498919592379.post-4732183405289614833</id><published>2015-01-13T14:01:00.001-05:00</published><updated>2015-01-22T15:53:26.185-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Functional"/><category scheme="http://www.blogger.com/atom/ns#" term="Java 8"/><title type='text'>Java 8 - &quot;The target type of this expression must be a functional interface&quot;</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;hr/&gt;
When learning new constructs of Java 8 you quickly learn about &lt;i&gt;method references&lt;/i&gt; (or functional references). The similarity is also often drawn to &lt;i&gt;object references&lt;/i&gt;. This may lead to one of these mistakes:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Object function = File::isHidden;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The above will result in compile error &quot;The target type of this expression must be a functional interface&quot;. &lt;br /&gt;
The correct way is to use the appropriate &lt;a href=&quot;http://docs.oracle.com/javase/8/docs/api/java/util/function/package-summary.html&quot;&gt;functional interface&lt;/a&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Predicate&amp;lt;File&amp;gt;&lt;file&gt;&lt;file&gt;&amp;nbsp;&lt;/file&gt;&lt;/file&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;= File::isHidden;&lt;/span&gt;&lt;/div&gt;
&lt;hr/&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://olegzk.blogspot.com/feeds/4732183405289614833/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4256227498919592379/4732183405289614833' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/4732183405289614833'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/4732183405289614833'/><link rel='alternate' type='text/html' href='http://olegzk.blogspot.com/2015/01/java-8-target-type-of-this-expression.html' title='Java 8 - &quot;The target type of this expression must be a functional interface&quot;'/><author><name>Oleg Zhurakousky</name><uri>http://www.blogger.com/profile/11081810519614445288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTWgr8OLMee67w9QBxLvwmcgUWEFuY_6A6jTgtHjWSvbLTcHQoHObrYyayybK92RVXqBxrhj2TWjIolZxaOMYBhK-RKOmXQASDCf1UJFc8bfdp7hKhTdLPgsPEPUGPfyw/s220/Oleg-Prove.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4256227498919592379.post-7100916282499762367</id><published>2014-12-13T17:15:00.002-05:00</published><updated>2014-12-13T17:24:08.385-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Tricks"/><title type='text'>Where the class is loaded from?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;hr /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Variety of exceptions could be categorized as &lt;b&gt;&lt;i&gt;class loading&lt;/i&gt;&lt;/b&gt; exceptions, since their root cause most often leads one to discover issues with the &lt;i&gt;classpath&lt;/i&gt;. Some of these are &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;NoClassDefFoundError&lt;/span&gt;, &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;LinkageError&lt;/span&gt;, &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;NoSuchMethodError&lt;/span&gt; etc. Debugging these issues is greatly simplified when you know where a class is loaded from (i.e., which JAR or directory).&lt;br /&gt;
The code below will extract the &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;URL&lt;/span&gt; for the location of the source for a particular class (&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Foo&lt;/span&gt; in this case)&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;URL fooClassSourceUrl = Foo.class.getProtectionDomain().getCodeSource().getLocation()&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://olegzk.blogspot.com/feeds/7100916282499762367/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4256227498919592379/7100916282499762367' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/7100916282499762367'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/7100916282499762367'/><link rel='alternate' type='text/html' href='http://olegzk.blogspot.com/2014/12/where-class-is-loaded-from.html' title='Where the class is loaded from?'/><author><name>Oleg Zhurakousky</name><uri>http://www.blogger.com/profile/11081810519614445288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTWgr8OLMee67w9QBxLvwmcgUWEFuY_6A6jTgtHjWSvbLTcHQoHObrYyayybK92RVXqBxrhj2TWjIolZxaOMYBhK-RKOmXQASDCf1UJFc8bfdp7hKhTdLPgsPEPUGPfyw/s220/Oleg-Prove.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4256227498919592379.post-1878492253249427954</id><published>2014-12-13T15:47:00.000-05:00</published><updated>2015-01-13T14:00:25.788-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Reflection"/><category scheme="http://www.blogger.com/atom/ns#" term="Tricks"/><title type='text'>Object instance without constructor invocation</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;hr /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
There are times when you need to create an instance of an object without invoking its constructor. This is typical in testing (e.g. mock) or integrating where you may need to comply with method that may perform a null check while downstream such object may not be used. &amp;nbsp;One of those un-documented classes in Java API (&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;sun.misc.Unsafe&lt;/span&gt;) could help.&lt;br /&gt;
&lt;br /&gt;
1. Create an instance of&amp;nbsp;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;sun.misc.Unsafe&lt;/span&gt;:&lt;br /&gt;
&lt;span class=&quot;s1&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt; java.lang.reflect.Constructor;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt; sun.misc.Unsafe;&lt;/span&gt;&lt;/div&gt;
. . .&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;span class=&quot;s1&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;static&lt;/span&gt; Unsafe getUnsafe() &lt;span class=&quot;s1&quot;&gt;throws&lt;/span&gt; Exception {&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; Constructor&lt;unsafe&gt; ctr = Unsafe.&lt;span class=&quot;s1&quot;&gt;class&lt;/span&gt;.getDeclaredConstructor();&lt;/unsafe&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&amp;nbsp; ctr.setAccessible(&lt;span class=&quot;s1&quot;&gt;true&lt;/span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; return&lt;/span&gt; ctr.newInstance();&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
2. Create an instance of an object without invoking its constructor:&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;Foo &lt;span class=&quot;s1&quot;&gt;foo&lt;/span&gt; =&amp;nbsp; (Foo) getUnsafe().allocateInstance(Foo.&lt;span class=&quot;s2&quot;&gt;class&lt;/span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;Caution:&lt;/span&gt; &lt;i&gt;you can invoke any method on such instance as if it was created using a constructor. However, realize the effects of this &quot;back-door&quot; where invocation of any method on such uninitialized instance could and most likely would lead to various exceptions.&amp;nbsp;&lt;/i&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;hr /&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://olegzk.blogspot.com/feeds/1878492253249427954/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4256227498919592379/1878492253249427954' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/1878492253249427954'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/1878492253249427954'/><link rel='alternate' type='text/html' href='http://olegzk.blogspot.com/2014/12/object-instance-without-constructor.html' title='Object instance without constructor invocation'/><author><name>Oleg Zhurakousky</name><uri>http://www.blogger.com/profile/11081810519614445288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTWgr8OLMee67w9QBxLvwmcgUWEFuY_6A6jTgtHjWSvbLTcHQoHObrYyayybK92RVXqBxrhj2TWjIolZxaOMYBhK-RKOmXQASDCf1UJFc8bfdp7hKhTdLPgsPEPUGPfyw/s220/Oleg-Prove.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4256227498919592379.post-4375903930751226538</id><published>2014-12-11T09:04:00.005-05:00</published><updated>2014-12-11T13:04:12.116-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Hadoop"/><category scheme="http://www.blogger.com/atom/ns#" term="Tez"/><category scheme="http://www.blogger.com/atom/ns#" term="YARN"/><title type='text'>Tez container memory allocations</title><content type='html'>&lt;hr&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;As a YARN application Tez must allocate YARN containers for Application Master and Tasks.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;The relevant properties and their default values are:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;tez.am.resource.memory.mb&lt;/span&gt;&lt;i style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt; - 1536 (MB)&lt;/i&gt;&lt;br /&gt;
&lt;i style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &lt;/i&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;tez.task.resource.memory.mb &lt;/span&gt;&lt;i style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;- 1024 (MB)&lt;/i&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;When setting, ensure that AM memory + Task memory fits in the overall capacity of the cluster (see &lt;a href=&quot;http://olegzk.blogspot.com/2014/12/yarn-total-memory.html&quot;&gt;YARN total memory&lt;/a&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;hr&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://olegzk.blogspot.com/feeds/4375903930751226538/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4256227498919592379/4375903930751226538' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/4375903930751226538'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/4375903930751226538'/><link rel='alternate' type='text/html' href='http://olegzk.blogspot.com/2014/12/tez-container-memory-allocations.html' title='Tez container memory allocations'/><author><name>Oleg Zhurakousky</name><uri>http://www.blogger.com/profile/11081810519614445288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTWgr8OLMee67w9QBxLvwmcgUWEFuY_6A6jTgtHjWSvbLTcHQoHObrYyayybK92RVXqBxrhj2TWjIolZxaOMYBhK-RKOmXQASDCf1UJFc8bfdp7hKhTdLPgsPEPUGPfyw/s220/Oleg-Prove.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4256227498919592379.post-2784501683499361556</id><published>2014-12-11T08:51:00.002-05:00</published><updated>2014-12-11T13:03:50.848-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Hadoop"/><category scheme="http://www.blogger.com/atom/ns#" term="YARN"/><title type='text'>YARN total memory</title><content type='html'>&lt;hr&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;background-color: white; color: #333333; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19.6000003814697px;&quot;&gt;&lt;span style=&quot;line-height: 20px;&quot;&gt;Shown as&amp;nbsp;&lt;b&gt;Memory Total&lt;/b&gt;&amp;nbsp;in YARN Resource Manager UI&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgL-yesx4Il-rO2s9aj-vpwllDI8Z6f9-p9T5zJNA1D6f8oAmrTMIlEYwrGeSm-82WYlvBBYu9ggJ29wyf4Xx_l9ndpNMyg_2SW7ZgDQpuW4sXox-BukuODdYfJrLvo-8YFtojco4IvG7P6/s1600/Screen+Shot+2014-12-11+at+10.21.56+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgL-yesx4Il-rO2s9aj-vpwllDI8Z6f9-p9T5zJNA1D6f8oAmrTMIlEYwrGeSm-82WYlvBBYu9ggJ29wyf4Xx_l9ndpNMyg_2SW7ZgDQpuW4sXox-BukuODdYfJrLvo-8YFtojco4IvG7P6/s1600/Screen+Shot+2014-12-11+at+10.21.56+AM.png&quot; height=&quot;95&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; color: #333333; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19.6000003814697px;&quot;&gt;&lt;span style=&quot;line-height: 20px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #333333; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19.6000003814697px;&quot;&gt;&lt;span style=&quot;line-height: 20px;&quot;&gt;To change it, modify&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: &#39;Helvetica Neue Light&#39;, HelveticaNeue-Light, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19.6000003814697px;&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;line-height: 20px;&quot;&gt;yarn.&lt;/span&gt;&lt;wbr style=&quot;display: inline-block; line-height: 20px;&quot;&gt;&lt;/wbr&gt;&lt;span style=&quot;line-height: 20px;&quot;&gt;nodemanager.&lt;/span&gt;&lt;wbr style=&quot;display: inline-block; line-height: 20px;&quot;&gt;&lt;/wbr&gt;&lt;span style=&quot;line-height: 20px;&quot;&gt;resource.&lt;/span&gt;&lt;wbr style=&quot;display: inline-block; line-height: 20px;&quot;&gt;&lt;/wbr&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-size: 14px; line-height: 20px;&quot;&gt;&lt;span style=&quot;background-color: white; font-family: Courier New, Courier, monospace;&quot;&gt;memory-mb&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif;&quot;&gt;&amp;nbsp;property.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #333333; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 20px;&quot;&gt;Could me modified with Ambari.&lt;/span&gt;&lt;/div&gt;
&lt;hr&gt;</content><link rel='replies' type='application/atom+xml' href='http://olegzk.blogspot.com/feeds/2784501683499361556/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4256227498919592379/2784501683499361556' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/2784501683499361556'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/2784501683499361556'/><link rel='alternate' type='text/html' href='http://olegzk.blogspot.com/2014/12/yarn-total-memory.html' title='YARN total memory'/><author><name>Oleg Zhurakousky</name><uri>http://www.blogger.com/profile/11081810519614445288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTWgr8OLMee67w9QBxLvwmcgUWEFuY_6A6jTgtHjWSvbLTcHQoHObrYyayybK92RVXqBxrhj2TWjIolZxaOMYBhK-RKOmXQASDCf1UJFc8bfdp7hKhTdLPgsPEPUGPfyw/s220/Oleg-Prove.jpeg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgL-yesx4Il-rO2s9aj-vpwllDI8Z6f9-p9T5zJNA1D6f8oAmrTMIlEYwrGeSm-82WYlvBBYu9ggJ29wyf4Xx_l9ndpNMyg_2SW7ZgDQpuW4sXox-BukuODdYfJrLvo-8YFtojco4IvG7P6/s72-c/Screen+Shot+2014-12-11+at+10.21.56+AM.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4256227498919592379.post-494739137905386984</id><published>2011-07-20T12:30:00.000-04:00</published><updated>2011-07-20T13:16:24.637-04:00</updated><title type='text'>Scala Named parameters</title><content type='html'>&lt;b&gt;Named parameters&lt;/b&gt; is one of the features of Scala which allows you to define a class which has a constructor that defines default values for the &lt;i&gt;named parameters&lt;/i&gt; which you can later override.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;class Person(name: String = &quot;Bill&quot;, age: Int = 25) {
      override def toString = name + &quot;:&quot; + age
}
&lt;/pre&gt;&lt;br /&gt;
First, this allows you to create an instance of this class without passing any arguments&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;println(new Person())
&lt;/pre&gt;and the output will be:&lt;br /&gt;
&lt;br /&gt;
Bill:25&lt;br /&gt;
&lt;br /&gt;
This is because the instance is created with the default values specified in the class definition.&lt;br /&gt;
&lt;br /&gt;
You can override any of these values by using the &lt;i&gt;name&lt;/i&gt; of the argument and specifying its new value&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;println(new Person(age=35))
&lt;/pre&gt;will result in:&lt;br /&gt;
&lt;br /&gt;
Bill:35&lt;br /&gt;
&lt;br /&gt;
and &lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;println(new Person(age=55, name=&quot;John&quot;))
&lt;/pre&gt;will result in:&lt;br /&gt;
&lt;br /&gt;
John:55&lt;br /&gt;
&lt;br /&gt;
And of course you can still do this:&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;println(new Person(&quot;Chris&quot;, 23))
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://olegzk.blogspot.com/feeds/494739137905386984/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4256227498919592379/494739137905386984' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/494739137905386984'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/494739137905386984'/><link rel='alternate' type='text/html' href='http://olegzk.blogspot.com/2011/07/scala-named-parameters.html' title='Scala Named parameters'/><author><name>Oleg Zhurakousky</name><uri>http://www.blogger.com/profile/11081810519614445288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTWgr8OLMee67w9QBxLvwmcgUWEFuY_6A6jTgtHjWSvbLTcHQoHObrYyayybK92RVXqBxrhj2TWjIolZxaOMYBhK-RKOmXQASDCf1UJFc8bfdp7hKhTdLPgsPEPUGPfyw/s220/Oleg-Prove.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4256227498919592379.post-5607225758022827916</id><published>2011-07-06T11:01:00.000-04:00</published><updated>2011-07-10T11:16:08.169-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="FactoryBean"/><category scheme="http://www.blogger.com/atom/ns#" term="Scala and Spring"/><title type='text'>Implementing Spring&#39;s FactoryBean in Scala</title><content type='html'>Spring Framework provides many different extension points. One of them is &lt;i&gt;FactoryBean&lt;/i&gt;&lt;br /&gt;
The details about &lt;i&gt;FactoryBeans&lt;/i&gt; are described &lt;a href=&quot;http://static.springsource.org/spring/docs/3.1.0.M2/spring-framework-reference/html/beans.html#beans-factory-extension-factorybean&quot;&gt;here&lt;/a&gt;. All I&#39;ll show is how to implement one in &lt;a target=&quot;_blank&quot;  href=&quot;http://www.amazon.com/Programming-Scala-Multi-Core-Complexity-Programmers/dp/193435631X?ie=UTF8&amp;tag=olesbl-20&amp;link_code=btl&amp;camp=213689&amp;creative=392969&quot;&gt;Scala&lt;/a&gt;&lt;img src=&quot;http://www.assoc-amazon.com/e/ir?t=olesbl-20&amp;l=btl&amp;camp=213689&amp;creative=392969&amp;o=1&amp;a=193435631X&quot; width=&quot;1&quot; height=&quot;1&quot; border=&quot;0&quot; alt=&quot;&quot; style=&quot;border:none !important; margin:0px !important; padding: 0px !important&quot; /&gt;, by extending on the previous post &lt;a href=&quot;http://olegzk.blogspot.com/2011/07/scala-function-as-spring-bean-spring.html&quot;&gt;Scala Function as Spring Bean (Spring and Scala)&lt;/a&gt; &lt;br /&gt;
Let&#39;s say creating an instance of the Scala function requires some logic that could not or should not be handled by a simple constructor invocation. This would be a perfect case for a &lt;i&gt;FactoryBean&lt;/i&gt; and we can easily implement one in Scala&lt;br /&gt;
&lt;br /&gt;
So to create our &lt;i&gt;PrintFunction&lt;/i&gt; via &lt;i&gt;FactoryBean&lt;/i&gt; we can implement one in Java or in Scala. Below is the Scala implementation of Spring&#39;s &lt;i&gt;FactoryBean&lt;/i&gt; which creates and instance of &lt;i&gt;PrintFunction&lt;/i&gt; while also printing a message stating that it is creating a &lt;i&gt;PrintFunction&lt;/i&gt;. &lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;class ScalaFactoryBean extends FactoryBean[PrintFunction] {
  
  val myFunction = new PrintFunction()

  def getObject(): PrintFunction = {  
    println(&quot;Creating &#39;PrintFunction&#39;&quot;)
 return myFunction
  }

  def getObjectType(): Class[PrintFunction] = { 
    classOf[PrintFunction]
  }

  def isSingleton(): Boolean = { 
    true 
  }
}&lt;/pre&gt;. . .and its configuration:&lt;br /&gt;
&lt;style type=&quot;text/css&quot;&gt;
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #4239f6}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; min-height: 15.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #4b9191}
span.s1 {color: #009292}
span.s2 {color: #4b9191}
span.s3 {color: #000000}
span.s4 {color: #961f8d}
span.Apple-tab-span {white-space:pre}
&lt;/style&gt;   &lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;&lt;span class=&quot;s1&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;bean&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&quot;prinitScalaFunctionFB&quot;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&quot;olegz.scala.spring.ScalaFactoryBean&quot;&lt;span class=&quot;s1&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;p2&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;p1&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;bean&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&quot;functionViaFactoryBean&quot;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&quot;olegz.scala.spring.SimpleSpringBean&quot;&lt;span class=&quot;s1&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;p1&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;property&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&quot;function&quot;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;ref&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&quot;prinitScalaFunctionFB&quot;&lt;span class=&quot;s1&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;p3&quot;&gt;&lt;span class=&quot;s1&quot;&gt;&amp;lt;/bean&lt;span class=&quot;s1&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
From this point on it is pure Spring&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext(&quot;scala-config.xml&quot;, SpringDemo.class);
  
    SimpleSpringBean functionViaFactoryBean = context.getBean(&quot;functionViaFactoryBean&quot;, SimpleSpringBean.class);
    functionViaFactoryBean.printMessage(&quot;Hello Spring-Scala&quot;);
}
&lt;/pre&gt;&lt;br /&gt;
For more info check out the source code here: &lt;a href=&quot;https://github.com/olegz/scala-spring-samples/tree/master/src/test/scala/olegz/scala/spring&quot;&gt;https://github.com/olegz/scala-spring-samples/tree/master/src/test/scala/olegz/scala/spring&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://olegzk.blogspot.com/feeds/5607225758022827916/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4256227498919592379/5607225758022827916' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/5607225758022827916'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/5607225758022827916'/><link rel='alternate' type='text/html' href='http://olegzk.blogspot.com/2011/07/implementing-springs-factorybean-in.html' title='Implementing Spring&#39;s FactoryBean in Scala'/><author><name>Oleg Zhurakousky</name><uri>http://www.blogger.com/profile/11081810519614445288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTWgr8OLMee67w9QBxLvwmcgUWEFuY_6A6jTgtHjWSvbLTcHQoHObrYyayybK92RVXqBxrhj2TWjIolZxaOMYBhK-RKOmXQASDCf1UJFc8bfdp7hKhTdLPgsPEPUGPfyw/s220/Oleg-Prove.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4256227498919592379.post-2340464223636618933</id><published>2011-07-06T09:51:00.000-04:00</published><updated>2011-07-06T16:03:57.391-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Scala and Spring"/><category scheme="http://www.blogger.com/atom/ns#" term="Spring and Scala"/><title type='text'>Scala Function as Spring Bean (Spring and Scala)</title><content type='html'>With &lt;a href=&quot;http://www.scala-lang.org/&quot;&gt;Scala&lt;/a&gt; gaining popularity a lot of developers are now wondering how &lt;a href=&quot;http://www.amazon.com/Programming-Scala-Comprehensive-Step-Step/dp/0981531644?ie=UTF8&amp;amp;tag=olesbl-20&amp;amp;link_code=btl&amp;amp;camp=213689&amp;amp;creative=392969&quot; target=&quot;_blank&quot;&gt;Scala&lt;/a&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; height=&quot;1&quot; src=&quot;http://www.assoc-amazon.com/e/ir?t=olesbl-20&amp;amp;l=btl&amp;amp;camp=213689&amp;amp;creative=392969&amp;amp;o=1&amp;amp;a=0981531644&quot; style=&quot;border: none !important; margin: 0px !important; padding: 0px !important;&quot; width=&quot;1&quot; /&gt; can integrate with existing and popular JVM-based frameworks. &lt;br /&gt;
One of the questions I&#39;ve been asked recently if Scala Functions could be used as Spring Beans in the typical Dependency Injection model provided by &lt;a href=&quot;http://static.springsource.org/spring/docs/3.1.0.M2/spring-framework-reference/html/&quot;&gt;Spring Framework&lt;/a&gt;. In other words can I inject Scala function into a Spring configured Java bean? The answer is not only &#39;Yes&#39; but it is actually very simple, since Scala itself is very nicely integrated with Java and Scala Function is just a class.&lt;br /&gt;
&lt;br /&gt;
Let&#39;s say we have a Scala function called &lt;i&gt;PrintFunction&lt;/i&gt;&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;class PrintFunction extends Function1[String, Unit]{
   def apply(in: String) = println(&quot;From Scala function: &quot; + in)
}
&lt;/pre&gt;It is worth pointing out that Scala defines a group of traits from &lt;i&gt;scala.Function0&lt;/i&gt; to &lt;i&gt;scala.Function9&lt;/i&gt;, allowing you to define functions with 0 to 9 parameters so you can easily integrate them with other classes. In our case we are using &lt;i&gt;Function1&lt;/i&gt; since we only passing one parameter. However we can clearly see that there is a second type argument in our definition of &lt;i&gt;PrintFunction&lt;/i&gt; (e.g., &lt;i&gt;Function1[String, Unit]&lt;/i&gt;). That is the return value and in our case it is &lt;i&gt;Unit&lt;/i&gt; which would be the equivalent of Java &#39;void&#39;.&lt;br /&gt;
&lt;br /&gt;
So, to bootstrap this function as a Spring Bean all we need is to define it as Spring Bean&lt;br /&gt;
&lt;style type=&quot;text/css&quot;&gt;
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #4239f6}
span.s1 {color: #009292}
span.s2 {color: #4b9191}
span.s3 {color: #000000}
span.s4 {color: #961f8d}
&lt;/style&gt;   &lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;&lt;span class=&quot;s1&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;bean&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&quot;prinitScalaFunction&quot;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&quot;olegz.scala.spring.PrintFunction&quot;&lt;span class=&quot;s1&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
Now it is just another Spring Bean which could be injected into any other bean that has &lt;i&gt;PrintFunction&lt;/i&gt; property (see below).&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;public class SimpleSpringBean {

    private PrintFunction function;

    public void setFunction(PrintFunction function) {
        this.function = function;
    }
        
    public void printMessage(String message) {
        function.apply(message);
    }
}
&lt;/pre&gt;. . . and its configuration:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;style type=&quot;text/css&quot;&gt;
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #4239f6}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #4b9191}
span.s1 {color: #009292}
span.s2 {color: #4b9191}
span.s3 {color: #000000}
span.s4 {color: #961f8d}
span.Apple-tab-span {white-space:pre}
&lt;/style&gt;   &lt;/div&gt;&lt;div class=&quot;p1&quot;&gt;&lt;span class=&quot;s1&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;bean&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&quot;olegz.scala.spring.SimpleSpringBean&quot;&lt;span class=&quot;s1&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;p1&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;property&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&quot;function&quot;&lt;span class=&quot;s3&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s4&quot;&gt;ref&lt;/span&gt;&lt;span class=&quot;s3&quot;&gt;=&lt;/span&gt;&quot;prinitScalaFunction&quot;&lt;span class=&quot;s1&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;p2&quot;&gt;&lt;span class=&quot;s3&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;lt;/bean&lt;span class=&quot;s1&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
Now all we need is start Spring Application Context and call &lt;i&gt;printMessage(String)&lt;/i&gt; method of &lt;i&gt;SimpleSpringBean&lt;/i&gt;. This method will invoke Function&#39;s &lt;i&gt;apply(String)&lt;/i&gt; method, or we can simply get the function itself and call its &lt;i&gt;apply(String)&lt;/i&gt; method.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext(&quot;scala-config.xml&quot;, SpringDemo.class);
    SimpleSpringBean bean = context.getBean(SimpleSpringBean.class);
    bean.printMessage(&quot;Hello Spring-Scala&quot;);
}
&lt;/pre&gt;You should see the following output:&lt;br /&gt;
&lt;pre class=&quot;text&quot; name=&quot;code&quot;&gt;From Scala function: Hello Spring-Scala
&lt;/pre&gt;For more details check out this sources here &lt;a href=&quot;https://github.com/olegz/scala-spring-samples/tree/master/src/test/scala/olegz/scala/spring&quot;&gt;https://github.com/olegz/scala-spring-samples/tree/master/src/test/scala/olegz/scala/spring&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://olegzk.blogspot.com/feeds/2340464223636618933/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4256227498919592379/2340464223636618933' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/2340464223636618933'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/2340464223636618933'/><link rel='alternate' type='text/html' href='http://olegzk.blogspot.com/2011/07/scala-function-as-spring-bean-spring.html' title='Scala Function as Spring Bean (Spring and Scala)'/><author><name>Oleg Zhurakousky</name><uri>http://www.blogger.com/profile/11081810519614445288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTWgr8OLMee67w9QBxLvwmcgUWEFuY_6A6jTgtHjWSvbLTcHQoHObrYyayybK92RVXqBxrhj2TWjIolZxaOMYBhK-RKOmXQASDCf1UJFc8bfdp7hKhTdLPgsPEPUGPfyw/s220/Oleg-Prove.jpeg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4256227498919592379.post-8307314002976056761</id><published>2011-07-04T16:46:00.000-04:00</published><updated>2011-07-06T15:46:37.553-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="pipes-and-filters"/><category scheme="http://www.blogger.com/atom/ns#" term="Spring Integration"/><title type='text'>Spring Integration and Channels</title><content type='html'>&lt;iframe src=&quot;http://rcm.amazon.com/e/cm?t=olesbl-20&amp;o=1&amp;p=8&amp;l=bpl&amp;asins=1935182439&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;m=amazon&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr&quot; style=&quot;align:left;padding-top:5px;width:131px;height:245px;padding-right:10px;&quot;align=&quot;left&quot; scrolling=&quot;no&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; frameborder=&quot;0&quot;&gt;&lt;/iframe&gt;&lt;a href=&quot;http://www.springsource.org/spring-integration&quot;&gt;Spring Integration&lt;/a&gt; is a POJO-based light weight, embeddable messaging framework with a loosely coupled programming model aimed to simplify integration of heterogeneous systems based on &lt;a target=&quot;_blank&quot;  href=&quot;http://www.amazon.com/Enterprise-Integration-Patterns-Designing-Deploying/dp/0321200683?ie=UTF8&amp;tag=olesbl-20&amp;link_code=btl&amp;camp=213689&amp;creative=392969&quot;&gt;Enterprise Integration Patterns&lt;/a&gt;&lt;img src=&quot;http://www.assoc-amazon.com/e/ir?t=olesbl-20&amp;l=btl&amp;camp=213689&amp;creative=392969&amp;o=1&amp;a=0321200683&quot; width=&quot;1&quot; height=&quot;1&quot; border=&quot;0&quot; alt=&quot;&quot; style=&quot;border:none !important; margin:0px !important; padding: 0px !important&quot; /&gt; and without requiring a separate ESB-like engine or proprietary development and deployment environment. &lt;br /&gt;
&lt;br /&gt;
One of the fundamental differences between Spring Integration and other EIP-like frameworks and products is that we treat EIP as specification and follow it to the letter. &lt;br /&gt;
At the very core of the EIP is one fundamental and probably the most important pattern of all; &lt;i&gt;&lt;b&gt;Pipes-and-Filters&lt;/b&gt;&lt;/i&gt; which describes the communication model between Message producers and Message consumers where instead of exchanging Messages directly producers and consumers communicate through the pipe (i.e., channel)&lt;br /&gt;
&lt;br /&gt;
Pipe is a core component of EIP for 2 main reasons:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;1. Pipes give you logical and physical decoupling. Because of that components on either side of the pipe are completely un-aware of one another. You can change producing or consuming component without affecting the flow (e.g., consumer could be a mock while in the early developing stages and than switched to a real component later on)&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;2. Pipes in collaboration with &lt;a href=&quot;http://www.eaipatterns.com/MessageDispatcher.html&quot;&gt;Message Dispatcher&lt;/a&gt; and &lt;a href=&quot;http://www.eaipatterns.com/PollingConsumer.html&quot;&gt;Polling Consumer&lt;/a&gt; are responsible for handling Message exchange protocol (e.g., point-to-point vs. pub-sub, sync or async, etc.). &lt;/i&gt;&lt;br /&gt;
Let&#39;s look at the example:&lt;br /&gt;
&lt;blockquote&gt;&lt;b&gt;producerA -&gt; channelA -&gt; consumerA &lt;/b&gt;&lt;br /&gt;
&lt;/blockquote&gt;In the above diagram &lt;i&gt;producerA&lt;/i&gt; sends Message to a &lt;i&gt;consumerA&lt;/i&gt; via &lt;i&gt;channelA&lt;/i&gt;. &lt;br /&gt;
As you can see neither producer nor consumer are aware of one another. They are physically and logically decoupled. We can change producer without affecting the consumer and vice versa.&lt;br /&gt;
&lt;br /&gt;
Message exchange protocol is being maintained by the channel? Is it point-to-point? pub-sub? sync or async? Well the diagram above does not show it and in Spring Integration the default channel implementation is &lt;b&gt;&lt;i&gt;synchronous point-to-point channel&lt;/i&gt;&lt;/b&gt;. However by simply changing the type of channel, one can completely change the Message exchange protocol without affecting producer or consumer.</content><link rel='replies' type='application/atom+xml' href='http://olegzk.blogspot.com/feeds/8307314002976056761/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4256227498919592379/8307314002976056761' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/8307314002976056761'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/8307314002976056761'/><link rel='alternate' type='text/html' href='http://olegzk.blogspot.com/2011/07/hello.html' title='Spring Integration and Channels'/><author><name>Oleg Zhurakousky</name><uri>http://www.blogger.com/profile/11081810519614445288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTWgr8OLMee67w9QBxLvwmcgUWEFuY_6A6jTgtHjWSvbLTcHQoHObrYyayybK92RVXqBxrhj2TWjIolZxaOMYBhK-RKOmXQASDCf1UJFc8bfdp7hKhTdLPgsPEPUGPfyw/s220/Oleg-Prove.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4256227498919592379.post-4672867199275081000</id><published>2008-12-08T14:19:00.002-05:00</published><updated>2011-07-06T15:46:08.227-04:00</updated><title type='text'>JMX Connectivity through Firewall</title><content type='html'>Recently I’ve been asked to help out a customer who was having issues with JMX connectivity to Spring Source dmServer through the firewall. However, one thing I want to point out right up front is that the issue is rather generic and has nothing to do with dmServer. It is really about understanding JMX, RMI and proper configuration. But I will use dmServer and its configuration as an example.&lt;br /&gt;
Here is the sample JMX configuration options provided in the dmServer startup script:&lt;br /&gt;
&lt;pre name=&quot;code&quot; class=&quot;java&quot;&gt;-Dcom.sun.management.jmxremote.port=${jmxPort} \
-Dcom.sun.management.jmxremote.authenticate \
-Dcom.sun.management.jmxremote.password.file=${jmxUsersPath} \
-Djavax.net.ssl.keyStore=${keystorePath} \
-Djavax.net.ssl.keyStorePassword=${keystorePassword} \
-Dcom.sun.management.jmxremote.ssl=true \
-Dcom.sun.management.jmxremote.ssl.need.client.auth=false”
&lt;/pre&gt;&lt;br /&gt;
This will enable JMX agent (MBean Server) when you start dmServer. Once started you can now monitor your process via JMX-compliant tool such as jconsole. Connectivity could be local or remote.&lt;br /&gt;
The above configuration seem to provide everything we need to access this process through the firewall, since com.sun.management.jmxremote.port is obviously the port that we need to open in the firewall. However there is a caveat.&lt;br /&gt;
Once connected to JMXRegistry running on the port specified by com.sun.management.jmxremote.port property, the actual objects are served by RMIServer which is running on different port. Unfortunately this port is chosen randomly by default instance of JMX Agent and there is no –D option to specify it. Obviously going through the firewall would require opening up two ports and with random port it presents a delicate issue.&lt;br /&gt;
Fortunately it is easily solvable by writing a custom Java Agent where you can programmatically specify each port and externalize it through custom properties (I am attaching sample code).&lt;br /&gt;
More info here: http://java.sun.com/javase/6/docs/technotes/guides/management/agent.html&lt;br /&gt;
In the nutshell, the custom agent will take the port value provided by the com.sun.management.jmxremote.port property and will create a second port (RMIServer port) by incrementing it by 1. (in our case the port specified is 44444 which makes RMIServer port 44445)&lt;br /&gt;
Once such agent is in place (JAR) and the appropriate ports are open in the firewall all you need is modify the startup script to include –javaagent option providing the JAR.&lt;br /&gt;
&lt;pre name=&quot;code&quot; class=&quot;java&quot;&gt;. . . . .
$JAVA_HOME/bin/java \
-javaagent:/Users/olegzhurakousky/../../../dmserver.jmx-0.0.1-SNAPSHOT.jar 
$JAVA_OPTS \
. . . . .
&lt;/pre&gt;Well, that really only solved one half of the problem, since by default RMI stubs sent to the client contain the server’s private address instead of the public&lt;br /&gt;
&lt;br /&gt;
Just look at this tcpdump fragment while monitoring the client’s access (jconsole running on the local network):&lt;br /&gt;
&lt;blockquote&gt;. . . . . . .&lt;br /&gt;
09:41:23.778663 IP 72.234.14.89.44444 &gt; 192.168.1.156.52926: . ack 71 win 65535 &lt;nop,nop,timestamp 919359579 313492&gt;&lt;br /&gt;
09:41:23.779958 IP 192.168.1.152.44444 &gt; 72.234.14.89.52926: P 20:251(231) ack 71 win 65535 &lt;nop,nop,timestamp 919359579 313492&gt;&lt;br /&gt;
09:41:23.780456 IP 72.234.14.89.44444 &gt; 192.168.1.156.52926: P 20:251(231) ack 71 win 65535 &lt;nop,nop,timestamp 919359579 313492&gt;&lt;br /&gt;
09:41:23.796075 IP 192.168.1.156.37861 &gt; 192.168.1.152.44445: S 1334070579:1334070579(0) win 5840 &lt;mss 1460,sackOK,timestamp 313496 0,nop,wscale 6&gt;&lt;br /&gt;
09:41:23.796328 IP 192.168.1.152.44445 &gt; 192.168.1.156.37861: S 1760846938:1760846938(0) ack 1334070580 win 65535 &lt;mss 1460,nop,wscale 3,nop,nop,timestamp 919359579 313496,sackOK,eol&gt;&lt;br /&gt;
. . . . . . .&lt;br /&gt;
&lt;/blockquote&gt;You can clearly see that 192.168.1.156 (client i.e., jconsole) is attempting to connect directly to 192.168.1.152 (server) instead of 72.234.14.89 which is a public IP, although the JMX URL is:&lt;br /&gt;
service:jmx:rmi://72.234.14.89:44445/jndi/rmi://72.234.14.89:44444/jmxrmi&lt;br /&gt;
&lt;br /&gt;
If I was behind the firewall I would obviously had problems connecting to 192.168.1.152&lt;br /&gt;
Fortunately, this one is easy to fix. All you need is to provide additional option on the server side (java.rmi.server.hostname) and add it to the script This option represents the host name string that should be associated with remote stubs for locally created remote objects, in order to allow clients to invoke methods on the remote object:&lt;br /&gt;
&lt;pre name=&quot;code&quot; class=&quot;java&quot;&gt;. . . . . . .
JMX_OPTS=” \
$JMX_OPTS \
-Dcom.sun.management.jmxremote.port=${jmxPort} \
-Djava.rmi.server.hostname=72.234.14.89 \
. . . . . . . 
&lt;/pre&gt;That is all .&lt;br /&gt;
Start jconsole: ./jconsole.sh service:jmx:rmi://&lt;pub-ip&gt;:&lt;rmi-port&gt;/jndi/rmi://&lt;pub-ip&gt;:&lt;registry-port&gt;/jmxrmi&lt;br /&gt;
Once you modify the script and start the dmServer you should see output similar to this:&lt;br /&gt;
&lt;blockquote&gt;. . . . . .&lt;br /&gt;
oleg-2:bin olegzhurakousky$ ./startup.sh&lt;br /&gt;
com.springsource.rmiregistry.port:44444&lt;br /&gt;
com.springsource.rmiserver.port:44445&lt;br /&gt;
Getting the platform’s MBean Server&lt;br /&gt;
Local Connection URL: service:jmx:rmi://oleg-2.local:44445/jndi/rmi://oleg-2.local:44444/jmxrmi&lt;br /&gt;
Public Connection URL: service:jmx:rmi://72.234.14.89:44445/jndi/rmi://72.234.14.89:44444/jmxrmi&lt;br /&gt;
Creating RMI connector server&lt;br /&gt;
[2009-02-26 18:53:34.031] main                     &lt;spkb0001i&gt; Server starting.&lt;br /&gt;
[2009-02-26 18:53:35.943] main                     &lt;spof0001i&gt; OSGi telnet console available on port 2401.&lt;br /&gt;
[2009-02-26 18:53:41.558] main                     &lt;spke0000i&gt; Boot subsystems installed.&lt;br /&gt;
&lt;/blockquote&gt;</content><link rel='replies' type='application/atom+xml' href='http://olegzk.blogspot.com/feeds/4672867199275081000/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4256227498919592379/4672867199275081000' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/4672867199275081000'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4256227498919592379/posts/default/4672867199275081000'/><link rel='alternate' type='text/html' href='http://olegzk.blogspot.com/2008/12/please-visit-my-bog-httpolegz_08.html' title='JMX Connectivity through Firewall'/><author><name>Oleg Zhurakousky</name><uri>http://www.blogger.com/profile/11081810519614445288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTWgr8OLMee67w9QBxLvwmcgUWEFuY_6A6jTgtHjWSvbLTcHQoHObrYyayybK92RVXqBxrhj2TWjIolZxaOMYBhK-RKOmXQASDCf1UJFc8bfdp7hKhTdLPgsPEPUGPfyw/s220/Oleg-Prove.jpeg'/></author><thr:total>0</thr:total></entry></feed>