• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Connecting from the Client to Local and Remote Server

 
Ranch Hand
Posts: 221
Scala Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everybody,


I am trying to come up with a clean API for my client to invoke My BusinessServices class
that I instatntiate in my GUI controller object.

I am following a similar approach to my BusinessServices class as it is described in the excellent postings
by Robert Perillo here and here.

Now somehow from my client, in this case the GUI Controller when I am working in standalone mode I need to pass the location (pathname) of the Database file,
and when I am working in a networked client mode I need to pass an IP address (or hostname) and a port number.

I am not sure if the path to go would be like making a Connector class like in the Monkhouse book you have a DvdConnector object for a direct connection and a different DvdConnector object
for a remote connection, where both DvdConnector objects have a different signature: pathname versus hostname and port number.


Any ideas? suggestions?

Thanks in advance,


Carlos.
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy, Carlos!!!

I am following a similar approach to my BusinessServices class as it is described in the excellent postings
by Robert Perillo here and here



Alright! Good choice!!!

Now somehow from my client, in this case the GUI Controller when I am working in standalone mode I need to pass the location (pathname) of the Database file, and when I am working in a networked client mode I need to pass an IP address (or hostname) and a port number.



Hum... how about arranging these objects when the application is starting? For instance, following the design proposed by me in these posts, you just need to have one constructor in your services class, which expects the interface provided by Sun (or your interface, if you created one that extends the interface provided by Sun). Now, when the application starts in standalone mode, you create the Data object and pass it to the services class. When it starts in server mode, you also create the Data object and pass it to the services class. The constructor of your GUI also has to have one constructor, which expects your services interface. In standalone mode, your GUI will have a reference to the DefaultServices class, and in client mode, your GUI will have a reference to the RMIRemoteServices, but since these 2 classes obey the Services API, then your GUI just needs a constructor expecting the Services interface. This way, you will promote polimorphism, since your GUI will work properly, but will not know where the data comes from.

The secret is connecting these objects properly when the application is starting.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Carlos,

My GuiController uses a LocalConnector and a RMIConnector to retrieve the appropriate connection. The first one just needs the dbLocation, The second one needs the server address and the port number.

Kind regards,
Roel
 
Carlos Morillo
Ranch Hand
Posts: 221
Scala Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Roberto,


I still don't quite clearly understand you, but
on the server side, that's exactly what I am doing.

The network server needs the pathname of the database file.

However, from the Controller in my GUI in standalone mode I should be able to instantiate the BusinessServices object.

In standalone I should be able to instantiate it just with the pathname of the database file.

In remote mode as a network client I should be able to instantiate it with the hostname/ip address and a port number.


I am going to try to take the approach with 2 different Connector objects like Roel.


Thanks,


Carlos.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Carlos,

The network server also needs the port it will run on. Actually the network server is not part of this discussion, because you have to start the registry and bind your business service implementation to the registry.

The constructor of my controller takes 3 arguments:
  • mode: the application mode in which the client application has to run (standalone or network)
  • database location: the path to the database file (in standalone mode) or the server's ip address (network mode)
  • port number: the port number the server application is running on (network mode)


  • And the rest of the constructor is nothing more than this code snippet:
    Kind regards,
    Roel
     
    Carlos Morillo
    Ranch Hand
    Posts: 221
    Scala Python Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Roel,


    Thanks.
    Yes, you are correct the network server also needs the port number where it's going to be bound to besides the pathname to the database file.

    By the way, I am getting very close to the end!


    Following the connector approach, I was able to start my network server in Solaris under NetBeans
    and connect 2 network clients: 1 from NetBeans in Solaris and 1 from my laptop in Windows XP and get the JTable object in their
    respective GUIs populated with all the Hotel Room records across the network:


    Thanks once again for your help!

    Carlos.
     
    Roberto Perillo
    Bartender
    Posts: 2292
    3
    Eclipse IDE Spring Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hey, Carlos!

    The network server needs the pathname of the database file.



    Exactly.

    Champion, here's an example of how you can do the stuff. This is the example I put in the article I wrote for a Java magazine here in Brazil (I'm trying to see with the guys of the magazine if I can translate it to english and put it on the internet). The example is a more complete, but try to see the modeling and see how you can connect the objects. In the example of the magazine, I said that it is possible to create an abstract class, called OKButtonListener, that is extended by StandaloneOKButtonListener and ClientOKButtonListener. The OKButtonListener has an abstract method called getServices(), that returns an implementation of the Services interface. The StandaloneOKButtonListener returns a DefaultServices object, and the ClientOKButtonListener returns a RMIRemoteServices object. You can then improve this design, and create an hierarchy of interfaces for each configuration window, etc. For this example, just notice the modeling and see how you can connect the objects.



    And that's it! Your window will not know whether the data is local or remote. In case of client mode, you instantiate a RMIRemoteServices object, based on the information the user provided in the configuration window and pass it to the MainWindow object.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic