Posts Tagged ‘development’

Lift: Replacing JavaScript with JVM Applets

Tuesday, May 18th, 2010

Java applets were originally introduced to provide interactive features for web applications (Wikipedia). With javascript based libraries (jquery, yui), proprietary plugins (flash, silverlight or javaFX) and the oncoming HTML5 this intended purpose disappeared, but java applets remain useful for following reasons:

  • Scala/Java is type safe: You can find errors early.
  • You can use the same language like you used for your web application.
  • The Implementation is browser independent.

Example: Distributed Computation of Perfect Numbers

Definition: Perfect Number (Wikipedia)

Testing numbers for perfection is a simple but process-time consuming task. It isn’t complicated to distribute the calculation on several computers.  You can easily think of other domains where similar types of computations could be useful.

Application Overview

Instead of a javascript a java applet is used to factorize numbers. With the typical features of the lift framework, the application looks as follows:

PerfectNumbers Overview

Details: Server -> Client Communication

The snippet: You can deploy your java/scala applet with your web application.


You can invoke your applet method like a javascript function:

// OnLoad(JsRaw("findFactors('"+ c.toJson +"');"))
   OnLoad(JsRaw(c.toJsCall))

Update your case class:

case class JobPackage(ticket: Int,
                   start: Long,
                   end: Long,
                   master: Long) {
  import net.liftweb.json._
  import net.liftweb.json.JsonDSL._
  def toJson = {
    val json = ("ticket" -> ticket) ~
      ("start" -> start) ~
      ("end"-> end) ~
      ("master" -> master)

    compact(JsonAST.render(json))
  }

  def toJsCall = "$('#some-div').html($('#clientEngine').get(0).doCalc(" + ticket
  + ", " + start + ", "+ end +", " + master +"));"

Client -> Server Communication

Add your ajax call to your applet:

JSONObject serverPackage = new JSONObject();
...
private void sendResult() {
		try {
			String sps = serverPackage.toString();
			getAppletContext().showDocument(
					new URL("javascript:replyResult('replyResult', '" + sps + "')"));
		} catch (MalformedURLException e) {
			errorText = "Error: " + e.getMessage();
		}
	}

and dispatch the result:

  def PMCall(s: String) = { 

    logger.info("PMCall "  + s)

    val cResJs = net.liftweb.json.JsonParser.parse(s)
    val ticket  = (cResJs \\ "ticket").extract[Int]

    // With 2.8: facs.extract[List[Long]]
    val facs = for{
      JInt(fac) <- cResJs \\ "factors"
    } yield fac.extract[Long]

    PerfectNumberMaster ! PerfectNumberMaster.CalcDone(ticket , facs)
    Empty
  }

Download and run the example

The Sourcecode is available here.
Type: mvn jetty:run and open the url http://localhost:8080

Trend Engine V0.73

Friday, October 9th, 2009

With the 73th version of the Kungle trend engine it is now possible to track a meaningful trend again.

It was difficult to rebuild a functional trend prediction after the decision to remove the search engine results from my calculations.

Cause of the decision:

The search terms got more and more insignificant. For Example on Sep. 29 (The Tsunami Day)  the highest ranked search phrase was “pink toed tarantula”.  Other examples were “who is mysterion” or “out of memory at line 130″ !

The Trend Analysis is now extremely fast. The response time is about  30 minutes after an occurrence. In contrary, searchengine results are delayed up to four hours!

I’m now using microblogs, blogs, and newsfeeds as datasource.

The Trend Score is calculated by following factors:

  • Time of publication
  • Frequency of occurrence
  • Subject significance (by Dictionary)
  • Subject insignificance (by Dictionary)
  • Registration Date
  • Publisher significance

Votes:

I have added a voting mechanism to compare the trend results with my readers opinions. To offer an incentive I have added a Trend bonus for every vote.

Next Steps:

Dependent on the success of Kungle.de and the related earnings:

  1. Switch to bigger hardware.
  2. Improve the topic identification.
  3. Deep text analysis.
  4. Global Impact calculation

Improved user interaction:

Kungle.de is a Scala/Lift Project based on HTML and Ajax.  Next Steps would require to build Restful Web Service and a Rich Internet Application. for a better user experience.

Technical Trouble

Friday, September 18th, 2009

Hacker and Botnets had been very alive this week. Several night-shifts were necessary to keep kungle alive. However some drop outs were unavoidable.

Features:

The development of  the translation feature has begun. The results are adequate so far.

Memory-Game on Ubuntu

Sunday, April 19th, 2009

You can now play my 3D memory-game on Ubuntu/Linux.

memorygameonubuntu

Make sure you have installed java6 from sun.

You can find it here: http://www.yousry.de/Memory-Game.html

Update: Verschlüsselung (eng.: Encryption)

Saturday, April 11th, 2009

First results show comparable processing speeds to commercial or proprietary products. A backport to Java5 / Mac was successful. The application may be used on all current desktop operation systems.

Algorithm Windows Mac
SHA1AndDESede
MD5AndTripleDES
SHA1AndRC2_40
MD5AndDES

In subsequent versions, major functional enhancements are planned. The complex user interface will be simplified.

Tasks until alpha release:

  • The user interface must be completed.
  • Software testing.

Tasks until beta release:

  • Add new encryption algorithms.
  • Add simplified user interface.
  • Add server functionality.
  • Batch processing.
  • Create API documentation.