Sunday, July 31, 2011

How to write a custom registry handler to handle associations

WSO2 Registry is a content repository which provides set of abstractions over a raw relational db. Registry provides a rich set of features for storing, managing and finding resources/content. However, sometimes, one have to go beyond existing default functionality to implement custom behavior to suite specific requirements. Handlers and Filters are such an extension point of registry which allows users to implement customizations by write small about of code.

A handler is written by extending the Handler class and overriding its necessary methods. Custom handler is registered with the registry by putting an entry in the registry.xml

public class CustomHandler extends Handler {
public void addAssociation(RequestContext requestContext) throws RegistryException {}
public void removeAssociation(RequestContext requestContext) throws RegistryException{}

<handler  class="org.wso2.carbon.regisry.samples.handler.CustomHandler">
<filter class="org.wso2.carbon.registry.samples.handler.CustomMediaTypeMatcher">
<property name="mediaType">mytype</property>

In order to invoke our CustomHandler, we have defined a custom media type and a CustomMediaTypeMatcher class. CustomMediaTypeMatcher class should extend the MediaTypeMatcher class. 

When a resource with media type mytype is added to the registry, associated registry filter classes will be called to perform an evaluation and based on its result, associated handlers will be invoked.

In our scenario, we want to invoke the methods addAssociation, and removeAssocation when a resource is associated with a resource which has the media type “mytype”. The code sample for the CustomMediaTypeMatcher class to handle it is shown below.

public class CustomMediaTypeMatcher extends MediaTypeMatcher{
public boolean handleAddAssociation(RequestContext requestContext)
            throws RegistryException {
        Resource resource = requestContext.getRepository().get(requestContext.getSourcePath());
        if (resource != null) {
            String mType = resource.getMediaType();
            return mType != null && (invert != mType.equals(getMediaType()));
        return false;

    public boolean handleRemoveAssociation(RequestContext requestContext)
            throws RegistryException {
        Resource resource = requestContext.getRepository().get(requestContext.getSourcePath());
        if (resource != null) {
            String mType = resource.getMediaType();
            return mType != null && (invert != mType.equals(getMediaType()));
        }       return false;

Happiness and Sadness

Types of Happiness: Emotion and Sentiment

It is not easy to find happiness in ourselves, and impossible to find it elsewhere.
—Agnes Repplier

What do you take me for, an idiot?
—General Charles de Gaulle, when a journalist asked him if he was happy.

A distinction can be made between two major types of happiness. A long term sentiment of happiness (flourishing, well-being) and a short term emotion of happiness ( Joy, satisfaction).

As an emotion, happiness is a short-term state of pleasure or satisfaction occurring as a result of ( real or imaginary ) positive changes.

A steady diet of simple pleasures will keep you above your set point. Find the small things that you know give you a little high—a good meal, working in the garden, time with friends—and sprinkle your life with them. In the long run, that will leave you happier than some grand achievement that gives you a big lift for a while. - David Lykken

It was found that those people who are relatively the happiest now will be the happiest ten years from now, despite day to-day fluctuations.

Determinants of Happiness

It is pretty hard to tell what does bring happiness; poverty and wealth have both failed.
—Kin Hubbard
We are no longer happy as soon as we wish to be happier.
—Walter Savage Landor

Happiness can be experienced as a result of being focus on an activity and not the result. Happiness is then to be found in activities we value in themselves.

"It's the hunt—not the money—that makes my blood race; after all, you can only sleep in one bed at a time, and drive one car at a time”

- Chris Verbiski

Happiness depends on the way we act than the specific result of our activities.

Happiness “arises more from the pursuit than from the attainment of any end
whatever”. It "depends more on the degree in which our minds are properly
employed, than it does on the circumstances in which we are destined to act, on the materials which are placed in our hands, or the tools with which we are furnished."

Linking happiness to an attainment of goal results in unhappiness than happiness and in the end when the goal is achieved, we may not actually enjoy it as much as expected. It may be due to the fact that original circumstances may have changed by the time achievement is obtained or the expectation and reality gap. 

“There are two tragedies in life. One is not to get your heart's desire. The other is to get it” - George Bernard Shaw

Post coitum omne animal triste est —"After sexual intercourse every animal is sad"

Maintaining Long-Term Happiness

Happiness is not a state to arrive at, but a manner of traveling.
—Margaret Lee Runbeck

The happiness of most people we know is not ruined by great catastrophes or fatal errors, but by the repetition of slowly destructive little things.
—Ernest Dimnet

Dealing with the baseline (expectation)  and reality (current situation) gap can be done by (a)  eliminating the gap by changing the baseline or reality (b) coping with the gap by changing our attitude toward it.

One can endure sorrow alone, but it takes two to be glad.
—Elbert Hubbard
It is our job to make women unhappy with what they have.
—B. Earl Puckett, an advertiser

Sadness confirms our appraisal of things as valuable; hence it may happen that we take pride in our ability to feel sadness.

When it gets dark enough you can see the stars

Let us so live that when we come to die, even the undertaker will be sorry.
—Mark Twain

Grief is the most profound type of sadness. It is concerned with death, the most substantial misfortune we encounter: it expresses the irrevocable loss of someone very close and of great value to us.

Moral Value

Happiness, it is said, is seldom found by those who seek it, and never by those
who seek it for themselves.
—F. Emerson Andrews

Thousands of candles can be lighted from a single candle, and the life of the candle will not be shortened. Happiness never decreases by being shared.

Sorrow makes men sincere.
—Henry Ward Beecher
If a way to the better there be, it lies in taking a full look at the worst.
—Thomas Hardy

Happiness is often achieved through positive illusions; in sadness, reality is better known. Sadness is unpleasant, but it is morally valuable for committing ourselves to the more profound moral obligations. Happiness is also morally valuable but for different reasons: its main value is in helping us to perform the "small" everyday moral deeds.

Source: The Subtlety of Emotions.

Thursday, July 21, 2011

Delivering Happiness


Most common belief is that “When I get ___, I will be happy, or When I achieve ___, I will be happy.”. But the reality is that, happiness gained in such manner tend do disappear very quickly.

Happiness Framework.

Happiness is really just about four things: perceived control, perceived progress, connectedness (number and depth of your relationships), and vision/meaning (being part of something bigger than yourself). 


Maslow’s Hierarchy.


Self actualization is the ultimate form of happiness according to Maslow’s hierarchy.



The pleasure type of happiness is about always chasing the next high.As soon as the source of stimuli goes away, people’s happiness levels drop immediately.


The passion type of happiness is also known as flow, where peak performance meets peak engagement, and time flies by.

Higher Purpose

The higher-purpose type of happiness is about being part of something bigger than yourself that has meaning to you. Research has shown that of the three types of happiness, this is the longest lasting. What I find interesting is that many people go through life chasing after the pleasure type of happiness, thinking that once they are able to sustain that, then they will worry about the passion and, if they get around to it, look for their higher purpose.

Start asking yourself the right questions.

  • Are you working toward maximizing your happiness each day?
  • What is the net effect of your existence on the total amount of happiness in the world each day?
  • What are your values?
  • What are you passionate about?
  • What inspires you?
  • What is your goal in life?
  • What are your company’s values?
  • What is your company’s higher purpose?
  • What is your higher purpose?

When you walk with purpose, you collide with destiny.



And read how to be happy.

Tuesday, July 19, 2011


People like those like them, who like them.

To influence people, win friends, through: Similarity:Create early bonds with new peers, bosses, and direct reports by informally discovering common interests—you’ll establish goodwill and trustworthiness.Praise:Charm and disarm.Make positive remarks about others—you’ll generate more willing compliance.

People repay in kind.

Give what you want to receive. Lend a staff member to a colleague who needs help; you’ll get his help later.

People follow the lead of similar others.

Use peer power to influence horizontally, not vertically; e.g., ask an esteemed “old timer” to support your new initiative if other veterans resist.

People fulfill written, public, and voluntary commitments.

Make others’ commitments active, public, and
voluntary. If you supervise an employee who should submit reports on time, get that understanding in writing (a memo); make the commitment public (note colleagues’ agreement with the memo); and link the commitment to the employee’s values (the
impact of timely reports on team spirit).

People defer to experts who provide shortcuts to decisions requiring specialized information.

Don’t assume your expertise is self-evident. Instead, establish your expertise before doing business with new colleagues or partners; e.g., in conversations
before an important meeting, describe how you solved a problem similar to the one on the agenda.

People value what’s scarce.

Use exclusive information to persuade. Influence and rivet key players’ attention by saying, for example:“…Just got this information today.It won’t be distributed until next week.”

Source : Harnessing the Science of Persuasion by Robert B. Cialdini

Thursday, July 7, 2011

Lessons learned from Bill Gates

What i really liked is Bill Gate’s 11 Rules of life.

  • Rule 1: Life is not fair
  • Rule 2: The world won’t care about your self-esteem.
  • Rule 3: You will NOT make $60,000 a year right out of high school.
  • Rule 4: If you think your teacher is tough, wait till you get a boss.
  • Rule 5: Flipping burgers is not beneath your dignity.
  • Rule 6: If you mess up, it’s not your parents’ fault, so don’t whine about your mistakes, learn from them.
  • Rule 7: Before you were born, your parents weren’t as boring as they are now.
  • Rule 8: Your school may have done away with winners and losers, but life HAS NOT.
  • Rule 9: Life is not divided into semesters.
  • Rule 10: Television is NOT real life.
  • Rule 11: Be nice to nerds.