ga

Thursday, June 16, 2011

I am doing an android app that will be reading JSON from the web. Initially I thought I was going to use Jackson, because I heard it was the fastest out there. Initially, I found the documentation and api a bit obtuse, but I figured it out and here is what I got:

HttpGet httpRequest = new HttpGet(ROTTEN_TOMATOES_IN_THEATERS);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
HttpEntity entity = response.getEntity();
BufferedHttpEntity bufferedHttpEntity = new BufferedHttpEntity(entity);
InputStream is = bufferedHttpEntity.getContent();

ObjectMapper mapper = new ObjectMapper();
mapper.configure(Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
long start = System.currentTimeMillis();
RTContainer movie = mapper.readValue(is, RTContainer.class);
start = System.currentTimeMillis() - start;
Log.v(TAG, movie.toString() + "runtime = " + start);
is.close();

Fetching 5 movies I got times like this:

06-16 16:29:00.989: VERBOSE/JacksonJsonReader(814): com.appease.movies.rt.util.RTContainer@4066af28runtime = 1117
06-16 16:29:08.770: VERBOSE/JacksonJsonReader(814): com.appease.movies.rt.util.RTContainer@4050fbe0runtime = 1181
com.appease.movies.rt.util.RTContainer@40651f50runtime = 943
06-16 16:29:15.238: VERBOSE/JacksonJsonReader(814): com.appease.movies.rt.util.RTContainer@405f1638runtime = 883
06-16 16:29:18.099: VERBOSE/JacksonJsonReader(814): com.appease.movies.rt.util.RTContainer@4062f2b8runtime = 1099
16:29:20.537: VERBOSE/JacksonJsonReader(814): com.appease.movies.rt.util.RTContainer@40650230runtime = 879


So, I decided to test out Gson, code:

HttpGet httpRequest = new HttpGet(ROTTEN_TOMATOES_IN_THEATERS);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
HttpEntity entity = response.getEntity();
BufferedHttpEntity bufferedHttpEntity = new BufferedHttpEntity(entity);
InputStream is = bufferedHttpEntity.getContent();

Reader reader = new InputStreamReader(is, "UTF-8");
Gson gson = (new GsonBuilder()).create();
long start = System.currentTimeMillis();
RTContainer movie = gson.fromJson(reader, RTContainer.class);
start = System.currentTimeMillis() - start;
Log.v(TAG, movie.toString() + "runtime = " + start);
is.close();

with times like this:
06-16 16:16:34.058: VERBOSE/GsonReader(745): com.appease.movies.rt.util.RTContainer@405b6550runtime = 789
06-16 16:16:38.508: VERBOSE/GsonReader(745): com.appease.movies.rt.util.RTContainer@40635008runtime = 614
06-16 16:16:41.247: VERBOSE/GsonReader(745): com.appease.movies.rt.util.RTContainer@4060fae8runtime = 755
06-16 16:16:43.607: VERBOSE/GsonReader(745): com.appease.movies.rt.util.RTContainer@405167c0runtime = 422
06-16 16:16:51.658: VERBOSE/GsonReader(745): com.appease.movies.rt.util.RTContainer@406421d0runtime = 414
06-16 16:16:54.078: VERBOSE/GsonReader(745): com.appease.movies.rt.util.RTContainer@405bc620runtime = 425
06-16 16:17:17.248: VERBOSE/GsonReader(745): com.appease.movies.rt.util.RTContainer@4063cca0runtime = 828
06-16 16:17:18.299: VERBOSE/GsonReader(745): com.appease.movies.rt.util.RTContainer@40679710runtime = 737
06-16 16:17:21.058: VERBOSE/GsonReader(745): com.appease.movies.rt.util.RTContainer@4059fc58runtime = 429
06-16 16:17:35.807: VERBOSE/GsonReader(745): com.appease.movies.rt.util.RTContainer@4052a5e0runtime = 385
06-16 16:17:39.348: VERBOSE/GsonReader(745): com.appease.movies.rt.util.RTContainer@40571c50runtime = 745

So, I am going to stick with Gson. The calls are being made in the same way via an async task with nothing else going on.

Tuesday, June 15, 2010

Looking a gift horse in the mouth

A few weeks ago, I had a post about DZone.com and them adding a Digg Bar. Anyhow, I didn't think much of it, but I was contacted by a person, which shall remain nameless, about this post. It was an explanation and I guess an apology, which was not needed at all, and as a consolation they sent me several RefCardz of my choice (I wanted to be greedy and order all of them).



Anyway, I am thankful for these, but if you look closely at them you will see something weird.

Hover between the arrows to see the answer:
-> That's right, they sent me #84 3x times. <-D'oh!
Anyhow these things are beautiful and I really like them, they should offer to sell these things. Very nice card stock, beautiful colors, and seemingly durable. You are missing out on some money DZone.

Tuesday, May 18, 2010

Bars and DZone

Why oh Why did DZone add this new browser bar. When digg did this there were so many articles on DZone itself saying how much it was hated. I guess the DZone people didn't read any of those posts. What about that Varung guy who would only posts links via linkive. UGHHHH!

Here is what is irritating. Visit a site off of DZone. Read the article and find something that is linked from that site that you find interesting. Go to that site, think to yourself "Hmmm, guess I need to get rid of the DZone bar". Click the 'X' and blammo you are back at the site you originally visited. And of course if you hit back you are back on the DZone bar'ed site.

Here is one good thing I think. When I am on DZone, I usually open a bunch of links at once (I love "Open In New Tab") and then I read the articles later. Bad thing is I hardly ever go back and rank the article on DZone so the bar helps, but I don't think its worth it.

Reward posts you find interesting by clicking an ad.

Tuesday, September 2, 2008

Google's Chrome

I believe I was the first to download this, because I was refreshing about every 5 minutes or so (by hand). I guess it would have been easier to do it in opera and tell it to refresh ever minute or whatever. Anyhow, I got it at 2:48pm EST. Here are my impressions.

Pros:
  • Start up is faster than I thought. The comic said initial startup would be slow.
  • Rendering is ultrafast, FF should integrate Webkit.
  • Interface is somewhat pretty, very minimalist.
  • Porn mode even blocks Google spying (more on this in the cons) it seems.
  • Open Source, although it is a humongous code base
  • Better resource handling sort of...  Trading in memory fragmenting for a bunch of processes.
  • Check out the "Inspect Element" on the context menu, it is like a stripped down Firebug.

Neutral:
  • The "Create Application" shortcut is just about useless to me, bookmark does it good enough

Cons:
  • Not keyboard friendly (can not access the menus with the alt key)
  • No ad blocking, but I am sure that will come with a plugin or modified source.
  • The changing of the fonts is a bit buggy. You change the size of the Serif fonts the other to change also, font family change does exhibit this behavior.
  • The never crash claim isn't all the great because FF has yet to crash on me, but I do get the memory fragmentation.
  • I like how in FF you can highlight a link in the "Awesome" Bar and delete it, this is not in Chrome.
  • The options dialog loads slowly and when it is loaded it works slow also.
  • As I type this the Ctrl+B is clashing with a accelerator in Chrome.
  • Also, as I was typing this blog, I surfed to activision.com in another tab and Chrome hung for about 15 seconds. I have only produced this once, but there is low framerate on activision.com.
Now here is where it gets really bad
  • Seemingly, maybe it was in the comic, but I hate that everytime you type in the address bar it makes a connection to Google. Just search the local history and steal my data when I close the browser ;-) I mean ;-(
  • It installs to the under the users "Local Settings" directory. WTF! Why can't I install to another drive? This is very dumb, but I guess it is expected because Google Desktop installs on the windows drive also. Google you really need to give us an option on where to install
Overall, I do like it and I think I will be keeping it due to the fact it renders so quickly and I will probably uninstall Opera. I am sure the next release will fix some of these issues, and put it closer to FF, but for now FF has nothing to worry about and IE is still safe also. Opera's last leg just broke for me, because I was using it only to browse dzone.com basically.

Saturday, August 9, 2008

I knew I was right... I think

I had a phone "chat" on Wednesday and it went fairly well I thought (couldn't have went too well because they chose to go no further). Ok, I was going to start complaining and what not, but I decided it will gain me nothing. But, here is where we kind of butted heads during the interview. He asked me about the disadvantages of Spring IOC (Inversion of Control), I guess my answer should have been overhead, but instead I talked about debugging. I stated that it was harder to debug, because you wouldn't get a good stack trace. He asked me if I was sure and I restated to say that during development if you wanted to get a call hierarchy it would work in a IOC container. Really when I think of it that wasn't a good answer either, but what got me is he was saying that that was wrong. I was like "No, it isn't" and he was like "Yes, it is". So this blog is to point out I am right.

So here is a simple controller defined in my xml:
<bean class="org.brh.ctrl.LoginFrmCtrl" name="/login.htm">
<property name="user" ref="user"/>
</bean>


So, what is going to happen here Spring will inject the user bean into the controller when it is created. Here is a snipped of the controller code:
public class LoginFrmCtrl extends SimpleFormController
{
private IUser user = null;
...
public void setUser( IUser u ){ user = u;}

...


So, what he is saying, is that you can right click on the setUser method and it should tell me that it is being called by some class in Spring. But here is what I get:


This is with Eclipse 3.4 and the latest version of Spring IDE.

Is there something that I am missing? What are some other disadvantages of IOC?

Tuesday, July 8, 2008

Spring MVC

I have been pretty busy lately, haven't had much time to concoct a decent post so I kept silent. Anyhow, why did I chose to move from EJB and JSF to Spring MVC?
  • I mainly use JSF at work
  • Indeed.com showed a major drop in JSF jobs.
  • There was a certain job that looked interesting and it wanted Spring experience

So, I figured no time like the present and on top of that it seems JSF 2.0 is going to address quite a few issues, so I will jump back into it then. What I like about Spring so far is it just seems a little more straight forward, especially since you use regular old html/jsp tags. Of course you can use JSF inside of Spring, but I have gotten to that yet.

As I have been learning Spring, I've been using the book "Expert Spring MVC and Web Flow" from Apress. It is a good book and if you have a general idea Spring and its concepts, I think it is better to start with it.

The Meat
I ran into an issue on storing the login info from the form bean (backing object) in the session, the book seemingly suggested method injection to tell the controller to get the backing object from the ApplicationContext. Well, before I read that part I remembered reading about Spring having web scoping for its beans. So, I add the bean to the spring xml file and then added a dependency in each appropriate controller, overrode the formBackingObject method, and it worked fine. This seems a lot easier than injecting a method.

Here are some reading assignments (more for me to store for future reference actually):
Form input vs button
Some nice firefox add-ons
Java Vs C vs interpreted langs
Rest Antipatterns
Something I want to do on the side


A little complaint about my homepage MSN. Why does MS feel they need to change the focus when you pull up msn.com. I open IE and start typing in the address bar and hit enter and before I realize it 1/2 the text I typed has went into the crappy MSN search box on the top of the page. UGHHHHHHH

Tuesday, April 22, 2008

EJB 3. Wooohooo???

I was trying to decide if I should learn EJB 3 and more of JEE 5 or if I should jump into Spring. Looking at the available jobs on indeed points to Spring, but I went with EJB anyway because I think it may eventually pick up steam.

So, I did a simple app and my first complaint is that unless I missed something Sun's documentation/tutorial isn't that good. It seems the samples are geared to a single server install where the EJB and the clients are bundled into the same EAR file. My first foray I wanted to have them separate so I could easily test on remote servers. Thankfully, there is google and I found why my client could never find the EJB. Apparently, you have to do something like this:

Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.appserv.naming.S1ASCtxFactory");
env.put(Context.PROVIDER_URL, "iiop://127.0.0.1:3700/");
InitialContext ic = new InitialContext(env);
bf2EJB = (BF2Remote) ic.lookup("BF2");

I guess I should mention I was using Glassfish. I suppose the code is simple enough, but I think the client has to do to much. IMHO, the only thing the client should have to do is specify a protocol (iiop, rmi, etc.) and the address:port (new InitialContext("iiop://127.0.0.1:3700). When the server gets a connection it should resolve to a default factory to talk to unless another is specified. Again, I wanted to try this on geronimo, but I just don't have time to be bothered with the extra hoops you have to jump through with it.

Do all JEE 5 servers require the initial context factory to be set?

Is it bad to have a server receive a lookup call and that server looks for it locally and returns it if it is found (in my case you have to specify the server address)?