[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ExternalDatabase.isOpen() implementation



Maxim, I'm sure all the ozone users are interested in this discussion so I Cc:
this to the list too.

On Mon, 30 Oct 2000, you wrote:
> Dear Falko!
> 
> Thanks for the reply and for the explanations.
> But if you are right then is there a way to find
> out whether my db is open or not (that is can I make
> any db operations like createObject())? Is an
> exception the only way to know it? And what if I want
> not to deal with this exception but rather check the
> condition before action and open the db if it's
> closed?

The isOpen() method is meant to provide exactly this information. The open()
method establishes a socket connection to the server and so proofs that the
server is there and willing to serve my requests. Afterwards the
ExternalDatabase is considered to be open (isOpen() == true) until close() is
called. If you call isOpen() from another thread, then it simple assumes that
it can open a socket to the server too. Maybe isOpen() could open a socket to
the server (using connectionForThread()) to proof that this is actually
possible for this thread. But this is not really a difference. The server could
die in between of the call to isOpen() and the actual request. So making one
socket when opening the ExternalDatabase seemed a good solution.

> 
> Thank you in advance
> Maxim
> P.S. Sorry for annoying, but is the following correct?

It seemes that you just cut off the code for closing no longer needed
connections from the original code. It maybe will work but you will get more
and more open sockets and it would probably very slow.


Falko

> /** Return the server connection for the specified
> thread. If the thread is not yet joined to a
> connection create a new one and associate with the
> thread. */
>     protected synchronized DbClient
> connectionForThread (Thread thread) throws Exception {
> ...
>                      // make a new connection
>             connection = newConnection();
>             connections.addForKey (connection,
> Thread.currentThread());
>             }
>         return connection;
>         }
> May be there should be
> // make a new connection
>             connection = newConnection();
>             connections.addForKey (connection,
> thread);
>             }
>         return connection;
>         }
> Well, if you'll answer that I'm an idiot, then I'll
> stop asking about what I see in the sources, I swear
> :)
> 
> --- Falko Braeutigam <falko@softwarebuero.de> wrote:
> > Maxim,
> > sorry, sorry, sorry for the late response. There are
> > so many things to do
> > currently (including vacation;) . Anyway, I will try
> > to do better next time. ;)
> > 
> > On Thu, 28 Sep 2000, Maxim Shinkarev wrote:
> > > Dear Falko
> > > 
> > > I'm at the very beginning of using Ozone, so may
> > be
> > > I've done something wrong, or, may be 0.5.5 is
> > > outdated now, but I've found strange behavior of
> > the
> > > method
> > > ExternalDatabase.isOpen()
> > > It always returns TRUE. 
> > > When I saw the source, I found the following
> > > //...
> > >     public ExternalDatabase() {
> > >         txTable = new DxHashMap();
> > >         connections = new DxHashMap();
> > >         }
> > > //...
> > >     public boolean isOpen() throws Exception {
> > >         return connections != null;
> > >         }
> > > //...
> > > So the method returns TRUE for every database,
> > even
> > > without connections. Is it made on purpose? May
> > be, it
> > > would be better to write something like
> > > //...
> > >     public boolean isOpen() throws Exception {
> > >         return connections.isEmpty();
> > >         }
> > > //...
> > 
> > From the first look this seems to be a good idea,
> > but.. ;)
> > 
> > The connections are internally handled by
> > ExternalDatabase. There might be a
> > situation were no connections are pressent but
> > isOpen() must return true. For
> > example just after initialization ExternalDatabase
> > makes a connection for the
> > current thread but this is not really needed. It
> > might also wait until the
> > first request comes in. So isOpen() returns true
> > until close() is called. DO
> > you think this is suited behaviour?
> > 
> > Maxim, please keep on sending your questions.
> > 
> > 
> > Falko
> > -- 
> >
> ______________________________________________________________________
> > Falko Braeutigam                             
> > mailto:falko@smb-tec.com
> > SMB GmbH                                       
> > http://www.smb-tec.com
> > 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Messenger - Talk while you surf!  It's FREE.
> http://im.yahoo.com/
-- 
______________________________________________________________________
Falko Braeutigam                              mailto:falko@smb-tec.com
SMB GmbH                                        http://www.smb-tec.com