Archive for January, 2010

You cant always close the persitencemanager when you are done with it.

I am used to close all recources when i am done with these but that seems not to be the case in app engine world.
Here is little method that gets all countries, adds these to List and closes PersistenceManager as its not needed anymore, we have all the data we need in List.

public List<Country> getCountries() {
PersistenceManager pm = PMF.get().getPersistenceManager();
String query = "select from " + Country.class.getName();
List<Country> countries = (List<Country>) pm.newQuery(query).execute();
pm.close();
return countries;
}

Countries are used in simple dataTable below, but when running this code app engine starts to complain “Object Manager has been closed”. To fix this issue pm.close(); can be commented out and hope that guys from google will close it eventually themselves. Google in its documentation does not recommend this though.

<h:dataTable value="#{countryBean.countries}" var="country">
<h:column>
</h:column>
</h:dataTable>

Probably appengine is lazy to actually get items from datastore to List but gets them only when particular item is used. So another way to fix it is to force appengine to force loading all entries from datastore by copying.

public List<Country> getCountries() {
PersistenceManager pm = PMF.get().getPersistenceManager();
String query = "select from " + Country.class.getName();
List<Country> countries = (List<Country>) pm.newQuery(query).execute();
List<Country> countries2=new ArrayList<Country>();
Collections.copy(countries, countries2);
pm.close();
return countries;
}

What i have not figured out yet is why all request take awful lot of CPU recource and how to reduce it. over 5000ms is like crazy

01-24 04:18AM 54.222 /faces/insertcountry.xhtml 200 930ms 5289cpu_ms 4570api_cpu_ms 0kb Mozilla/5.0 (X11; U; Linux x86_64; et; rv:1.9.1.7) Gecko/20100106 Ubuntu/9.10 (karmic) Firefox/3.5.7,gzip(gfe),gzip(gfe)
...
01-24 04:18AM 54.729 org.datanucleus.ObjectManagerImpl close: Outstanding nontx update being committed to datastore
An Error Occurred:
Object Manager has been closed
+- Stack Trace
 Read the rest of this entry »
Share on TumblrSubmit to StumbleUponSave on DeliciousDigg ThisSubmit to reddit

Appengine sample Guestbook Datastore works but yours fails.

When you first start experimenting with google app engine then you may get Exception below when trying to save data to datastore and checking out PercistenceManager for that. One thing to check it to see, if jdoconfig.xml in source packages and META-INF. Appengine example config is also included here.

<?xml version="1.0" encoding="utf-8"?>
<jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig">

<persistence-manager-factory name="transactions-optional">
<property name="javax.jdo.PersistenceManagerFactoryClass"
value="org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory"/>
<property name="javax.jdo.option.ConnectionURL" value="appengine"/>
<property name="javax.jdo.option.NontransactionalRead" value="true"/>
<property name="javax.jdo.option.NontransactionalWrite" value="true"/>
<property name="javax.jdo.option.RetainValues" value="true"/>
<property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true"/>
</persistence-manager-factory>
</jdoconfig>

Read the rest of this entry »

Share on TumblrSubmit to StumbleUponSave on DeliciousDigg ThisSubmit to reddit

How to translate KTurtle and what the hell is gettext

When you have kids then they will eventually leave the nest and go to school. But before that it is mandatory that they have learned to program. One program that can be used to teach little kids programming is KTurtle with its logo programming language.

Unfortunately there are still many little kids are not fluent in English by the age of 5. Fortunately KTurtle commands can be translated to any language and lot of languages are available for download in launchpad. When you download language from launchpad.net then you get some .po file like po_kturtle-et.po that you should stick somewhere.

Solution for sticking is

1. Compile .po to .mo
   msgfmt -cv po_kturtle-et.po -o kturtle.mo
2. Put the .mo file in the right place
   mv kturtle.mo /usr/share/locale-langpack/et/LC_MESSAGES/
3. Restart kturtle

et in this context means languagecode for estonian (eesti) language.
Once thats done you get into Settings> Script Language your native langage alongside builtin English.

More reading in http://en.wikipedia.org/wiki/GNU_gettext

Share on TumblrSubmit to StumbleUponSave on DeliciousDigg ThisSubmit to reddit

Appengine + JSF aka “but it runs on my computer”

You finally get your JSF running on google appengine SDK, upload it to real appengine and of course this is not working, message states:

Error: Server Error
The server encountered an error and could not complete your request.
If the problem persists, please report your problem and mention this error message and the query that caused it

You get the stacktrace and logs from Google app engine managment site https://appengine.google.com/ an you see Read the rest of this entry »

Share on TumblrSubmit to StumbleUponSave on DeliciousDigg ThisSubmit to reddit

JSF 2.0 dont like google appengine

You write nice simple JSF application and when you try to run it in appengine browser shows:

HTTP ERROR: 404
NOT_FOUND
RequestURI=/
Powered by jetty://

Stacktrace looks like:

[java] The server is running at http://localhost:8080/
     [java] 19.01.2010 19:42:14 com.google.apphosting.utils.jetty.JettyLogger warn
     [java] WARNING: failed com.google.apphosting.utils.jetty.DevAppEngineWebAppContext@6ee3849c{/,/home/user/NetBeansProjects/HelloWorld/build/web}
     [java] java.lang.NoClassDefFoundError: javax.naming.InitialContext is a restricted class. Please see the Google  App Engine developer's guide for more details.
     [java]         at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51)
     [java]         at com.sun.faces.config.WebConfiguration.processJndiEntries(WebConfiguration.java:578)
     [java]         at com.sun.faces.config.WebConfiguration.(WebConfiguration.java:114)
     [java]         at com.sun.faces.config.WebConfiguration.getInstance(WebConfiguration.java:174)

Problem is that appengine has issue with JSF implementation and you must rewrite jsf-impl.jar to fix it. Fortunately there is guy who already did this, see http://javadocs.wordpress.com/2009/10/17/mojarra-jsf-2-0-rc2-and-google-app-engine-sdk-1-2-6/

IMPORTANT! If this seems not to do the trick then clean and build is needed.

One more useful link is https://sites.google.com/a/wildstartech.com/adventures-in-java/Java-Platform-Enterprise-Edition/JavaServer-Faces/sun-javaserver-faces-reference-implementation/configuring-jsf-20-to-run-on-the-google-appengine

Share on TumblrSubmit to StumbleUponSave on DeliciousDigg ThisSubmit to reddit

Spam moderation tip with wordpress and akismet

Currently this blog is getting around 1000 spam comments a day, Most of them is caught by akismet but around 0.05% is held for manual moderation which can be in order of tens if comments are left unmoderated in a few weeks. For some time I tried to see whats inside these comments but it boring and fortunately there is fast trick. Click Check for Spam and in second attempt akismet has learned and marks now all spam correctly as spam.

Share on TumblrSubmit to StumbleUponSave on DeliciousDigg ThisSubmit to reddit

Linksys WRT54GL with or without DD-WRT not getting any internet.

You might have Speedtouch router which acts as DSL modem and digi-TV bridge and also offers you internet. Now you want second router like Linksys WRT54GL to serve your needs better.

Speedtouch has ip 192..168.1.254, linksys factory default is 192.168.1.1. If you take cable from your computer and stick linksys between modem and computer then your computer will not get any internet. This is because speedtouch and linksys networks “collide”. You cant change speedtouch network but you can change it for linksys. You must change Router local ip address some other than 192.168.1.XXX eg change it to 192.168.5.1 and enter to gateway your speedtouch modem ip 192.168.1.254.

Save, apply and reboot and you have yourself internet through 2 routers.

Share on TumblrSubmit to StumbleUponSave on DeliciousDigg ThisSubmit to reddit

fixing ipkg in dd-wrt

You installed dd-wrt on your Linksys WRT54GL or Bullafo or whatever wifi router and now you want to install some packages but updateing package lists you get :

root@DD-WRT:/jffs# ipkg update
Downloading http://downloads.openwrt.org/whiterussian/packages/Packages ...
Connecting to downloads.openwrt.org (78.24.191.177:80)
ipkg_download: ERROR: Failed to retrieve http://downloads.openwrt.org/whiterussian/packages/Packages, returning 
ipkg_update: Error downloading http://downloads.openwrt.org/whiterussian/packages/Packages to /jffs/usr/lib/ipkg/lists/whiterussian

To fix this you neet to enable JFFS2 which gives you some rw space, which you already did i guess. Now select Enable “Clean JFFS2″ Save, Apply settings and reboot router which formats this filesystem and you can use it properly.

Share on TumblrSubmit to StumbleUponSave on DeliciousDigg ThisSubmit to reddit