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?
> >
> >
> >
>
>
>