Code I/O

A topnotch WordPress.com site


2 Comments

Ruminations on leadership …

Whether it is the family, a team or a business, it is governed by mutual trust.  In family trust is bonded with love, but must be managed by rules; and so is business.  One can apply such a principal for running teams.  The prime most important ingredient is “trust” and “rules”.

Following few analogies from great epics like Ramayana, Mahabharata and Bhagvata; one must understand that they must be a bit of Rama and a bit of Krishna in order to bring balance for running the unit.  This is essential because, Rama is a true follower of rules while Krishna breaks them depending on what time he is managing it.  However, both uphold dharma (righteous duties) from a fundamental view point.

In the modern world, we’re torn between the different avatars of our lives avatars such as, personal, professional, friends, networks, and so on.  Each avatar must function as required in its form yet strike balance in the entirety.  One cannot be compromised for the sake of the other.

Here are few thoughts on leadership in a dharmic sense.

Loyalty: In my perspective, being loyal to ones duties is really being a loyalist.  The kind of values you really want to uphold in any circumstances for the benefit of the whole is the key.  For example: Consider a fictional story: A king is a very religious person and is a vegetarian, however during British rule, his kingdom is plagued.  He asks a favor from the British General, however the general humiliates the king and asks him to eat meat to get the favor possible.  The king politely disagrees and firmly states that he cannot give up his values for his duties.

Responsibilities: One must know their duties and responsibilities, forgetting that is the beginning of a domino effects.  Knowing ones duties and taking responsibility is fundamental to being dharmic.

Leadership: Being leader is not in the sense of being dominant or being at top of the peck order.  It is not the sense that one demands order and obedience in everyday lives.  It is much beyond these rules.

  • A leader empowers people to be independent.
  • A leader increases sensitivity of team members to take responsibilities.
  • A leader brings unity and builds trust among members, and creates situations to demonstrate loyalty.
  • A leader builds integrity in the team during crisis.
  • A leaders invests time in next generation and nurtures them for the future.

Leadership is driven by principals of dharma, and not from emotions. He has learned that opportunistic individuals cannot be leaders.  Leaders understand that their journey is long and can have difficulties.  No matter what situation he is in, he uploads the dharma and performs his duties, at the same time he devotes time and energy to nurture the new generations for taking up responsibilities.

One can apply these principals in everyday lives when dealing with family, business, or other team plays to make a difference.

Advertisements


Leave a comment

Ruminations on social-networks

Social networks is becoming part of our everyday lives.  Some can’t live without it, and some avoid it.  The technology is constantly changing the way we see our world and interact with it; and at some point in time, we all will converge.  Believe it or not, our generations will be in a totally new era of computing.

In a world so inter-twined, even those who avoid socializing on the ethernet will not be spared.  Few thoughts on that: how many of our friends are not on Facebook or MySpace?  Yet, they get tagged and written about by other connections; “unplugged, yet part of the network”.  Has the evolving network spared those who are unplugged?  In reality, the answer is “No”.   So how does this inter-connections help us?

The benefits of such inter-twining are just amazing from exosphere level.  Since all of us depend on each other and know each others worlds, we can help each other in distress, bring in harmony and feel that it is a bliss.

The world can now work as a single unit: thus enabling the social-networks as a platform for all our day-to-day needs, such as

Services: Even before you realize that you need it, it’ll be brought to you.

Marketplace: Need something; no problem; it’ll be at your door-step.

Education: Upgrade skills; just ask and find out in your network.

Work environment: Work from home will become a new standard.

Governance: Choose our community leaders.

News: Delivering personalized interesting news and facts.

Advertisements: Personalized ads.

One can let the imagination go wild, the possibilties are just endless.  Having said that there are benefits in such inter-twining, there are great risks of being in such a new world.  Privacy and Security issues, Scams, identity thefts, legal matters will all change as we progress.  Unstructured data-mining can be used for good and for bad, and every industry has to use mining for purposes of running its operations, tactical positioning of services and strategic decision making.  So will the offenders of the system use such mining for infringing privacy and security, create personalized scams, impersonate identities.

To be or not to be connected is one piece of the puzzle; we’re so plugged that it is inevitable to avoid being plugged; and for others have to start their no-niche communities.  However, the risks must be addressed and counter measures designed for protecting and safe-guarding personal interests and liabilities.

Softwares to assess security, privacy policy, unearth scams, warning systems (intrusion detection) for social networks will be the next wave of technologies to think of.  As well, making such social-networks be reliable, scalable, supportable and performant will be a new niche for the current generations of software experts.

In a nut-shell, social-networks are here to stay, and inevitably each one of us will be plugged-in whether one desires are not.  For the technology drivers addressing the risks while designed the next wave of new frameworks and platforms is the key.  So let us bravely create a new world that can be safe and secure for all of us.


11 Comments

5 Minutes on Java: GWT consumer + Server push tutorial

The previous 2 posts on server push demonstrated the idea of push information to the consumers with Java services and Flex client. However, many might argue that a generic consumer should work on any device and it is better to develop and support such framework.  In an environment where rapid prototyping is the key driver, with a responsibility to drive development frameworks and technologies; the constraints can be many.

On that pretext, I tried GWT framework to see if we can do things quickly and effectively as done with Flash, and I find it to be promising in many ways.

  • It generates JavaScript which is compact and optimized and can be obfuscated.
  • Can run on various browsers and platforms.
  • Development cost can be reduced as most enterprise developers are experienced in Java.
  • At the same time, can create proof-of-concepts quickly and efficiently.

However, one challenge I faced was getting the right blend of components to work with GWT.  Firstly, I tried ActiveMQ AJAX, which was good to begin with, however, when working with JQuery libraries, JavaScript really messes up the namespaces.  Secondly, was trying hard to see if Comet can save the day, but only in vain.  It became more messier as libraries were incompatible with some of the third-party components required in the backend.

After a lot of thoughts and architectural considerations, I finally decided to reuse most of the work done on the back-end (which is critical); which happens to be ActiveMQ (FUSE); Yet had to give up the idea of Flash moving forward; this  became a key driver for future; which means that rapid prototyping must be supported as a fundamental requirement, at the same time keeping the technology stack for building prototypes and learning curve as lean as possible.

Applications, be it RESTful or Presence based, it must inter-operate, change and grow with changing requirements.  So how do we put all of these together?

  • Jersey/Restlet fits the stack perfectly for exposing RESTful API
  • ActiveMQ becomes a preferred choice for messaging; which is scalable and reliable as well.

Bring them together with GWT for HTML(5) client, and stage is set for developing applications for the future.  There are challenges with data-binding that you’ll miss if you’re used to Adobe Flex a lot.  In my opinion that could be solved in few years.

Having said enough so far, let’s see the sample code to make this work with GWT; I used GWT Eventing to implement message handling on the client.

Download it from gwteventservice google code

Make sure you have the following inherits in *.gwt.xml file.

<inherits name='com.google.gwt.user.User' />
<inherits name='com.google.gwt.xml.XML' />
<inherits name='de.novanic.eventservice.GWTEventService' />

Add the following files to your gwt client package.
File: MessengerRemoteService

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

import de.novanic.eventservice.client.event.domain.Domain;
import de.novanic.eventservice.client.event.domain.DomainFactory;

@RemoteServiceRelativePath("MessengerRemoteService")
public interface MessengerRemoteService extends RemoteService {
	public static final Domain SERVER_MESSAGE_DOMAIN = DomainFactory.getDomain("server_message_domain");

	/**
	 * Utility class for simplifying access to the instance of async service.
	 */

	public void start();

	public static class Util {
		private static MessengerRemoteServiceAsync instance;
		public static MessengerRemoteServiceAsync getInstance(){
			if (instance == null) {
				instance = GWT.create(MessengerRemoteService.class);
			}
			return instance;
		}
	}
}

File: MessengerRemoteService

import com.google.gwt.user.client.rpc.AsyncCallback;

public interface MessengerRemoteServiceAsync {
	void start(AsyncCallback<Void> callback);
}

File: MessageEvent

import de.novanic.eventservice.client.event.Event;

public class MessageEvent implements Event {
	/**
	 *
	 */
	private static final long serialVersionUID = 1L;
	protected String message = null;

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public MessageEvent(String message){
		super();

		this.message = message;
	}

	public MessageEvent(){}
}

Finally, add the code to your entry point that will load the EventListener. This code will be the main event receiver, hence should be able use this to receive events from the server and let the visualization component render it based on the views.

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.xml.client.DOMException;
import com.google.gwt.xml.client.Document;
import com.google.gwt.xml.client.Element;
import com.google.gwt.xml.client.NodeList;
import com.google.gwt.xml.client.XMLParser;

import de.novanic.eventservice.client.event.Event;
import de.novanic.eventservice.client.event.RemoteEventService;
import de.novanic.eventservice.client.event.RemoteEventServiceFactory;
import de.novanic.eventservice.client.event.listener.RemoteEventListener;

public class ConnectorSample {
	public void connect(){
		RemoteEventService remoteEventService = RemoteEventServiceFactory.getInstance().getRemoteEventService();
		remoteEventService.addListener(MessengerRemoteService.SERVER_MESSAGE_DOMAIN,
			new RemoteEventListener() {
				@Override
				public void apply(Event anEvent) {
					if(anEvent instanceof MessageEvent){
						String message = ((MessageEvent)anEvent).getMessage();

						try {
							NodeList nodes = null;

							try {
								Document messageDocument = XMLParser.parse(message);
								nodes = messageDocument.getElementsByTagName("some tag name");
							}catch(DOMException domex){
								throw new Exception("XMLParseException while parsing message");
							}

							if(nodes != null && nodes.getLength() > 0){
								for(int index = 0; index < nodes.getLength(); index++){
									Element element = (Element) nodes.item(index);

									// Update DataModel
									// Updae View

								}
							}
						}
						catch(Exception e){
							GWT.log(e.getMessage());
						}
					}
				}
			}
		);

		MessengerRemoteService.Util.getInstance().start(new VoidAsyncCallback());
	}

	private class VoidAsyncCallback implements AsyncCallback<Void>
    {
        public void onFailure(Throwable aThrowable) {}

        public void onSuccess(Void aResult) {}
    }
}

Add the following file to your gwt server package
File: MessengerRemoteService

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

import org.apache.activemq.command.ActiveMQTextMessage;
import org.onesun.sfs.client.MessengerRemoteService;
import org.onesun.sfs.shared.event.MessageEvent;

import de.novanic.eventservice.client.event.Event;
import de.novanic.eventservice.service.RemoteEventServiceServlet;

public class MessengerRemoteServiceImpl extends RemoteEventServiceServlet
	implements MessengerRemoteService, MessageListener
{
	/**
	 *
	 */
	private static final long serialVersionUID = 1L;

	public void init(){
	}

	@Override
	public void start() {
	}

	private void sendToClient(Event event){
		addEvent(MessengerRemoteService.SERVER_MESSAGE_DOMAIN, event);
	}

	@Override
	public void onMessage(Message message) {
		String messageText = null;
		try {
			messageText = ((TextMessage)message).getText();
		} catch (JMSException e) {
			e.printStackTrace();
		}

		if(messageText != null && messageText.length() > 0){
			if(message instanceof ActiveMQTextMessage) {
				sendToClient(new MessageEvent(messageText));
			}
		}
	}
}

Now connect the code with configurations for the Web App to work well.

  <servlet>
    <servlet-name>EventService</servlet-name>
    <servlet-class>
      de.novanic.eventservice.service.EventServiceImpl
    </servlet-class>
  </servlet>

  <servlet>
  	<servlet-name>MessengerRemoteService</servlet-name>
  	<servlet-class>PACKAGE_NAME.MessengerRemoteServiceImpl</servlet-class>
  </servlet>

  <servlet-mapping>
  	<servlet-name>MessengerRemoteService</servlet-name>
  	<url-pattern>/feedvu/MessengerRemoteService</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>EventService</servlet-name>
    <url-pattern>/feedvu/gwteventservice</url-pattern>
  </servlet-mapping>

Update the applicationcontext.xml for spring injections

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:util="http://www.springframework.org/schema/util"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:jms="http://www.springframework.org/schema/jms"
	xmlns:p="http://www.springframework.org/schema/p"
	xmlns:s="http://www.springframework.org/s"
	xmlns:context="http://www.springframework.org/schema/context"

	xsi:schemaLocation="http://www.springframework.org/schema/beans
 		http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
 		http://www.springframework.org/schema/context
 		http://www.springframework.org/schema/context/spring-context-2.5.xsd
 		http://www.springframework.org/schema/jms
 		http://www.springframework.org/schema/jms/spring-jms-2.5.xsd
 		http://www.springframework.org/schema/util
 		http://www.springframework.org/schema/util/spring-util-2.0.xsd
 		http://camel.apache.org/schema/spring
 		http://camel.apache.org/schema/spring/camel-spring.xsd">

	<camelContext xmlns="http://camel.apache.org/schema/spring" />

	<!-- ActiveMQ JMS -->
	<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"
		p:brokerURL="tcp://localhost:61616" />

	<jms:listener-container container-type="default" destination-type="topic" connection-factory="connectionFactory" acknowledge="auto">
		<jms:listener destination="feed-message-topic" ref="messengerRemoteService" method="onMessage" />
	</jms:listener-container>

	<bean id="messengerRemoteService" init-method="init" class="PACKAGE_NAME.MessengerRemoteServiceImpl">
	</bean>
</beans>

Finally startup the services and send messages to the topic using FUSE admin, the GWT client should render the messages as they are pushed on the Bus.

Summary and some thoughts:

Flash will still remain a way to quickly develop proof-of-concepts.  It provides a way to seamlessly bind data and visualization.  It is good to turn vapor-ware thoughts into tangible concepts; which is a good proposition in a life-cycle of prototyping.

On the other hand, if I were to build concepts that need to work on non-flash devices; then have to look into GWT like frameworks (since coming from Java world).  There are challenges with data-binding to visualization, rendering of changing data can be challenging.  HTML5 features of client side storage can help to build tactics on the client to resolve certain limitations.

In either case, depending on the time available, features of the application, and the case to demonstrate on diverse platforms, you can decide one over the other.

Server Push is essential for messaging; and clients must be built with the future in mind.  I’m sure you’ll find the samples for both frameworks simple and reusable.