Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Q] cannot bind to Compound name using Java 1.6 Corba server

3 views
Skip to first unread message

VSP

unread,
May 18, 2009, 1:09:44 AM5/18/09
to
I have been trying to get this to work for about 10 hours but
no matter what I try it does not work.

Basically my Combond name is

Level1->Level2->object

so all I want to do is to fist see if
Level1->Level2 naming contexts exist, if not create them
and then bind the objec to them

But Sun returns NotFound when I am trying to use
bind_new_context and I just cannot figure out why
(my naming server is OmniOrb, and it appears that I can do things
if my Contexts are not combound (that is there is only Level1)

here is the code

what am I doing wrong?
---------------------------

org.omg.CosNaming.NameComponent lvl1Name=new
org.omg.CosNaming.NameComponent("Level1","kind1");

org.omg.CosNaming.NameComponent lvl2Name=new
org.omg.CosNaming.NameComponent("Level2","kind2");

org.omg.CosNaming.NameComponent[] nameTree1={lvl1Name};
org.omg.CosNaming.NameComponent[] nameTree2={lvl2Name};

org.omg.CosNaming.NameComponent[] nameTree=new
org.omg.CosNaming.NameComponent[2];

nameTree[0]=lvl1Name;
nameTree[1]=lvl2Name;


NamingContext currContext=null;

try{

//fails when tree is more than 1
currContext=rootContext.bind_new_context(nameTree);
}
catch (org.omg.CosNaming.NamingContextPackage.AlreadyBound ex)
{
System.out.println("nameTree already bound");
}
catch (org.omg.CosNaming.NamingContextPackage.NotFound ex)
{
System.out.println("BIGPROBLEM nameTree not found: "+ex);
}


/* Now, bind the server to the naming context tree we have done
above */

NameComponent lvl3Name=
new NameComponent("OBJNM__monster__2800","aa_bbb");

NameComponent[] last={lvl1Name,lvl2Name,lvl3Name};

try
{
currContext.bind(last,obj);
}
catch (org.omg.CosNaming.NamingContextPackage.AlreadyBound ex)
{
// if the context already exists then we just need to bind the object
//to that naming context
currContext.rebind(last, obj);
}


-------------------------

I also tried to bind piece by piece, but I do not think it is possible
because while I can bind_new_context for level 1 and then for level2

if both level1 and level2 exist (created by another server)
the there is no way for me to get the NamingContext
of the Level1->Level2

I tried bind_context (nameTree,newContext) and the newContext
never gets reset to anything valid;

thank you in advance,
VSP

Raghu V. Hudli

unread,
May 18, 2009, 9:56:43 AM5/18/09
to

Think of the naming graph to be much like a file system with contexts
being subdirectories or folders and object bindings to be like files.
Just like in the file system, where you need to make sure
all sub directories/folders in the path to create a file, in CosNaming
you need to make sure each
intermediate naming context object exists. Your approach of binding
"piece by piece" is correct and should work. The naming context of
Level1->Level2 can be obtained by invoking resolve
on the root name context with nameTree as the name. Alternatively, you
can bind last (name) to obj by invoking bind on the root name context.

Hope this helps...

Raghu

VSP

unread,
May 18, 2009, 12:52:12 PM5/18/09
to
Thank you very much for reply

That is true, if I think of it

I cannot go to a root file system and do

mkdir Level1/Level2

I have to do either
1)
Mkdir Level1
cd Level1
mkdir Level2

or
2)
mkdir Level1
mkdir Level1/Level2


The 2) option worked for me.

I cannot however understand how in corba
I can do the first way, when Level1 and Level 2 already exist


for example, I cannot understand how to
obtain a NamingContext of a second level
when Level 1 and Level 2 already exist


When I try

curr=bind_new_context on level 1 it throughs exception that it is
already bound

that's fine, but it also does NOT assign anything to 'curr'

when I then try
curr=null;
...

catch (AlreadyBound )
{
rootContext.bind_context( Level1, curr)
}

that does not work either (curr remains empty)

so how do I 'walk' a graph when first level and second level are
NamingContextes and not object
?


thank you

Raghu V. Hudli

unread,
May 18, 2009, 8:25:54 PM5/18/09
to VSP
VSP wrote:
Thank you very much for reply

That is true, if I think of it

I cannot go to a root file system and do

mkdir   Level1/Level2

I have to do either
1)
Mkdir Level1
cd Level1
mkdir Level2

or
2)
mkdir Level1
mkdir Level1/Level2


The 2) option worked for me.

I cannot however understand how in corba
I can do  the first way, when Level1 and Level 2 already exist


for example, I cannot understand how to
obtain a NamingContext of a second level
when Level 1 and Level 2 already exist

  
As you would know to get any object reference, including one for naming context,
you have to resolve a name. As I wrote earlier, rootContext.resolve(nameOfLevel2Context)
will give you the NamingContext of Level2.

When I try

curr=bind_new_context  on level 1 it throughs exception that it is
already bound

that's fine, but it also does NOT assign anything to 'curr'

when I then try
curr=null;
...

catch (AlreadyBound )
{
  rootContext.bind_context( Level1, curr)
}

that does not work either (curr remains empty)

so how do I 'walk'  a graph when first level and second level are
NamingContextes and not object
?
  
You can invoke the "list" method on any context. You will get a sequence of Bindings and
a BindingIterator to iterate through the rest. Each Binding will tell you whether the binding
is for a context or a (non naming context) object. For the bindings of a context type you
can invoke list and walk the graph. Binding also returns the name of the binding.

Again, here think of "ls" or "dir" command. These list "files" in the directory or folder.
Subdirectories are special files that one can "cd" to and further "ls" or "dir".

Raghu
0 new messages