Well... "dedicated.connection=true" is not documented :)))
  Second. There ARE drawbacks.
  The method you show in the message will lead you to resource leakage.
  Try reusing contexts for one and the same target.
  Anyway. The Answer is: YES, it WILL work.

  However. The classes, for the Home and remote interfaces for the beans you
are looking-up for have to be in the Bootstrap class-path (in most cases in
the boot jar, or specified on the commandline). Otherwise you will get a
ClassCastException ( "MyClass" implements "MyInterface" and not
"MyInterface" and the VM thinks these are different classes :((( ).

  Anyway. for a simple stand-alone client this works fine, as long as you
stay out of dynamic-class-loading and keep in mind, that each ne Context
gets another thread, socket and leads to resource shortage.

  Otherwise the code in your case would work just fine. :)))

  Lachezar

> Brilliant -- thanks. What I couldn't find was any documentation
> on what goes in the environment Hashtable. :)
>
> What does the dedicated.connection=true property do? If I were
> to do this:
>
>   public FooRemote getRemote(String jndiURL)
>   {
>      Hashtable env = new Hashtable();
>      env.put(Context.PROVIDER_URL, jndiURL);
>      InitialContext context = new InitialContext(env);
>      Object ref = context.lookup(EJB_NAME);
>      FooHome home =
>       (FooHome)PortableRemoteObject.narrow(ref, FooHome.class);
>      FooRemote remote = home.create();
>      return fooRemote;
>   }
>
>   public void doStuff()
>   {
>     FooRemote beanOne = getRemote("ormi://fred/app");
>     FooRemote beanTwo = getRemote("ormi://wilma/app");
>     // do stuff...
>   }
>
> Will it work? Or is the remote going to get confused as to
> which server it points to?
>
> On Thu, 2002-04-18 at 00:53, Lachezar Dobrev wrote:
> >   Hi.
> >   A working model is to create two Initial Context-s for each server.
> >   Use a "dedicated.connection=true" property to create the context.
> >   The "dedicated.connection" however leads to resource leakage, and if
you
> > keep creating more and more of them you will eventualy get
> > "java.lang.OutOfMemoryError: Can not create native thread" at some
200-300
> > contexts.
> >   If you create an context for both servers, and then use them later you
> > might not have this problem.
> >
> >   public static Context[] connections;
> >
> >   public void ejbCreate(){
> >     if ( connections != null ) return;
> >     Hashtable env = new Hashtable();
> >
> >     // Use any of these.
> >     env.put("dedicated.connection", Boolean.TRUE );
> > //    env.put("dedicated.connection", "true");
> >
> >     // Set up user, pass,
> >     // factory (RMIInitialContextFactory).
> >     env.put(".......", "...."); // Set up things
> >
> >     connections = new Context[2];
> >
> >     // For The first server
> >     env.put(Context.PROVIDER_URL, "ormi://Comp1/App1");
> >     connections[0] = new InitialContext(env);
> >
> >     // Now for the other server
> >     env.put(Context.PROVIDER_URL, "ormi://Comp2/App2");
> >     connections[1] = new InitialContext(env);
> >   }
> >
> >   public void connectServer1(){
> >     connections[0].lookup("MyBean1");
> >   }
> >   public void connectServer2(){
> >     connections[1].lookup("MyBean2");
> >   }
> >
> >    You DO understand this is Orion-specific, right?
> >
> >   Good luck. Lachezar.
> >
> > > I've got the same beans deployed on two different app servers (each
> > > backed by a different database). I want my client to talk to both.
> > > Say the two app servers are running on machines named Fred and Wilma;
> > >
> > > I know I can choose which one I talk to by setting
> > >
> > >   java.naming.provider.url=ormi://fred/app
> > >
> > > or
> > >
> > >   java.naming.provider.url=ormi://wilma/app
> > >
> > > But how do I switch at run time? I don't want to keep changing the
> > > system property every time I get an InitialContext(), because the
> > > system property is a global setting and one piece of code might not
> > > know what another piece of code is doing. Is there a way to specify
> > > the JNDI url when you create an InitialContext?
> > >
> > >
> > >
> >
> >
> >
>
>


Reply via email to