Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • 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
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

observer and observable

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ,
i need to create 2 vectors which are observed and as soon as they r changed(vectors) , an intimation should be given .
i want to use Observer interface and Observable class for this . i want to understand how the flow goes between the update() method and hasChanged() method and notifyObservers() method .
could u help me with this please . i need this very urgently .
shalu
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a lovely example of an observed object in this article: http://developer.java.sun.com/developer/qow/archive/59/index.html
The one problem that I see is that to be an observed object, the class needs to extend observble. Vector does not extend observable (it already extends AbstractList).
However if you make a class ObservedVector extends observable and it just happens to have a Vector (and not much else) in it, you should be able to achieve a similar result.
 
shalu saxena
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanx cindy . i have one more problem now . i have to monitor a database , for which i have 2 classes , one in which i change the database and another in which i override the update() method of Observer interface and accordingly take required action . i have these 2 classes on different machines . if in the first class(in which i am changing the database) , i extend Observable , do i have to put the setChanged() and notifyObservers() methods ? is there any way in which i can have a class which observes the database on 1 machine , and a class which changes the database on another machine ? I again need this urgently .
shalu
 
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well yes, you can do that. You need to set it up as an RMI (Remote Method invocation) or use a Corba tool (Object Broker) or J2EE etc.
RMI is probably the best approach unless you are already inbolved with one of the other methodologies. This sets up stubs and skeletons on each of the machines and shuffles the requests back and forth. We have a forum here for each of the above topics.
 
shalu saxena
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanx again cindy . that was helpful . could u give me some idea how could i do it with rmi ?
shalu
 
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Start by reading this.
http://java.sun.com/products/jdk/rmi/
Then ask any questions in the RMI forum here a JavaRanch.
 
reply
    Bookmark Topic Watch Topic
  • New Topic