Pages

Develop java applications for Iphone

Using a concept called XMLVM (its opensource!!) its possible to develop java for iphone by cross compiling bytecode.

XMLVM serves as an umbrella for several projects. For all projects, a Java class file or a .NET executable is first translated to an XML-document. Based on the XML-document generated by the front-end, various transformations are possible. The first transformation cross-compiles from .NET to JVM byte code. Another transformation enables Java or .NET applications to be cross-compiled to JavaScript so that they can run as AJAX applications in any browser. Yet another transformation allows to cross-compile a Java program to Objective-C to create a native iPhone application.


The technology is in early stage... Take a look at the recent google talk video.


Ambient Intelligence and location aware web

Ambient intelligence(Aml) is explained by wikipedia as
In computing, ambient intelligence (AmI) refers to electronic environments that are sensitive and responsive to the presence of people.In an ambient intelligence world, devices work in concert to support people in carrying out their everyday life activities, tasks and rituals in easy, natural way using information and intelligence that is hidden in the network connecting these
devices.
Its also called pervasive computing or ubiquitous computing.We can build up Necromancer-like future visions of ultra sci-fi devices roaming invisibly around us mumbling 0s and 1s wrapping us inside its matrix... In the Wikipedia , you can read an interesting scenario about the use of ambient intelligence.This idea will be used by most gadgets now in market.. all those smart home appliances,wifi devices, mobiles,RFID, GPS etc.There is a lot to know about the concepts and implementation (complex middle-ware architectures ) for Aml.

In the web world some recent works brought everyone's attention are location aware technology standards and APIs.Geographical Information systems was here for a longtime.Those tools like ARCGIS are prominent in the field.After the Gmap revolution hit the web, there was such an insurge of developing applications based on the geo spatial information.The virtual representation of real world is always the cyber punk readers dreams.The recent technological innovations do make them viable .

Yes the web browsers are the ubiquitous application which will connect the real space to virtual one.Now most mobile devices have browsers.So the web is getting ready for the opera of next generation location aware applications.W3C has now recently released the draft of Geolocation API specification standard.

Mozilla has developed Geode,an experimental add-on to explore geo-location in Firefox 3. It includes a single experimental geolocation service provider so that any computer with WiFi can get accurate positioning data.






Yahoo! Fire Eagle is a service that acts as a broker for your location, creating a single place where any web service, from any device can get access to your last updated location.service enables you to share your geographic position over many different applications, websites and services. You can update your location with your GPS-enabled phone (e.g. iPhone 3G) or any other software that integrates with FireEagle and you can allow websites and services to use this information.

Google released its Geo location API for google Gears .The Geolocation API provides the best estimate of the user's position using a number of sources (called location providers). These providers may be on board(GPS for example) or server-based (a network location provider).


So it is possible to use these apis to develop environmentally intelligent applications in devices especially mobile .It is possible to read my feeds / news based on locality ... like reading The Times of India epaper from Bangalore edition or Hyderabad edition based on location while I am traveling.

What about a web based Advertising platform based on location ..?

No wonder why Google urge to allocate ambient spaces for wifi ... free the airwaves !! These technologies will give numerous possibilities for Android development

Cartography did give the light to Renaissance.It did make revolutions,wars,civilizations ... Now the neo-geographers is leading the world to the cyberspace navigation.World is again shrinking... an invisible revolution ?

The ambient intelligence is realized by the human centric products than technology centric products.The information technology is now spreading from big corporates dealing with the mammoth analytical data and transactions to common man...where the data is unimaginably galactic.. geo-spatial data.. the paradigm of consumerism enabled by the new generation web ideologies. These ubiquitous location aware devices could form the new era of invisible computing
a term invented by Donald Norman in his book The Invisible Computer published a decade ago to describe the coming age of ubiquitous task-specific computing devices. The devices are so highly optimized to particular tasks that they blend into the world and require little technical knowledge on the part of their users.

image from here

Experimenting on Space4j , an in memory java database system

Its always challenging to develop scalable and high performance applications in java.There are different form of data persistence made available in all programming platforms.Considering the back end data persistence , when there is another layer of mapping ... Object Relational Mapping layer to map java objects and data store , then it will be easy for providing maintenance, supporting multi-vendor products at the cost of performance.I am not expertise in the vast numbered ORM tools (I had written an article before ).In java its a hack .. using the Reflection and collection APIs effectively.This article is about a new form of database system for java.I think its better suitable for real time ,standalone applications .We know the key value pair data structure is used mostly in applications.So the said to be database system is based on maps in Java Collections API.This is an in memory database.It reads and persists data using serialization.For always on application data is always in the memory.If there is any crash then the data is regenerated from the commands previously exectued.
I have read an article in InfoQ regarding the primary in-RAM application.The hardware level changes could tend to rapidly redesign all the framework paradigms, tools ,design patterns etc

So I decided to play around with the Space4j .The data is the space.We have to create a space in memory and we assign data to it.The map stores the serializable objects.Clients will use the Space4J object to execute commands in the underlying space. Space4J will be running in the same JVM the client is running, directly accessing from memory.

ie space4jObj.exec(Command)

Commands can be
- CreateMapCmd that will initiate the map.Like creating table.
- PutCmd to insert data
- RemoveCmd to remove data

We create a map and store in the space.There are different implementations for space.I tried with SimpleSpace4j I have created a CURD operation for space4j sample.Create a movie list and
store.Add jar to classpath.

Movie.java

package com.space4j.sample;
import java.io.Serializable;
public class Movie implements Serializable {
private static final long serialVersionUID = -1L;
private String name ;
private String id;
public Movie(String name,String id){
this.name = name;
this.id = id;
}
public String getName(){
return name;
}
public String getId(){
return id;
}
@Override
public String toString(){
return id+":"+name;
}
@Override
public boolean equals(Object obj){
boolean b = false;
if(obj instanceof Movie){
Movie mov = (Movie) obj;
if (mov.getId() == this.id){b = true;}
}
return b;
}

}
SpaceDAO.java

package com.space4j.sample;
import java.io.IOException;
import java.net.UnknownHostException;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.space4j.CommandException;
import org.space4j.LoggerException;
import org.space4j.Space4J;
import org.space4j.Space;
import org.space4j.command.CreateMapCmd;
import org.space4j.command.PutCmd;
import org.space4j.command.RemoveCmd;
import org.space4j.implementation.SimpleSpace4J;


public class SpaceDAO {


private static String MAP_NAME = "movies";
private Space4J space4j = null;
private Space space = null;
public SpaceDAO(){
try {
space4j = new SimpleSpace4J("SpaceDAO");
space4j.start();
space = space4j.getSpace();
if(!space.check(MAP_NAME)){
space4j.exec(new CreateMapCmd(MAP_NAME));
}


} catch (LoggerException ex) {
Logger.getLogger(SpaceDAO.class.getName()).log(Level.SEVERE, null, ex);
} catch (CommandException ex) {
Logger.getLogger(SpaceDAO.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnknownHostException ex) {
Logger.getLogger(SpaceDAO.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(SpaceDAO.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(SpaceDAO.class.getName()).log(Level.SEVERE, null, ex);
}
}

public void create(Movie mov){


try {
space4j.exec(new PutCmd(MAP_NAME,mov.getId(), mov));

} catch (CommandException ex) {
Logger.getLogger(SpaceDAO.class.getName()).log(Level.SEVERE, null, ex);
} catch (LoggerException ex) {
Logger.getLogger(SpaceDAO.class.getName()).log(Level.SEVERE, null, ex);
}

}

public void update(Movie mov){

try {
space4j.exec(new PutCmd(MAP_NAME, mov.getId(), mov));

} catch (CommandException ex) {
Logger.getLogger(SpaceDAO.class.getName()).log(Level.SEVERE, null, ex);
} catch (LoggerException ex) {
Logger.getLogger(SpaceDAO.class.getName()).log(Level.SEVERE, null, ex);
}


}

public Iterator read(){
return space.getIterator(MAP_NAME);
}
public void delete(Movie mov){
try {
space4j.exec(new RemoveCmd(MAP_NAME, mov.getId()));
} catch (CommandException ex) {
Logger.getLogger(SpaceDAO.class.getName()).log(Level.SEVERE, null, ex);
} catch (LoggerException ex) {
Logger.getLogger(SpaceDAO.class.getName()).log(Level.SEVERE, null, ex);
}

}

public void createSnapshot(){
try {
space4j.executeSnapshot();
} catch (LoggerException ex) {
Logger.getLogger(SpaceDAO.class.getName()).log(Level.SEVERE, null, ex);
}
}

}

Test.java

package com.space4j.sample;

import java.util.Iterator;

/**
*
* @author Haris
*/
public class Test {

public static void main(String ars[]){
SpaceDAO sp = new SpaceDAO();
Movie mov1 = new Movie("Shawshank Redemption","M1");
sp.create(mov1);
Iterator iter = sp.read();
Movie mov = null;
while(iter.hasNext()){
mov = iter.next();
System.out.println(mov.getName());
}
mov1 = new Movie ("No Country for Old Men","M1");
sp.update(mov1);
sp.createSnapshot();

}
}


There will be a space4j_db folder created in your work directly automatically storing all the log files based on the persistent class names.When we take a snapshot a file with extension ".snap" is created.Things i donn like: No package structure for files.Files are named by numbers. like 000000000001.log etc.Creating too many files.
It supports indexing , sequence numbers,clustering,db replication etc.
I did this for a study purpose only.Actually read an article from InfoQ .. so tried out hows it .. Article
Project site

Edge Computing

In our academic final year BTech project , we built a Linux cluster to demonstrate how an on demand SaaS philosophy (actually we didn't know the term at that time !) application could be implemented.It was not a 100% ideological demonstration.We could run the cluster of 4 nodes in the lab and the application ... but not the grid level implementation . We as a team did work well to make it happen.It was cutting edge at a smaller level...

Edge computing ... ?

I did write an article on CDNs(Content Delivery Network) before. But I didn't know about the concept of edge computing even when I saw Beijing Olympics through NBC online. I never guessed when i watched Youtube videos. The real transformation that is happening in this web 2.0 cyberspace.The web uses additional metadata to cache and transport data than traditional web caching.Its content-aware caching(CAC).This form of computing is made available to on demand applications too. All those web 2.0 mashups,widget networks, etc I thinks its too complex in the architectural and deep theoretical level to understand the technology, because it seems so "cloudy".All these data network latencies, jittering, content replications ,databases spread throughout... and so on.The request to an html or javascript are delivered from a nearby cdn node in networks like Akamai or Limelight (used by Youtube) to our pc/gadget. What about the personlized pages? They also need dynamically generated content.They get data from databases.The databases are spread across the web. The database cache mechanisms deliver the data. What about business applications ? Their database results are to be cached.Suppose two queries having same subset of data . They are to be cached reducing frequent database access.Using query templates and containment check it can be done. I saw a ppt from here explaining web application replication strategies. .Technologies like sharding using MysQl , database clustering etc are used these days.There were a lot papers published on this technology for a long time.Its practical and becoming the backbone of internet for technologies like video streaming , VOIP, mashup services ,even illegal botnets !! etc these days.Its providing high QoS, availability,virtualized computing,but security through firewalls at all the nodes (centralized as well as network level).So the internet at the network level is becoming strong needing more complex administration.... cool for network engineers.Its complex it sounds interesting and promising.

Its about data ...More curious What about the computing and implementation level ?

I grabbed an article from Akamai regarding the deployment of java enterprise applications in their CDNs from here

Another article was found about Objectweb's JonAS application server working on a self-* autonomic computing based on IBM research.

From the manifesto i read about the comparison of today's internet autonomic computing and our autonomic nervous system, freeing the conscious mind with all those involuntary activities .....

Many intelligent students,professors, engineers working on it .Yes the collective intelligence is in the embryo stage....

The breadcrumb folk tale and intelligent user interfaces

In the old German folk tale of Hansel and Gritel the two young children attempt to mark their trail by leaving breadcrumbs on their path as they walk through a forest. In information architecture, especially interface design or GUIs, breadcrumb refers to some sort of visual path that allows the user to see where they are in the interface and to retrace their steps if needed.The technology is called hyperlink connecting Univeral Resource Identifiers.Its the human psychology to virtually traverse through his thoughts on sorting out the infomration he needs.The words in the mind-space is connected through the virtual links tracing the inner thoughts in the process of the data quest.The cliche information at the tip of fingers ... The links in the web page you see in the browser are the virtual representation of information deep down in the cyberspace.Are we entering a metaphysical psyche warp of our mind through these portals? :P

A psychology paper from the University of Wichita shows that using the breadcrumbs in the model tends the users to use these shortcuts more .This is definitely a good approach to define the related entities and the users will be able to navigate through the huge data in web.Is it possible for an intelligence in web, some mention it as collective intelligence, converse to user using this tool of navigation?


As semantic technologies will become more prominent in near future internet information architecture,the user interfaces to communicate this collective intelligence effectively to user are expected to be simple and elegant.May be the touch screens and 3D interfaces will provide an immersive user interaction.What will the fastest way of traversal?

An old Buddhist monk revealed to his disciple that mind is the fastest traveler in this universe.. Will the future interfaces catch up with lightning speed of mind? We can expect warp holes in our web pages ? Will there be information teleporters on our desktops ( that sucks!)? Even hyper links are based on these ideologies .. may that will suffice.. The problem is we choose the path now ...

Ha there I saw an old paper describing about AI based interfaces.It says

Most researchers would agree that a system that can maintain a human dialogue would be considered intelligent (remember the Turing test?). The problem is that there are a lot of interfaces that we would consider intelligent, that do not look "human" in any sense at all. An example is the PUSH interface , which presents hypertext in a manner that is adapted to the user's current task. The system is controlled mainly through direct manipulation, but the output consists of a text where certain pieces of the text are "hidden" from view, to give a comprehensive overview of the pieces of text that are most relevant to the user in his or her current task. This very passive form of user adaptation does not in any way mimic human behaviour, but is constructed to be a natural extension of the hypertext view of information.
I like playing computer games.In games the interface , or the protagonists goals can be changed by the AI of the game as per the user interaction.I will say thats what happening in web.The information we seek will be based on the understandings made by a collective intelligence in the web.Suppose you want travel to a place during your vacation.. what if the application itself choose the best destination,information about it , the room,the flight ,the travelers tools.. so on to be displayed in the browser within a second..? Sounds cool even if you are your way back home with your personal intelligent assistant (possibly a future iphone !)See this movie made by Apple in 1980s , a film short that also imagines a future of computing via intelligent agents a long way back internet blips occurred. Link


In future choice wont be yours..

Google Guice - sample code on multiple bindings

Google Guice is a dependency injection framework in Java.Its lightweight because it is not a container like other AOP(Aspect Oriented Programming) containers such as PicoContainer or Spring.They are based on Inversion of Control principle.I don't have much experience in Spring or PicoContainer.Guice is used in Apache Shindig.Guice is a dependency injector using the features of generics and annotations.I wanted to know more about aspect oriented programming,IoC etc.So I tried with a simple one .. Guice.If you want to know more about IoC and Dependency Injection go through Martin Fowler's article . I wrote some an example.This example shows how multiple dependency bindings can be done in Guice.


IM.java

package com.im.sample;

public interface IM {
void sendMessage(String message);
}

An interface IM is created to be implemented by different classes.We can bind this interface
to a class by @ImplementedBy annotation, while it supports for one.We need multiple
implementations.

GTalkIMImpl.java

package com.im.sample;

public class GTalkIMImpl implements IM{
@Override
public void sendMessage(String message){
System.out.println("Gtalk:"+message);
}
}

YahooIMImpl.java

package com.im.sample;

public class YahooIMImpl implements IM {

@Override
public void sendMessage(String message){
System.out.println("Yahoo:"+message);
}
}


We use Modules to bind classes to interface.It acts as the configuration mechanism.

IMModule.java

package com.im.sample;

import com.google.inject.Binder;
import com.google.inject.Module;
import com.google.inject.name.Names;

public class IMModule implements Module{

@Override
public void configure(Binder binder) {

binder.bind(IM.class).annotatedWith(Names.named("GTalk")).to(GTalkIMImpl.class);
binder.bind(IM.class).annotatedWith(Names.named("Yahoo")).to(YahooIMImpl.class);
}

}


Here we have to create two annotations to bind the implementations.Names calss will
automatically bind the annotation to the specific classes.Names.named will take the annotation name.

GTalk.java

package com.im.sample;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import com.google.inject.BindingAnnotation;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@BindingAnnotation
public @interface GTalk{}


Yahoo.java

package com.im.sample;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import com.google.inject.BindingAnnotation;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@BindingAnnotation
public @interface Yahoo{}


These annotations provide the named binding.@Retention defines the class to be available in runtime.@Target define where we the elements are applicable.During injection the target define the elements.@BindingAnnotation annotates annotations which are used for binding.More here here

Messenger.java

package com.im.sample;

import com.google.inject.Inject;
import com.google.inject.name.Named;

public class Messenger {

@Inject @Named("GTalk") private IM gtalk;
@Inject @Named("Yahoo") private IM yahoo;

public Messenger(){

}

public IM getGtalk() {
return gtalk;
}

public IM getYahoo() {
return yahoo;
}

}

Test.java

package com.im.sample;

import com.google.inject.Guice;
import com.google.inject.Injector;

public class Test {

public static void main(String[] args) {

Injector injector = Guice.createInjector(new IMModule());
Messenger msg = new Messenger();
injector.injectMembers(msg);
msg.getGtalk().sendMessage("Hello Gtalk");
msg.getYahoo().sendMessage("Hello Yahoo");

}

}


Guice automatically finds the IM class and injects it into Messenger class. Guice seems simple and cool.Using guice we can mostly avoid configuration files (I donno whether this will be advantage in all situations!) , we can provide better maintainability.The coding is smooth.Using annotations it becomes more flexible.

Go through users guide here.

If there is anything to be changed or to be improved .. try out anyway.

Debug open social gadgets : Error codes

I was playing around with Apache shindig to develop a simple open social application.
I find it easy to use the error codes available in open social specification.Use this sample gadget for testing purposes.In the specification http://code.google.com/apis/opensocial/docs/0.8/reference/#opensocial.ResponseItem.getErrorCode

it says like to get error code from getErrorCode function. Its returning an enumeration.So its easy to get error codes from Error class.I tried for response.getErrorCode().. hopeless .. its undefined while response.hadError() was working !! I think spec document should be clear with examples ...mmm try the code ..





<script type="text/javascript" >
function getData() {
var req = opensocial.newDataRequest();
req.add(req.newFetchPersonRequest('VIEWER'), 'viewer');
req.send(callback);
}


function callback(response){


if(!response.hadError()){
alert("Success");
var html = "Test OK"
document.getElementById('message').innerHTML = html;

}else {
alert(response.getErrorMessage());
var viewer_resp_item = response.get('viewer')
switch(viewerresp.getErrorCode())
{
case opensocial.ResponseItem.Error.INTERNAL_ERROR :
/*The request encountered an unexpected condition that prevented it from fulfilling the request*/
alert('There was an error on the server.');
break;
case opensocial.ResponseItem.Error.UNAUTHORIZED :
/*The gadget does not have access to the requested data.*/
alert('There was a permissions issue: the app is not allowed to show the data.');
break;
case opensocial.ResponseItem.Error.BAD_REQUEST :
/*The request was invalid.Parameters are wrong etc.*/
alert('There was an error in the Container.');
break;
case opensocial.ResponseItem.Error.FORBIDDEN :
/*The gadget can never have access to the requested data.*/
alert('The Container was unable to contact the server.');
break;
case opensocial.ResponseItem.Error.NOT_IMPLEMENTED :
/*This container does not support the request that was made.
Different version of implementations*/
alert('did not implement this particular OpenSocial interface.');
break;
case opensocial.ResponseItem.Error.LIMIT_EXCEEDED :
/*The gadget exceeded a quota on the request.*/
alert('Limit exceeded.');
break;


}

}
}


gadgets.util.registerOnLoadHandler(getData);

</script>





Cool opensource projects associated with Apache Shindig

There are a lot open source initiative happening for the open social application development.Apache shindig is an incubator project helps to develop opensocial containers .

Guice

The dependency injection framework from Google.It helps in developing custom handlers in shindig.It takes creating instances in the form of Services from the Application client code and the Dependency between the Clients to its Services is automatically injected through some easy injection configuration mechanism.
http://code.google.com/p/google-guice/

Apache commons

The popular resusable components.
http://commons.apache.org/
-Lang
Extends java.lang functionality
http://commons.apache.org/lang/
-Betwixt
Maps java beans to XML
http://commons.apache.org/betwixt/
-Codec
For encoding decoding algorithms (base64 etc) utility.
http://commons.apache.org/codec/

Oauth

The security protocol.I have written about oauth here
For java.
http://oauth.googlecode.com/svn/code/java/core/

JSON

The javascript data interchange objects.
http://json.org/

Joda Time

Replaces java date and time.
http://joda-time.sourceforge.net/

Abdera

Implementing ATOM protocol and syndication.Its all about data in google..

http://incubator.apache.org/abdera/

Caja

Caja (pronounced ka-ha) makes it possible to run third-party JavaScript alongside existing code. Mechanism for javascript security.
http://code.google.com/p/google-caja/

Maven

The popular build tool.Commonly used project management tool for open source projects.Build,manage dependencies,update and so on.Very flexible.It appear as many things ..
http://maven.apache.org/

Jetty is used to run sample applications provided with shindig.

ICU4j

For internationalization.
http://www.icu-project.org/