• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Data.close()

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to shutdown the server from a server UI. The first step in the process would be to call: data.close(). My question is that the method, close() is not in the DBAccess interface. So how can I add the public close method? I have looked at previous threads which have said they either put it in an interface or made it public static. Is this acceptable for the B&S project or the other newer project versions?

Thanks very much.


-Paula
 
Paula Decker
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would it be adviseable to include the following code in the server shutdown:

data = null;

and let the finalize method of data handle the closing of the file?

Thanks.

-Paula
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
-------------------------------------
My question is that the method, close() is not in the DBAccess interface. So how can I add the public close method?
-------------------------------------

In my assigment,the DBInterface is named (DB).
I think I can't work just under this interface, So I added some other methods to the Data.java for using.

So if you want close(),just add it to the Data.java class.
 
Paula Decker
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dennis,

Thanks for the email. I have just changed my code to add a public static method in my Data class called, close(). This should be legal. I made this change because it impacts my code the least amount. Thanks again.

-Paula
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paula Decker:

I have just changed my code to add a public static method in my Data class called, close().


How does this work?
I am afraid it is not a good design to use a static method in class Data to control instances of Data.
Also, the assignment defines an interface DB, so the server should rather reference DB interface to hide the implementation, than reference directly the class Data.
What do you think?
 
Paula Decker
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Charles,

Thanks for the post. My Data class implements DBAccess and uses a singleton for the database access, so its like a singleton itself. That is why I think a static is ok. I call Data.close() from my gui controller to close the database if I'm in standalone mode. I call Data.close() from the server.close() method. Both the standalone client and the server use an instance of Data to make all calls to the database. I don't really like using the static but it should work. I was wondering if I should add it because close() is not in the DBAccess interface. What do you think? Normally, I would just add another method, close() to the interface and be done with it.

Thanks.

-Paula
 
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paula Decker:
Hi Charles,

Thanks for the post. My Data class implements DBAccess and uses a singleton for the database access, so its like a singleton itself. That is why I think a static is ok. I call Data.close() from my gui controller to close the database if I'm in standalone mode. I call Data.close() from the server.close() method. Both the standalone client and the server use an instance of Data to make all calls to the database. I don't really like using the static but it should work. I was wondering if I should add it because close() is not in the DBAccess interface. What do you think? Normally, I would just add another method, close() to the interface and be done with it.

Thanks.

-Paula



This question is actually about "session" control. Without sessions you don't really need to close Data objects except at program exit where you could use finalize.

I added a second interface that I call Session to the Data class. The Session interface includes connect, and disconnect methods. My Data and DataProxy classes both implement DBAccess and Session, these act as a Facade to the data access layer which consists of a singleton LockManager and DataBaseTable class.

The LockManager requires an instance of Session so that it can handle orphan locks when clients crash. I use a factory to provide instances of DataAdapter to clients, so there is always a single Session instance per client. The factory is the only object registered in the rmi registry.
 
Paula Decker
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Peter,

Thanks for the input. I am only calling Data.close() when the server or standalone client applications are closed. I tried closing the file from Data during its finalize method. I don't believe the finalize method got called. I wasn't sure if this was a reliable approach.

What are the thoughts about Data.finalize() ?? Is it reliable?

I am not implementing the notion of a client session. The reason for this is that a user login was not required. I handle a record lock which was left by a crashed client by using: wait(<10 minutes> ; After the 10 minutes, the user receives a message that the record is still locked, and to please inform an administrator.

Thanks.

-Paula
 
Charles Fung
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paula Decker:
I call Data.close() from my gui controller to close the database if I'm in standalone mode. I call Data.close() from the server.close() method. Both the standalone client and the server use an instance of Data to make all calls to the database. I don't really like using the static but it should work. I was wondering if I should add it because close() is not in the DBAccess interface. What do you think?


I would use the following design:
(-> for reference; => for method call)
server->FileManager->file handle
server->DB (instantiate Data from FileManager)
FileManager has a constructor using the data file path, and provides access to the underlying data file.
server.close()
=>shuts down server so no more client request will be handled
=>FileManager.close()=>close file and release file handle
The GUI controller follows similar pattern.
This allows use of DB interface instead of the Data class.
This would not need to depend on finalize() to close file. Finalize() is called on garbage collection. There is no guarantee VM calls finalize() on each and every object on VM shut down.
Note that server.close() should make sure no thread is writing to the data file while calling FileManager.close(). Otherwise, you may risk corrupting the data file.
Hope this helps.
 
Paula Decker
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Charles,

Thanks for the reply. My RandomAccessFile is wrapped pretty tightly by my Data class. I don't think I want to pull any of it out at this point. I guess I'll take my chances with Data.close(). Thanks for your valuable input about the finalize() method. I also read that it may not always be called. Thanks again.

-Paula
 
Oh. Hi guys! Look at this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic