Posts Tagged ‘Java’

Avatar : HTML5 and JavaME

Posted: October 8, 2011 in IT/Dev
Tags: , , ,

While previews of JDK7 and JavaFX 2 are available for MacOSX (here and there), Oracle announced its strategy to unify Java and HTML5 :

– by standardising communications between HTML5 clients and Java server side (listed technologies – Websockets, etc. – are however still in use, and Oracle didn’t provide hints about a common JSON description format for describing action messages).

You can make an HTML5 client work with a Java back-end today, but it’s not that fun, it’s not that easy to use, and it’s not that easy for HTML folks to collaborate with Java folks.
HTML5 brings new standard for new and/or existing features (Canvas) provided by browsers, and mainly derived from WebKit advances. However Avatar does not provide abstraction/media layer to these various APIs (Canvas, WebGL, CSS3) that allow to display a modern user interface (in such a way as Cappuccino’s DocumentBridge and implementation of Quartz/Core Animation), nor an applicative framework (such as Cappuccino’s implementation of AppKit).
Finally there is no information about client/server bridge solution (messages serializing, session and profiles management, authentication, access to remote data through cursor, sorting) like CP2JavaWS.

– by providing access to HTML5 layer from a Java JME application code on mobile devices, through a new sort of a JVM (JIT that creates native code instead bytecode – however it isn’t completed yet), in order to circumvent Apple’s restrictions. Other solutions still exist, like GWT4Titanium, that allows developing in Java and then converting code in javascript and finally in native code.

As I had supposed, Google may use Cappuccino to replace Java as Android SDK. Besides solving the licensing problems, this solution could lure iOS developers, easing Cocoa to Android porting.
The new Google mobile OS would just have to be based on WebKit, in the same way Palm/HP’s WebOS does.

A new 1.1 version of CP2JavaWS (Cappuccino to remote Java services framework) is available here. It includes the following new features/enhancements :

– Added Basic Authentication scheme besides Digest, and a generic Active Directory/Ldap authentication service (automatic check of user password and retrieve of its profiles related to the application from the directory, that are then stored on the client side’s endpoint for UI conditional display – besides being used on the server side from the authorization service).

– global authentication to an endpoint (in order to allow connect/disconnect menu for login/logout) besides per service check, by calling a dummy service listed in authenticated services (needed to keep – not duplicate – authentication process managed by the authentication filter).

– better error management, and easy to read full server error trace in the client’s alert window.

– parameter to set the encoding information sent from the Json filter to the client (depends from encoding used in custom services and/or database).

A new release (1.0.1) of CP2JavaWS is available. It adds support for Cappuccino 0.8 (won’t work with previous versions – use CP2JavaWS 1.0 for these).

Note : when creating a tableView manually, and setting CP2JavaWSTableViewDelegate as the delegate,
we now have to define the sortDescriptor on each column, for example :
[column setSortDescriptorPrototype:[[CPSortDescriptor alloc] initWithKey:[column identifier] ascending:true]];
This is done automatically when using Direct2CP mode (see CP2JavaWSMasterDetailView).

Documentation : http://sourceforge.net/apps/mediawiki/cp2javaws/index.php?title=Main_Page

We knew Xmlvm, a Java to Objective-C cross-compiler (that uses XSL stylesheets to transform JVM calls to Objective-C instructions) – that also provides a subset of Cocoa APIs in Java. Now we can discover iSpectrum from FlexyCore (french startup founded in 2008 by people that worked at INRIA and Texas Instruments), a solution composed of an Eclipse plugin (3.4 version min), Java ports of iPhone APIs (UIKit, CoreLocation, MediaPlayer), and an emulator. The Java code is compiled into Objective-C, and the Eclipse debugger is available. Compiling and using the emulator however require an Intel mac.

A 30 days demo (15 compilations) is downloadable, and a free open licence is provided for applications released under open source licences (for commercial applications, a Pro or Entreprise licence has to be purchased – prices not listed yet).

The Cappuccino/Java bridge, CP2JavaWS, follows its growth, and now reaches 150 downloads a month. It has been completed in late November, however it will be maintained as Cappuccino evolves (and may be included as an Atlas plugin).

The final version (1.0) of CP2JavaWS is available :

Added support for service protocol (CP class with methods signatures) specifying when retrieving a proxy, in order to allow :
– arguments type check
– nil arguments values (the expected type can then be retireved from the protocol – required for Java reflect)
– generic methods arguments (CPObject in CP, Object in Java)

Renamed HabiltationService/Filter to AuthorizationService/Filter.

Bug fix in CP2JavaWSJSONPConnection (synch. with latest code since addition of URL class).

MasterDetailView now uses alternating row color for table view, and background for detail view .

Note : documentation has been moved to MediaWiki.

The video of the full Atlas presentation at London FOWA 2009 is now available at carsonified (30′ length). It demoes the fully fonctionnal screens compositing (nested views), the RSS controller (that had also been seen during the first Atlas presentation in March) – we can also see Array Controller, FaceBook and Twitter controllers -, various project templates (among these a new document-based one), a Bespin text editor component, and a new “native” target mode (that is said to use an own solution instead of Titanium Appcelerator, for some explained reasons).

Finally I would like to thank Francisco for his kind words about Java server-side support for Cappuccino – that is CP2JavaWS –  (26′) :

About backend support, there are Lift, Scala, Rails, and Java as well [was the first, January, 5].  The Java support is pretty amazing, as it takes Java Objects [full objects graphs, through JSON] and serializes these into Objective-J objects.

The Direct2CP mode of CP2JavaWS, and its digest authentication management and automatic session tracking per endpoint, are also complementary to Atlas (that focuses mainly on UI components, but not to their behaviour on the server side – except the RSS feader component).

An extension mechanism to Atlas (through plugins) was suggested initially (in March’s first announcement), and I then explained it was a great idea, that could use Osgi bundles concepts, and would open the way for business (alla Eclipse plugins). I proposed to write a plugin for remote services calls (through CP2JavaWS), such a controller that could be added to existing RSS, FaceBook and Twitter ones. I hope such architecture will be provided by Atlas beta’s mid-November release.

CP2JavaWS_direct2CPA new version of CP2JavaWS is available. It completes the master/detail view(Direct2CP) :

– added automatic support for creation/insert (add button) and delete in generic detail view, with full state management.

– added management for business key(s) in master and detail views, besides technical one. Moreover the business key can be multiple (composite). The detail view allows to set these key elements at creation time (once). If using a technical key, it is set by the database (sequence, identity, etc.) and retrieved/displayed back in the detail view after creation.

– added support for combo lists and radio buttons : through codes/labels descriptors we can associate codes/labels pairs with an attribute (its detail view field). That collection can be setted in the client side or retrieved using a specified remote service (useful for long lists read from a database, and for localization).

– added the innovative DatePicker component from Randall Luecke (RCL concepts) as date field editing (requires some provided images resources).

– master and detail views can use the generic DAO service (typically for services backed by a relational database) or custom ones (read elements, read one element, update, insert, delete) if using a specific datastore or connector.
The master/detail view provides then 4 modes : generic detail view with generic DAO service or custom service, or custom detail view with generic DAO service or custom service.

– the HTTP requests sender now behaves as expected when using synchronous requests : the result is returned (does not use anymore a delegate and handlers).

Here are some limitations to consider when we plan using AppEngine. They are most likely due to clouds constraints and consistent performance concern. We can read a compatibility list of various J2EE frameworks and supported Java APIs.

1000 files limit
Each application is limited to 1000 files. Then when using Cappuccino we have to use Press tool (with flatten option – to be tested with 0.71 version as it was broken in 0.70 beta) or remove the .j files (keep only the .sj). For CP2JavaWS, images resources from unused components were also removed (load time should be however better using Press).
As the concept of physical machine is gone with clouds computing, we cannot write in files, and we can only read files in WEB-INF (or accessibles through the classloader).

1000 results limit / limited offset for requests
For performance concerns, requests results are limited to 1000 records. Moreover the offset cannot be higher (requests return 0 records when the offset reaches the 1000th position). Then we cannot browse a thousands of lines table with limit(offset, count) if not using a filter/condition.
We could still add a criteria on the index to fetch records in multiple parts (for each thousand step). However this would only work if we are sorting by the index (wouldn’t work if sorting by another column). It is the same if using two requests (one for retrievinig the indexes and another using selection where index in (index range) limit count), as the first request result will be limited. Same problem if we use a temporary sort table (the result from the select request used to retrieve the data to insert is limited), moreover that solution requires to compute again the temporary table if the sort criteria (or condition criterias) vary.
One solution would be to define a special key (see Python section Queries on Keys, _key_), in memory managed and without read limit (same section for Java/JDO doesn’t however include these informations). It would require to be able to modify dynamically this key (as it depends from the sort column), or to define for each sort column an additional column (setted alongwith each insert), composed with the sort column value and index value. We could then add to the request a _key_>previous limit value criteria (value of the composite column fot the last element retrieved during the last 1000 elements fetch). Adding a criteria on the primary key wouldn’t work if using another sort column, as the criteria applies before sorting (that problem is worked around if the criteria uses the composite column that corresponds to the sort column).
We can however assume that search criterias have to be refined/tighten if more than 1000 results are expected.

Mapping limitation / caches synchronization
Hibernate isn’t supported as it instancies statically a UUID generator, using inetAddress class (is among the restricted/unsupported APIs by AppEngine, as well as other machine related instructions : threads, etc.) Then a modified version of an Hibernate class is provided in CP2JavaWS (uses code from JUG framework instead).
The demo of CP2JavaWS uses an HSQLDB in-memory database to easier the example install (no databse server to create), and table and initial data are created at launch time (from a context listener). The values of the third column (age) are generated randomly, in order to allow testing of sort feature. Then these values can change depending the timeframe we access the application (as these values are in memory, they are different from an application instance to another). That isn’t a problem however for that demo (no persistance required).
We could configure an url to a database server, however it would have to be hosted elsewhere (if not datastore). And we cannot also use a local file to persist the database (only read allowed).

The main concern is memory synchronization between cloud nodes (application instances), as mapping solutions use two objects caches. The first level cache (one per persistanceManager/MappingSession – typically per user session) allows to compare a working object copy with the corresponding original (fieldLocking), and second level cache (one per persistanceManagerFactory/SessionFactory) allows to compare orignal object from persistanceManagers with current corresponding objects in the central cache (that is necessary for optimistic locking. Direct access – back door – to the database without passing through the persistanceManagerFactory – that is generally retrieved from JNDI – is forbidden, in order to keep integrity).

The GAE datastore is based on the DataNucleus mapping framework (implements JDO and JPA). By default the level 2 cache is off in DataNucleus, however by activating it (through settings) we can choose among various implementations : EHCache, Oracle Coherence, memcached, etc. In that list only Oracle Coherence and memcached allow work in a distributed environment (second level cache replication) – also the case for more recent versions of EHCache. Thanks to the plugin architecture in DataNucleus we can develop extensions to use another cache framework that manages distributed mode : JBoss cache, OSCache, Terracotta, etc.
The Google datastore uses a proprietary implementation of JCache specification (JSR107) to allow a distributed mode, and manages replication automatically. DataNucleus provides a manual API to manage datastores replication (for example the JDOReplicationManager to synchronize PersistanceManagerFactory). The AppEngine SDK also provides Memcache APIs, to manage (manually) replication of custom objects if needed.

Replacing DataNucleus with Hibernate (can use distributed caches like JBossCache, OSCache, Coherence and more recent versions of EHCache) in a GAE application would require to have hooks into the replication process (synchronize the HibernateSessionFactory). The distributed caches configuration (static) would however require to know exactly the nodes hosts, and GAE doesn’t provide such information.

Finally we are tied with the Google datastore, with the following restrictions (do not come from Datanucleus limitations) : no aggregate requests, no polymorphic requests, limited filters, limited joins, limited many-to-many relations support, etc.
As BigTable isn’t relational, JDO looks interesting as it isn’t restricted to relational datastores (contrary to JPA). DataNucleus manages various datastore types, and an extension (plugin) to BigTable had to be developed by Google (notably to manage access through JPA interface). Despite the GAE datastore being at a higher level of abstraction than BigTable, some limitations seem directly tied with that implementation choice, whose goal is to provide consistent response time whatever the request (thus the above limitations).

No support for SOAP webservices
This shouldn’t be a problem as recent RDA solutions (GWT and Cappuccino/CP2JavaWS) use JSON (enhanced with proprietary fields).

Inter-applications communication
Applications have to use URL Fetch APIs from AppEngine SDK to communicate.

Tools and WTP integration
The Eclipse plugin allows to create a web project (with AppEngine webapp configuration file, and required jars – have to be added manually to the buildpath), but doesn’t provide integration with WTP (and no mean to stop the AppEngine server once stared – have to use WTP stop button). We can in fact deploy an AppEngine project from a WTP project, by renaming WebContent to war, and by adding the appengine-web.xml file to WEB-INF folder of the WTP project. However we then haven’t support for classes enhancement (required for the datastore JDO and JPA implementations). We could probably add this automatic task by adding the appropriate builder in the .project file.
The enhancement step required for the mapping adds to the previous constraint of client code generation if using GWT. Some JDO solutions like LIDO still allowed to remove the enhancement step if needed (leading however to some performance hit as expected).

Java update for Leopard

Posted: June 18, 2009 in Apple, IT/Dev
Tags: , , ,

A new update to Java 6, 5 and 1.4.2 is available for Leopard (Java 6 however only supports Intel macs). The updated versions are then 1.6.0_13, 1.5.0_19, and 1.4.2_21.

A new 0.6 version of CP2JavaWS bridge is available at Sourceforge. It includes the following new features :

– added a mode for custom (Cappuccino based) digest authentication dialog (previous version client-side digest authentication and dialog were managed by the browser only). The mode is setted on the server-side authentication filter configuration (browserMode parameter in the web.xml – set it to false for custom dialog).

– a default Cappuccino authentication dialog is provided (CP2JavaWS client code also manages transparently digest authorization request creation, cnonce and nonce counter, and sending of original request when authentication successes). That dialog also shows the endpoint’s url (we could use a composite app that makes calls to various enpoints/different webapps on the same domain – same protocol, host and port -, and then have multiple authentication challenges).

– a custom CPWindowsController can be set when creating a endpoint to use another window. It has to implement the initWithTarget:(id) okAction:(SEL) cancelAction:(SEL) method (see the provided CP2JavaWSLoginWindowController).

– passing sameDomain information isn’t required anymore when creating an endpoint. CP2JavaWS compares the passed endpoint url with the index.html document.location (protocol, host and port) to determine the proper mode. However the sameDomain parameter can still be passed if needed (required if the index.html is local – for dev configuration).