Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Service interface extending Remote.

 
Mahendra Shelke
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers,

Javaranch has been always a great help to everyone seeking one, I really appreciate everyone's efforts in solving other's query.
I have a design question , I am not sure if it contradict's with Sun's requirement , as highlighted below;

In either case, the program must allow the user to specify the location of the database, and it must also accept an indication that a local database is to be used , in which case, the networking must be bypassed entirely.

I have a service interface which extends from Remote and two classes one for standalone viz. DirectUrlyBirdServiceImpl and another for RMI implementation (RemoteUrlyBirdServiceImpl) implement this interface. Out of which only RMIUnicastRemoteObject extends from UnicastRemoteObject out the two.

Please see the code snippet below;




UrlyBirdServiceFactory.getInstance() is being used when binding the remote object , and also while creating an instance of DirectUrlyBirdServiceImpl in Controller for direct connections.


Now whenever I run rmic tool on all the classes stub & skeleton are generated for both DirectUrlyBirdServiceImpl and RemoteUrlyBirdServiceImpl ( As UrlyBirdService is extending from Remote interface )

Is this approach correct ?

Am I contradicting SCJD's requirement mentioned above or other in any way ?

Though I am bypassing networking completely , I feel the generated stubs may send incorrect signals to the examiner , although stub & skeleton for DirectUrlyBirdServiceImpl can be very well suppressed , I do not feel it would be the right way of doing things.

I really appreciate your help on this.

Thanking in advance & wishing you all a very happy and prosperous new year!

Mahendra
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, Mahendra!

Champ, as long as the server code is not used, it's fine. The only thing I think I don't like about your design is that your DirectUrlyBirdServiceImpl class is to be used locally, but since the interface it implements extends Remote, then DirectUrlyBirdServiceImpl is Remote, which is sort of weird. Please take at this post, with a proposal of design that I think is more adequate. I think it might be helpful!

And finally, I myself didn't generate skeletons and stubs. I justified that I was using Java 6, and this was no longer necessary.
 
Mahendra Shelke
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy Roberto,

I am doing great , thanks for a prompt reply, I appreciate it.

UrlyBirdServiceFactory.getInstance() returns DirectUrlyBirdServiceImpl for direct connections and returns RemoteUrlyBirdServiceImpl in case of remote connections.

UrlyBirdService is a wrapper over low level DB operations , I am using it directly in my Controller , like

The real problem is UrlyBirdService is extending from Remote, which I cannot remove as there would be ClassCastException , after casting the object received from lookup.

So do you think DirectUrlyBirdServiceImpl extending from Remote is okay ?

I have been through the post you mentioned, I don't think my design is getting cloudier as of now , apart from the service extending Remote issue, I hope you agree.

Looking forward to your reply.

Thanks,
Mahendra
 
Roel De Nijs
Sheriff
Posts: 9828
103
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roberto Perillo wrote:Please take at this post, with a proposal of design that I think is more adequate.

I followed this approach too, although not exactly the same.

And I generated stubs and skeletons, because I didn't want to take the risk of automatic failure. If you use the Ant build script I created (see ScjdFaq for more info) it is just 1 line you have to (un)comment for using rmic or not.
 
Mahendra Shelke
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your quick reply Roel,

I have modified my design to include the following interface



UrlyBirdService no longer extends from Remote hence DirectUrlyBirdServiceImpl wont be a Remote object any more.

Please let me know if this makes sense ?


Thanks
Mahendra
 
Roel De Nijs
Sheriff
Posts: 9828
103
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mahendra Shelke wrote:Please let me know if this makes sense ?

Makes no sense at all in my opinion. Your direct interface has no relation anymore with the remote one. That will clutter up your code at the client side a lot, because you have to work with 2 distinct interfaces.
 
Mahendra Shelke
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Roel,

I guess you did not see the implementation properly or I miscommunicated.

These interfaces are not similar in anyway, I am only dealing with one interface ( UrlyBirdService ) in my Controller.

UrlyBirdRemoteService.getURLyBirdServiceInstance() will return UrlyBirdService instance which I'll use for invoking high level service actions.

UrlyBirdRemoteServiceImpl is only a wrapper for binding the remote object and implementing Remote.

Please let me know if its not making sense even now.

Thanks
Mahendra



 
Mahendra Shelke
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To make it cleaner, I have removed UrlyBirdRemoteServiceImpl class completely , and now RemoteUrlyBirdServiceImpl is implementing UrlyBirdRemoteService.

Please see the code below;




Thanks,
Mahendra

 
Roel De Nijs
Sheriff
Posts: 9828
103
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mahendra Shelke wrote:I guess you did not see the implementation properly or I miscommunicated.

Ok, I didn't see the implementation properly, but in my defense: having a UrlyBirdRemoteServiceImpl and a RemoteUrlyBirdServiceImpl is quiet confusing So it's a good thing you decided to remove one completely. But the functionality has changed: now each invocation of the getInstance method returns the same instance and before it always returned a new instance. I don't know if it's intentional (and your program needs it).
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, Mahendra!

I just didn't get well the point of your getInstance method: do you want your UrlyBirdRemoteServiceImpl class to be a singleton? I think it is better to only instantiate the business component when the application starts and use this instance throughout the code. How about something like this:

 
Mahendra Shelke
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:But the functionality has changed: now each invocation of the getInstance method returns the same instance and before it always returned a new instance. I don't know if it's intentional (and your program needs it).

No Roel , The functionality is exactly the same , If you see the implementation RemoteUrlyBirdServiceImpl , getURLyBirdServiceInstance() method always returns "this" which dosent make it a singleton.


 
Mahendra Shelke
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roberto Perillo wrote:Howdy, Mahendra!

I just didn't get well the point of your getInstance method: do you want your UrlyBirdRemoteServiceImpl class to be a singleton? I think it is better to only instantiate the business component when the application starts and use this instance throughout the code. How about something like this:


There is no singleton involved.

The basic problem I was facing was UrlyBirdService was also a Remote , It was difficult to remove as It would have thrown a Cast exception.
A simpler way of doing it was to create a new interface UrlyBirdRemoteService only to be implemented by Remote object , i.e RemoteUrlyBirdServiceImpl .

Now RemoteUrlyBirdServiceImpl is bound to the registry, and in the controller I simply do a getURLyBirdServiceInstance() on RemoteUrlyBirdServiceImpl , which returns me the UrlyBirdService.

This solves the purpose.
 
Roel De Nijs
Sheriff
Posts: 9828
103
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mahendra Shelke wrote:No Roel , The functionality is exactly the same , If you see the implementation RemoteUrlyBirdServiceImpl , getURLyBirdServiceInstance() method always returns "this" which dosent make it a singleton.

I have a different opinion, but maybe I'm missing something.



And as a side note: I don't get why you need this getURLyBirdServiceInstance-method
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:And as a side note: I don't get why you need this getURLyBirdServiceInstance-method


Me neither!
 
Mahendra Shelke
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roberto Perillo wrote:
Roel De Nijs wrote:And as a side note: I don't get why you need this getURLyBirdServiceInstance-method


Me neither!


You guys are right, ofcourse I dont need getInstance there , the reason I had added it because I was facing class cast exception , which was totally wierd , had forgotten to mention it , I have removed it now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic