CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2011
    Posts
    2

    Lightbulb How to check jndi bind/unbind status?

    I'm looking for way of checking bind status of object and appropriate JNDI name.

    For example, I've got some LDAP jms queue name: "/TheRootContext/SomeSubContext/SOME.QUEUE.NAME:queue"

    I need to check that appropriate queue exists and it is binded with passed name.

    What will be the correct way to check "bind status"?

    I see such algorithm:

    • Perform jndi lookup to ensure that provided name exists.

    Code:
    Object obj;
    try {
        obj = ctx.lookup("/TheRootContext/SomeSubContext/SOME.QUEUE.NAME:queue");
    } catch(NamingException ex) {
        // process naming exception: name not found, name syntax incorrect, ...
    }
    • %I don't know what to do next%, but suggest something like checking that:

    Code:
    obj != null && obj instanceof javax.jms.Queue

    ===
    Another way, suggested here: http://stackoverflow.com/questions/5...-unbind-status
    is to use listBindings method, passing to it parent context name: and checking what interested binding present in returned NamingEnumeration. But this is actually the same as previous method. This way something like this should be done:
    Code:
    NamingEnumeration bindings;
    try {
        bindings = ctx.listBindings("/TheRootContext/SomeSubContext/SOME.QUEUE.NAME");
    } catch(NamingException ex) {
        // process naming exception: name not found, name syntax incorrect, ...
    }
    
    boolean isFound, isBinded;
    while (bindings!=null && bindings.hasMore()) {
        Binding bd = (Binding) bindings.next();
        if(bd.getName().equals("queue")) {
             isFound = true;
             isBinded = bd.getObject() != null && bd.getObject() instanceof javax.jms.Queue) ;
            break;
        }
    }
    
    System.out.println("Is binded: " + isFound && isBinded);
    So, what is the correct way?

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: How to check jndi bind/unbind status?

    Use the simplest, clearest way that works. If the second technique is a more complicated and indirect way that adds unnecessary code to the first technique, it should be obvious which to use.

    Everything should be made as simple as possible, but not simpler...
    A. Einstein
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  3. #3
    Join Date
    Mar 2011
    Posts
    2

    Re: How to check jndi bind/unbind status?

    dlorde, thx.

    Agreed. But I'm not shure what I understand correctly what does "check for unbind" mean.

    As I understand LDAP name may exist, but no appropriate object (JMS queue) exist. Or both may exist, but they may be "unbind".

    I need to check three things:
    1. JNDI name (LDAP name in that case) exists
    2. JNDI name is bound to expected object (JMS queue)
    3. Not shure here: JMS queue really exists


    How is it possible and is it really necessary to perform this checks separately?

    As I see now, everything is too simple. There could be done only one operation -- lookup that will return object bound to name or throw exception if name doesn't exist. So this operation in couple with checking it's result covers first 2 (or may be all 3) upper list items.

    Is it enough and am I correct in my understanding "check for unbind" activity?

  4. #4
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: How to check jndi bind/unbind status?

    It's been a while since I messed with this stuff, but as I understand it, JNDI binding is simply the mapping of an object to a name in a specified naming context (e.g. map).

    If a name exists in the context, and there is an object mapped to it, the object and name are bound in that context. If there is no object mapped to the name, or if the name is not found in the context, there is no binding of that name/object.

    It's pretty simple really - binding is the JNDI synonym for mapping.

    Doing more things faster is no substitute for doing the right things...
    S. R. Covey
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured