About Me

My photo
PhD Candidate at Purdue University, Computer Science.
Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Sunday, April 26, 2009

embedding ftpServer

I was trying to embed the ftpserver in my Java code. I had a problem exception:

Exception in thread "main" java.lang.IllegalAccessError: tried to access field org.slf4j.impl.StaticLoggerBinder.SINGLETON from class org.slf4j.LoggerFactory


I looked to the source files of the slf4j and found that in the latest release slf4j-1.5.6 there is a private modifier in Class org.slf4j.impl.StaticLoggerBinder

private static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();


ftpserver puts slf4j-api-1.5.2.jar, that's why it deals with this member as public.

All you need to do is
1- change the modifier of this member.
2- or get the latest sl4fj-api-1.5.6.jar

Tuesday, April 14, 2009

Scala threading

Scala augments Java's native support for concurrency by adding actors. The Scala's actors library does address the fundamental problem of shared data and locks model by providing an alternative, share-nothing, message passing model that programmers tend to find much easier to reason about. They are implemented on top of normal Java threads, so that every actor must be given its own thread, so that all the act methods get their turn.

It is clear, that this model is not efficient as the creation and switching of threads are not cheap in Java. The normal implementation of receive returns after it finds and processes a message. To overcome this problem Scala adds an alternative to the usual receive method which is called react. react takes a partial function, but it doesn't return, its result type is Nothing.

Scala users, you should be ware that you are still on top of Java threading model...

Friday, March 20, 2009

Erlang propaganda

It's weird when I first noticed the propaganda around Erlang specially in 2007..Everyone was going crazy talking about Erlang.
You can see it is not the case the last year.
I was thinking that maybe this was due to the launching of other languages built on Java. the new languages like Scala, Clojure made many enhancements to the concurrency problems in the Java model while preserving the knowledge and the libraries of this famous language.

Thursday, December 11, 2008

Back to Shell

Finally, I am back to the open source world.

After getting my new used Toshiba Satellite A100, I downloaded Ubuntu 8.10.
Something I liked when installing the new ubuntu is its ability to be installed within Windows. So, u don't have to bother about restarting, disk formats..bla..bla..bla.

I checked the new OS installation on my laptop. Well, I am impressed, everything seemed to be working smoothly.

My next step was to run the JikesRVM on eclipse to start some development.
in order to achieve this:

if you run
$ dpkg --get-selections | egrep '32|gcc'

u will get a list of the libraries you have on your system.
While for the jikes compilation u will need gcc multilib and g++ multilib
so, you should get the g++-multilib by running
$ sudo apt-get install g++-multilib
You will also need Bison
$ sudo apt-get install bison
get ant
$ sudo apt-get install ant
get your Java packages by running..
$ sudo apt-get update
$ sudo apt-get install sun-java6-jre sun-java6-jdk sun-java6-plugin

In case you have other java installations ..Run this command to fix configurations.
$ sudo update-java-alternatives -s java-6-sun
Set your $JAVA_HOME variable
$ sudo gedit /etc/environment
and add JAVA_HOME = "/usr/lib/jvm/java-sun-6"

Re-login
Download eclipse from its official site.
$ sudo apt-get install subversion
$ svn co https://jikesrvm.svn.sf.net/svnroot/jikesrvm/rvmroot/trunk jikesrvm
$ cd jikesrvm
jikesrvm$ bin/buildit --eclipse localhost -j $JAVA_HOME
Import the project into workspace.

I found some errors in the source code after getting the project into eclipse.
My friend Morshedy advised that it may be a common problem with the eclipse, so I run the
jikesrvm$ find -wholename *.java  -exec touch {} \;
but didn't solve it.

So, I guess I will wait for an update on the SVN.

Update: it was not my lucky day when I was building jikes..I tried to build it many times on that day. but I got errors when openening in eclipse...
So, I retired again a day later by :
jikesrvm$ rm rf components
jikesrvm$ ant very-clean
and then rebuild..it worked fine this time

Friday, May 23, 2008

An introduction to Ruby language

My second technical session at Bibliotheca Alexandrina emphasized on the Ruby language..
I posted the presentation on my scribd here. I hope you find it useful.

Feel free to post your comments.
Read this doc on Scribd: ruby intro

Sunday, December 16, 2007

JAI handling files

I am using JAI to display images. First I run my development environment was MAC. Everything was going smooth with me.
The problems started when I moved to Windows. Somehow, when I try to delete the image file from the hard disk, it didn't work.
Seems that JAI keeps a reference over the file indefinitely.
Example:
PlanarImage image = JAI.create("fileload",path)

The file load operation doesn't release the handler.
I tried to nullify the source handling the image, then call the System.gc(). (which is a really bad solution)

another solution is as following:
//replace fileLoad operation
File image = new File(path);
FileInputStream fis = new FileInputStream(file);
byte[] buffer = new byte[(int)file.length()];
fis.read(buffer);
fis.close();
PlanarImage image = JAI.create("stream",new ByteArraySeekableStream(buffer));

//replace file store operation
JAI.create("filestore",image,file.getAbsolutePath(),"jpg",null);

If this doesn't work, it maybe because file descriptor is not released. you may need to call the garbage collector.