Proactive Computing:What is it?

•November 12, 2009 • Leave a Comment

What is proactive computing?
Proactive computing is carried out continuously on your behalf. By contrast, reactive computing reacts to your commands by executing the tasks that you specify. Servers in proactive computing continuously sense and respond on your behalf – they acquire data from multiple sources, analyze the data, and determine actions that you want taken on your behalf.
Almost 2 years ago, Intel Research initiated work on Proactive Computing – working towards environments in which networked computers proactively anticipate our needs and, sometimes, take action on our behalf.
For more on proactive computing visit Link

Microsoft’s WebsiteSpark Program

•September 25, 2009 • Leave a Comment

Microsoft, the Redmond based company has announced the launch of WebsiteSpark Program, aimed at offering professional Web development and designer companies that have up to ten employees the possibility to join a partner network that will help them grow their businesses. Along with the new program, the software giant also announced the launch of Web Platform Installer 2.0 and the Windows Web Application Gallery 2.0, which should also drive the development of richer Web experiences.Read more…..

websiteSpark

Implementing Services and Applications using Netty

•September 9, 2009 • Leave a Comment

In an earlier post on XMPP:What can you do with XMPP ? , I talked about XMPP and the applications that can be designed with the technology. In recap, there are two basic high level categories namely Services and Applications. In design, one will need to host the services (which means implementing a server or using an existing one) so that the applications can use them.

In case of implementing the server, i recommend an extensible, asynchronous network framework called Netty from JBoss.org. In the hype of Event Driven Architecture, developing network application with Netty which is built on event model will be fun.

Netty is a NIO client server framework which enables quick and easy development of network applications such as protocol servers and clients. It greatly simplifies and streamlines network programming such as TCP and UDP socket server(Source :Netty Home).

Event Based Programming :Loose Coupling In Applications

•September 3, 2009 • Leave a Comment

What is an Event Based System?

A software system is said to be event-based if it parts interact primarily using event notifications. In this context, a part is anything containing code, such as a module of functions, an object, or a component made up by classes and objects. Notifications are basically signals sent from one part to another, in response to an event.

Source:  Book “Event Based Programming, Taking events to the limit written by Ted Faison.

Merits of Event Based Systems:

  • It is easier to build, test and maintain.
  • It reduces the overall complexity of the system.
  • It tries to solve the problem of coupling in systems.

All architectures cannot completely solve the problems of system design hence Event Driven Architecture has some side effects too including:

  • An increase in complexity at the local level : Parts that interact in event-based systems are generally simpler from coding standpoint but their operations can be difficult to understand without understanding the whole or seeing the rest of the system.

In the merits of Event Based System,i made mention of event-based systems trying to solve the problem of coupling. At this point, one will ask what is actually coupling?.

Coupling

It is the single greatest problem in large software systems. To measure coupling in a system, one will define coupling as the measure of the strength of association established by a connection from one module to another. In the event context, module  can be considered component.

One coupling scenario is circular coupling. Build tools like Maven helps to minimize this type of coupling between module dependencies.  Coupling is mostly cited with another parameter called cohesion.

In their paper, Stevens et al. defined cohesion as the degree of connectivity among the elements of a single module.

Theorem 1 from Ted Faison: It is impossible to build a software system in which all components are completely decoupled from each other.

Common coupling scenario is coupling introduced by instantiation of  classes which can be solve by a binder.

In the next blog event(trying to process my blog with events) will look at more coupling scenarios and how to fix them, and expressed coupling mathematically.


the word coupling represents a measurement of some kind between the i-th part and all the other n-1
parts in the system. In the next section, I’ll introduce a mathematical symbol to represent coupling.
A bit later I’ll show how to measure coupling.
An important job during the design phase is to reduce the overall coupling in a system to the
lowest level possible. But a problem arises: How do you know when you’re finished? In other words,
how do you know when coupling is at the lowest level possible? The goal is to ensure that all complex
classes and components are entirely decoupled from other components. To accomplish this, and
because you know that you can’t eliminate coupling completely from a system, you must find ways
to shift coupling around in the system until it occurs only in desirable places. The rest of the chapter
shows ways to accomplish this nontrivial goal.
The Coupling Symbol
Coupling is a kind of dependency between two entities, but no universal symbol exists to represent
coupling in software diagrams. Unified Modeling Language (UML) relies on the use of stereotypes to
depict relationships. The <<uses>> dependency is often used to indicate a dependency between
components, as shown in Figure 1-2.
Figure 1-2. Showing coupling with the UML <<uses>> stereotype
The diagram simply tells you that C1 uses C2. The problem is that there are many ways for C1 to
use C2, so you have no idea what sort of coupling exists between C1 and C2, or if there is any coupling
at all. If there is, does it affect compile time, run time, or both? Is the coupling due to the use of userdefined
types or not? Knowing the kind of coupling you’re dealing with is not an exercise in futility,
because each kind can affect different phases of the software development life cycle in different
ways, introducing constraints in the project.
Given the significance of coupling in software systems, I’ll use a dedicated symbol to represent
coupling in diagrams and logic equations. The symbol is 􀁶. Using this symbol, the previous diagram
becomes the one shown in Figure 1-3.
In some math and physics textbooks, the symbol 􀁶 is used to indicate a proportionality relationship.
The decision to use this symbol for coupling was not entirely arbitrary, because proportionality
is a form of dependency. For readers wishing to reproduce the symbol in their own documents, the
coupling symbol is available in the Symbol font in Microsoft Word. The symbol is not a Greek letter
and should be read as coupling or is coupled to. There are several ways in which classes, objects, and
components can become coupled, so I’ll use subscripts to denote the specific kind of coupling in
effect at a given time.
􀂦􀀠

How to fix java.lang.OutOfMemoryError: unable to create new native thread?

•August 20, 2009 • Leave a Comment

In setting up a system for some activity, after running the system for sometime the error “java.lang.OutOfMemoryError: unable to create new native thread” keeps poping up .It came to realisation after research that the JVM allocated to your application affects the number of threads that can be allocated to your application so hence the error.

This formula gives a decent estimate for the number of threads you can create:
(MaxProcessMemory – JVMMemory – ReservedOsMemory) / (ThreadStackSize) = Number of threads

Memory Allocation to JVM=Perm Size + Heap Size.

ThreadStackSize=1M for Java 1.5

JVM and OS use a more likely 150MB of Memory.

For Java 1.5 I got the following results assuming that the OS reserves about 150MB:
1.5GB allocated to JVM: (2GB-1.5Gb-150MB)/(1MB) = ~362 threads
1.0GB allocated to JVM: (2GB-1.0Gb-150MB)/(1MB) = ~874 threads

Absurd but true: to create more threads you have to reduce the memory allocated to the JVM.

After Maker Faire Event

•August 18, 2009 • Leave a Comment

The Maker Faire Event ended on the last Sunday and it was great seeing people (programmers ) of similar interest and making friends at the same time. Sorry i couldn’t get pictures to show you guys but you can visit Erik Hersman’s for much of these. BugLabs wasn’t able to be at the event but Erik brought one of the device and i got the chance to have a look at it.

The modules were the BUG BASE,  GPS, CAMERA, LCD , POWER CHARGER and A USB CABLE.

bugbaseFirst impression,  great device for prototyping and my background really got me into it. Java in embedded device is fun and i really recommend you guys having a look at it and that means buying one i suppose. I have to thank Erik Hersman for giving me the chance to try the Bug. I had the device for only two days that means less fun but i am hoping of spending more time with it and  see the possibilities ,and sharing some with you.

If you did miss this event then try and make it another time because i don’t know what you might meet the next time.

Preparing to attend Maker Faire Africa Event

•August 12, 2009 • Leave a Comment

This will be my first time at the Maker Faire Africa Event and i am not letting it go. From the information i got from a Java enthusiast, there is an exhibition by Bug Labs, which design bugs :) .

You would be wondering if it is a software bug or not.  Well, you are right it’s not :) .  A bug from Bug Labs definition is a modular, open source system for building devices. Visit Bug Labs for more information on their bugs.

XMPP: What can you do with XMPP?

•July 28, 2009 • 1 Comment

The Extensible Messaging and Presence Protocol (XMPP) is an open technology for realtime communication, using the Extensible Markup Language (XML) as the base format for exchanging information. In essence, XMPP provides a way to send small pieces of XML from one entity to another in close to real time. In XMPP, there are two basic high level categories namely Services and Applications.

Services:

In this context, a service is a feature or function that can be used by any given application.
XMPP implementations typically provide the following core services:

1. Presence

2. Authentication

3. Channel Encrpytion

4. Contact List

5. Notifications

6. Service Discovery

7. Peer-to-Peer Media Sessions, etc.

Applications:

With all the services above at your disposal, then building applications is the next thing in XMPP.

Let go through a few applications that can be built with the technology:

1. Group Chat

2. Gaming

3. System Control

4. Geolocation

Communication Primitives:

In XMPP design, there are three basic communication primitives called XML Stanzas. In XMPP, a stanza is a basic unit for communication like message or packet. These stanzas are message, presence and iq(query).

Enough of the definitions and stuff.

How do i built an XMPP application (Service and Applications)?

These are basically services and applications (makes use of services). In design, you will think about how to host the services so that applications can use them.

In design perspective, you will need to think about the following:

1. An XMPP Server to host your services.

2. An XMPP Service API to access server services, which will be used to built the applications.

3. Deployment strategies

Open Source Implementations:

There are a few open source implementations of XMPP that you can use to built some of the applications above. Popular ones like Jabber, Tinder. There is a complete list at XMPP website.

Further Reading:

1. XMPP

2. Ignite Realtime

3. Jabber

Qt Support in Netbeans 6.7

•July 3, 2009 • Leave a Comment

Netbeans IDE 6.7 has added support for Qt. Qt developers including me can enjoy with our great IDE in developing some great applications with the QT framework.Get a Netbeans 6.7 executable from Netbeans.org and give it a try.Enjoy Qt funs

Get a Netbeans 6.7 executable from Netbeans.org and give it a try.Enjoy Qt funs

PART I: Dependency Injection with Guice

•June 1, 2009 • Leave a Comment

Introduction

Guice(pronounced “juice”) is an ultra-lightweight, next-generation dependency injection container for Java 5 and later.In this article we’ll look at Guice in Action and Plain Old Factory for dependency injection. We will decide what and when to use dependency injection in our applications(desktop or web).

Why do you need Guice ?

Guice enables and provides the best of all worlds:

  • Easy unit testing
  • Maximal flexibility and maintainability
  • Minimal repetition.

Can’t this be done without Guice?

Yes you can with factory design pattern, but as the your application thens to grow Guice will be of great beneficial to your application.

Factory Patten

Before the term “Dependency Injection” was discovered, developers make use of factory design pattern to achieve the same effect in some aspects.In this example, a client depends on a UserAuthentication service interface for authenticating a user either by via JDBC (Database Server) or LDAP (LDAP Server).We’ll call it UserAuthentication.

We have two implementations of the service with JDBC as the default implementation of this service which the client should not depend directly on. If we decide to use a different service implementation in the future, we don’t want to go around and change all of our clients.

Implementations of UserAuthentication service :

  1. JDBC Implementation
  2. LDAP Implementation


Next, we will need to implement the factory class for our clients to use in getting an implementation of the service as well as a means of testing in a mock service.

Logic of UserAuthentication factory :

Pass the name of implementation to the factory service and the factory returns an instance of that implementation.By default, a JDBC implementation will be handed to the client if name of implementation cannot be found or is null.


The client uses the factory directly to access the service if it needs one. Additionally you can add extra logic so that service implementations can be registered to the factory. The factory then have knowledge of all different implementations (Registry, you call it) and can access an implementation from the registry.

A simple client for our UserAuthentication Service


What is happening?

Get an instance of factory and use factory to get an implementation based on the name. Use the implementation to test a dummy user by creating an instance of user and calling the login method of the service interface via which you pass the dummy user.

Running the Factory Client


Dependency injection by Hand

From Guice 1.0 Guide, I quote:

“The dependency injection pattern aims in part to make unit testing easier. We don’t necessarily need a specialized framework to practice dependency injection. You can get roughly 80% of the benefit writing code by hand.”

While the client asked the factory for a service in our previous example, with dependency injection, the client expects to have its dependency passed in. Don’t call me, I’ll be there when you need me.

Dependecy injection by hand will require us implementing a factory for the client so that each implementation of the service will be returned by the client factory.

Summary on Plain Old Factories and Dependency Injection by Hand

You will notice that both (plain old factories and injection by hand) require barely the same amount of code to accomplish.

Dependency injection by Guice

Writing factories and dependency injection logic by hand for every service and client can become tedious. Some other dependency injection frameworks even require you to explicitly map services to the places where you want them injected.

From Guice 1.0 Guide, I quote:

“Guice aims to eliminate all of this boilerplate without sacrificing maintainability.”

  1. In using Guice, you implement modules, com.google.inject.Module.I prefer AbstractModule class.
  2. Guice passes a binder to your module, and your module uses the binder to map interfaces to implementations.
  3. Guice allows you to scope services (Singleton:one instance or Prototype: an instance for each injection by default).

As a proof of concept, we will create a module called SimpleAuthenticationModule to bind UserAuthentication to JdbcUserAuthentication.

A module tells Guice what you want to be injected. Guice can inject to fields, contructors and methods.

How is the service injected to the client?

By annotating your fields, methods and constructors with @Inject.


public class Client {

@Inject

public void Client(Service service) { this.service=service;}

}

Use of @ImplementedBy annotation

Instead of implementing the AbstractModule, you can annotate the service with @ImplementedBy. This annotation takes the implementation class as its parameter. It eliminates even more boilerplate code.

Use of @Singleton annotation

Instead of binding a scope to your implementation as done in the SimpleAuthenticationModule, you can annotate your implementation with this annotation to single instance of your service.

Architectural Overview of Guice

There are two distinct stages in the architecture of Guice as enumerated in Guice 1.0 Guide. They are startup and runtime. Injection Points are created by the Injector after supplying it with modules and injection class.Guice can look at the classes you tell it about during this startup stage and any classes those classes know about, and tell you whether or not you’re missing any dependencies.

Guice Runtime model:
see Guice 1.0 User Guide for more details about the runtime stages.


Source: Guice 1.0 User Guide

Annotation Binding

For the UserAuthentication service, there are two implementation of it namely JdbcUserAuthentication and LdapUserAuthentication. How do we differentiate between the two implementations? Guice has an answer to that and this is what the annotation binding is to solve.

For this example, we will bind the annotation @LdapAuthentication to the service LdapUserAuthentication implementation and @JdbcAuthentication annotation to JdbcUserAuthentication implementation. Refer to Guice 1.0 Guide on how to create Binding Annotations.


Guice provides production-worthy implementation called @Named but we will implement our own as proof of concept.

Bootstrapping your application

The idea of bootstrapping is fundamental to dependency injection. Always explicitly asking the Injector for dependencies would be using Guice as a service locator, not a dependency injection framework.

Implementation of UserAuthentication using Guice

  1. Implement the AbstractModule and configure all your services for injection.


  2. Bootstrap your application and provide an access to Injector class.


  3. Use Injector object from the bootstrap stage and call injectMembers method for dependency injection.


Summary

We implemented factory pattern, dependency injection by hand and dependency injection by Guice ,and truly Guice gives you easy unit testing, minimal repetition and maximal flexibility and code maintainability.

In Part II, we will look at Dependency Injection with Guice in Spring.

Source code for this article can be downloaded at http://groups.google.com/group/jaccra/web/GuiceExample.zip. To run the application you will need:

  • IDE (Netbeans/Eclipse or just Ant)
  • Guice Library

Further Reading

http://code.google.com/p/google-guice/