Blogs Related Items on Java.nethttp://www.java.net/taxonomy/term/46/atom?type=All
enCase Study: Moving To The Pull Request Workflow & Integrating Quality Engineers On The Team For Better Software Quality http://www.java.net/blog/manningpubs/archive/2015/02/23/case-study-moving-pull-request-workflow-integrating-quality-engineers-team-better-software-q
<div class="field field-type-filefield field-field-thumb-100x70">
<div class="field-items">
<div class="field-item odd">
<img class="imagefield imagefield-field_thumb_100x70" width="172" height="216" alt="" src="http://www.java.net/sites/default/files/manning_pubs/cover_5.jpg?1424726679" /> </div>
</div>
</div>
<p><body><b>By Christopher W. H. Davis, <a href="http://www.manning.com/davis2/">Continuous Improvement </a></b></p>
<p> <b>Save 40%</b> on <a href="http://www.manning.com/davis2/">Continuous Improvement </a> with discount code <b> jn15ci</b> at manning.com. </P></p>
<p>The book <a href="http://www.manning.com/davis2/">Continuous Improvement </a> walks the reader through the collection and analysis of data to provide metrics that guide the continuous improvement of agile teams. Each chapter ends in a case study outlining the application of this technique with specific types of data. This is an excerpt of a real world scenario from the end of Chapter 4 that shows the reader how to apply source control data toward continuous improvement. We’ve been through how to collect and analyze SCM and CI data so it’s time to see it in action. </p>
<p>This real world scenario will show you how this can be applied to your process. </p>
<p>The team in question was generating a lot of bugs. Many of them were small issues that likely should have been caught much earlier in the development process. Regardless, every time they would cut a release they would deploy their code, turn it over to the Quality Management (QM) team, and wait for the bugs to come in. They decided to make a change to get to better quality. </p>
<p>After discussing the issue. the team decided to try out the pull request workflow. They were already using Git, but developers were all committing their code to a branch and merging it all into master before cutting a release. They decided to start tracking commits, pull-requests and bugs to see if using pull-requests decreased their bug count. After a few sprints they had the graph shown in Figure 1. </p>
<p><img src="http://www.java.net/sites/default/files/fig1_1.jpg" title="Fig1"></p>
<p><i>Figure 1 Bugs aren’t trending down as the team starts doing pull requests. </i></p>
<p>To make trends a bit easier to see, we will divide pull requests and commits by 2 so there isn’t such a discrepancy between the metrics. That is shown in Figure 2.</p>
<p> <img src="http://www.java.net/sites/default/files/fig2_1.jpg" title="Fig2"></p>
<p><i>Figure 2 The same data with variance decreases between bugs and other data </i></p>
<p>That makes it a lot easier to see the variance. As you can see from Figure 2 not much changed; even though there is a big dip from bugs from sprint 18 to 19, we aren’t decreasing over time – there was just a big jump in bugs in sprint 18. After discussing it a bit more, the team decided to add some more data points to the mix. To see how much collaboration was happening in the pull requests, they started adding comments to their graphs as well. That resulted in the chart shown in Figure 3. To keep consistent, we’ll divide comments by 2 as well.</p>
<p><img src="http://weblogs.java.net/sites/default/files/fig3_0.jpg" title="Fig3"> </p>
<p><i>Figure 3 Adding comments to our graph and finding an ugly trend </i></p>
<p><o>Figure 3 shows that there aren’t many comments along with the pull request, which implies there wasn’t much collaboration going on at all. Since the bug trend wasn’t changing it looked like the changes to their process wasn’t quite taking effect yet. The workflow itself wasn’t effecting the change they wanted, they needed to make a bigger impact to their process. To do this, they decided to make their developers act like the QM team when they were put on a pull request. The perspective they needed wasn’t just “is this code going to solve the problem?”, but “is this code well-built and what can go wrong with it”? There was some concern about developers getting less done if they had to spend a lot of time commenting on other developers’ code and acting like the QM team. To help coach them, they moved one of their QM members over to the development team and the team agreed that if this could result in fewer bugs then the time spent up front was well spent. They started taking the time to comment on each other’s code and ended up iterating quite a bit more on tasks before checking them in. A few sprints of this resulted in Figure 4. </p>
<p><img src="http://weblogs.java.net/sites/default/files/fig4.jpg" title="Fig4"> </p>
<p><i>Figure 4 Everything is trending in the right direction! </i></p>
<p>Figure 4 shows that as collaboration between development and quality increased, in this case shown through comments in pull-requests, the number of bugs was going down. This was great news to the team so they decided to take the process one step further. They brought another member of the QM team down to work with the developers on code reviews and quality checks to avoid throwing code over the wall to the QM team. </p>
<hr>
<b>Test Engineers </b> </p>
<p>For a long time, the role of the quality department in software has involved checking to make sure features were implemented to spec. That is not an engineering discipline, and as result many people in the quality assurance (QA) and quality management (QM) space were not engineers. To truly have an autonomous team, quality engineering has to be a significant part of the team. The role of the quality engineer, aka QE aka SDET aka Test Engineer has started to become more and more popular. However as quality moves from one state to another in the world of software engineering, this role is not very clearly defined and often you have either someone with an old quality background who recently learned to write code, or you have an expert in test running technology. Neither of these actually works; you need a senior engineer with a quality mindset. </p>
<hr>
</p>
<p>As shown in Figure 4, over time commits and pull requests started increasing as well. As the development team started thinking with a quality mindset they started writing better code and producing fewer bugs. Also by combining the QM team with the development team many issues were found and fixed before deploying code out to the test environment. </p>
<table id="attachments" class="sticky-enabled">
<thead><tr><th>Attachment</th><th>Size</th> </tr></thead>
<tbody>
<tr class="odd"><td><a href="http://www.java.net/sites/default/files/fig1_1.jpg">fig1.jpg</a></td><td>18.41 KB</td> </tr>
<tr class="even"><td><a href="http://www.java.net/sites/default/files/fig2_1.jpg">fig2.jpg</a></td><td>19.04 KB</td> </tr>
<tr class="odd"><td><a href="http://www.java.net/sites/default/files/fig3_0.jpg">fig3.jpg</a></td><td>17.35 KB</td> </tr>
<tr class="even"><td><a href="http://www.java.net/sites/default/files/fig4.jpg">fig4.jpg</a></td><td>20.93 KB</td> </tr>
</tbody>
</table>
http://www.java.net/blog/manningpubs/archive/2015/02/23/case-study-moving-pull-request-workflow-integrating-quality-engineers-team-better-software-q#commentsBloggingBlogsJava EnterpriseMon, 23 Feb 2015 21:25:05 +0000manning_pubs931653 at http://www.java.netGo in Action: Exploring the Work Package by By Brian Ketelsen, Erik St. Martin, and William Kennedy http://www.java.net/blog/manningpubs/archive/2015/02/23/go-action-exploring-work-package-brian-ketelsen-erik-st-martin-and-william-kennedy
<div class="field field-type-filefield field-field-thumb-100x70">
<div class="field-items">
<div class="field-item odd">
<img class="imagefield imagefield-field_thumb_100x70" width="374" height="467" alt="" src="http://www.java.net/sites/default/files/manning_pubs/cover.png?1424700744" /> </div>
</div>
</div>
<p><body>
<p><b><i>By Brian Ketelsen, Erik St. Martin, and William Kennedy</i></b></p>
<p> <b>Save 40%</b> on <a href="http://www.manning.com/ketelsen/">Go in Action </a> with discount code <b> jn15goia </b> at manning.com. </P></p>
<p>The purpose of the work package is to show how you can use an unbuffered channel to create a pool of goroutines to perform and control the amount of work that gets done concurrently. This is a better approach that using a buffered channel of some arbitrary static size that acts as a queue of work and throwing a bunch of goroutines at it. </p>
<p>Unbuffered channels provide a guarantee that data has been exchanged between two goroutines. The approach this package takes by using an unbuffered channel allows the user to know when the pool is performing the work and pushes back when it can't accept any more work because it is busy. No work is ever lost or stuck in queue that has no guarantee it will ever be worked on.</p>
<p>Let's take a look at the <code class="prettyprint">work.go</code> code file from the work package:</p>
<p><b>Listing 1</b></p>
<pre class="prettyprint"><code>chapter7/patterns/work/work.go<br />01 // Example provided with help from Jason Waldrip.<br />02 // Package work manages a pool of goroutines to perform work.<br />03 package work<br />04<br />05 import "sync"<br />06<br />07 // Worker must be implemented by types that want to use<br />08 // the work pool.<br />09 type Worker interface {<br />10 Task()<br />11 }<br />12<br />13 // Pool provides a pool of goroutines that can execute any Worker<br />14 // tasks that are submitted.<br />15 type Pool struct {<br />16 work chan Worker<br />17 wg sync.WaitGroup<br />18 }<br />19<br />20 // New creates a new work pool.<br />21 func New(maxGoroutines int) *Pool {<br />22 p := Pool{<br />23 tasks: make(chan Worker),<br />24 }<br />25<br />26 p.wg.Add(maxGoroutines)<br />27 for i := 0; i < maxGoroutines; i++ {<br />28 go func() {<br />29 for w := range p.work {<br />30 w.Task()<br />31 }<br />32 p.wg.Done()<br />33 }()<br />34 }<br />35<br />36 return &p<br />37 }<br />38<br />39 // Run submits work to the pool.<br />40 func (p *Pool) Run(w Worker) {<br />41 p.work <- w<br />42 }<br />43<br />44 // Shutdown waits for all the goroutines to shutdown.<br />45 func (p *Pool) Shutdown() {<br />46 close(p.tasks)<br />47 p.wg.Wait()<br />48 }</code></pre>
<p>The work package in listing 2 starts off with the declaration of an interface named <code class="prettyprint">Worker</code> and a struct named <code class="prettyprint">Pool</code>:</p>
<p><b>Listing 2</b></p>
<pre class="prettyprint"><code>07 // Worker must be implemented by types that want to use<br />08 // the work pool.<br />09 type Worker interface {<br />10 Task()<br />11 }<br />12<br />13 // Pool provides a pool of goroutines that can execute any Worker<br />14 // tasks that are submitted.<br />15 type Pool struct {<br />16 work chan Worker<br />17 wg sync.WaitGroup<br />18 }</code></pre>
<p>The <code class="prettyprint">Worker</code> interface in listing 1 on line 10 declares a single method called <code class="prettyprint">Task</code>. Then on line 15, a struct named <code class="prettyprint">Pool</code> is declared which is the type that implements the pool of goroutines and will have methods that process the work. The type declares two fields, one named <code class="prettyprint">work</code> which is a channel of the <code class="prettyprint">Worker</code> interface type and a <code class="prettyprint">sync.WaitGroup</code> named <code class="prettyprint">wg</code>.</p>
<p>Next, let's look at the factory function for the work package:</p>
<p><b>Listing 3</b></p>
<pre class="prettyprint"><code>20 // New creates a new work pool.<br />21 func New(maxGoroutines int) *Pool {<br />22 p := Pool{<br />23 work: make(chan Worker),<br />24 }<br />25<br />26 p.wg.Add(maxGoroutines)<br />27 for i := 0; i < maxGoroutines; i++ {<br />28 go func() {<br />29 for w := range p.work {<br />30 w.Task()<br />31 }<br />32 p.wg.Done()<br />33 }()<br />34 }<br />35<br />36 return &p<br />37 }</code></pre>
<p>Listing 3 shows the <code class="prettyprint">New</code> function that is used to create work pool that is configured with a fixed set number of goroutines. The number of goroutines is passed in as a parameter to the <code class="prettyprint">New</code> function. On line 22, a value of type <code class="prettyprint">Pool</code> is created and the <code class="prettyprint">work</code> field is initialized with an unbuffered channel.</p>
<p>Then on line 26, the <code class="prettyprint">WaitGroup</code> is initialized and on lines 27 through 34 the specified number of goroutines are created. The goroutine just receives interface values of type <code class="prettyprint">Worker</code> and calls the Task method on those values:</p>
<p><b>Listing 4</b></p>
<pre class="prettyprint"><code>28 go func() {<br />29 for w := range w.work {<br />30 w.Task()<br />31 }<br />32 p.wg.Done()<br />33 }()</code></pre>
<p>The <code class="prettyprint">for range</code> loop blocks until there is a <code class="prettyprint">Worker</code> interface value to receive on the work channel. When a value is received, the <code class="prettyprint">Task</code> method is called. Once the <code class="prettyprint">work</code> channel is closed, the <code class="prettyprint">for range</code> loop ends and the call to <code class="prettyprint">Done</code> on the <code class="prettyprint">WaitGroup</code> is called. Then the goroutine terminates.
<p>Now that we can create a pool of goroutines that can wait for and execute work, let's look at how work is submitted into the pool:</p>
<p><b>Listing 5</b></p>
<pre class="prettyprint"><code>39 // Run submits work to the pool.<br />40 func (p *Pool) Run(w Worker) {<br />41 w.work <- w<br />42 }</code></pre>
<p>Listing 5 shows the <code class="prettyprint">Run</code> method. This method is used to submit work into the pool. It accepts an interface value of type <code class="prettyprint">Worker</code> and sends that value through the work channel. Since the <code class="prettyprint">work</code> channel is an unbuffered channel, the caller must wait for a goroutine from the pool to receive it. This is what we want because the caller needs the guarantee that the work being submitted is being worked on once the call to <code class="prettyprint">Run</code> returns.</p>
<p>At some point the work pool need to be shutdown. This is where the <code class="prettyprint">Shutdown</code> method comes in:</p>
<p><b>Listing 6</b></p>
<pre class="prettyprint"><code>44 // Shutdown waits for all the goroutines to shutdown.<br />45 func (p *Pool) Shutdown() {<br />46 close(p.work)<br />47 p.wg.Wait()<br />48 }</code></pre>
<p>The <code class="prettyprint">Shutdown</code> method in listing 6 does two things. First, it closes the <code class="prettyprint">work</code> channel which causes all of the goroutines in the pool to shut down and call the <code class="prettyprint">Done</code> method off the <code class="prettyprint">WaitGroup</code>. Then the <code class="prettyprint">Shutdown</code> method calls the <code class="prettyprint">Wait</code> method on the <code class="prettyprint">WaitGroup</code> which causes the <code class="prettyprint">Shutdown</code> method to wait for all the goroutines to report they have terminated.</p>
<p>Now that we have seen the code for the <code class="prettyprint">work</code> package and learned how it works, let's review the test program in the <code class="prettyprint">main.go</code> source code file:</p>
<p><b>Listing 7</b></p>
<pre class="prettyprint"><code>chapter7/patterns/work/main/main.go<br /><br />01 // This sample program demonstrates how to use the work package<br />02 // to use a pool of goroutines to get work done.<br />03 package main<br />04<br />05 import (<br />06 "log"<br />07 "sync"<br />08 "time"<br />09<br />10 "github.com/goinaction/code/chapter7/patterns/work"<br />11 )<br />12<br />13 // names provides a set of names to display.<br />14 var names = []string{<br />15 "steve",<br />16 "bob",<br />17 "mary",<br />18 "therese",<br />19 "jason",<br />20 }<br />21<br />22 // namePrinter provides special support for printing names.<br />23 type namePrinter struct {<br />24 name string<br />25 }<br />26<br />27 // Task implements the Worker interface.<br />28 func (m *namePrinter) Task() {<br />29 log.Println(m.name)<br />30 time.Sleep(time.Second)<br />31 }<br />32<br />33 // main is the entry point for all Go programs.<br />34 func main() {<br />35 // Create a work pool with 2 goroutines.<br />36 p := work.New(2)<br />37<br />38 var wg sync.WaitGroup<br />39 wg.Add(100 * len(names))<br />40<br />41 for i := 0; i < 100; i++ {<br />42 // Iterate over the slice of names.<br />43 for _, name := range names {<br />44 // Create a namePrinter and provide the<br />45 // specific name.<br />46 np := namePrinter{<br />47 name: name,<br />48 }<br />49<br />50 go func() {<br />51 // Submit the task to be worked on. When RunTask<br />52 // returns we know it is being handled.<br />53 p.Run(&np)<br />54 wg.Done()<br />55 }()<br />56 }<br />57 }<br />58<br />59 wg.Wait()<br />60<br />61 // Shutdown the work pool and wait for all existing work<br />62 // to be completed.<br />63 p.Shutdown()<br />64 }</code></pre>
<p>Listing 7 shows the test program that uses the package work to perform the displaying of names. The code starts out on line 14 with the declaration of a package level variable named <code class="prettyprint">names</code> which is declared as a slice of strings. The slice is also initialized with five names. Then a type named <code class="prettyprint">namePrinter</code> is declared:</p>
<pre class="prettyprint"><code>22 // namePrinter provides special support for printing names.<br />23 type namePrinter struct {<br />24 name string<br />25 }<br />26<br />27 // Task implements the Worker interface.<br />28 func (m *namePrinter) Task() {<br />29 log.Println(m.name)<br />30 time.Sleep(time.Second)<br />31 }</code></pre>
<p>On line 23 in listing 7, the type <code class="prettyprint">namePrinter</code> is declared and the implementation of the <code class="prettyprint">Worker</code> interface follows. The purpose of the work is to display names to the screen. The type contains a single field named <code class="prettyprint">name</code> which will contain the name to display. The implementation of the <code class="prettyprint">Worker</code> interface uses the <code class="prettyprint">log.Println</code> function to display the name and then waits a second before returning. The second wait is just to slow the test program down so we can see the concurrency is action.</p>
<p>With the implementation of the <code class="prettyprint">Worker</code> interface, we can look at the code inside the main function:</p>
<pre class="prettyprint"><code>33 // main is the entry point for all Go programs.<br />34 func main() {<br />35 // Create a work pool with 2 goroutines.<br />36 p := work.New(2)<br />37<br />38 var wg sync.WaitGroup<br />39 wg.Add(100 * len(names))<br />40<br />41 for i := 0; i < 100; i++ {<br />42 // Iterate over the slice of names.<br />43 for _, name := range names {<br />44 // Create a namePrinter and provide the<br />45 // specific name.<br />46 np := namePrinter{<br />47 name: name,<br />48 }<br />49<br />50 go func() {<br />51 // Submit the task to be worked on. When RunTask<br />52 // returns we know it is being handled.<br />53 p.Run(&np)<br />54 wg.Done()<br />55 }()<br />56 }<br />57 }<br />58<br />59 wg.Wait()<br />60<br />61 // Shutdown the work pool and wait for all existing work<br />62 // to be completed.<br />63 p.Shutdown()<br />64 }</code></pre>
<p>On line 36 in listing 7, the New function from the <code class="prettyprint">work</code> package is called to create the <code class="prettyprint">work</code> pool. The number 2 is passed into the call indicating the pool should only contain two goroutines. Then on lines 38 and 39 a <code class="prettyprint">WaitGroup</code> is declared and initialized to each goroutine that is going to be created. In this case, a goroutine for each name in the names slice is going to be created 100 times. This is to create a lot of goroutines competing to submit work to the pool.</p>
<p>Then on line 41 and 43, inner and outer <code class="prettyprint">for</code> loops are declared to create all the goroutines. Inside each iteration of the inner loop, a value of type <code class="prettyprint">namePrinter</code> is created and provided with a name to print. Then on line 50, an anonymous function is declared and created as a goroutine. The goroutine calls the <code class="prettyprint">Run</code> method against the work pool to submit the <code class="prettyprint">namePrinter</code> value to the pool. Once a goroutine from the work pool receives the value, the call to <code class="prettyprint">Run</code> returns. This is turn causes the goroutine to decrement the <code class="prettyprint">WaitGroup</code> count and terminate.</p>
<p>Once all the goroutines are created, the <code class="prettyprint">main</code>function calls <code class="prettyprint">Wait</code> on the <code class="prettyprint">WaitGroup</code>. The function will wait until all the goroutines that were created submit their work. Once <code class="prettyprint">Wait</code> returns, the <code class="prettyprint">work</code> pool is shut down by calling the <code class="prettyprint">Shutdown</code> method. This method will not return until all the work is complete. In our case, there would only be two outstanding pieces of work by this time.</p>
http://www.java.net/blog/manningpubs/archive/2015/02/23/go-action-exploring-work-package-brian-ketelsen-erik-st-martin-and-william-kennedy#commentsBlogsMon, 23 Feb 2015 14:13:23 +0000manning_pubs931654 at http://www.java.netMeteor in Action: Authenticating users with oAuthhttp://www.java.net/blog/manningpubs/archive/2015/02/12/meteor-action-authenticating-users-oauth
<div class="field field-type-filefield field-field-thumb-100x70">
<div class="field-items">
<div class="field-item odd">
<img class="imagefield imagefield-field_thumb_100x70" width="369" height="460" alt="" src="http://www.java.net/sites/default/files/manning_pubs/cover.jpg?1423509693" /> </div>
</div>
</div>
<p><b>By Stephan Hochhaus and Manuel Schoebel, excerpted from <a href="http://www.manning.com/hochhaus/"> Meteor in Action </a></b><br />
<P><B>Save 40%</b> on <a href="http://www.manning.com/hochhaus/"> Meteor in Action </a> with discount code <b>jn15met </b> at manning.com.
<p> Oftentimes usernames and passwords are not the only option you want to give your users to log into an application. Being able to use an existing account to log into a site lowers the barrier of signing up by not having to type in a single bit of information. Additionally it simplifies using an application by not having to remember additional usernames or passwords.
<p>Meteor ships with multiple authentication providers that allow users to use a social network instead of a local username. These networks include: </p>
<ul>
<li>Facebook </li>
<li>Github</li>
<li>Google </li>
<li>Meetup </li>
<li>Meteor Developer Account </li>
<li>Twitter </li>
<li>Weibo </li>
</ul>
<p>All of the above are based on oAuth, a complex way to pass authentication data from one site to another. There are also many community packages available that enable other authentication providers such as LinkedIn or Dropbox. As the fundamentals of working with Auth providers are the same for each provider, we will not need to discuss each. </p>
<h3>An introduction to oAuth</h3>
<p>The Open Authentication – or short: <i>oAuth</i> – mechanism has become very popular among web applications since its beginnings in 2007. The main idea behind it is to use a service provider, e.g., Facebook, to authenticate a user and allow a third-party application to access specific information from the authenticated user (access authorization). This could be simply the username or more sensitive information such as friends or a permission to post to the user’s wall. </p>
<p><img src="http://weblogs.java.net/sites/default/files/fig1.jpg" title="text"></p>
<p><i>Figure 1: oAuth flow using Facebook as the Service Provider </i></p>
<p>As Figure 1 shows, there are three main ingredients to every oAuth scenario: </p>
<ol>
<li>A Service Provider – e.g. Facebook or Twitter </li>
<li>A Consumer – e.g. your Meteor application </li>
<li>The user – e.g. an existing Facebook user wanting to log into your Meteor application </li>
</ol>
<p>Many sites on the web can act as a service provider for oAuth. We are going to use Facebook as an example to illustrate the process. Our Meteor application must be connected to Facebook. This is done by creating a new application on Facebook’s developer site. To verify our application is not a malicious script, it will be able to identify itself using the corresponding application ID (App ID) and a secret key (App Secret). These are basically the username and password for our Meteor server process. Once both are connected we can allow users to sign in with their Facebook account. </p>
<p>Instead of entering any credentials in our Meteor app, users can now click a button to log them in via Facebook. Assuming they are already logged in on Facebook they will now see a dialog asking them whether they want to share information with the Meteor application. </p>
<p>Behind the scenes the Meteor application forwarded the login request to Facebook as the service provider. If the user agrees to share their login information with the Meteor application, then Facebook generates an access token. This token lets the Meteor app know that the user has been authenticated properly and it grants the permissions provided by the user. In the simplest case Meteor may only have read access to the user’s e-mail address. Depending on the configuration settings we could also request more permissions such as posting to the user’s wall. </p>
<p>Not all oAuth providers support the same set of permissions, so they must all be individually configured. The advantage of using oAuth is that the consumer application can talk directly with the service provider to exchange data, if permissions exist. That way all Facebook friends, recent Tweets or number of private repos on Github can easily be accessed and added to the user’s profile.</p>
<h3>Integrating Facebook authentication </h3>
<p>To integrate oAuth authentication via Facebook in a Meteor app we need to perform the following steps: </p>
<ol>
<li>Add the accounts-facebook package </li>
<li>Create a new Facebook application </li>
<li>Configure the Facebook integration</li>
</ol>
<h3>ADDING ACCOUNTS-FACEBOOK TO AN APPLICATION </h3>
<p>The first step is to add Facebook as the authentication provider for our application. If the application already supports username/password authentication, it is sufficient to add a single package <code class="prettyprint">$ meteor add accounts-facebook </code>
<p>This package will not add any templates to the application. Therefore, if <code class="prettyprint">accountsfacebook</code> is the only package available in the project you would need to manually call all functionality within your templates. Or you can add the <code class="prettyprint">accounts-ui</code> package, which not only provides a login box for use with password authentication, but also for many oAuth services. </p>
<p>All oAuth packages require configuration. Just like users, this configuration is stored inside a MongoDB collection. A collection named <code class="prettyprint">meteor_accounts_loginServiceConfiguration</code> will be created as soon as the service is configured. Additionally, pending credentials will be stored temporarily as well, which is done in a dedicated collection. This collection is created at server startup already and is called <code class="prettyprint">meteor_oauth_pendingCredentials</code>. </p>
<p>There is no need to manually access either of these two collections. Meteor will use these internally only and there is no benefit in querying data from them directly.</p>
<h3>Add a login link in the HTML code</h3>
<p>Navigate to your HTML file. You can place the login link anywhere you like by simply adding the following code:</p>
<code class="prettyprint">{{&amp;gt; loginButtons}}</code>
<p>This will include the appropriate templates for each user action. </p>
<h3>CREATING A FACEBOOK APPLICATION </h3>
<p>If Meteor cannot find a configuration for integration with Facebook, the UI will show a red button labeled “Configure Facebook Login” instead of the regular log in button. Clicking on it will bring up a short configuration guide as well as two fields to provide the application ID and secret. </p>
<p>You will need to register yourself as a Facebook developer, which is free of charge but requires you to have a Facebook account. A new Facebook application can be created at <a href="https://developers.facebook.com"> <a href="https://developers.facebook.com" title="https://developers.facebook.com">https://developers.facebook.com</a> </a>. Under the Apps tab you can add a new application of type Web/WWW. Next you need to assign an application ID. This can be any name that helps you and your users to identify the application. As your users may eventually see the application name it is good practice to use the site name or something that closely describes your application. The actual category for your application and whether it is a test version of another Facebook application do not have any influence on the functionality and can be set to the values that best describe your project. </p>
<p>The site URL for a Facebook application that is used with a local development environment should typically be set to <a href="http://localhost:3000">http://localhost:3000</a>. The correct URL setting can be taken from the configuration dialog shown by Meteor. </p>
<p>Once you have made these settings, Facebook requires a contact e-mail to be set up for the application before you can activate the application. Navigate to the application dashboard on the Facebook Developer site and enter a contact e-mail in the settings section (see Figure 2). Finally you need to activate the application in the Status &amp; Review tab. </p>
<p><img src="http://weblogs.java.net/sites/default/files/fig2.jpg" title="text"></p>
<p><i>Figure 2: Settings for a Facebook application to integrate with Meteor </i></p>
<p>An activated Facebook application can be used to authenticate users. The last step to implement logging in via Facebook is to configure the Meteor application.</p>
<h3>CONFIGURING </h3>
<p>Open the Meteor application in the browser and click on the Facebook button to bring up the configuration dialog as shown in Figure 3.</p>
<p><img src="http://weblogs.java.net/sites/default/files/fig3.jpg" title="text"> </p>
<p><i>Figure 3: Configuration dialog for Facebook integration </i></p>
<p>Besides the basic instructions on how to create a Facebook application the configuration dialog lets you add the application credentials (App ID and App Secret) as well as a login style. The default is to use a popup-based dialog, which means the application window will remain when the user logs into Facebook and a new window with the Facebook dialog is opened. In contrast, the redirect-based login style will leave the application, redirect the current browser window to Facebook, and reload the entire application once the authentication was successful. Unless you plan on running your application inside a Cordova container on mobile devices13 it is preferable to use the popupbased login.</p>
<p>Save the configuration and users can start logging in via Facebook. Should you have misconfigured the application you can either manually delete the configuration information from the meteor_accounts_loginServiceConfiguration collection inside the MongoDB or simply issue meteor reset to empty all collections. </p>
<p><b>REMEMBER</b> All oAuth configuration is stored inside the application database. Whenever you issue the meteor reset command to empty the database it will also remove all oAuth configuration data from the database.</p>
<table id="attachments" class="sticky-enabled">
<thead><tr><th>Attachment</th><th>Size</th> </tr></thead>
<tbody>
<tr class="odd"><td><a href="http://www.java.net/sites/default/files/fig1.jpg">fig1.jpg</a></td><td>20.48 KB</td> </tr>
<tr class="even"><td><a href="http://www.java.net/sites/default/files/fig2.jpg">fig2.jpg</a></td><td>40.99 KB</td> </tr>
<tr class="odd"><td><a href="http://www.java.net/sites/default/files/fig3.jpg">fig3.jpg</a></td><td>41.34 KB</td> </tr>
</tbody>
</table>
http://www.java.net/blog/manningpubs/archive/2015/02/12/meteor-action-authenticating-users-oauth#commentsBlogsWeb Development ToolsThu, 12 Feb 2015 12:38:47 +0000manning_pubs931597 at http://www.java.netRMI Unplugedhttp://www.java.net/blog/kcpeppe/archive/2015/01/27/rmi-unpluged
<!-- | 0 --><p>I've just finished tuning a client's application where one of the items on the table was to find the source of calls to System.gc(). Using <a href=http://www.jclarity.com/censum>Censum</a> made easy work of understanding the source of the calls. The team I was working with not only missed that these calls to System.gc() where creating havoc with their end users experience, they didn't even realize that something, some where was messing things up!</p>
<p>It's not to say that developers are completely oblivious to the issue. Developers have gotten better about not placing calls to System.gc() in their code, but they often still don't see the call being made in their GC logs. One of the confusing causes of unwanted calls to <code class="prettyprint">System.gc()</code> comes from Java (typically Java EE) applications that have remote objects, and therefore use <a href=http://www.oracle.com/technetwork/java/javase/tech/index-jsp-136424.html>RMI</a>. In the early days these calls came into applications at the rate of 1 a minute and as you can imagine, it caused a lot of consternation for those analyzing the performance of Java EE applications making use of Session or Entity beans. After much discussion, the call rate was reduced to the current rate of once an hour. Better but it can still be disruptive as much as it can be useful. Lets expose a little bit of how the JVM works by digging into how RMI plays with the Garbage Collectors.</p>
<p>The Remote Procedure Call (RPC) protocol (originally written in C) allowed one process to call an exposed function in another process. The function in the other process was expected to manage all of it’s resourses on it own. For example, if it allocated memory, it was responsible for freeing it. The only piece of management that relied on the “client” doing the right thing was to shutdown the connection. Even then, a broken socket would cause the RPC library to close down the connection on its own.</p>
<p>Move forward and we can see that the RPC style of removing is re-implemented in Java with RMI and CORBA. Together, these protocols expose classes that you can instantiate and interact with, in a remote JVM. Without getting in too deeply into how all this works one can quickly see that this leaves us with a problem. In Java, all objects that are unreachable will be garbage collected. For a remote JVM to access an object in our heap we must hold a pointer to that object in the remote JVM's behalf. This implies that to clean up, the remote JVM has to some how signal when it's finished with the remote object. Given the nature of the resources needed to make all this work, the implementors of RMI decided that they should force a call to a collection of tenured space on a regular basis. In practical terms this means, RMI makes regular calls to System.gc().</p>
<p>If you look deep inside RMI you’ll run across the class <code class="prettyprint">ObjectTable</code>. That class is responsible for retaining the roots of all objects that support a remote call. All of the objects added to this table are wrapped in a <code class="prettyprint">WeakReference</code>. Further more, <code class="prettyprint">ObjectTable</code> manages it's own <codeReferenceQueue</code> using an internal <code class="prettyprint">Reaper</code> (implements <code class="prettyprint">Runnable</code>). Additionally, the connection classes from java.io all rely on finalization to clean up resources such as file handles. In addition, to ObjectTable holding onto the roots for the Distributed Garbage Collector (DGC - which cleans up for RMI), all newly disconnected objects must be identified by a regular garbage collection cycle, cleaned out of their respective <code class="prettyprint">ReferenceQueue</code>, and then reclaimed with a subsequent collection.</p>
<p>To support all of this, you can find a reference to the class <code class="prettyprint">GC.LatencyRequest</code>. The class <code class="prettyprint">sun.misc.GC</code> class is a singleton whose primary function is to make sure that a collection of tenured has run within a fixed period of time (otherwise known as gcLatency). The class is supported by the native method <code class="prettyprint">GC.LatencyRequest gcLatencyRequest()</code>. This native call returns an estimate of the elapsed time since the last GC. In the case of the Serial, Parallel, CMS and G1 collectors, it returns the elapsed time since tenured space was collected. If that elapsed time exceeds the latency target, then a <code class="prettyprint">System.gc()</code> is called. As long as there are objects in <code class="prettyprint">ObjectTable</code>, the <code class="prettyprint">GC::run()</code> method (listing below) will remain active.</p>
<pre class="prettyprint"><code>public void run() {<br /> for (;;) {<br /> long l;<br /> synchronized (lock) {<br /> l = latencyTarget;<br /> if (l == NO_TARGET) {<br /> /* No latency target, so exit */<br /> GC.daemon = null;<br /> return;<br /> }<br /><br /> long d = maxObjectInspectionAge();<br /> if (d >= l) {<br /> /* Do a full collection. There is a remote possibility<br /> * that a full collection will occurr between the time<br /> * we sample the inspection age and the time the GC<br /> * actually starts, but this is sufficiently unlikely<br /> * that it doesn't seem worth the more expensive JVM<br /> * interface that would be required.<br /> */<br /> System.gc();<br /> d = 0;<br /> }<br /><br /> /* Wait for the latency period to expire,<br /> * or for notification that the period has changed<br /> */<br /><br /> try {<br /> lock.wait(l - d);<br /> } catch (InterruptedException x) {<br /> continue;<br /> }<br /> }<br /> }<br /> }</code></pre>
<p>The default value for latencyTarget is 3600000ms. Oddly enough, you can override this by setting your own latency target in code as follows.</p>
<pre class="prettyprint"><code> public static void main(String[] args) throws Throwable {<br /> System.out.println( “latency target: “ + GC.currentLatencyTarget());<br /> System.out.println("turn on GC");<br /> LatencyRequest request = GC.requestLatency( 1000);<br /> System.out.println( “latency target: “ GC.currentLatencyTarget());<br /> Thread.sleep(6000);<br /> System.out.println("turn off GC");<br /> request.cancel();<br /> Thread.sleep( 6000);<br /> }</code></pre>
<p>If you run this code with the flags -verbose:gc and -XX:+PrintGCDetails, you will see a call to System.gc() made once a second for 6 seconds. The output you should see will look something like;</p>
<pre class="prettyprint"><code>latency target: 0<br />turn on GC<br />latency target: 1000<br />[GC (System.gc()) 5243K->792K(251392K), 0.0010124 secs]<br />[Full GC (System.gc()) 792K->582K(251392K), 0.0045390 secs]<br />[GC (System.gc()) 3203K->678K(251392K), 0.0006147 secs]<br />[Full GC (System.gc()) 678K->571K(251392K), 0.0108860 secs]<br />[GC (System.gc()) 1882K->571K(251392K), 0.0006402 secs]<br />[Full GC (System.gc()) 571K->568K(251392K), 0.0060488 secs]<br />[GC (System.gc()) 568K->568K(251392K), 0.0003195 secs]<br />[Full GC (System.gc()) 568K->568K(251392K), 0.0018367 secs]<br />[GC (System.gc()) 568K->568K(251392K), 0.0005905 secs]<br />[Full GC (System.gc()) 568K->568K(251392K), 0.0028363 secs]<br />[GC (System.gc()) 568K->568K(251392K), 0.0003654 secs]<br />[Full GC (System.gc()) 568K->568K(251392K), 0.0018081 secs]<br />turn off GC</code></pre>
<p>If <code class="prettyprint">ObjectTable</code> is becomes empty, it will reset the GC latency to 0 which will overwrite your settings and turn off the GC::run method. If another RMI request is made, the target latency will be set to the preset value for RMI. This implies that any settings we make in code are subject to change at any time. A safer way to set the GC latency for RMI is to set the system properties sun.rmi.dgc.client.gcInterval and sun.rmi.dgc.server.gcInterval.</p>
<p>Generally I don’t find these extraneous calls to <code class="prettyprint">System.gc()</code> to be useful so I often tune down the values to as much as <code class="prettyprint">Long.MAX_LONG</code> milliseconds. However, if you are using RMI and tenured is never collected, it’s likely that you want to schedule a Full collection simply to recycle things like file descriptors. File descriptors in particular a special as they are processed with finalization, which means a full GC must run in order for these objects to be inserted into the finalization <code class="prettyprint">ReferenceQueue</code>.</p>
<p>Final note, there are other sources of JDK internal calls to <code class="prettyprint">System.gc()</code>. These include:<br />
* Use of <code class="prettyprint">FileChannel.map</code><br />
* Use of <code class="prettyprint">ByteBuffer.allocateDirect()</code>.<br />
The later will make the call if reference processing isn’t keeping up and you are hitting MaxDirectMemorySize.</p>
<p>Yet Another Final Note, Yes, I know the Java API spec says that a JVM can ignore calls to <code class="prettyprint">System.gc()</code> if it so chooses to. The reality is, in OpenJDK all calls to <code class="prettyprint">System.gc()</code> are honoured unless -XX:+DisableExplicityGC is set on the command line. If not, the calls are synchronized resulting in all of the calls being stacked up all running one right after the other.... I have an expercise in my <a href=http://www.kodewerk.com/workshop.html>performance tuning workshop</a> that does just this and believe me, it messes things up very badly. People are always looking at me very badly when they finally sort out what is happening. But then, if they were to use <a href=http://www.jclarity.com/censum/>Censum</a>. they'd see the problem in seconds!</p>
<p>In a note from Charlie Hunt... he kindly pointed out that I forgot to mention that using -XX:+ExplicitGCInvokesConcurrent is an option for CMS and G1 to avoid the single threaded Full GC that typically is triggered with a System.gc() is called. Thanks for reminding me Charlie.</p>
http://www.java.net/blog/kcpeppe/archive/2015/01/27/rmi-unpluged#commentsBlogsDistributedEJBJ2EEJ2SEOpen JDKPerformanceTue, 27 Jan 2015 16:44:05 +0000kcpeppe931533 at http://www.java.netIf Flipper extends Flapper, Slapper implements Slipper, and Flipper extends Slipper, is Flipper a class or an interface?http://www.java.net/blog/manningpubs/archive/2015/01/24/if-flipper-extends-flapper-slapper-implements-slipper-and-flipper-extends-slipper-flipper-cl
<div class="field field-type-filefield field-field-thumb-100x70">
<div class="field-items">
<div class="field-item odd">
<img class="imagefield imagefield-field_thumb_100x70" width="150" height="187" alt="" src="http://www.java.net/sites/default/files/manning_pubs/1coverOCP.jpg?1422119189" /> </div>
</div>
</div>
<p><b>By Mala Gupta, <a href="http://www.manning.com/gupta2/">OCP Java SE 7 Programmer II Certification Guide</a></b></p>
<p>Save 40% on <a href="http://www.manning.com/gupta2/">OCP Java SE 7 Programmer II Certification Guide</a> with discount code <b>jn15ocp</b> at manning.com.</p>
<p>You’ll be amazed at how easily you can identify and implement IS-A and HAS-A relationships between classes and objects, if you remember one simple rule—follow the literal meaning of these terms:<.p></p>
<p>1. IS-A—This relationship is implemented when: </p>
<ul>
<li>A class extends another class (derived-class IS-A base-class).</li>
<li>An interface extends another interface (derived interface IS-A baseinterface).</li>
<li>A class implements an interface (class IS-A implemented interface).</li>
</ul>
<p>2. HAS-A—This relationship is implemented by defining an instance variable. If a class— say, <code class="prettyprint">MyClass</code>—defines an instance variable of another class—say, <code class="prettyprint">YourClass—MyClass</code> HAS-A <code class="prettyprint">YourClass</code>. If <code class="prettyprint">MyClass</code> defines an instance variable of an interface—say, <code class="prettyprint">YourInterface—YourClass</code> HAS-A <code class="prettyprint">YourInterface.</code>
<blockquote><p><b>EXAM TIP</b> Representing IS-A and HAS-A relationships by using (quick) UML diagrams can help you on the exam. Though you may not see UML diagrams on the exam, creating quick UML diagrams on an erasable board (or something similar) provided to you during the exam will help you answer these questions. The exam will test whether you can identify and implement these relationships in your code, so let’s start with an example of an IS-A relationship.</p></blockquote>
<h2>Identifying and implementing an IS-A relationship</h2>
<p>An <i>IS-A relationship</i> is implemented by extending classes or interfaces and implementing interfaces. Traverse the inheritance tree <i>up</i> the hierarchy to identify this relationship. A derived class IS-A type of its base class and its implemented interfaces. A derived interface IS-A type of its base interface. The reverse isn’t true; a base class or interface is not a type of its derived class or interface.</p>
<p>Here’s a simple but long example for you to read and comprehend:</p>
<pre class="prettyprint"><code>interface Movable {}<br />interface Hunter extends Movable {}<br /><br />class Animal implements Movable {}<br />class Herbivore extends Animal {}<br />class Carnivore extends Animal implements Hunter {}<br /><br />class Cow extends Herbivore {}<br />class Goat extends Herbivore {}<br /><br />class Lion extends Carnivore {}<br />class Tiger extends Carnivore {}</code></pre>
<p>Which of the following options do you think are correct?</p>
<ul>
<li>Cow IS-A Hunter.</li>
<li>Tiger IS-A Herbivore.</li>
<li>Cow IS-A Movable.</li>
<li>Animal IS-A Herbivore.</li>
</ul>
<p>To answer this question, refer to the preceding code, and you’ll notice that interface <code class="prettyprint">Hunter</code> is implemented only by class <code class="prettyprint">Carnivore</code>. The class <code class="prettyprint">Cow</code> doesn’t extend class <code class="prettyprint">Carnivore</code>. So, <code class="prettyprint">Cow</code> IS-A <code class="prettyprint">Hunter</code> is incorrect.</p>
<p>Similarly, you can refer to the preceding code to answer all the other options. Option 2 is incorrect because class <code class="prettyprint">Tiger</code> doesn’t extend class <code class="prettyprint">Herbivore</code>. Option 3 is correct because interface <code class="prettyprint">Movable</code> is implemented by class <code class="prettyprint">Animal</code>, which is the base class of <code class="prettyprint">Herbivore</code>, extended by class <code class="prettyprint">Cow</code>.</p>
<p>Option 4 is incorrect because you can’t traverse the hierarchy tree down to determine an IS-A relationship. Evaluate it like this– A <code class="prettyprint">Herbivore</code> IS-A type of <code class="prettyprint">Animal</code> with some additions or modifications because a <code class="prettyprint">Herbivore</code> can modify (override) methods of class <code class="prettyprint">Animal</code> and add new ones. But <code class="prettyprint">Animal</code> IS-NOT-A <code class="prettyprint"> Herbivore</code>. <code class="prettyprint">Animal</code> can also be <code class="prettyprint">Carnivore</code>.</p>
<p>Phew! So we had to refer to the code multiple times to answer each option. How about representing the relationships between these classes and interfaces by using UML notation, as shown in figure 1?</p>
<p><img src="http://weblogs.java.net/sites/default/files/Fig1OCP.jpg"></p>
<p><b><i>Figure 1 A UML representation can help answer questions about IS-A relationships between classes and interfaces.</i></b></p>
<p>If you can traverse up, from a derived class or interface to a base class or interface, following the connecting arrows (lined or dashed), the derived entity shares an IS-A relationship with the base entity. If you think that the preceding figure seems to depict a rather polished form of a class-and-interface relationship, look at figure 2, which shows the same relationship in a rather raw form.</p>
<p><img src="http://weblogs.java.net/sites/default/files/fig2OCP.jpg"></p>
<p><b><i>Figure 2 A rather raw form of the UML diagram that you may draw on an erasable board while taking your exam to represent an IS-A relationship between classes and interfaces.</i></b></p>
<p>I understand that you may not have the time or patience to draw neat diagrams during the exam because of time constraints or space available to you on an erasable board. The main point to remember is to use correct connecting lines to connect two types. Use an arrow to show IS-A relationship and a line to show HAS-A relationship.
<p>When I attempted this exam, I drew similar not-so-good-looking diagrams. Believe me, they helped me answer questions quickly, without referring to the code again and again. Also, the questions on the exam may not use names that indicate an obvious relationship between classes and interfaces. The next “Twist in the Tale” exercise will ensure that you get the hang of this point.</p>
<p><b>Twist in the Tale 2</b></p>
<p>Let’s modify the code used in this example as follows:</p>
<pre class="prettyprint"><code>interface InterH {}<br />interface SameY extends InterH {}<br />class JamD implements InterH {}<br />class SunP extends JamD {}<br />class BreaU extends JamD implements SameY {}</code></pre>
<p>Your task is to identify which of the following statements are true:</p>
<pre class="prettyprint"><code>a) SunP IS-A InterH.<br />b) JamD IS-A SameY.<br />c) InterH IS-A InterH.<br />d) SameY IS-A JamD.</code></pre>
<p>First attempt the exercise without drawing a UML diagram, and then by drawing and using a UML diagram. Do you think using the UML diagram helps you answer the questions quicker?</p>
<blockquote><p><b>EXAM TIP</b> The key to finding the types that participate in an IS-A relationship is to find your way, up the hierarchy tree, in the direction of the arrows. This technique will not only help you with the exam, but also go a long way in your professional career.</p></blockquote>
<h3>IMPLEMENTING AN IS-A RELATIONSHIP</h3>
<p>You can implement an IS-A relationship by extending classes or interfaces, or by implementing interfaces. Here is a quick set of rules for implementing inheritance between classes and interfaces in code:</p>
<ul>
<li>A class inherits another class by using the keyword extends.</li>
<li>A class implements an interface by using the keyword implements.</li>
<li>An interface inherits another interface by using the keyword extends.</li>
</ul>
<p>How will you implement the following relationship in code?</p>
<code class="prettyprint">Herbivore</code> IS-A <code class="prettyprint">Animal</code>
<p>Because you don’t know whether either <code class="prettyprint">Herbivore</code> or <code class="prettyprint">Animal</code> refers to a class or an interface, you have the following possibilities:</p>
<ul>
<li>Herbivore and Animal are classes. Herbivore extends Animal.</li>
<li>Herbivore and Animal are interfaces. Herbivore extends Animal.</li>
<li>Herbivore is a class, and Animal is an interface. Herbivore implements Animal.</li>
</ul>
<p>Figure 3 shows these three possible implementations.</p>
<p><img src="http://weblogs.java.net/sites/default/files/fig3OCP.jpg"></p>
<p><b><i>Figure 3 How to implement an IS-A relationship, if you don’t know whether the relationship is between classes, interfaces, or both.</i></b></p>
<p>Now, let’s add another relationship to the previous one. How would you implement the following relationship and rules in code?</p>
<ul>
<li><code class="prettyprint">Herbivore</code> IS-A <code class="prettyprint">Animal</code>.</li>
<li><code class="prettyprint">Carnivore</code> IS-A <code class="prettyprint">Animal</code>.</li>
<li><code class="prettyprint">Animal</code> can define only abstract methods and constants.</li>
</ul>
<p>The third rules makes it clear that <code class="prettyprint">Animal</code> is an interface. But you still don’t know whether <code class="prettyprint">Herbivore</code> or <code class="prettyprint">Carnivore</code> are classes or interfaces. So you can have the following possibilities:</p>
<ul>
<li><code class="prettyprint">Herbivore</code> and <code class="prettyprint">Carnivore</code> are interfaces that extend interface <code class="prettyprint">Animal</code>.</li>
<li><code class="prettyprint">Herbivore</code> and <code class="prettyprint">Carnivore</code> are classes that implement interface <code class="prettyprint">Animal</code>.</li>
<li><code class="prettyprint">Herbivore</code> is a class that implements interface <code class="prettyprint">Animal</code>. <code class="prettyprint">Carnivore</code> is an interface that extends interface <code class="prettyprint">Animal</code>.</li>
<li><code class="prettyprint">Herbivore</code> is an interface that extends interface <code class="prettyprint">Animal</code>. <code class="prettyprint">Carnivore</code> is a class that implements interface <code class="prettyprint">Animal</code>.</li>
</ul>
<p>These relationships can be implemented as shown in figure 4.</p>
<p><img src="http://weblogs.java.net/sites/default/files/fig4OCP.jpg"></p>
<p><b><i>Figure 4 How to implement an IS-A relationship between three entities, one of which is an interface</i></b></p>
<p>The exam may specify a similar set of rules and ask you to choose the code that you think correctly implements the specified conditions. Let’s work through another set of rules and implement the relationships in code. How would you implement the following relationships and rules in code?</p>
<ol>
<li>Abc IS-A Xyz.</li>
<li>Abc defines methods and instance variables.</li>
<li>Xyz can declare only abstract methods.</li>
<li>Xyz IS-A Lmn.</li>
</ol>
<p>Rule 2 states that <code class="prettyprint">Abc</code> is a class, because an interface can’t define instance variables. Rule 3 states that <code class="prettyprint">Xyz</code> is an interface, because a class can declare both abstract and nonabstract methods. When you go up the hierarchy tree of an interface, you can find only another interface. In other words, <code class="prettyprint">Lmn</code> is also an interface. The preceding rules evaluate to the following:</p>
<ul>
<li>Abc is a class.</li>
<li>Xyz and Lmn are interfaces.</li>
<li>Abc implements Xyz.</li>
<li>Xyz extends Lmn.</li>
</ul>
<p>After the evaluation, these rules seem simple to implement. Figure 5 shows the relationships in UML notation and in code.</p>
<p><img src="http://weblogs.java.net/sites/default/files/fig5OCP.jpg"></p>
<p><b><i>Figure 5 Implementing a set of rules and an IS-A relationship between three entities: two interfaces, and a class</i></b></p>
<p>When a class defines an instance variable of another class, they share a HAS-A relationship, covered in the next section.</p>
<h2>Identifying and implementing a HAS-A relationship</h2>
<p>As compared to an IS-A relationship, a <i>HAS-A relationship</i> is easy to identify and implement. I hope this statement relieves you! Consider this definition of the bare-bones class <code class="prettyprint">Engine</code>:</p>
<code class="prettyprint">class Engine {}</code>
<p>Which of the following classes (<code class="prettyprint">Statistics, Car, PartsFactory, TestCar</code>) do you think shares a HAS-A relationship with class Engine?</p>
<pre class="prettyprint"><code>class Statistics {<br /> static Engine engine; #A<br />}<br />class Car {<br /> Engine engine; #B<br />}<br />class PartsFactory {<br /> Object createEngine() {<br /> Engine engine = new Engine(); #C<br /> //.. code<br /> return engine;<br /> }<br />}<br />class TestCar {<br /> boolean testEngine(Engine engine) { #D<br /> //.. code<br /> }<br />}</code></pre><br />
<b>#A Statistics defines class variable of type Engine<br />
#B Car defines instance variable of type Engine<br />
#C PartsFactory defines local variable of type Engine<br />
#D TestCar defines method parameter of type Engine</b></p>
<p>Of all the preceding classes—<code class="prettyprint">Statistics, Car, PartsFactory</code>, and <code class="prettyprint">TestCar</code>—only <code class="prettyprint">Car</code> shares a HAS-A relationship with the class <code class="prettyprint">Engine</code> because <code class="prettyprint">Car</code> defines an instance variable of type <code class="prettyprint">Engine</code>. Note that it doesn’t matter whether the instance variable engine in class <code class="prettyprint">Car</code> is initialized with an object. The HAS-A relationship is shared by the classes.</p>
<blockquote><p><b>EXAM TIP</b> Class and interfaces can share a HAS-A relationship with each other. If a class or interface—say, Type1—defines an instance variable of class or interface—say, Type2, Type1 HAS-A Type2 is correct. The reverse isn’t correct. Also, the HAS-A relationship is shared by classes, and so the relationship is not affected, whether the instance variable is initialized or not.</p></blockquote>
<table id="attachments" class="sticky-enabled">
<thead><tr><th>Attachment</th><th>Size</th> </tr></thead>
<tbody>
<tr class="odd"><td><a href="http://www.java.net/sites/default/files/Fig1OCP.jpg">Fig1OCP.jpg</a></td><td>38.59 KB</td> </tr>
<tr class="even"><td><a href="http://www.java.net/sites/default/files/fig2OCP.jpg">fig2OCP.jpg</a></td><td>18.52 KB</td> </tr>
<tr class="odd"><td><a href="http://www.java.net/sites/default/files/fig3OCP.jpg">fig3OCP.jpg</a></td><td>45.71 KB</td> </tr>
<tr class="even"><td><a href="http://www.java.net/sites/default/files/fig4OCP.jpg">fig4OCP.jpg</a></td><td>43.63 KB</td> </tr>
<tr class="odd"><td><a href="http://www.java.net/sites/default/files/fig5OCP.jpg">fig5OCP.jpg</a></td><td>16.17 KB</td> </tr>
</tbody>
</table>
http://www.java.net/blog/manningpubs/archive/2015/01/24/if-flipper-extends-flapper-slapper-implements-slipper-and-flipper-extends-slipper-flipper-cl#commentsBlogsJava EnterpriseSat, 24 Jan 2015 21:49:15 +0000manning_pubs931503 at http://www.java.netWhat if your logs were in JSON?http://www.java.net/blog/timboudreau/archive/2015/01/18/what-if-your-logs-were-json
<!-- | 0 --><p>Bunyan is a NodeJS library that rethinks logging in some really useful ways. I wrote a <a href="http://j.mp/1AOGgUe">Java port you can use in your applications</a>.</p>
<p>In particular, with Bunyan, logs are JSON - and Bunyan comes with a great filtering and analysis tool.</p>
<p>The Java port uses some innovative techniques to make logging simple and foolproof - in particular, a use of <code class="prettyprint">AutoCloseable</code> to make a logging code simple and foolproof.</p>
<p>A walkthrough <a href="http://j.mp/1AOGgUe">on my real blog on timboudreau.com</a>.</p>
http://www.java.net/blog/timboudreau/archive/2015/01/18/what-if-your-logs-were-json#commentsBlogsDeploymentDistributedGlassFishJ2EEJ2SEJava EnterpriseJava Web Services and XMLNetBeansOpen SourceWeb Development ToolsMon, 19 Jan 2015 02:43:19 +0000timboudreau931458 at http://www.java.netCongratulations - you're a (horrible) mobile developer! from Apache Cordova in Action by Raymond Camdenhttp://www.java.net/blog/manningpubs/archive/2015/01/18/congratulations-youre-horrible-mobile-developer-apache-cordova-action-raymond-camden
<div class="field field-type-filefield field-field-thumb-100x70">
<div class="field-items">
<div class="field-item odd">
<img class="imagefield imagefield-field_thumb_100x70" width="150" height="188" alt="" src="http://www.java.net/sites/default/files/manning_pubs/camden_cover150.jpg?1421627201" /> </div>
</div>
</div>
<p> Save 40% on <a href=http://manning.com/camden/>Apache Cordova in Action</a> with discount code <b> jn15acia </b>at manning.com</p>
<p>Ok, that may be just a tiny bit over the top, but most likely there is a bit of truth to it as well. You know how to install Cordova, how to generate native binaries from HTML, and how to make use of fancy device features with plugins. That’s all fairly straightforward: Install a SDK, install the command line tool, write some HTML, and whammo, see it on your device. But that doesn’t mean you know how to create a good mobile application. Taste is subjective.</p>
<p>While it is difficult to precisely describe what makes a good mobile application, there are definitely a set of guidelines that help define what a successful mobile application looks like. And notice I'm not saying a successful hybrid mobile application. Your users don't care what you used to build your application. They only care about the end result. Therefore the guidelines for a good hybrid mobile application are going to be same as a good 100% native built mobile application as well. </p>
<p>A good mobile application is readable on a variety of form factors. Whether opened in an iPhone 5 or some enormous Android phablet, text should be readable and buttons easy to click with fat fingers. A good mobile application demonstrates these features: </p>
<ul>
<li>It has a simple, easily understandable user interface. By using common design idioms (a shopping cart icon for example) users have a better idea of what to expect when using your application. </li>
<li>It performs well with little to no noticeable lag. </li>
<li>It works in a variety of network conditions (both off and online). </li>
<h3>A Good Example of Bad UI </h3>
<p>Imagine the most simple application possible - an application that prompts you for your name and then simply tells you hello. Figure 1 is a mock-up of the UI for the application, both the initial view and what is displayed after entering a name. </p>
<p><img src="http://www.java.net/sites/default/files/Fig1.png" title="Fig1"></p>
<p><b><i>Figure 1 Our simple little application. Looks pretty now, right? </i></b></p>
<p>Building this application would be rather trivial. You should create a new Cordova application if you want to test this. The source code is available in the zip downloaded from the Manning web site. You will find it in the c5/simple folder. Listing 1 represents the HTML used for the application. </p>
<p><b>Listing 1 Simple application HTML (simple/www/index.html)</b></p>
<pre class="prettyprint"><code><html> <br /> <head> <br /> <title>Simple App</title> <br /> </head> <br /> <br /> <body> <br /> <br /> <form id="nameForm"> <br /> <label for="name">Enter your name</label> #1 <br /> <input type="text" id="name" name="name"> #2 <br /> <input type="submit" value="Submit"> #3 <br /> </form> <br /> <br /> <div id="result"></div> #4 <br /> <br /> <script src="cordova.js"></script> <br /> <script src="js/app.js"></script> <br /> </body> <br /></html> </code></pre>
<p><b>
<ul>
<li>#1 Label used to prompt for your name. </li>
<li>#2 Input field where the user enters their name. </li>
<li>#3 Button used to submit the form. </li>
<li>#4 Empty div that will be filled with the user's name. </li>
</ul>
<p></b></p>
<p>There isn't anything particularly interesting about this code, but note the lack of any styling via an embedded or included CSS file. That's totally OK - you don't have to style anything, but as you can probably guess, this is going to bite us in the rear in a few moments. Now look at the JavaScript in listing 2. </p>
<p><b>Listing 2 Simple application JavaScript (simple/www/js/app.js) </b></p>
<pre class="prettyprint"><code>document.addEventListener("deviceready", init, false); function init() { <br /> <br /> document.querySelector("#nameForm").addEventListener("submit", <br /> function(e) { <br /> e.preventDefault(); <br /> var name = document.querySelector("#name").value; var msg = "Hello, "+name; <br /> document.querySelector("#result").innerText = msg; <br /> }, false); <br /> <br />} </code></pre>
<p>So far so good. Since our application has one feature (get the name and display it), the code is trivial to the point of being pointless. To be clear, this is not something you want to use Cordova for, but it will be very useful in demonstrating the type of design issues you're going to be running into when building hybrid applications. Let's fire up the application and send it to an Android device to see how beautiful it looks. </p>
<p><img src="http://weblogs.java.net/sites/default/files/fig2a.png" title="fig2a"></p>
<p><b><i>Figure 2 Our simple application is displayed in Android<</i></b></p>
<p>While readable in this book, that text would be rather small on a real mobile device. The field where users need to enter their name is also somewhat small. Your author has rather large hands and if there was anything else by that field it would be difficult to not touch the wrong thing. Even worse, the button to submit the form is tiny. If your user needs to carefully think before they interact with your application than you've probably got a problem. Figure 3 calls out these issues, and more. </p>
<p><img src="http://www.java.net/sites/default/files/fig3_0.png" title="fig3"></p>
<p><b><i>Figure 3 Our application's UI criticized. </i></b></p>
<p>This is a perfect example of a case where our code works, but isn't optimized for the mobile platform. This is definitely not a bug in Cordova, it simply reflects the fact that when building hybrid applications, you need to think differently than you would when building web sites for the desktop. </p>
<table id="attachments" class="sticky-enabled">
<thead><tr><th>Attachment</th><th>Size</th> </tr></thead>
<tbody>
<tr class="odd"><td><a href="http://www.java.net/sites/default/files/Fig1.png">Fig1.png</a></td><td>9.04 KB</td> </tr>
<tr class="even"><td><a href="http://www.java.net/sites/default/files/fig3_0.png">fig3.png</a></td><td>17.33 KB</td> </tr>
<tr class="odd"><td><a href="http://www.java.net/sites/default/files/fig2a.png">fig2a.png</a></td><td>44.87 KB</td> </tr>
</tbody>
</table>
http://www.java.net/blog/manningpubs/archive/2015/01/18/congratulations-youre-horrible-mobile-developer-apache-cordova-action-raymond-camden#commentsBlogsJava ToolsMobilitySun, 18 Jan 2015 17:04:02 +0000manning_pubs931455 at http://www.java.netIntroduction to Graphs from Grokking Algorithms by Aditya Y. Bhargavahttp://www.java.net/blog/manningpubs/archive/2015/01/15/introduction-graphs-grokking-algorithms-aditya-y-bhargava
<div class="field field-type-filefield field-field-thumb-100x70">
<div class="field-items">
<div class="field-item odd">
<img class="imagefield imagefield-field_thumb_100x70" width="150" height="188" alt="" src="http://www.java.net/sites/default/files/manning_pubs/bhargava_cover150_0.jpg?1421391374" /> </div>
</div>
</div>
<p><b>By Aditya Y. Bhargava, author of <a href="http://www.manning.com/bhargava/"> Highlighted text </a>Grokking Algorithms</a></b></p>
<p>Save 40% on <a href="http://www.manning.com/bhargava/">Grokking Algorithms</a> with discount code <b>jn15ga</b> at manning.com.</p>
<p>Suppose you are in San Francisco, and you want to go from Twin Peaks to the Golden Gate bridge. You want to get there by bus, in the minimum number of transfers. Here are your options:</p>
<p><img src="http://www.java.net/sites/default/files/fig1_1.png" title="fig1"></p>
<p>What’s your algorithm to find the path with the least number of steps?</p>
<p>Well, can you get there in one step? Here are all the places you can get to in one step:</p>
<p><img src="http://www.java.net/sites/default/files/fig2.png" title="fig2"></p>
<p>The bridge is not highlighted, you can’t get there in one step. Can you get there in two steps?</p>
<p><img src="http://www.java.net/sites/default/files/fig3.png" title="fig3"></p>
<p>Again, the bridge isn’t there, so we can’t get to the bridge in two steps. What about three steps?</p>
<p><img src="http://www.java.net/sites/default/files/fig4.png" title="fig4"></p>
<p>Aha! Now the Golden Gate bridge shows up. So it takes three steps to get from Twin Peaks to the bridge using this route:</p>
<p><img src="http://www.java.net/sites/default/files/fig5.png" title="fig5"></p>
<p>There are other routes that will get you to the bridge too, but they are longer (4 steps). Our algorithm found that the shortest route to the bridge is three steps long.</p>
<p>This type of problem is called a "shortest path" problem. You are always trying to find the shortest *something*. It could be the shortest route to your friend’s house.</p>
<p>It could be the shortest number of moves to checkmate in a game of chess. The algorithm to solve a "shortest path" problem is called breadth-first search.</p>
<p>To figure out how to get from Twin Peaks to the Golden Gate bridge, there were two steps:</p>
<ul>
<li>Model the problem as a graph.</li>
<li>Solve the problem using breadth-first search.</li>
<p>I’ll cover what graphs are. </p>
<p>A graph models a set of connections. For example, suppose you and your friends are playing poker, and you want to model who owes whom money. Here’s how you could say "Alex owes Rama money":</p>
<p><img src="http://www.java.net/sites/default/files/fig6.png" title="fig6"></p>
<p>The full graph could look something like this:</p>
<p><img src="http://www.java.net/sites/default/files/fig7.png" title="fig7"></p>
<p>(Graph of people who owe other people poker money)<br />
Alex owes Rama money, Tom owes Adit money, and so on. Each graph is made up of nodes and edges:</p>
<p><img src="http://www.java.net/sites/default/files/fig8.png" title="fig8"></p>
<p>That’s all there is to it! Graphs are made up of nodes and edges. A node can be directly connected to many other nodes. Those nodes are called its neighbors. In neighbors this graph, Rama is Alex’s neighbor. Adit is not Alex’s neighbor, because they are not directly connected. But Adit is Rama’s and Tom’s neighbor.</p>
<p>Graphs are a way to model how different things are connected to one another.</p>
<table id="attachments" class="sticky-enabled">
<thead><tr><th>Attachment</th><th>Size</th> </tr></thead>
<tbody>
<tr class="odd"><td><a href="http://www.java.net/sites/default/files/fig1_1.png">fig1.png</a></td><td>18.07 KB</td> </tr>
<tr class="even"><td><a href="http://www.java.net/sites/default/files/fig2.png">fig2.png</a></td><td>11.47 KB</td> </tr>
<tr class="odd"><td><a href="http://www.java.net/sites/default/files/fig3.png">fig3.png</a></td><td>10.54 KB</td> </tr>
<tr class="even"><td><a href="http://www.java.net/sites/default/files/fig4.png">fig4.png</a></td><td>11.81 KB</td> </tr>
<tr class="odd"><td><a href="http://www.java.net/sites/default/files/fig5.png">fig5.png</a></td><td>10.52 KB</td> </tr>
<tr class="even"><td><a href="http://www.java.net/sites/default/files/fig6.png">fig6.png</a></td><td>3.02 KB</td> </tr>
<tr class="odd"><td><a href="http://www.java.net/sites/default/files/fig7.png">fig7.png</a></td><td>6.32 KB</td> </tr>
<tr class="even"><td><a href="http://www.java.net/sites/default/files/fig8.png">fig8.png</a></td><td>3.68 KB</td> </tr>
</tbody>
</table>
http://www.java.net/blog/manningpubs/archive/2015/01/15/introduction-graphs-grokking-algorithms-aditya-y-bhargava#commentsBlogsFri, 16 Jan 2015 01:18:29 +0000manning_pubs931430 at http://www.java.netThinking about the future: What are your goals? from Soft Skills by John Somnezhttp://www.java.net/blog/manningpubs/archive/2015/01/15/thinking-about-future-what-are-your-goals-soft-skills-john-somnez
<div class="field field-type-filefield field-field-thumb-100x70">
<div class="field-items">
<div class="field-item odd">
<img class="imagefield imagefield-field_thumb_100x70" width="139" height="174" alt="" src="http://www.java.net/sites/default/files/manning_pubs/ssCover.jpg?1421369753" /> </div>
</div>
</div>
<p><b>By John Sonmez, <a href="http://www.manning.com/sonmez/"> Soft Skills: The software developer's life manual</a></b></p>
<p>Save 40% on <a href="http://www.manning.com/sonmez/">Soft Skills: The software developer's life manual</a> with discount code <b>jn15ss</b> at manning.com.</p>
<p>Now that you’re thinking about your software development career as a business, it’s time to start defining the goals you have for this business.</p>
<p>Not everyone is alike. You might have a very different set of goals for your career than I do, but if you’re ever going to achieve any of those goals, you have to know what they are. This is, of course, easier said than done. I’ve found that most people, software developers included, drift through life without really having a concrete realization of what their goals are or what they’re trying to accomplish in life. This is the natural state of most human beings. We don’t tend to really give enough thought to what to focus on and as a result our steps lack purpose or direction.</p>
<p>Think about sailing a ship across the ocean. You can get into a ship and raise your sails, like most people do. But if you don’t have a clear destination picked out and you don’t take steps to steer the ship in that direction, you’ll just drift aimlessly at sea. Perhaps you’ll end up sailing your ship by chance to an island or other land mass, but you’ll never really make any solid progress until you define where you want to go. Once you know your destination, you can use all of the tools at your disposal to actively steer the ship in the direction that will take you there.</p>
<p>It seems pretty obvious, yet so few software developers ever define goals for their career—why? I can only guess here, but I’d say that most software developers are afraid of committing to a long-term vision for their career. They want to leave all options open to them, because they’re afraid of choosing one path and going down that path. What if it’s the wrong path? What if I don’t like where it takes me? These are scary questions indeed.</p>
<p>Some developers just haven’t even really given it much thought at all. Left to our own devices, we tend to just follow the path that’s laid out for us. It’s a much more difficult job to create our own path, so we just don’t do it. Instead, we just take the first job we get an offer for and stay at that job until a better opportunity comes along or we get fired—I mean “laid off.”</p>
<p>Whatever your reason may be for not defining goals for your career, now is the time to do it. Not tomorrow, not next week, but right now. Every step you take without a clear direction is a wasted step. Don’t randomly walk through life without a purpose for your career.</p>
<p><H3>How to set goals</H3></p>
<p>Okay, so now that I’ve convinced you that you need to set goals, how do you do it? It’s easiest to start out with a big goal in mind and then create smaller goals along the way that will help you get to the bigger goal. A big goal is usually not very specific, because it’s hard to define something that’s potentially very far off very clearly. But, that’s okay. You don’t have to be very specific when you define a big, far-off goal. Your big goal just has to be specific enough to give you a clear direction in which to travel. Going back to the ship analogy, if I want to sail to China, I don’t have to know the exact latitude and longitude of the port I want to get to right away. I can get in my ship and start heading in the direction of China, and when I get closer, I can always get more specific. All I need to know to get started out is whether I’m getting closer to China or further from it.</p>
<p>So, your big goal should be something not too specific, but clear enough that you can know if you’re steering toward it or not. Think about what you want to ultimately do with your career. Do you want to become a manager or executive at a company? Do you want to go out and start your own software development business some day? Do you want to become an entrepreneur creating your own product and bringing it to market? For me, my goal was always to eventually be able to get out on my own and work for myself. </p>
<p>It’s really up to you to define what your big goal is. What do you want to get out of your career? Where would you like to see yourself in 5 or 10 years? Go ahead and spend some time thinking about this—it’s really important.</p>
<p>Once you’ve figured out what your big, far-off goal is, the next step is to chart a course to get there by making smaller goals along the way. Sometimes it helps to think backwards from your big goal to your present situation. If you had already achieved your big goal, what would have been some of the milestones along the way? What path could you imagine tracing backwards from your big goal to your present situation?</p>
<p>At one time, I had a big goal of losing about 100 pounds of weight. I had let myself get out of shape and I wanted to get back on track. So, I set for myself smaller goals of losing 5 pounds every two weeks. Every two weeks that I was able to reach my smaller goal, it moved me forward toward my big goal.</p>
<p>If you can make small goals that gradually move you forward in the direction toward your bigger goals, you’ll eventually reach your destination. It’s important to have various sizes of goals that lead you in the direction of your big goal. For example, you might have a yearly goal of reading so many technical books or learning a new programming language. That yearly goal might be a smaller goal that will lead you toward your bigger goal of becoming a senior-level developer. But that yearly goal might be broken up into smaller goals of reading a single book each month or making some defined amount of progress each day.</p>
<p>The smaller goals keep you on track and keep you motivated so that you keep heading in the direction of your bigger goals. If you just set out to accomplish a big goal and don’t have smaller goals along the way, you don’t end up having time to course-correct when you’re off track. Smaller goals also give you frequent rewards that help motivate you. Small victories each day and each week help us feel like we’re making progress and accomplishing things, which makes us feel good about ourselves and helps us keep moving forward. Smaller goals also don’t seem as daunting as a big goal. </p>
<p>Consider writing this book. Right now I have a goal for writing so much of this book each day and each week. I’m not trying to tackle the huge goal of writing the entire book, but instead I’m looking at it from the perspective of what my goal is for each day, knowing that by doing what I need to do each day, I’ll eventually reach my big goal of completing the entire book.</p>
<p>So, if you haven’t given much time to think about your future and you don’t have at least one clear and definite goal you’re aiming toward, put down this book and define some goals for yourself. It’s not easy, but you’ll be glad you did it. Don’t be a ship floating aimlessly in the ocean. Chart a course before you set sail.</p>
<h3>Tracking your goals</h3>
<p>Periodically, you should track and update the goals you have set for yourself—and adjust them if necessary. You don’t want to travel miles off course before you discover your mistake, and you probably don’t want to travel very far down a path that turns out to be the wrong one, either.</p>
<p>I’d recommend setting regular intervals for checking up on your goals. This will help you to make adjustments when needed and help keep you accountable. You might want to review the goals you set for each week at the end of that week before you plan out the next week. That same goes for every month, quarter, and even year.</p>
<p>It can be very helpful to reflect on what you accomplished during small and large time periods so that you can figure out if you’re making the right amount of progress or you need to make some kind of adjustment.</p>
<table id="attachments" class="sticky-enabled">
<thead><tr><th>Attachment</th><th>Size</th> </tr></thead>
<tbody>
<tr class="odd"><td><a href="http://www.java.net/sites/default/files/SoftSkills.jpg">SoftSkills.jpg</a></td><td>16.35 KB</td> </tr>
</tbody>
</table>
http://www.java.net/blog/manningpubs/archive/2015/01/15/thinking-about-future-what-are-your-goals-soft-skills-john-somnez#commentsBlogsProgrammingFri, 16 Jan 2015 01:02:51 +0000manning_pubs931429 at http://www.java.netSafely loading different versions of a native library in JNA (or JNI)http://www.java.net/blog/wvreeven/archive/2015/01/07/safely-loading-different-versions-native-library-jna-or-jni
<!-- | 0 --><p>Over the past years I have been working on a Java project that uses a native library written in C by a third party to process data. Recently the data format was changed and a new version of the native library was made available. Unfortunately, the native library, for very good reasons, is not backward compatible with the old data format but my project, also for very good reasons, needs to be able to process both formats of data. Therefore my project needs to determine if the data format is the old one or the new one and use the corresponding library to process the data.</p>
<p>Unloading a native library in Java is considered unsafe because it depends on the garbage collector to run. It is impossible to force a GC run (you can only suggest a GC run to the JVM) and there is no guarantee that, when the GC has run, a library (or any other object in memory) has been garbage collected. However, the concept of Dynamically Loaded libraries in C allows for safely unloading a library and loading it or a different version again.</p>
<h3>An example library</h3>
<p>In order to clarify how to unload a library and load a different version, this "library" will be used as an example. The header file version.h looks like this</p>
<pre class="prettyprint"><code>int getVersion(void);</code></pre>
<p>So it will be a very simple piece of code returning a version number. Of course this is not a real life example The corresponding C code version.c is</p>
<pre class="prettyprint"><code>#include &lt;stdio.h&gt;<br />#include "version.h"<br /><br />int getVersion(void) {<br /> return 1;<br />}</code></pre>
<p>To use the getVersion() function in C, this code can be used</p>
<pre class="prettyprint"><code>#include &lt;stdlib.h&gt;<br />#include &lt;stdio.h&gt;<br />#include "version/version.h"<br /><br />int main(int argc, char **argv) {<br /> printf("%d\n", getVersion());<br /> return 0;<br />}</code></pre>
<p>To build all this and separate the library with the getVersion() function from the code that uses it, I created a directory called "src" and in it a directory called "version". So, the directory structure is</p>
<ul>
<li>src
<ul>
<li>version
<ul>
<li>version.c</li>
<li>version.h</li>
</ul>
</li>
<li>test.c</li>
</ul>
</ul>
<p>Finally, all needs to be built before we can execute it. I am not a Make file guru, so I created a bash script:</p>
<pre class="prettyprint"><code>#!/bin/bash<br />cd src/version<br />gcc -c -Wall -Werror -fpic version.c -o version.o && gcc -shared -o libVersion.so version.o<br />cd ..<br />gcc -I./version -L./version -Wall test.c -o test -lVersion<br />cd ..<br />export LD_LIBRARY_PATH=src/version:$LD_LIBRARY_PATH<br /><br />echo "Calling library from C:"<br />./src/test</code></pre>
<p>Running the script generates this output:</p>
<pre class="prettyprint"><code>$ ./compile.sh <br />1<br />$</code></pre>
<h3>Calling the library from Java</h3>
<p>Please refer to the <a href="https://github.com/twall/jna">JNA documentation</a> for more info on JNA.</p>
<p>To call the getVersion() function in the libVersion.so library from Java, I created this class</p>
<pre class="prettyprint"><code>package version;<br /><br />import com.sun.jna.Library;<br />import com.sun.jna.Native;<br /><br />public class VersionModule {<br /><br /> private Version version;<br /> private static VersionModule vm;<br /><br /> public static void main(String[] args) {<br /> vm = new VersionModule();<br /> vm.callVersion();<br /> }<br /><br /> private void callVersion() {<br /> vm.init();<br /> System.out.println(vm.getVersion());<br /> }<br /><br /> public void init() {<br /> version = (Version) Native.loadLibrary(Version.LIBRARY_NAME, Version.class);<br /> }<br /><br /> public int getVersion() {<br /> return version.getVersion();<br /> }<br /><br /> private interface Version extends Library {<br /><br /> String LIBRARY_NAME = "Version";<br /><br /> int getVersion();<br /><br /> }<br /><br />}</code></pre>
<p>I put the java file in the src/java/version directory, like this</p>
<ul>
<li>src
<ul>
<li>java
<ul>
<li>version
<ul>
VersionModule.java
</ul>
</li>
</ul>
</li>
<li>version
<ul>
<li>version.c</li>
<li>version.h</li>
</ul>
</li>
<li>test.c</li>
</ul>
</ul>
<p>and I modified the complie.sh bash script to call the Java class as well:</p>
<pre class="prettyprint"><code>#!/bin/bash<br />cd src/version<br />gcc -c -Wall -Werror -fpic version.c -o version.o && gcc -shared -o libVersion.so version.o<br />cd ..<br />gcc -I./version -L./version -Wall test.c -o test -lVersion<br />cd ..<br />export LD_LIBRARY_PATH=src/version:$LD_LIBRARY_PATH<br /><br />echo "Calling library from C:"<br />./src/test<br /><br />cd src/java<br />javac -cp .:/usr/share/java/jna-3.2.7.jar version/VersionModule.java<br /><br />echo "Calling library from Java:"<br />java -Djna.library.path=../version -cp .:/usr/share/java/jna-3.2.7.jar version.VersionModule</code></pre>
<p>Running the script now generates this output:</p>
<pre class="prettyprint"><code>$ ./compile.sh <br />Calling library from C:<br />1<br />Calling library from Java:<br />1</code></pre>
<h3>Using two versions of the library via a proxy library</h3>
<p>Suppose now that we get a new version of the library. The header file didn't change but the implementation of the getVersion() function did. Here is the new version</p>
<pre class="prettyprint"><code>#include &lt;stdio.h&gt;<br />#include "version.h"<br /><br />int getVersion(void) {<br /> return 2;<br />}</code></pre>
<p>In order to keep both versions next to each other, I renamed the directory holding the old code to version1 and I put the new code in a separate folder called version2 (for want of better names):</p>
<ul>
<li>src
<ul>
<li>java
<ul>
<li>version
<ul>
VersionModule.java
</ul>
</li>
</ul>
</li>
<li>version1
<ul>
<li>version.c</li>
<li>version.h</li>
</ul>
</li>
<li>version2
<ul>
<li>version.c</li>
<li>version.h</li>
</ul>
</li>
<li>test.c</li>
</ul>
</ul>
<p>In order to switch from one version to another, we introduce yet another C code file. This code will act as a proxy library and will perform the actual loading and unloading of the correct version of the library as well as calling the corresponding functions in the loaded library. In order to minimize code changes in the test.c file, the Java code and the compile.sh bash script, the header and code files are placed in the src/version directory. The header file version.h looks like this</p>
<pre class="prettyprint"><code>void set_library_path(char *_library_path);<br />int getVersion(void);</code></pre>
<p>The proxy C code looks like this</p>
<pre class="prettyprint"><code>#include &lt;stdlib.h&gt;<br />#include &lt;stdio.h&gt;<br />#include &lt;dlfcn.h&gt;<br /><br />void *handle;<br /><br />void set_library_path(char *_library_path) {<br /> if (handle) {<br /> dlclose(handle);<br /> }<br /> handle = dlopen(_library_path, RTLD_NOW);<br /> if (!handle) {<br /> fputs (dlerror(), stderr);<br /> }<br />}<br /><br />int getVersion(void) {<br /> int (*getVersion)(void);<br /> char *error;<br /> getVersion = dlsym(handle, "getVersion");<br /> if ((error = dlerror()) != NULL) {<br /> fputs(error, stderr);<br /> }<br /><br /> return (*getVersion)();<br />}</code></pre>
<p>The set_library_path function loads the requested version of the library using functions in the dlfcn (dynamic library function) library. Then, each function (in the API of the library for which different versions exist) needs to be mapped to a proxy function that tries to execute the required function in a way similar to Java reflection. It can be hard to get the proper mapping, depending on the definition of the functions that you need to proxy for. More on dynamically loading libraries can be found <a href="http://www.tldp.org/HOWTO/Program-Library-HOWTO/dl-libraries.html">here</a>.</p>
<p>The source tree now looks like this</p>
<ul>
<li>src
<ul>
<li>java
<ul>
<li>version
<ul>
VersionModule.java
</ul>
</li>
</ul>
</li>
<li>version
<ul>
<li>version.c</li>
<li>version.h</li>
</ul>
</li>
<li>version1
<ul>
<li>version.c</li>
<li>version.h</li>
</ul>
</li>
<li>version2
<ul>
<li>version.c</li>
<li>version.h</li>
</ul>
</li>
<li>test.c</li>
</ul>
</ul>
<p>Please note that in order for the Java code to be able to load the proxy library, that library needs to be called libVersion.so or else JNA will not be able to load the library! The test.c code to use the old library and then the new is this</p>
<pre class="prettyprint"><code>#include &lt;stdlib.h&gt;<br />#include &lt;stdio.h&gt;<br />#include "version/version.h"<br /><br />int main(int argc, char **argv) {<br /> set_library_path("src/version1/libVersion.so");<br /> printf("%d\n", getVersion());<br /> set_library_path("src/version2/libVersion.so");<br /> printf("%d\n", getVersion());<br /> return 0;<br />}</code></pre>
<p>Here is the compile.sh bash script to compile the code and execute the C test program:</p>
<pre class="prettyprint"><code>#!/bin/bash<br />cd src/version1<br />gcc -c -Wall -Werror -fpic version.c -o version.o && gcc -shared -o libVersion.so version.o<br />cd ../version2<br />gcc -c -Wall -Werror -fpic version.c -o version.o && gcc -shared -o libVersion.so version.o<br />cd ../version<br />gcc -c -Wall -Werror -fpic -rdynamic version.c -o version.o && gcc -shared -o libVersion.so version.o<br />cd ..<br />gcc -I./version -L./version -Wall test.c -o test -lVersion -ldl<br />cd ..<br />export LD_LIBRARY_PATH=src/version:$LD_LIBRARY_PATH<br /><br />echo "Calling library from C:"<br />./src/test</code></pre>
<p>The script now generates this output:</p>
<pre class="prettyprint"><code>$ ./compile.sh <br />Calling library from C:<br />1<br />2</code></pre>
<h3>Calling the proxy library from Java</h3>
<p>With this new proxy library, the code changes to call the different versions from Java are quite small as well. Here is the new code</p>
<pre class="prettyprint"><code>package version;<br /><br />import com.sun.jna.Library;<br />import com.sun.jna.Native;<br /><br />public class VersionModule {<br /><br /> private Version version;<br /> private static VersionModule vm;<br /><br /> public static void main(String[] args) {<br /> vm = new VersionModule();<br /> vm.callVersion();<br /> }<br /><br /> private void callVersion() {<br /> String pwd = System.getProperty("user.dir");<br /> vm.init("../version1/libVersion.so");<br /> System.out.println(vm.getVersion());<br /> vm.init("../version2/libVersion.so");<br /> System.out.println(vm.getVersion());<br /> }<br /><br /> public void init(String path) {<br /> version = (Version) Native.loadLibrary(Version.LIBRARY_NAME, Version.class);<br /> version.set_library_path(path);<br /> }<br /><br /> public int getVersion() {<br /> return version.getVersion();<br /> }<br /><br /> private interface Version extends Library {<br /><br /> String LIBRARY_NAME = "Version";<br /><br /> int getVersion();<br /> void set_library_path(String _library_path);<br /><br /> }<br /><br />}</code></pre>
<p>and the new compile.sh bash script:</p>
<pre class="prettyprint"><code>#!/bin/bash<br />cd src/version1<br />gcc -c -Wall -Werror -fpic version.c -o version.o && gcc -shared -o libVersion.so version.o<br />cd ../version2<br />gcc -c -Wall -Werror -fpic version.c -o version.o && gcc -shared -o libVersion.so version.o<br />cd ../version<br />gcc -c -Wall -Werror -fpic -rdynamic version.c -o version.o && gcc -shared -o libVersion.so version.o<br />cd ..<br />gcc -I./version -L./version -Wall test.c -o test -lVersion -ldl<br />cd ..<br />export LD_LIBRARY_PATH=src/version:$LD_LIBRARY_PATH<br /><br />echo "Calling library from C:"<br />./src/test<br /><br />cd src/java<br />javac -cp .:/usr/share/java/jna-3.2.7.jar version/VersionModule.java<br /><br />echo "Calling library from Java:"<br />java -Djna.library.path=../version -cp .:/usr/share/java/jna-3.2.7.jar version.VersionModule</code></pre>
<p>Running the script produces this output</p>
<pre class="prettyprint"><code>$ ./compile.sh <br />Calling library from C:<br />1<br />2<br />Calling library from Java:<br />1<br />2</code></pre>
<h3>Performance impact</h3>
<p>The 3rd party native library that is used by my project required me to create proxy functions for no less than 81 functions! Clearly this raises concerns about the performance of the proxy library w.r.t. the performance of direct use of one version of the library, even though 72 of these functions are getters and setters. A simple test, which was to call the whole processing sequence several times in a row with the old library and then the same with the proxy library calling the old library, The test shows there is no measurable overhead.</p>
<h3>Caveats</h3>
<p>There are a few caveats for this method to be aware of. The most important one is what to do when the API changes. A function in the new version may have the same signature but with different arguments or different argument types. Functions may exist in one version of the library and not the other. From the JNA point of view, all that matters is that the methods in the interface extending Library map one on one to functions in the proxy library. It is perfectly ok to construct the proxy library in such a way that its functions call functions in the loaded library with an entirely different name. As long as those functions get called with the proper arguments, it will work fine. If you do such a thing, then of course make sure to document this well, either in inline comments or in a technical design document, or both!</p>
<p>By the way, it is very tempting to delegate determining the location of the libraries to load and which functions can be called and which not to the end user. But this should be avoided as much as possible. You know about the internals of your Java code and proxy library so it is your responsibility to make sure that end users do not need to go to the trouble of making sure it all works fine.</p>
<p>Then of course it is a very bad practise to hard code the path to the libraries in source code. It is much better to determine the location of the library to load at runtime. This can be done via properties, command line flags, values in a database or whatever way you prefer. And again, make sure to document this well in your software user manual!</p>
<p>Finally, loading and unloading libraries takes time so it is important to minimize the need for that as much as possible. My project, for example, needs to deal with mixed content of data so I have made sure that I gather together all data of the old format and all data of the new format and then process them sequentially.</p>
http://www.java.net/blog/wvreeven/archive/2015/01/07/safely-loading-different-versions-native-library-jna-or-jni#commentsBlogs[no association]Thu, 08 Jan 2015 01:56:30 +0000wvreeven931376 at http://www.java.netValidating Oracle Java Cloud Service HAhttp://www.java.net/blog/bleonard/archive/2015/01/07/validating-oracle-java-cloud-service-ha
<!-- 581 | 49 --><img src="/images/people/brian_leonard.jpg" border="0", align="left" /><h1>Validating Oracle Java Cloud Service HA</h1>
<p>One of my favorite applications from my Sun Java System Application Server days was the <a href="http://docs.oracle.com/cd/E19644-01/817-5444/gsghajsp.html" target="_blank">Cluster JSP Sample Application</a>. In a cluster configuration fronted by a load balancer, this simple JSP provides a nice summary of which cluster node handled the request as well as the ability to test session failover. Therefore, why not try it on the <a href="https://cloud.oracle.com/java" target="_blank">Oracle Java Cloud Service</a> (JCS):</p>
<p><img src="http://weblogs.java.net/sites/default/files/ClusterHAJSPSample.JPG" alt="Cluster - HA JSP Sample" /></p>
<p>I have a JCS instance with 2 managed server nodes, Alpha01J_server_1 and Alpha01J_server_2:</p>
<p><img src="http://weblogs.java.net/sites/default/files/InstanceAlpha01JCS.JPG" alt="Instance Alpha01JCS" /></p>
<p>My <a href="https://docs.oracle.com/cloud/latest/jcs_gs/JSCUG/GUID-31F00F2C-221F-4069-8E8A-EE48BFEC53A2.htm#JSCUG-GUID-82213C7B-BD8C-4B07-9117-17631FE25399" target="_blank">Load Balancer Policy</a> is set to Round Robin. If I start a new session (by using a different browser), the load balancer will direct me to managed server Alpha01J_server_2 hosted on alpha01jcs-wls-2:</p>
<p><img src="http://weblogs.java.net/sites/default/files/ClusterHAJSPSampleIEMarked.JPG" /></p>
<p>So I have easily confirmed that the load balancer is working as expected. Let's add some data to the session hosted on Alpha01J_server_1 hosted on alpha01jcs-wls-1:</p>
<p><img src="http://www.java.net/sites/default/files/ClusterHAJSPSampleWithSessionMarked.jpg" alt="Cluster - HA JSP Sample with session data m" /></p>
<p>Now let's simulate a failure condition. To do that, I will SSH into alpha01jcs-wls-1 and kill the Alpha01J_server_1 WebLogic server process:</p>
<p><img src="http://weblogs.java.net/sites/default/files/SSHKill.JPG" alt="SSH Kill Alpha01JCS" /></p>
<p>When I then return to my application and reload the page, my execution server has failed over to alpha01jcs-wls-2 and my session data remains intact:</p>
<p><img src="http://weblogs.java.net/sites/default/files/ClusterHAJSPSampleWithSessionFailoverMarked_0.JPG" alt="Cluster - HA JSP Sample with Session Failover" /></p>
<p>Through the WebLogic Administration Console, I can verify all sessions have failed over to Alpha01J_server_2. </p>
<p><img src="http://weblogs.java.net/sites/default/files/ServerFailoverStatus.JPG" alt="Server Failover Status" /></p>
<p>You'll also notice that the node manager has already started my failed Alpha01J_server_1 server. </p>
<p>One other point to note, the application needs to inform WebLogic that its session should be replicated. This is done via the <a href="http://docs.oracle.com/middleware/1212/wls/WBAPP/weblogic_xml.htm#WBAPP587" target="_blank">session-descriptor</a> in the WebLogic deployment descriptor, so I added the following weblogic.xml to the sample application:</p>
<code class="prettyprint">&lt;?xml version = '1.0' encoding = 'windows-1252'?&gt;<br />&lt;weblogic-web-app xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;<br /> xsi:schemaLocation=&quot;http://xmlns.oracle.com/weblogic/weblogic-web-app <a href="http://xmlns.oracle.com/weblogic/weblogic-web-app/1.5/weblogic-web-app.xsd&quot;<br" title="http://xmlns.oracle.com/weblogic/weblogic-web-app/1.5/weblogic-web-app.xsd&quot;<br">http://xmlns.oracle.com/weblogic/weblogic-web-app/1.5/weblogic-web-app.x...</a> /> xmlns=&quot;http://xmlns.oracle.com/weblogic/weblogic-web-app&quot;&gt;<br /> &lt;session-descriptor&gt;<br /> &lt;persistent-store-type&gt;REPLICATED_IF_CLUSTERED&lt;/persistent-store-type&gt;<br /> &lt;/session-descriptor&gt;<br />&lt;/weblogic-web-app&gt;</code></br></p>
<p>Finally, if you wish to experiment with the application yourself, I have uploaded it here: <a href="/sites/all/modules/pubdlcnt/pubdlcnt.php?file=http://weblogs.java.net/sites/default/files/clusterjsp.zip&nid=931379" target="_blank">custerjsp.war</a>.</p>
<p>Enjoy</p>
<table id="attachments" class="sticky-enabled">
<thead><tr><th>Attachment</th><th>Size</th> </tr></thead>
<tbody>
<tr class="odd"><td><a href="/sites/all/modules/pubdlcnt/pubdlcnt.php?file=http://www.java.net/sites/default/files/clusterjsp.zip&nid=931379">clusterjsp.zip</a></td><td>2.42 KB</td> </tr>
</tbody>
</table>
http://www.java.net/blog/bleonard/archive/2015/01/07/validating-oracle-java-cloud-service-ha#commentsBlogsJ2EEJava EnterpriseJSPWed, 07 Jan 2015 20:39:35 +0000bleonard931379 at http://www.java.netHow to Use SQL, Hadoop, Drill, REST, JSON, NoSQL, and HBase in a Simple REST Clienthttp://www.java.net/blog/caroljmcdonald/archive/2015/01/06/how-use-sql-hadoop-drill-rest-json-nosql-and-hbase-simple-rest-client
<!-- | 0 --><p>SQL will become one of the most prolific use cases in the Hadoop ecosystem, according to Forrester Research. Apache Drill is an open source SQL query engine for big data exploration. REST services and clients have emerged as popular technologies on the Internet. Apache HBase is a hugely popular Hadoop NoSQL database. This blog post discusses combining all of these technologies: SQL, Hadoop, Drill, REST with JSON, NoSQL, and HBase, by showing how to use the Drill REST API to query HBase and Hive. It also shares a simple jQuery client that uses the Drill REST API, with JSON as the data exchange, to provide a basic user interface</p>
<p><a href="https://www.mapr.com/blog/how-use-sql-hadoop-drill-rest-json-nosql-and-hbase-simple-rest-client#.VKyvdCvF90Y" title="https://www.mapr.com/blog/how-use-sql-hadoop-drill-rest-json-nosql-and-hbase-simple-rest-client#.VKyvdCvF90Y">https://www.mapr.com/blog/how-use-sql-hadoop-drill-rest-json-nosql-and-h...</a></p>
http://www.java.net/blog/caroljmcdonald/archive/2015/01/06/how-use-sql-hadoop-drill-rest-json-nosql-and-hbase-simple-rest-client#commentsAjaxBlogsWed, 07 Jan 2015 04:04:21 +0000caroljmcdonald931370 at http://www.java.netBook review: "JavaServer Faces: Introduction By Example" by Josh Juneauhttp://www.java.net/blog/bhaktimehta/archive/2015/01/06/book-review-javaserver-faces-introduction-example-josh-juneau
<!-- 202 | 0 --><img src="/images/people/bhakti_mehta.jpg" border="0", align="left" /><p> I had the pleasure to review <b>JavaServer Faces: Introduction by Example</b> by <a href="http://jj-blogger.blogspot.com/">Josh Juneau</a> which has been published by Apress in December 2014.<br />
<img src="http://www.apress.com/media/catalog/product/cache/9/image/9df78eab33525d08d6e5fb8d27136e95/A/9/A9781484208397-3d_1.png"> </img><br />
The highlight of the book was the simplicity with which Josh has covered some of the most complicated topics related to JavaServer Faces (JSF).<br />
I like how smoothly and seamlessly he can transition from the simple recipes to the more involved and detailed discussions in each chapter. I also<br />
appreciated the way he covers every topic as a recipe and has an example source code and a detailed explanation for each recipe's code.</p>
<p>
Here are the details of each chapter in the book</p>
<p><h2>Chapter 1: Introduction to Servlets</h2>
<p>Chapter 1 covers detailed introduction to Servlets with examples from setting up the Java Enterprise environment, installing GlassFish,<br />
developing the first servlet, to packaging and deploying the servlet. It also discusses about topics related to dispatching requests,<br />
filtering web requests, adding listeners, downloading files etc. There is a section that covers Servlet 3.0 Non-Blocking I/O and Async APIs<br />
which will be very beneficial for readers interested in processing requests asynchronously and not having to block for a long running task<br />
to complete and send the response.</p>
<h2>Chapter 2: JavaServer Pages</h2>
<p>Chapter 2 covers JavaServer Pages(JSP) and starts with a simple JSP. It covers the lifecycle of the JSP, embedding Java in JSP page,<br />
embedding expressions in EL, creating custom JSP tags, error handling, disabling scriptlets in JSP pages etc. I particularly liked the<br />
database sample which shows how to create an input form for a database record and loop through the records.<br />
The first two chapters covered the initial foundation extremely well to get started with JavaServer Faces in Chapter 3.</p>
<h2>Chapter 3: The Basics of JavaServer Faces</h2>
<p>This chapter begins with developing a simple JSF example. It covers details on breaking down a JSF application which consists of the<br />
components for a JSF application. It covers the life cycle of a JSF application. Further sections discuss on writing a managed bean<br />
and access it within a JSF view using EL. The Managed Bean Scopes section was very informative. The building sophisticated views<br />
with components covered how to build well formed views with JSF and HTML. It also highlighted navigation techniques within JSF applications<br />
and how to validate inputs in the application before they can be persisted.</p>
<h2>Chapter 4: Facelets</h2>
<p>Chapter 4 starts off with Facelets which is the default view definition language since JSF 2.0. Josh shows how to use Netbeans IDE<br />
to create Facelet Template view and then how to apply the template to a view. This section also covered how to reuse a<br />
component and its resources in any JSF view within the application by utilizing the facelets <b>ui:component</b> tag.<br />
Also it covered handling variable length data with <b>ui:repeat</b> tag<br />
I particularly liked the section on debugging the view layout with <b>ui.debug</b> tag</p>
<h2>Chapter 5: Java Server Faces Standard components </h2>
<p>This chapter focusses on JSF component library and shows how to use external component libraries. It showed how to use<br />
Bean validation with JSF. Using a concrete example of subscribing to a news letter the chapter demonstrates various<br />
topics layering one on the other. This is one of the best chapters of the book.</p>
<h2>Chapter 6: Advanced Java Server Faces and Ajax </h2>
<p>This chapter delves into using JSF components with Ajax. It covers Ajax validation using <b>f:ajax</b> tag to add immediate validation<br />
to JSF views thus avoiding the need for JavaScript for client side validation and allows asynchronous validation between the client and<br />
server logic in the JSF managed bean. Additionally it covers how to make partial page updates which was very interesting.<br />
This chapter demonstrates how to listen for system life cycle events such as <b>PreDestroyApplicationEvent</b> and <b>PostConstructApplicationEvent</b>.<br />
Another example is how to get periodic updates to pages without doing a manual refresh using the poll component. The section on<br />
developing JSF components containing HTML5 was very good read which demonstrated how to create an HTML5 video component<br />
from a JSF composite component. It also covers a flow instance which is a new feature in JSF 2.2 allowing sharing of information<br />
between the views of a flow instance.</p>
<p>Overall I found that this book was a great source of information for JavaEE developers wanting to develop component based<br />
user interfaces running on browsers for rapid development and deployment.<br />
I would highly recommend this book to anyone who wishes to know about JavaServer Faces from scratch as well as advanced users<br />
who want to get more acquainted with the nuts and bolts of newer features.</p>
http://www.java.net/blog/bhaktimehta/archive/2015/01/06/book-review-javaserver-faces-introduction-example-josh-juneau#commentsAjaxBlogsGlassFishNetBeansTue, 06 Jan 2015 21:50:49 +0000bhaktimehta931367 at http://www.java.netPoll Results: About Which Feature Targeted for Java 9 are You Most Excited?http://www.java.net/blog/rwlarsen/archive/2015/01/04/poll-results-about-which-feature-targeted-java-9-are-you-most-excited
<!-- | 0 --><p>
According to the <a href="https://www.java.net/poll/about-which-feature-targeted-java-9-are-you-most-excited">recent Java.net poll</a>, the most exciting feature targeted for Java 9 is JEP 201: Modular Source Code. The exact results were as follows:
</p>
<blockquote><ul>
<li>JEP 102: Process API Updates - 16% (108 votes)</li>
<li>JEP 110: HTTP 2 Client - 12% (79 votes)</li>
<li>JEP 143: Improve Contended Locking - 5% (35 votes)</li>
<li>JEP 197: Segmented Code Cache - 3% (20 votes)</li>
<li>JEP 198: Light-Weight JSON API - 14% (92 votes)</li>
<li>JEP 199: Smart Java Compilation, Phase Two - 11% (75 votes)</li>
<li>JEP 201: Modular Source Code - 28% (187 votes)</li>
<li>Other - 10% (68 votes)</li>
</ul>
</blockquote>
<p>
As usual, this poll is not even remotely scientific, and the sample size of 664 votes out of the millions and millions of Java developers is far from statistically significant. It does, however offer some insight into the opinions of a certain subset of the Java community.
</p>
<p>
Because JEP 201 is one of the first steps in the implementation of <a href="http://openjdk.java.net/projects/jigsaw/">Project Jigsaw</a>, it comes as no surprise that there is tremendous interest in these features. In fact, over a quarter of voters considered this to be the most interesting feature, making it clearly the run away leader with almost twice as many votes as the next group of features.
</p>
<p>
This group was most exciting to between 1 in 6 and 1 in 9 voting developers, and includes JEP 102: Process API Updates, JEP 198: Light-Weight JSON API, JEP 110: HTTP 2 Client, and JEP 199: Smart Java Compilation, Phase Two.
</p>
<p>
The final group consists of JEP 143: Improve Contended Locking, and JEP 197: Segmented Code Cache as well as all the "other" votes. The "other" features listed in the comments included Ahead Of Time Compilation, JavaFX Media Capture, JNI Replacement, Extended Mixin Support, and Value Types. While each of these may not be the most popular, combined these represent over 20 percent of the developers surveyed, certainly not an insignificant group.</p>
http://www.java.net/blog/rwlarsen/archive/2015/01/04/poll-results-about-which-feature-targeted-java-9-are-you-most-excited#commentsBlogsMon, 05 Jan 2015 07:05:50 +0000rwlarsen931362 at http://www.java.netConnecting CloudBerry Explorer to the Oracle Storage Cloud Servicehttp://www.java.net/blog/bleonard/archive/2014/12/30/connecting-cloudberry-explorer-oracle-storage-cloud-service
<!-- 878 | 0 --><img src="/images/people/brian_leonard.jpg" border="0", align="left" /><p>The <a href="https://cloud.oracle.com/storage" target="_blank">Oracle Storage Cloud Service</a> provides both <a href="http://www.oracle.com/pls/topic/lookup?ctx=cloud&amp;id=CSSTO3177" target="_blank">REST</a> and <a href="http://www.oracle.com/pls/topic/lookup?ctx=cloud&amp;id=CSSTO3178" target="_blank">Java</a> APIs for managing storage containers. As the REST APIs are <a href="http://docs.openstack.org/developer/swift/" target="_blank">OpenStack Swift</a> compliant, you can also use third party tools such as the <a href="http://www.cloudberrylab.com/free-openstack-storage-explorer.aspx" target="_blank">CloudBerry Explorer for OpenStack</a> to manage your storage containers.</p>
<p>The values needed to add a new OpenStack Storage Account connection will be found in the REST Endpoint, which you can find on your Oracle Storage Cloud Service Details page:</p>
<p><img src="http://www.java.net/sites/default/files/OracleStorageCloudServiceDetails.JPG" width="653" height="189" alt="Oracle Storage Cloud Service Details" /></p>
<p>&nbsp;</p>
<p><img src="http://www.java.net/sites/default/files/AddNewOpenStackStorageAccount.JPG" width="399" height="340" alt="Add New OpenStack Storage Account" /></p>
<p>Set the User name setting to: <strong>Storage-&lt;your Oracle Cloud Identity Domain&gt;:&lt;your Oracle Cloud User Name&gt;</strong>. </p>
<p>The API key is your Oracle Cloud Password.</p>
<p>The Authentication Service is <strong>https://storage.us2.oraclecloud.com/auth/v1.0</strong>.</p>
<p>Un-check the option to Use Keystone authentication.</p>
<p>Testing the Connection should show you a Connection success:</p>
<p><img src="http://www.java.net/sites/default/files/ConnectionSuccess.JPG" width="304" height="134" alt="Connection Success" /></p>
<p>Once connected you will be able to manage your storage containers:</p>
<p><img src="http://www.java.net/sites/default/files/CloudBerryExplororForOpenStackStorage.JPG" width="936" height="476" alt="CloudBerry Explorer for OpenStack Storage" /></p>
<p><img src="http://www.java.net/sites/default/files/ObjectProperties.JPG" width="386" height="465" alt="Object Properties" /></p>
<p>Enjoy.</p>
http://www.java.net/blog/bleonard/archive/2014/12/30/connecting-cloudberry-explorer-oracle-storage-cloud-service#commentsBlogsOpen SourceTools[no association]Tue, 30 Dec 2014 13:39:56 +0000bleonard931352 at http://www.java.net