Pages

Showing posts with label JNDI. Show all posts
Showing posts with label JNDI. Show all posts
0

JNDI !! What the heck is it ? Part 2 'Directory services'

If you understood the first part of the series , this should be cake walk. We will talk about Directory services in this part. So lets start.
To understand directory services, think of any travel website where you can book a flight based on various parameters like price, timing, etc. E.g. London to Tokyo flight in 1000$ at 11pm on wednesday.
Directory services are similar to naming services where you can associate resources with names and you can get the objects by their names. However directory services are very similar to how these travel websites work as well. We can search an entity or resource based on their different attributes. Most commonly directory services allow us to store objects hierarchically.

So if we think directory services are nothing but a database like systems where we can query required objects based on our own criteria by specifying a criteria filter. These filters allow us to configure different parameters like 'depth of tree nodes' etc.

Following diagram represents the concept of directory services that we just talked about.



The most common protocol for accessing the directory service is LDAP (lightweight directory access protocol) LDAP defines how client applications can access or manipulate the data on the directory servers. As mentioned above, LDAP provides APIs to search the directory servers based on filters and parameters.

This is pretty much it as far as concept of directory services goes. In next section we will talk about the real thing; the JNDI

See you then :)


0

JNDI !! What the heck is it ? Part 1 'Naming services'

Short answer : It is Java Naming and Directory Interface :)
Well that's not enough obviously... So
Long answer : To understand the Java naming and directory services we first need to understand what naming services and directory services are and what good are they (what purpose do they serve) .. So this is a 3 part explanation of JNDI and we will talk about the first part here


Naming services : To understand naming service, ask yourself a question 'why do I need a contact book in my mobile phone ? ' Answer will most probably be : 'How the hell am I supposed to remember everybody's phone number. I need to look up phone numbers of my contacts. Also if somebody's number changes, I can pretty easily update my contact using just my left thumb'
Right.. When we store the numbers in our contact book there are following purposes we serve
1. We don't want to remember 10 or more alpha-numerics per person. It is easier to remember a 'John Nash' than 555-223-2422 (fictious name and number ofcourse)
2. If John Nash changes his number, we don't lose anything. We anyway remember his number by his contact so we just update the number. In technical terms we call this 'Loose coupling'
So this is exactly why we need naming services in our lives.

Couple of examples of naming services :
1. DNS (Domain naming service) : If it weren't for DNS we would have gone bananas remembering IP addresses of our favourite websites. Thank god we have DNS servers which hide the ugly ip address and gift wrap it in a nice name which we can remember (or bookmark :) )
2. Our file systems : Well file systems hide the actual storage location of our contents and give us a facility of file names, folders etc.


Enough blabbering !! Getting down to brass technical terms


Naming service is a software application that associates a 'name' with the required 'service' or 'information'
The definition implies that we in our software can utilize an entity or an object without the knowledge of their exact location. They can reside in the naming service itself or can be hosted on a completely different machine (it has to be accessible though)

Now in our analogy, we can find any contact only as long as we look in the correct contactbook. Similarly, when we use naming services, we need to know where we are supposed to find our required entity. This is called as 'context' in the naming service world.
So basic steps in using naming services are :
  1. Obtain the context.
  2. Lookup the entity
  3. Get the resource by the name it is bound with in the context.
Following diagram represents the architecture that we just explained.



So why exactly use a naming service ??

  1. To decouple the provider from the user or consumer. As long as we know the name which the service is registered under we are good to go. Why bother about how it is implemented!
  2. It is good to have a central registry sort of systems where you keep all your services registered. Good to have a uniform way of accessing our services or objects or whatever may be. It frees us from having to implement each and every service on our own like message queues, EJBs, data sources etc.
  3. We can pretty easily change the hosting of any service if we are accessing it through naming service since we just need to update the entry and we are good to go.

Most popular examples of naming services are :

CORBA Common object services : This service provides a hierarchical way of storing the entities
Network information services (NIS) : This is java based naming service developed by sun.

So this concludes the first part 'Naming services'. We will talk about directory services in the next part.


Back to Top