Thursday, May 23, 2013

Spring, Camel consumer shutdown hack


import java.lang.reflect.Field;
import java.util.List;

import org.apache.camel.Consumer;
import org.apache.camel.spring.remoting.CamelServiceExporter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.SmartLifecycle;

import amqp.spring.camel.component.SpringAMQPConsumer;

/**
 * Bean to help shutdown Camel beans that do not have a doStop() method that does what's needed to shut them down
 *
 */
public class AmqpConsumerShutdownBean implements SmartLifecycle {
@Autowired(required = false)
List<CamelServiceExporter> camelExports;
private boolean running = false;
public AmqpConsumerShutdownBean() {
}

@Override
public void start() {
this.running = true;
}

@Override
public void stop() {
if (this.camelExports == null) {
return;
}
for (CamelServiceExporter bean : this.camelExports) {
Field f = null;
try {
f = bean.getClass().getDeclaredField("consumer");
f.setAccessible(true);
Consumer consumer = (Consumer)f.get(bean);
consumer.getEndpoint();
if (consumer instanceof SpringAMQPConsumer) {
consumer.getEndpoint().stop();
((SpringAMQPConsumer) consumer).doShutdown();
f.set(bean, null);
bean.destroy();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (f != null) {
f.setAccessible(false);
}
}
}
this.running = false;
}

@Override
public boolean isRunning() {
return this.running;
}


@Override
public int getPhase() {
return 1;
}

@Override
public boolean isAutoStartup() {
return true;
}

@Override
public void stop(Runnable callback) {
if (this.isRunning()) {
this.stop();
}
callback.run();
}


}

Wednesday, May 15, 2013

Google I/0 2013 Take aways


Some amazing things that came out of the introduction to the conference.
  1.  Google all access pass looks cool, basically you pay 10 bucks a month for unlimited access to music via Google Play.
  2. WebM has two important parts Webp for pictures and VP9 for videos. Extreme compression to shrink media down to a small size, especially useful for streaming video.
  3. Web components and actions aka build you own html tags, could be cool, but I am not sure.
  4. Google+ hangouts with history
  5. Google highlight allows you to instantly pick the photos from a album that are worth keeping. It works by detecting blurry or duplicate photos, bad exposure, landmarks, happy people, aesthetics, affinity. It uses machine learning to do all the work. Happy people is worth noting as it tries to detect smiles and other characteristics of the emotion -- prioritizes those pictures.
  6. AutoEnhance uses algorithms to automatically make your photos look as if a professional enhanced them. It uses tonal distribution, noise reduction, white balancing, and skin softening among others to do the magic!
    1. Because of some break throughs in computer vision, it can identify individual parts of the face. The skin, hair, and other pieces of the anatomy can be found to determine if the person in the picture is wearing glasses or jewelry, ... etc
  7. Knowledge Graph is now being expanded to many more entities. 
  8. Google Voice Experience is very fast and accurate. Watch out Siri!

Google Maps has some really impressive new features coming.

  1. Map maker is cool in what it has allowed people to accomplish. We now have some of the best maps of a particular area from user contributed sources.
  2. 3D photo tour shows interiors of buildings automatically via photo sphere.
  3. Zagat is now integrated into Maps to allow you to see reviews without leaving.
  4. Maps are now customized to you, it shows you how your friends reviewed a place.
  5. Clicking on a placemark will show you important roads around it.
  6. Google maps Schedule Viewer is pretty sweet, it allows you to compare how using different means of transport will get you to your destination.
  7. Google earth is now integrated into Maps!
    1. When zooming out it even shows you the earth inside the solar system. This includes an accurate representation of the stars.