Books I Like

Sunday, November 22, 2009

Solving Project Euler Problem #10 in Ruby

Problem Statement :-

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

Find the sum of all the primes below two million.

Solution :-



require "mathn"
require "benchmark"
module Enumerable
def lazy_select
Enumerator.new do |yielder|
each do |obj|
yielder.yield(obj) if yield(obj)
end
end
end
end

p 5+((5..2000000).lazy_select {|v| (v%6 == 1 || v%6 ==5) && v.prime?}.take(2000000)).inject(0) {|s,v| s+=v}
#Benchmark.bm(12) { |b| b.report('Report:') {5+((5..2000000).lazy_select {|v| (v%6 == 1 || v%6 ==5) && v.prime?}.take(2000000)).inject(0) {|s,v| s+=v}} }

Saturday, November 14, 2009

Solving Project Euler Problem #9 No code Required

Problem Statement :-

A Pythagorean triplet is a set of three natural numbers, a b c, for which,

a^2 + b^2 = c^2
For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.

There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.

Solution :-
Lets have a look on the first Pythagorean triplet 3, 4 and 5.

All their multiples, would also be a Pythagorean triplet (e.g. 6, 8 and 10 or 9, 12 and 15 , and so on..)

Also, any odd number can be represented as x^2 - y^2
For e.g.
3 = 2^2 - 1^2
5 = 3^2 - 2^2
7 = 4^2 - 3^2

Since, (x^2 - y^2)^2 + (2xy)^2 = (x^2 + y^2)^2, we can always generate a triplet for any odd number x^2 - y^2.

So, using this any triplet is of the form :
k*(x^2-y^2), k*2xy and k*(x^2+y^2), where k is any number (1, 2, ...n).

Well, now let us solve the current problem.

a = k*(x^2-y^2)
b = k*2xy
c = k*(x^2+y^2)
Since a+b+c = 1000, and they are the sides of a triangle,

a,b,c < 500
=> k*(x^2+y^2) < 500
=> x,y < 500^(1/2) < 23

Now, given a+b+c = 1000
=> k(x^2-y^2+2xy+x^2+y^2) = 1000
=> 2kx(x+y) = 1000
=> k*x(x+y) = 500 (Factors of 500 is , 2,2,5,5,5)
=> k*x(x+y) = 20*(20+5) (This is the only value, which satisfies x,y < 23)
=> for k =1 , x = 20, y = 5

So, a = 20^2 - 5^2 = 375
b = 2*20*5 = 200
c = 20^2 + 5 ^2 = 425

So, the product is : 375*200*425 = 31875000

Solving Project Euler Problem #8 No code Required

Problem Statement :-
Find the greatest product of five consecutive digits in the 1000-digit number.
73167176531330624919225119674426574742355349194934
96983520312774506326239578318016984801869478851843
85861560789112949495459501737958331952853208805511
12540698747158523863050715693290963295227443043557
66896648950445244523161731856403098711121722383113
62229893423380308135336276614282806444486645238749
30358907296290491560440772390713810515859307960866
70172427121883998797908792274921901699720888093776
65727333001053367881220235421809751254540594752243
52584907711670556013604839586446706324415722155397
53697817977846174064955149290862569321978468622482
83972241375657056057490261407972968652414535100474
82166370484403199890008895243450658541227588666881
16427171479924442928230863465674813919123162824586
17866458359124566529476545682848912883142607690042
24219022671055626321111109370544217506941658960408
07198403850962455444362981230987879927244284909188
84580156166097919133875499200524063689912560717606
05886116467109405077541002256983155200055935729725
71636269561882670428252483600823257530420752963450


Solution :

One way to solve is :-
starting from the beginning 5 numbers (strating from the 1st), multiplying them, storing it in as max, continuing the process for the next 5 numbers(starting from the 2nd), replacing the max value if the current product is more than the max stored earlier and so on till we reach the last 5 elements.
We may minimize the number of iterations based on the fact that for every zero found we don't need to calculate the product.


Lucky Solution :-
I started looking for 99999 using "ctrl+F" (as I knew if I find this any where), this would be the max no matter what the other numbers are.
Since it was not there, I started looking for the combination of for 9's and one 8 (it was also not there) and so on, and eventually found 99879. Definitely, i was lucky to get the number in a minute or so (The data set for the problem was friendly, otherwise I would have probably coded it.

You may use another fact to code your logic. If you know the sum of n numbers x1+x2+..xn, the maximum value of their product is when x1=x2=..=xn.

For e.g. sum of 9,9,8,8,8 and 9,9,8,7,9 is equal, the product of 9,9,8,8,8 would be
larger (8+7+9 = 24 = 8+8+8).

Sunday, November 1, 2009

Solving Project Euler Problem #7 in Ruby, Clojure

Problem Statement :
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

What is the 10001st prime number?

Solution :

This works on Ruby 1.9+. Here we have taken advantage of the method discusses here to create Lazy enumerator in Ruby. I started looking for the ruby equivalent as the clojure code becomes so easy to deal with using the lazy sequences.


require "mathn"
infinity = 1.0/0.0
module Enumerable
def lazy_select
Enumerator.new do |yielder|
each do |obj|
yielder.yield(obj) if yield(obj)
end
end
end
end

p (1..infinity).lazy_select { |v| v.prime? }.take(10001).last



The clojure code is as follows :
Here we have added one optimization (Any prime number after 2 and 3, when divided by 6, leaves the remainder 5 or 1).


(defn sqrt [x]
(int (Math/sqrt x)))

(defn get-smallest-prime-factor [n]
(loop [n n d 2]
(cond (> d (sqrt n)) n
(= n d) n
(= 0 (rem n d)) d
true (recur n (inc d)))))

(def get-nth-prime
(lazy-cat '(2 3)
(filter
#(= % (get-smallest-prime-factor %))
(filter
#(or (= 1 (rem % 6)) (= 5 (rem % 6)))
(take-nth 2 (iterate inc 3))))))

(println (nth get-nth-prime 10000))


Here is another cheat, if you have installed the clojure contrib library.


(use 'clojure.contrib.lazy-seqs)
(println (nth primes 10000))

Solving Project Euler Problem #6

Problem Statement :
The sum of the squares of the first ten natural numbers is,
1**2 + 2**2 + ... + 10**2 = 385
The square of the sum of the first ten natural numbers is,(1 + 2 + ... + 10)**2 = 55*2 = 3025
Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 385 = 2640.
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.

Solution is -> (n(n+1)/2)**2 - (n*(n+1)*(2n+1))/6



(defn euler6 [n] (- (* (/ (* n (+ n 1)) 2) (/ (* n (+ n 1)) 2)) (/ (* n (+ n 1) (+ 1 (* n 2))) 6)))
(println (euler6 100))

Sunday, October 25, 2009

Dual Pivot Quicksort in Java

This is from the paper published by Vladimir Yaroslavskiy (Read it for more details : here

Sorting data is one of the most fundamental problems in Computer Science, especially if the arranging objects are primitive ones, such as integers, bytes, floats, etc. Since sorting methods play an important role in the operation of computers and other data processing systems, there has been an interest in seeking new algorithms better than the existing ones. We compare sorting methods by the number of the most "expensive" operations, which influence on effectiveness of the sorting techniques, — comparisons and swaps. Quicksort algorithm is an effective and wide-spread sorting procedure with C*n *ln(n) operations, where n is the size of the arranged array. The problem is to find an algorithm with the least coefficient C. There were many attempts to improve the classical variant of the Quicksort algorithm:

1. Pick an element, called a pivot, from the array.
2. Reorder the array so that all elements, which are less than the pivot, come before the pivot and all elements greater than the pivot come after it (equal values can go
either way). After this partitioning, the pivot element is in its final position.
3. Recursively sort the sub-array of lesser elements and the sub-array of greater elements.

We can show that using two pivot elements (or partitioning to three parts) is
more effective, especially on large arrays. We suggest the new Dual-Pivot Quicksort
scheme, faster than the known implementations, which improves this situation. The
implementation of the Dual-Pivot Quicksort algorithm has been investigated on different inputs and primitive data types. Its advantages in comparison with one of the most effective known implementations of the classical Quicksort algorithm [1], [2], and implementation of Quicksort in JDK™ 6.0 platform [3] have been shown.

It is proved that for the Dual-Pivot Quicksort the average number of
comparisons is 2*n*ln(n), the average number of swaps is 0.8*n*ln(n),
whereas classical Quicksort algorithm has 2*n*ln(n) and 1*n*ln(n)
respectively.




Here is the source code for the implementation : Code by Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch.


Comparision between Current JDK Quicksort vs Dual Pivot Quick sort : comparision

Friday, October 23, 2009

Solving Euler Project Problem #4 using Ruby

Problem Statement : A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 99.

Find the largest palindrome made from the product of two 3-digit numbers

Solution : Please check the comments before the code which explains the logic/approach to the problem. We are trying to minimize the iterations to check against the generated palindromic number. Also this divisibility by holds true only for all the even numbered palindroms.



#
#A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 99.
#
#Find the largest palindrome made from the product of two 3-digit numbers
#
# Observations :
# Number = xyzzyx = 100001*x + 100010*y + 1100*z (which is divisible by 11)
#
#




def largest_palindrome_for_even_digits(n)
max_val = 0
multiplier_x = get_multiplier_x(n)
n.downto(100) { |y|
multiplier_x.each { |x|
product = x * y
if product.to_s == product.to_s.reverse
max_val = [max_val, product].max
end
}
}
max_val
end


def get_multiplier_x (n)
multipliers = []
current_val = n/11*11
while current_val > 100
multipliers << current_val
current_val-=11
end
multipliers
end

puts largest_palindrome_for_even_digits(999)

Solving Euler Project Problem #3 using Ruby

Problem Statement : The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143

Solution : Please check the code comments which explains the logic.

#The prime factors of 13195 are 5, 7, 13 and 29.
#
#What is the largest prime factor of the number 600851475143
#
#Start dividing the number by the first prime (i.e. 2). Keep dividing by the current factor
#till the remainder is zero. So, the number left is n/(current_prime_factor)**m, where m is the no. of times
#current factor was able to divide the number without remainder. Repeat this process with the next
#prime factor and the number left as a result of previous division and so on, unless the result of
#division becomes 1. As the prime factor we are using to divide keeps on increasing, and the loop ends
#when the number is completely divided (or say n become 1), return the current prime factor. This is our
#largest prime factor

require 'mathn'

def find_largest_prime(n)
primes = Prime.new
while n > 1
current_prime_factor = primes.next
while n % current_prime_factor == 0
n /= current_prime_factor
end
end
current_prime_factor
end

puts find_largest_prime(600851475143)

Wednesday, October 21, 2009

Google Guice : Part 2 : Inject Config Value

Was Spring 3.0 just released ?

Right, Here is a link mentioning the same Spring3.0 release. I am really excited to check it out, specially the REST part of it. But yeah, let us save it for other posts.

I directly came here, where is the part One ?

If you haven't gone through the part 1 of this article, and are totally new to Google Guice, please check it out and set up your environment as described there.

What is the goal for this article ?

Since in the previous article we were able to set up a working project/program. Let us extend it further. Almost all of the applications needs to have some configuration properties, today we will learn to inject the property value from a config file.

Ummm.. before you dive into it, I just forgot what was the spring bean I used to configure it in a Spring App?

I guess you are probably talking about PropertyPlaceholderConfigurer.java. By the way, the other day I blogged about extending it.

Well...Lets code it :


public interface IPrinter {
public void print();
}

public class MyDummyPrinter implements IPrinter {
public void print() {
System.out.println("Article Printed !");
}
}

public interface IMailSender {
public void sendMail();
}

public class MyDummyMailSender implements IMailSender {
public void sendMail() {
System.out.println("Mail Sent !");
}
}

public interface ArticleService {
public void publishArticle();
}

import com.google.inject.Inject;
import com.google.inject.name.Named;
public class Article implements ArticleService {
private IMailSender mailSender;
private IPrinter printer;

private String advertizedAt;
private String articleHeading;

@Inject
Article(
@Named("advertised.at") String advertizedAt,
@Named("article.name") String articleHeading,
IMailSender mailSender, IPrinter printer) {
this.mailSender = mailSender;
this.printer = printer;
this.advertizedAt = advertizedAt;
this.articleHeading = articleHeading;
System.out.println("This article has been advertized at :" + advertizedAt +
" with the heading :" + articleHeading);
}

public void publishArticle() {
mailSender.sendMail();
printer.print();
}
}



Check out the Article.java code. We want to inject two properties namely "advertizedAt" and "articleHeading" throgh a config file. As you can see Guice comes with a built in annotation - named. So, as it appears, Guice should inject the value for these keys as defined in the config file.

Well, let us define our property file :


advertised.at=dZone
article.name=googleGuicePartTwo


But How will Guice know the property value unless it loads it. Does it has something like PropertyPlaceholderConfigurer ?

You are right, we are going to write some code to load the property file. As of now, I am not aware about any helper class who does it for us. If you know one please comment, or else I would update it once I know.


import com.google.inject.AbstractModule;
import com.google.inject.name.Names;
import java.util.Properties;
import java.net.URL;

public class MyArticleModule extends AbstractModule {
@Override
protected void configure() {
try {
Properties props = loadProperties();
Names.bindProperties(binder(),props);
} catch (Exception e) {
e.printStackTrace();
}
bind(IPrinter.class).to(MyDummyPrinter.class);
bind(IMailSender.class).to(MyDummyMailSender.class);
}

private static Properties loadProperties() throws Exception {
Properties properties = new Properties();
ClassLoader loader = MyArticleModule.class.getClassLoader();
URL url = loader.getResource("config.properties");
properties.load(url.openStream());
return properties;
}
}


So, before injection we are loading the config.properties. The code is straight forward. The piece important here to note is the use of com.google.inject.name.bindProperties which creates a constant binding to @Named(key) for each property.

Well , Let us see it in action :


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

public class MyBootStrapInvoker {
public static void main(String[] args) {
Injector injector = Guice.createInjector(new MyArticleModule());
Article article = injector.getInstance(Article.class);
article.publishArticle();
}
}


Sample Run :-


This article has been advertized at :dZone with the heading :googleGuicePartTwo
Mail Sent !
Article Printed !


Is this the best approach to do this way :

I am sure there must be a better way, as Guice always discourages bindings that uses a string, because the compiler can not check the string. So that means, if there is some spelling mistakes, we would see run time error (like we see in spring, if you make spelling mistakes). Let me know, if you know a better way.
Would appreciate your comments.

Solving Euler Project Problem #2 using Ruby

Problem Statement : Each new term in the Fibonacci sequence is generated by adding the previous two terms.
By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

Find the sum of all the even-valued terms in the sequence which do not exceed four million.

Solution : For the explanation please see the comments. Later I realized that I could have probably used Binet's formula, however this solution also kind of looks good.



#Each new term in the Fibonacci sequence is generated by adding the previous two terms.
#By starting with 1 and 2, the first 10 terms will be:
#
#1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
#
#Find the sum of all the even-valued terms in the sequence which do not exceed four million.
#
#Obersevations : starting with 2 every 3rd number is even (it must be, as to make an even number
#one needs to add two odds (or two even unlikely here))
#So, lets try to decompose the fibonacci series in terms of n-3,n-6,n-9, etc...as it make us do
#less iteration while adding
#
# F(n) = F(n-1)+F(n-2) = F(n-2)+F(n-3)+F(n-2) = F(n-3)+2(F(n-2)) = F(n-3) + 2(F(n-3)+ F(n-4))
# = 3F(n-3) + 2F(n-4)
# = 3F(n-3) + F(n-4)+F(n-5)+F(n-6) = 4F(n-3) + F(n-6)
#
#


def find_sum_of_even_terms(limit)
if(limit<2)
return 0
end
if(limit<8)
return 2
end
second_last_even_number = 2
last_even_number = 8
current_number = 4*last_even_number+second_last_even_number
sum=second_last_even_number+last_even_number

while current_number<=limit
sum+=current_number
second_last_even_number = last_even_number
last_even_number = current_number
current_number = 4*last_even_number+second_last_even_number
end
sum
end

puts find_sum_of_even_terms(4000000)

Solving Euler Project Problem #1 using Ruby

Problem statement : If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.

Solution :


#If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9.
#The sum of these multiples is 23.
#
#Find the sum of all the multiples of 3 or 5 below 1000.
#
#3(1+2+3+....+333)+5(1+2+3+.....+199)-15(1+2+3+...+66)
#puts 3*333*334/2+5*199*200/2-15*66*67/2
#

def sum_of_n_consecutive_numbers (n)
n*(n+1)/2
end

def sum_of_multiples_of_m(max,m)
m*sum_of_n_consecutive_numbers(max/m)
end

puts sum_of_multiples_of_m(999,3)+sum_of_multiples_of_m(999,5)-sum_of_multiples_of_m(999,15)

Monday, October 19, 2009

Solving Project Euler Problem #5 in Ruby

The problem statement :

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest number that is evenly divisible by all of the numbers from 1 to 20?

Solution/s :

One of the solution is straight forward as Ruby exposes such a nice library (Actually it feels like a cheat :))


require 'rational'
puts (1..20).inject(1) { |result, n| result.lcm n }


The other solution involves a little bit of math/algorithm. Hopefully you will enjoy it.


#
# Directly using the ruby library
# require 'rational'
# puts (1..20).inject(1) { |result, n| result.lcm n }
#
# The other solution (Code below) Steps :
# 1. Fetch all the primes less than "n" in an array (it would be automatically sorted, which will save our efforts later)
# 2. For the smallest member "k" of the prime list, find the maxm power "m" such that k**m <=n (For, e.g. 2**4<20)
# 3. Replace the smallest member from the array with k**m (For e.g. replace 2 with 16, because anything divisible by k**m
# would be itself be divisible by k**0..m-1)
# 4. Repeat the steps 2-3, for the next member of the array (starting with the power #m-1). when the power becomes 1, no need
# to iterate.
# 5. Multiply the members of the final array.
#
# Sample runs :
# For n = 10
#
# All the primes :
# [2, 3, 5, 7]
# All the multipliers :
# [8, 9, 5, 7]
# 2520
#
# For n = 20
#
# All the primes :
# [2, 3, 5, 7, 11, 13, 17, 19]
# All the multipliers :
# [16, 9, 5, 7, 11, 13, 17, 19]
# 232792560
#

require 'mathn'

def collect_primes(n)
primes_list = []
primes = Prime.new
primes.each { |x| break if x >= n; primes_list<<x; }
puts "All the primes :"
p primes_list
primes_list
end

def root(arg, base)
arg**(1/base)
end

def get_all_the_multipliers(n)
primes_list = collect_primes(n)
max_base = get_max_base_for_two(n)

primes_list.each_with_index do |item, index|
primes_list[index]=item**max_base
max_base = get_max_base_for_current_number(n,max_base,primes_list[index+1])
if max_base <=1 then break
end
end
puts "All the multipliers :"
p primes_list
primes_list
end

def get_mulitiplied_value(n)
list_of_multipliers = get_all_the_multipliers(n)
list_of_multipliers.inject(1){|total, i| total*i}
end

def get_max_base_for_two(n)
i=2
while root(n,i) >= 2
i = i+1;
end
return i-1
end

def get_max_base_for_current_number(n,max_base, current_number)
base = max_base - 1
while current_number**base > n
base = base - 1
end
return base
end


puts get_mulitiplied_value(20)
#puts get_mulitiplied_value(10)



Comments are welcome .

Sunday, October 18, 2009

Google Guice : Part 1

Over the weekend I was going through this video presented at Google IO 2009.
Please watch it if DI (a.k.a Dependency Injection) interests you.


Where is Guice being used in production :-
The video mentions Google uses it for Google Wave, Google Adwords, GMail, Orkut, Google Docs, Youtube...pretty much every new project .

This is how I talked with myself, in case it is gonna help you let us learn together.

Should I care to learn Guice, I already know/use Spring :-
Spring framework is much more than a DI framework.It made DI popular (although there were older DI framework available before it). Spring competes with JEE stack.
So, yeah we can say Spring is a super set of Google Guice. Guice wholly embraces annotations and generics, thereby enabling you to wire together and test objects with measurably less effort. Guice proves you can use annotations instead of error-prone, refactoring-adverse string identifiers.And of course it is much light weight.

Spring uses annotations too :- That is true. The newer versions (probably 2+) focuses more to use annotations. We may discuss the benefits of XML declarations vs annotations in a separate post, as it is a topic in itself .

There are so many annotations for different DI libraries, shouldn't it be standardized :- You are in luck. Check it out JSR330- http://code.google.com/p/atinject/

Well...so show me some code :-

I won't boar you with the definition(s) of DI, IOC (search it on google rather in case you are new to this). Goal of this post is to make you run a simple Guice Program.

Download the guice library, and add it in your classpath.

The interfaces and it's implementations are self explanatory :-



public interface IPrinter {
public void print();
}

public class MyDummyPrinter implements IPrinter {
public void print() {
System.out.println("Article Printed !");
}
}

public interface IMailSender {
public void sendMail();
}

public class MyDummyMailSender implements IMailSender {
public void sendMail() {
System.out.println("Mail Sent !");
}
}

public interface ArticleService {
public void publishArticle();
}

import com.google.inject.Inject;
public class Article implements ArticleService{
private IMailSender mailSender;
private IPrinter printer;

@Inject
Article (IMailSender mailSender, IPrinter printer) {
this.mailSender = mailSender;
this.printer = printer;
}
public void publishArticle() {
mailSender.sendMail();
printer.print();
}
}


As shown in the above program, we want the mailSender and printer to be injected.
So, note the @inject annotation over the Article Constructor.

Lets inject the dependencies. Well, if you have worked with Spring's XML declarations for defining and injecting the dependencies, then think the next java code to be it's counter part in Guice.


import com.google.inject.AbstractModule;
public class MyArticleModule extends AbstractModule {
protected void configure() {
bind(IPrinter.class).to(MyDummyPrinter.class);
bind(IMailSender.class).to(MyDummyMailSender.class);
}
}


What I like here is the readability (It is like I am coding in Ruby :)). The code clearly shows that IPrinter.class is bound to MyDummyPrinter.class. Similarly, with the other line.

Cool..Now let us launch/bootstrap the Guice. For the Spring folks, think it similar to the code you write to load spring config beans (remember : ApplicationContext ctx = new ClasspathApplicationContext("example.xml")).


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

public class MyBootStrapInvoker {
public static void main(String[] args) {
Injector injector = Guice.createInjector(new MyArticleModule());
Article article = injector.getInstance(Article.class);
article.publishArticle();
}
}


And that's it. You are running Guice !!!

Hopefully, we will dive more in depth in the second post on the same topic.
Please let me know your comments, so the next time I could offer more.

Introducing JRugged library : Make your Java Programs Rock Solid




This book, is definitely among one of the best books, I've read this year. It lays out some critical aspects to creating and rolling out stable software systems. Each of the case studies discussed is based on real events.

While reading the book you will feel, how nice it would be if there is a library you could use to gain the advantages discussed to make your programs/software/systems rock solid.

The JRugged is such a library written to be used in Java. To summarize, what it offers , here it is (directly from the project home page) :-

The jrugged library provides straightforward add-ons to existing code to make it more robust and easier to manage.

Although there are several lower-level building block classes here available for custom solutions, most clients will find they can use just the following classes:

CircuitBreaker provides a way to wrap a service in a way that provides a bulkhead against system failure; when a remote service fails, further calls to the service are prevented for a period of time to allow the remote service to recover.

Initializer provides a way to decouple service construction from initialization/startup and allows the latter to occur in the background, even retrying if initial attempts to initialize fail.

PerformanceMonitor provides a way to wrap a service and collect a series of useful statistics about its latency and throughput, even calculating moving averages across different time windows.

Monitorable, Status, and RolledUpStatus are related classes that provide a simple RED/YELLOW/GREEN encoding for service health, possibly useful for constructing operational dashboards.

Generally speaking, most of these classes implement a ServiceWrapper interface to allow them to be applied around existing services using the Decorator design pattern. Those classes providing operational information, such as PerformanceMonitor and Monitorable can be wrapped in classes that expose their data to JMX controls or on web-accessible health status pages as desired.



Here I would show you, how easy it to use this in your existing code base. It provides it by the classic use of the Decorator Pattern.



import org.fishwife.jrugged.CircuitBreaker;
import org.fishwife.jrugged.PerformanceMonitor;
import org.fishwife.jrugged.Status;
import org.springframework.jmx.export.annotation.ManagedAttribute;

public abstract class AbstractMonitor implements IMonitorable {

/** Circuit breaker to detect server oveloading */
protected final CircuitBreaker cBreaker = new CircuitBreaker();

/** Performance stat monitor */
protected final PerformanceMonitor perfMonitor = new PerformanceMonitor(5);


@ManagedAttribute(description = "My System status")
public String getHealthCheck() {
return cBreaker.getStatus().getSignal();
}


@ManagedAttribute
public double getAverageFailureLatencyLastDay() {
return perfMonitor.getAverageFailureLatencyLastDay();
}

@ManagedAttribute
public double getAverageFailureLatencyLastHour() {
return perfMonitor.getAverageFailureLatencyLastHour();
}

@ManagedAttribute
public double getAverageFailureLatencyLastMinute() {
return perfMonitor.getAverageFailureLatencyLastMinute();
}

@ManagedAttribute
public double getAverageSuccessLatencyLastDay() {
return perfMonitor.getAverageSuccessLatencyLastDay();
}

@ManagedAttribute
public double getAverageSuccessLatencyLastHour() {
return perfMonitor.getAverageSuccessLatencyLastHour();
}

@ManagedAttribute
public double getAverageSuccessLatencyLastMinute() {
return perfMonitor.getAverageSuccessLatencyLastMinute();
}

@ManagedAttribute
public long getFailureCount() {
return perfMonitor.getFailureCount();
}

@ManagedAttribute
public double getFailureRateLastDay() {
return perfMonitor.getFailureRateLastDay();
}

@ManagedAttribute
public double getFailureRateLastHour() {
return perfMonitor.getFailureRateLastHour();
}

@ManagedAttribute
public double getFailureRateLastMinute() {
return perfMonitor.getFailureRateLastMinute();
}

@ManagedAttribute
public double getFailureRateLifetime() {
return perfMonitor.getFailureRateLifetime();
}

@ManagedAttribute
public long getRequestCount() {
return perfMonitor.getRequestCount();
}

@ManagedAttribute
public double getRequestRateLastDay() {
return perfMonitor.getRequestRateLastDay();
}

@ManagedAttribute
public double getRequestRateLastHour() {
return perfMonitor.getRequestRateLastHour();
}

@ManagedAttribute
public double getRequestRateLastMinute() {
return perfMonitor.getRequestRateLastMinute();
}

@ManagedAttribute
public double getRequestRateLifetime() {
return perfMonitor.getRequestRateLifetime();
}

@ManagedAttribute
public long getSuccessCount() {
return perfMonitor.getSuccessCount();
}

@ManagedAttribute
public double getSuccessRateLastDay() {
return perfMonitor.getSuccessRateLastDay();
}

@ManagedAttribute
public double getSuccessRateLastHour() {
return perfMonitor.getSuccessRateLastHour();
}

@ManagedAttribute
public double getSuccessRateLastMinute() {
return perfMonitor.getSuccessRateLastMinute();
}

@ManagedAttribute
public double getSuccessRateLifetime() {
return perfMonitor.getSuccessRateLifetime();
}

public CircuitBreaker getCBreaker() {
return cBreaker;
}

public PerformanceMonitor getPerfMonitor() {
return perfMonitor;
}

public Status getStatus (){
return cBreaker.getStatus();
}
}



Now, your class just needs to extend this abstract class inherits all those JMX statistics as well as the handles to the Circuitbreaker and PerformanceMonitor Object.


@ManagedResource(objectName = "com.example:type=manager,name=mysystem",
description = "shows the running status of mysystem")
public class MySystem extends AbstractMonitor {

.........
.........
//This is the method I want to decorate
public BackEndData processArgument(final String myArg) {
final BackEndService theBackend = backend;
try {
return cBreaker.invoke(new Callable< BackEndData >() {
public BackEndData call() throws Exception {
return perfMonitor.invoke(new Callable< BackEndData >() {
//This is the actual method which you were using earlier without decoration
public BackEndData call() throws Exception {
return theBackend.processArgument(myArg);
}
});
}
});
} catch (RuntimeException re) {
throw re;
} catch (Exception e) {
throw new RuntimeException("wrapped", e);
}
}

}



You probably would change this code a little bit depending on the definitions of your critical components, and the health status (But you get the idea).


Now just fire up the JConsole and you can see all the statistics for your classes. And it handles failures as well, showing you the status of the system as Green/Red/Yellow (depending on your definition of the critical system/components).

Please check it out for details, as the code base is pretty terse.

You may wish to extend it to be used as an Aspect (AOP), so that your classes could avail the benefits without changing your java code. The project mentions, it is looking to offer AOP wrapper to make it easier to do drop-in decoration of existing code.
So wait if you could or if you implement it yourself, please post it so others could use it.

Thursday, October 15, 2009

Intellij Idea IDE OpenSourced - The current state of the Java IDE's

It is a great news that Jetbrains has opensourced the Intellij Idea, a well known Java Editor. I have used it along with both Eclipse and Netbeans in the past.

Last year, I decided to buy a professional license for the intellij and never looked back. So, what would I say about eclipse, Netbeans and Intellij ?

Well, frankly speaking, they all have their positives. In fact, they are all competing on a very high level now.

Lets compare them based on few criterias :

1. User Adoption : Eclipse wins easily. However, I guess with today's announcement, it is going to be exciting. Don't forget Netbeans is releasing the 6.8 beta shortly, and it has significantlly improved.

2. Company Backing : Although Eclipse was started by IBM, Jetbrains owns intellij and Netbeans is owned by Sun (ohh.. I guess it is Oracle), but now the open source has changed the game. It is all about users, developers, speed and plugins.

3. Speed :- I don't have a benchmark, however the last time I felt, Eclipse and Intellij both were better. Netbeans still needs to work on it (I last tried the full j2ee version of it - 6.5, never tried 6.7).

4. Plugins :- Again Eclipse wins by the numbers. As far as quality is concerned, Intellij would probably be the best. Again, used mostly the in-built plugins for the netbeans (Correct me, and add comments if you find it better). However, now I see all the three editors have got a nice plugin framework and lots of developers writing for them.

5. Maven Support :- Hmm....Here the Netbeans is the one, closely followed by Intellij.

6. Usability :- Power users like Intellij with the best Refactoring offering , intelligent shortcuts, the awesome customer care support.

7.Dynamic Language Support (Ruby/JRuby/Groovy) :- NetBeans is the best IDE for Ruby/JRuby(I am not including Rubymine from Jetbrains, as it is a separate product). For Groovy, my vote goes to Intellij again.

I think as now Intellij has provided the free editor (Community Edition), more people would give it a try, and hence would be in a better position to compare it (And who knows may be then buy the Professional Edition eventually).

What do you think ?

Update : Here is the comparison chart for the OpenSource version vs the Commercial One.

Tuesday, October 13, 2009

Simple Feed Aggregator in Ruby

Ruby already has few RSS standard libraries (0.9, 1.0 , 2.0) in built, and it is good enough for simple purpose.

Today, I am trying to work on a simple feed aggregator, which could take multiple feed source url's and enlists the stories published there. I was tempted to use the standard library, however since it would not support the Atom standard, started looking for another library which supports both.

SimpleRSS lib by Lucas Carlson looks great.

So, here goes the code. You may extend it if you wish.


require 'simple-rss'
require 'open-uri'

class FeedAggregator
def initialize(urls)
@urls = urls
@feeds = []
read_feeds
end

def read_feeds
@urls.each { |url| @feeds.push(SimpleRSS.new(open(url).read)) }
end

def feed_source_counts
@feeds.each_with_index do |feed, index|
feed_source = "Feed Source [#{index}]: #{feed.channel.title}"
published_articles = "Published Articles: #{feed.items.size}"
puts feed_source + ', ' + published_articles
end
end

def list_articles(id)
puts "-----Feed Source [#{id}] : #{@feeds[id].channel.title}-----"
@feeds[id].items.each { |item| puts ' ' + item.title }
end

def list_all_articles
@feeds.each_with_index { |f, i| list_articles(i) }
end
end

MyFeedAggregator = FeedAggregator.new(ARGV)
MyFeedAggregator.feed_source_counts
puts "------------ Feed Details ------------------"
MyFeedAggregator.list_all_articles



Here is the test run :


C:\Ruby\bin\ruby.exe -e STDOUT.sync=true;STDERR.sync=true;load($0=ARGV.shift) C:/Users/anshu/RubymineProjects/TestRubyProjectTwo/test_two.rb http://rubyforge.org/export/rss_sfnewreleases.php http://www.dzone.com/links/feed/frontpage/rss.xml
Feed Source [0]: RubyForge New Releases, Published Articles: 10
Feed Source [1]: dzone.com: latest front page, Published Articles: 25
------------ Feed Details ------------------
-----Feed Source [0] : RubyForge New Releases-----
Dr Nic's Utilities
WysMacs Trainable Text and Code Editor
Loofah
autotest-fsevent
state_pattern
codeforpeople
Seattle.rb Projects
rjack
snk's open source
Spidr
-----Feed Source [1] : dzone.com: latest front page-----
Non-Technical Factors that Lead to Poor Architectures
My Tools of the Trade – 2009
Week Calendar using Jquery
Oracle Taunts IBM with $10M Challenge
Rant about developers or how I stopped worrying and love the simplicity
ScalaTest 1.0 Release "A Path Forward" to Scala
Resolving a Relative URL to a Full URL in ASP.NET
JxBrowser 2.0 Early Access Program
PrimeFaces UI 0.9.3 Released
Mozilla Join Microsoft in Slamming Google Chrome Frame
TDD is not test-first. TDD is specify-first and test-last.
Five super-secret features in Windows 7
Git# Offers Git Access for .NET and Mono Projects
Getting Started with Scrum
Apparent risk and actual risk
8 Hand Drawn Icon Sets For Bloggers
Optimize your Mac experience with the LaunchBar multitasker
18 Really Beautiful and Creative Web Designs
Google Released Page Speed for Firefox
Objective-C's niche: why it survives in a world of alternatives
Mobile Ajax Push for iPhone with JSF and PrimeFaces
Book Review - Spring in Practice
Tips for Designing an Awesome Coming Soon Page
Abstracting away Dependencies for Simpler code
MacRuby 0.5 Pulls the Plug on YARV

Process finished with exit code 0

How To : A Simple Generic SOAP Test Client written in Java

There are lots of libraries which are available to consume/generate a web service, like Spring Webservices, XFire, Apache Axis, to name a few.

While each one has its own pro/cons (that we can leave for a separate blog entry), many a times, one needs a simple (1 or 2) methods of a webservice calls to make. She may or may not care about the response, as long as the response is not leading to error.

For testing purposes, many use soapui, which is a wonderful tool. You may use it to point towards your soap end point, and it will generate request stub for you . Just fill in few params required by the method you are calling.

Here, I am ind of demonstrating the same thing, using a simple java program.
I am not using any WSDL2JAVA tool kind of stuff, to generate the stubs. [Please note, these stubs help you with the xml to java bindings, so if you are planning to use many methods, or you have sufficient time and want to do it right way, please follow that way].

Here is the code, you may use to call any end point. please note, it has some security headers just to show you. You may/may not need it.



package example;

import org.apache.axis.client.Service;
import org.apache.axis.client.Call;
import org.apache.axis.message.SOAPEnvelope;

import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.net.URL;


public class TestClient {
public static String wsURL =
"{YOUR_END_POINT}?WSDL";

public static String mySoapRequest =
new StringBuilder().
append("\n").
append(" \n").
#If your soap end point doesn't need security just remove these elements, or if it implements other sceurity standards, replace here
append(" \n").
append(" \n").
append(" \n").
append(" testusername\n").
append(" testpassword\n").
append("
\n").
append("
\n").
append("
\n").
append("
\n").
append(" \n").
#Here goes your request body
.......................
.......................
append("
\n").
append("
").toString();

public static void test() throws Exception {
InputStream input = new ByteArrayInputStream(mySoapRequest.getBytes());
Service service = new Service();
Call call = (Call) service.createCall();
SOAPEnvelope soapEnvelope = new SOAPEnvelope(input);
call.setTargetEndpointAddress(new URL(wsURL));
call.setUseSOAPAction(true);
System.out.println("Request:\n"+ mySoapRequest);
soapEnvelope = call.invoke(soapEnvelope);
System.out.println("Response:\n" + soapEnvelope.toString());
}

public static void main(String args[]) throws Exception {
TestClient callClient = new TestClient();
callClient.test();
}
}

Monday, October 12, 2009

XDepend : Java Code Base Analysis

Today morning, when I checked my email I was offered a Pro License for XDepend. Thanks to them for letting me explore it. I would post my findings once my hands get a little bit dirty.

The installer which I got was for a PC (I work on mac in my office), probably they have released a linux version as well. Would be nice, if they plan a release for the mac too.

By now what I know about is, it is from the same people who have offered NDepend, a well known code base analyzer in .Net environment.

Here is a short and nice intro to it by Mat Huston :- http://www.coderanch.com/t/462565/Blatant-Advertising/New-Tool-Java-code-base#2065255

Give it a try, as the trial version is available on the XDepend.com.
Once I get chance to explore more, I would update this thread.

Sunday, October 11, 2009

Writing Google Wave Robots using Java on Intellij




I got my google wave invite two days back (friday night, can't be a better time). And within 4 hours I was talking with my "HelloWorldish" Robot, such is the power and ease to write and deploy a robot is.

If you use eclipse, you already are set and this is the best place to start with : http://code.google.com/apis/wave/extensions/robots/java-tutorial.html

In fact, I used the same page for the sourcecode, and the steps. Make sure, you have a google wave id before you start looking at the next steps.

Steps :-

1.Make sure you are using Java 1.6.

2. I am using Intellij Maia (9). If you are on older version install the google appengine plugin.

3. Use this plugin to generate a dummy web project. In the wizard, choose google app engine. We are not going to use either GWT/ JDO or JPA for this project, so just uncheck them.

4. You can see a "AppEngine Dev" settings to run. Run it ,and you should be able to browse the dummy page at localhost:8080

5. To write the Robot, we need few libraries. Download it from http://code.google.com/p/wave-robot-java-client/downloads/list.

6.create a lib directory inside WEB-INF and copy all these jars . Also, add servlet-api-2.4.jar or higher.

7.Make a package src/parroty.server and copy paste the ParrotyServlet code described at http://code.google.com/apis/wave/extensions/robots/java-tutorial.html

8.Make a web/_wave dir. Create a capabilties.xml file and copy paste the code


<?xml version="1.0" encoding="utf-8"?>
<w:robot xmlns:w="http://wave.google.com/extensions/robots/1.0">
<w:capabilities>
<w:capability name="WAVELET_PARTICIPANTS_CHANGED" content="true" />
</w:capabilities>
<w:version>1</w:version>
</w:robot>


9. Register your application on appengine site.

In you appengine-web.xml file substitute your application id (instead of mine, "mytestwaveapp") :-


<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>mytestwaveapp</application>
<version>1</version>
</appengine-web-app>


10. Configure your ParrotyServlet inside the web.xml :

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>Parroty</servlet-name>
<servlet-class>parroty.server.ParrotyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Parroty</servlet-name>
<url-pattern>/_wave/robot/jsonrpc</url-pattern>
</servlet-mapping>
</web-app>


Go to "Tools->Upload AppEngine Application", and you are good enough to deploy this Robot.It would ask you your appengine loginid/pwd.The console would show, that everything went fine. You can confirm by accessing the capabilties.xmlfile :- http://applicationName.appspot.com/_wave/capabilities.xml

11.Well, now you are done. Use this robot as a participant for your wave and it should answer as I have shown in the picture. More Sample Robot Codes :- http://code.google.com/p/google-wave-resources/source/browse/trunk/samples/extensions/robots/java

Happy Coding ! Happy Waving !!!

Easy Graph with Scruffy on Ruby


This weekend, I was going through the first chapter of the book Ruby in Practice. Kind of like it as of yet , although have read only 4-5 pages.

It shows an example of using the graphing library Scruffy. Thought to give it a try on my home PC (Vitsa).

This blog is to save your time, in case you want to use this nice library and run into configuration problem.

1. You need to install the "Scruffy" gems
gem install scruffy

2. Then I tried the example discussed at :- http://scruffy.rubyforge.org. However, was getting error, which made it clear, you need to install another gem - RMagick. Won't bother you with my trial and errors, so to cut long story short, RMagick in turn requires other graphing lib (for e.g., I opted for IMageMagick).

So, download http://rubyforge.org/frs/download.php/38052/RMagick-2.5.0-ImageMagick-6.4.1-5-Q8.zip

3. Extract this to a temp directory, and run the IMageMagick installer.

4. Follow the readme file, which mentions to update your gem and install the RMagick gem.

5.Now, the most important part. Reboot your machine [:)]. Don't forget it.

6.After this, the sample codes described here :- http://scruffy.rubyforge.org/ started to work, except the graphs being generated was exactly as it appears on this site (as of this writing, wonder why it hasn't been fixed ?), i.e. blank images.

7. One blog post which helped me to fix this was :- http://www.ruby-forum.com/topic/193988
It suggests to replace the line 35, of the base.rb (for me it is C:\Ruby\lib\ruby\gems\1.8\gems\scruffy-0.2.6\lib\scruffy\renderers\base.rb)with

svg.svg(:xmlns => "http://www.w3.org/2000/svg", 'xmlns:xlink' =>"http://www.w3.org/1999/xlink",:viewBox => "0 0 #{options[:size].first} #{options[:size].last}") {

After it, the graphs started working like a charm. Looking forward to explore it more. Hope, it saves your time.

Monday, October 5, 2009

Recipe : How to get property value in a Spring Application

If you work with Spring, I am sure you might have come across the scenario when you need to access the value of a property key in your application.

The class "org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" is normally used to resolve the runtime key/value pairs. However, if you need to use a property value in your bean, it doesn't expose that to be read.

Here is a very simple work-around :-

1. Extend the PropertyPlaceholderConfigurer


public class OpenPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {

Properties mergedProperties;

public Properties getMergedProperties() throws IOException {
if (mergedProperties == null) {

mergedProperties = mergeProperties();

}
return mergedProperties;

}
}



2. Configure it to be used instead of PropertyPlaceholderConfigurer

  
<bean id="propertyConfigurer" class="com.mypackage.OpenPropertyPlaceholderConfigurer">
<property name="ignoreResourceNotFound" value="false"/>
<property name="locations">
<list>
<value>classpath:common.properties</value>
<value>classpath:${YOUR_ENV}.properties</value>
</list>
</property>
</bean>


3. Inject this "propertyConfigurer" in your defined bean.

4. Get the key value propertyConfigurer.getMergedProperties().getProperty("your.prop.key")

I am sure, there could be some better ways. Let me know, if you know one.

Credit goes to Mat for this recipe.

Mac Terminal Error : Could not determine audit condition

When I launched my terminal today, was welcomed with this error :-

login: PAM Error (line 396): System error
login: Could not determine audit condition

[Process completed]

It is most probably because I was playing with my /usr/bin permissions the other day.
The fix is easy. Just delete the "/usr/bin/login" dir.

But how do I delete it, if I can't access the "Terminal" altogether ?
Come on - You can access any folder using the "Finder".

1. Open "Finder"
2. Open "Go To Folder"
3. Type "/usr/bin/login"
4. Delete it.

You are done.

Sunday, October 4, 2009

Typica library - Added my patch to set connection timeout

Typica :- is a simple API to access Amazon's SQS, EC2, SimpleDB and DevPay LS web services

A couple of month ago, I was using this library to interact with the Amazon's SQS queue. While testing, a bug popped up where in case of a network failure, the code was trying to make the connection endlessly.

Here is the history of this bug. I changed the jar and suggested a patch.

The good news is that they applied my patch to the code base and from the version 1.6 onwards, this bug shouldn't appear.

Sunday, September 13, 2009

Why are we happy?

TED.com: Dan Gillbert asks, Why are we happy?:

...When our ambition is bounded, it leads us to work joyfully. When our ambition is unbounded, it leads us to lie, to cheat, to steal, to hurt others, to sacrifice things of real value. When our fears are bounded, we're prudent, we're cautious, we're thoughtful. When our fears are unbounded and overblown, we're reckless, and we're cowardly.



The lesson I want to leave you with from these data is that our longings and our worries are both to some degree overblown, because we have within us the capacity to manufacture the very commodity we are constantly chasing when we choose experience.







"

Saturday, August 29, 2009

How spirituality awakens in a human being

How spirituality awakens in a human being: "


Spirituality is like the water hidden in the depth of the earth: hidden in the heart of man, this water which is spirituality must be, so to speak, dug out. This digging is done when one takes pains in awakening ones sympathy towards others, in harmonizing with others and in understanding others. -says my beloved Sufi saint Hazrat Inayath Khan (1882-1927).


I find it a beautiful explanation of how the spirituality is generally born in a human being. The next step is when one starts seeking the Spirit everywhere – in oneself, in others, in nature. One starts seeking for the very depth, for the very essence and beauty of everything and… one day finds it!


LOVE; axinia


(image by me)


Posted in Evolutionary Learning, how to, India, meditation, philosophy, psychology, spirituality, thoughts Tagged: beautiful, God, Hazrat Inayath Khan, heart, interesting, meditation, peace, philosophy, psychology, spirituality, Sufism, thoughts
"

Episode 173: Screen Scraping with ScrAPI

Episode 173: Screen Scraping with ScrAPI: "Screen scraping is not pretty, but sometimes it's your only option to extract content from an external site. In this episode I show you how to fetch product prices using ScrAPI."

Amazon, Open Your eBooks or Watch Out

Amazon, Open Your eBooks or Watch Out: "

sony_reader_wireless_logo.jpgHardly a day went by this week without a major new announcement in the eBook and eReader arena. The wireless eReaders from Sony and the Irex/Barnes & Noble partnership were probably some of the most interesting announcements. In addition, Google also opened up its EPUB archive, which will give readers easy access to over 1 million free public-domain books for their eReaders. The only company that didn't have anything to announce this week was Amazon, which is now in danger of losing its early lead to Sony and Barnes & Noble.


Sponsor



Before this week, Amazon's Kindle still had one major advantage: wireless syncing. Now that both Sony and Barnes & Noble will offer the same functionality before the holiday season, the eBook market is once again completely open.



Everybody Now Offers Wireless Syncing



While wireless syncing and book delivery may not be that important to every potential eReader user, it did give Amazon a major leg up in marketing its Kindle and Kindle DX. In a month or two, this advantage will be gone. Amazon's competitors also offer more stylish devices, and some of the upcoming new eReaders will also offer touch screens - another feature that Amazon's Kindle doesn't currently offer.



EBook Price is Now the Same Everywhere, But Sony Supports Downloads From Local Library



In terms of pricing, Sony will soon offer an eReader for $199, which will put a lot of pressure on Amazon - though Sony's cheapest device will not offer wireless capabilities. As for books, prices everywhere are converging around a reasonable $9.99, the price Amazon pioneered as the default price for bestsellers in its Kindle store.



What's even more exciting is that eReader users will soon be able to borrow eBooks from their local libraries. Sony just announced a partnership with OverDrive, which supplies eBook technology to over 9,000 libraries. Amazon doesn't offer a similar program (yet).



Amazon's Problem: The Kindle is Closed



What's giving Amazon's competitors a major advantage right now is that their devices are far more open than the Kindle. As Slate's Farhad Manjoo points out, Sony and company could still be far more open and do away with all copyright restrictions. But at least you will be able to move your books to different devices, even though Sony still uses the standard EPUB format with a DRM wrapper, for example. Amazon's proprietary format, on the other hand, doesn't allow you to move your Kindle eBook to your new Sony Reader, for example.



For now, most publishers are still weary about releasing books without copyright. We can only assume that the book publishing industry will go through a similar cycle as the music industry, however, and that DRMed eBooks will also go the way of DRMed MP3s.



The eBook market is still young. For now, Amazon's only other advantage over its competitors is that it currently has a lot of momentum among early adopters. But, as Forrester Research's Sarah Rotman Epps argued in a recent report, as eBooks move into the mainstream, late adopters may not feel the same loyalty towards Amazon that early adopters had.



Of course, Amazon could still come out with a new eReader and a more open strategy. But for now, it doesn't look like Amazon is planning to change its strategy anytime soon, and we haven't heard any news (or even rumors) of a new Kindle for quite a while. If Amazon doesn't watch out, it could soon be left behind, because other eBook vendors and hardware manufacturers offer a more open and attractive platform for publishers and users.


Discuss



"

Saturday, August 22, 2009

The Truth: What’s Really Going On With Apple, Google, AT&T And The FCC

The Truth: What’s Really Going On With Apple, Google, AT&T And The FCC: "

Apple has responded to the FCC’s request for information around its rejection of various Google and third party iPhone applications for the iPhone.


In short, Apple denies that they rejected the Google Voice application, but they go into great detail about how the Google Voice application hurts “the iPhone’s distinctive user experience.” All of those statements are either untrue, or misleading, or both.


The first part of Apple’s argument, that they never rejected the application, is “a total lie,” according to many sources with knowledge of the Google Voice application process.


The second part of Apple’s argument, that the Google Voice application hurts the iPhone’s distinctive user experience, is seriously misleading. I know this because I’ve become intimately familiar with the Google Voice service and applications over the last few months. See here, here, here and here, for example. I haven’t used the Google Voice app for the iPhone specifically, because it never launched. But I have been briefed by the Google team on two separate occasions on how the app would work over the last couple of months. Also, I’ve demo’d the Blackberry version of the app, and now use the Android version of the app.


Here’s the key language from Apple’s letter, with my comments:


Apple: “Contrary to published reports, Apple has not rejected the Google Voice application, and continues to study it.”


Reality: One third party Google Voice app developer disclosed to us in July that Apple SVP Phil Schiller told them that Google’s own app would be or already was rejected. Google also confirmed this to us later. There is overwhelming evidence that Apple did in fact reject the application.


Apple: “The application has not been approved because, as submitted for review, it appears to alter the iPhone’s distinctive user experience by replacing the iPhone’s core mobile telephone functionality and Apple user interface with its own user interface for telephone calls, text messaging and voicemail. Apple spent a lot of time and effort developing this distinct and innovative way to seamlessly deliver core functionality of the iPhone.”


Reality: This strongly suggests that the Google Voice app replaces much of the core Apple iPhone OS function. This certainly isn’t accurate, and we believe the statement is misleading. More details below, but in general the iPhone app is a very light touch and doesn’t interfere with any native iPhone apps at all.


Apple: “For example, on an iPhone, the “Phone” icon that is always shown at the bottom of the Home Screen launches Apple’s mobile telephone application, providing access to Favorites, Recents, Contacts, a Keypad, and Visual Voicemail. The Google Voice application replaces Apple’s Visual Voicemail by routing calls through a separate Google Voice telephone number that stores any voicemail, preventing voicemail from being stored on the iPhone, i.e., disabling Apple’s Visual Voicemail.”


Reality: Not true and misleading. The Google Voice application has its own voicemail function, which also transcribes messages. But it only works for incoming Google Voice calls, not calls to the iPhone. The Google Voice app in no way “replaces” Apple’s voicemail function.


Apple: “Similarly, SMS text messages are managed through the Google hub—replacing the iPhone’s text messaging feature.”


Reality: Not true and misleading. The Google Voice app doesn’t replace or in any way interfere wtih the iPhone’s text messaging feature. If someone sends a text message to your Google Voice number, the Google Voice app shows it. If it is sent directly to the iPhone phone number, nothing is different.


Apple: “In addition, the iPhone user’s entire Contacts database is transferred to Google’s servers, and we have yet to obtain any assurances from Google that this data will only be used in appropriate ways. These factors present several new issues and questions to us that we are still pondering at this time.”


Reality: Complete fabrication, way beyond misleading. The Google Voice app can access the iPhone’s contacts database, like thousands of other iPhone apps. But the Google Voice app never syncs the contacts database to their own servers. There is no option for users to do this. However, Apple offers the ability to sync iPhone contacts with Google via iTunes. So not only is Apple’s statement untrue, but they also provide this exact feature themselves via their own service.


So how did Google answer the same question in their own separate letter to the FCC, also made publicly available today? We don’t know, because Google requested that the answer be redacted. But my guess is that the answer, which the FCC has and can compare to Apple’s response, tells a significantly different (approximately the exact opposite) story:



Our sources at Google tell us in no uncertain terms that Apple rejected the application. And we have an independent third party app developer who tells us that an Apple Exec also told them back in July that the Google Voice Application was rejected.


In other words, there is strong evidence that Apple is, well, lying.


Which also is the easiest was to explain Apple’s long rambling letter to the FCC. Why go into so much detail about the problems with the Google Voice application, and then say that it was never rejected? If the app does actually replace all of those core apple phone, contact and SMS features, why not reject it out of hand? I don’t believe anyone would say Apple made the wrong decision if that laundry list of nonsense had any truth to it (we have an answer to that, below).


Multiple sources at Google tell us that in informal discussions with Apple over the last few months Apple expressed dismay at the number of core iPhone apps that are powered by Google. Search, maps, YouTube, and other key popular apps are powered by Google. Other than the browser, Apple has little else to call its own other than the core phone, contacts and calendar features. The Google Voice App takes things one step further, by giving users an incentive to abandon their iPhone phone number and use their Google Voice phone number instead (transcription of voicemails is reason enough alone). Apple was afraid, say our sources, that Google was gaining too much power on the iPhone, and that’s why they rejected the application.


Apple seemed to be fine telling Google and others that the real reason they wouldn’t accept the Google Voice app on the iPhone was a fear of being turned into little more than a hardware manufacturer over time as users spent more and more time on Google Voice and less time on the competing native iPhone apps. Or simply letting people believe that AT&T was behind the rejection. Until the FCC got involved, that is. Then Apple denied the rejections and directed the FCCs attention to misleading or simply untrue factual statements about the App.


Of course, now both Google and AT&T are required to tell their side of the story to the FCC, too. And those stories aren’t adding up.


What Happens Next?


Here’s what we believe Apple is preparing to do next. Their statement that they haven’t rejected the app, along with the long laundry list of complaints (none of which are true) tells us that they’re backtracking, and fast. Sometime soon, we guess, Apple will simply accept the Google Voice application. They have to - any serious investigation into the app by the FCC will show that the complaints around the app are unfounded and that it does none of the things Apple accuses it of doing. So Apple will save face by simply asking Google to ensure that the App doesn’t take over native phone, sms and other functions, and doesn’t sync the contacts to Google’s servers. Google will comply (they already have), and Apple will graciously accept the application.


But we’ll all know exactly where Apple stands - jealously guarding control of their users and trying to block Google and other third party developers at every turn from getting their superior applications in front those users.


This isn’t about protecting users, it’s about controlling them. And that’s not what Apple should be about. Put the users first, Steve, and don’t lie to us. We’re not that dumb.


Crunch Network: CrunchBoard because it’s time for you to find a new Job2.0







"

Get at Amazon