Monday, March 18, 2013

Play Job monitoring



SiIf you want to monitor Play jobs (1.2.5) easily , you can use CRaSH and with command line, you type the following :
% dashboard | thread ls -n "jobs-thread*"
More information on http://www.crashub.org/

Thursday, March 14, 2013

First step with the cloud OpenShift of RedHat

My goal : Deploy an Play 1.2.5 on OpenShift.

For this purpose, I follow that link : planet_jboss


Steps summary:


- Create my application :

I create my application directly on the web site.It was quick and simple.
Moreover, all usefull command to connect with ssh and clone are available.You just have to make copy and paste.

- Gentoo install :


emerge dev-ruby/rubygems
ruby -e 'puts "Welcome to Ruby"
gem install rhc


- Initialisation (as a user)

rhc setup

- Clone of our application's repository


git clone ssh://XXX/~/git/monapp.git/

Then, I follow steps ICI

- Export of the war dans monapp/deployements :


play war -o /home/toto/monapp/deployments/cookies.war
git add deployments/cookies.war*
git push

- Check of the deployement

- Connexion with ssh on the RedHat cloud
- tail -f jbossas-7/logs/server.log


Comment:

- I try the cloud at my job but I didn't succeed because of proxy and firewall.I also tried to use ssh over
90 but without success.
- At home, no problem : it was easy end fast.

Saturday, March 9, 2013

JavaFx project on GitHub


To learn JavaFx, I've began a small project on GitHub.
I use JavaFx 2 and Maven.Perhaps, It could help you to begin  in your project.

See https://github.com/drieu/MetricViewer for more information.

Thursday, February 7, 2013

sbt.ResolveException: download failed: org.slf4j#slf4j-api;1.6.6

Problem


 When I ran play run , I have the following error :

[error] (*:update) sbt.ResolveException: download failed: org.slf4j#slf4j-api;1.6.6!slf4j-api.jar
[warn] some of the dependencies were not recompiled properly, so classloader is not avaialable


Solution

vi ./project/plugins.sbt

You only have to edit this file and add the last version of play (2.1.0) :

// Comment to get more information during initialization
logLevel := Level.Warn

// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"

// Use the Play sbt plugin for Play projects
addSbtPlugin("play" % "sbt-plugin" % "2.1.0")

Then you can launch play run again

Saturday, January 26, 2013

KnowledgeBlackBelt will definitely shut down.

Bad news ! KnowledgeBlackBelt will definitely shut down on Jan 31st 2013.
Content is available for free ...

play 2.1 : Create yout first projetc with IntelliJ Tips


Create a project with Play is easy :

$ play new my-app 
$ cd my-app 
$ play idea


However, I had some diificulties with how to import in IntelliJ.In the documentation, it says that you have to import a module.But it doesn't work for me.
To succes, I've just done the following :

File --> Open

And now it works every times :-)



Sunday, January 6, 2013

java 8 : Functional Interfaces


In this article, we will try to learn new Java 8 concept : functional interface. It's an entry point for using lambdas and other JAVA 8 features ...

Definition from JSR 335

A functional interface is an interface that has just one abstract method, and thus represents a single function contract. (In some cases, this "single" method may take the form of multiple abstract methods with override-equivalent signatures (8.4.2) inherited from superinterfaces; in this case, the inherited methods logically represent a single method.)
In addition to the usual process of creating an interface instance by declaring and instantiating a class, instances of functional interfaces can be created with lambda expressions, method references, or constructor references.
The function descriptor of a functional interface I is a method type—type parameters, formal parameter types, return types, and thrown types—that can be used to legally override the abstract method(s) of I.

 In short, a functional interface is only one interface with just one abstract method. The goal of Functional Interface is to use JAVA 8 feature like lambdas.

Simple example


Here is a short example :

ICode.java

 package fr.dr.practice;

/**
 * Interface with just one abstract method.
 */
public interface ICode {
    String generate(int codeNumber);
}
Main.java

package fr.dr.practice;

/**
 * Created with IntelliJ IDEA.
 */
public class Main {

    public static String generateTmpCode(int newCode) {
        ICode code = new ICode() {
            @Override
            public String generate(int codeNumber) {
                return "MAIN_" + codeNumber + Math.random();
            }
        };
        return code.generate(newCode);
    }

    public static String generateTmpCodeWithLambda(int newCode) {
        ICode icode = codeNumber -> "MAIN_" + codeNumber + Math.random();
        return icode.generate(newCode);
    }

    public static void main(String[] args) {
        System.out.println(Main.generateTmpCode(12));
        System.out.println(Main.generateTmpCodeWithLambda(12));

    }
}

More complex examples

The JSR says the following :

In some cases, this "single" method may take the form of multiple abstract methods with override-equivalent signatures (8.4.2) inherited from superinterfaces; in this case, the inherited methods logically represent a single method.

So, you can make the following because equals method is public in Object class :

public interface ICode {

    String generate(int codeNumber);
    boolean equals(Object obj);
}

But you can't make this because clone method (protected Object clone() throws CloneNotSupportedException {) isn't public in Object class :

public interface ICode {

    String generate(int codeNumber);
    Object clone();
   
}

Function descriptor 

The JSR 335 add also a the concept of Functional descriptor.
Here is an example from JSR :

interface X { void m() throws IOException; }
interface Y { void m() throws EOFException; }
interface Z { void m() throws ClassNotFoundException; }
interface XY extends X, Y {}
interface XYZ extends X, Y, Z {}

// XY has descriptor ()->void throws EOFException
// XYZ has descriptor ()->void (throws nothing)

Conclusion

Functional interface permits to use lambda or other JAVA 8 features.It exists yet some functional interface (e.g : java.util.Comparator ). Java 8 has also a new package : java.util.functions which defines new Functional Interface.You could see this good blog for example with it : http://datumedge.blogspot.fr/2012/06/java-8-lambdas.html.
This article permits me to learn JAVA 8 feature.If you have comments or if you see errors, please post it ! In next article, we will study lambda feature ...