• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

How to add new feature to your application without bringing it down

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Consider I need to build a process to add client details. Today the application has 5 different type of customer.

pseudo code is like this



The process is up and running

Tomorrow a new type of customer is added by the business. Now how should I have written the process so that I can implement the new change without bringing down the existing process?

Looking at various options one thing that caught my eye is the use of Class.forName

Basically the solution would be to Build an interface CustomerType which has a method processCustomer() and create 5 Class (One for each customer type) which implements the interface CustomerType .

And the process code would be something like this



But this look to be error prone as it’s depending on the runtime input. And also can the new class added to the application can be implemented without stopping the running process. I tried but could not do it.
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm how different is the processCustomerTypeX() method between different types?

If you want to be the processXXX as generic as possible, you may want to look into Executor/Runnable/Callable. But then somewhere you will need to do a type check.

Unless the object/class the customer is calling can be configured using database table or properties file. That way, modifying this table/file will be sufficient and no code changes.
 
Marshal
Posts: 75719
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at Kendall Ponder's app in this thread. If he wants to add an option to his menu, how is he going to do it?
 
Karthick Pattabiraman
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Look at Kendall Ponder's app in this thread. If he wants to add an option to his menu, how is he going to do it?



Are you referring to the ENUM approach?

I did worked out a solution using HashMap Something like this



But here again I need to change the code (add to HashMap) if I add a new customer.
 
Campbell Ritchie
Marshal
Posts: 75719
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But in both those approaches the changes to code are minimal. If your CustomerX class is a true subclass of your plain simple Customer, then won't it work if you add a new customer type like that.

You can have configuration files which you add customer types too. Or you can have databases which you add customer types to. But you will have to write some code somewhere whichever approach you take.
 
Saloon Keeper
Posts: 9285
78
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Karthick Pattabiraman wrote:Consider I need to build a process to add client details. Today the application has 5 different type of customer.
The process is up and running
Tomorrow a new type of customer is added by the business. Now how should I have written the process so that I can implement the new change without bringing down the existing process?
But this look to be error prone as it’s depending on the runtime input. And also can the new class added to the application can be implemented without stopping the running process. I tried but could not do it.


My take on this is that you have a process that is up and running 24/7 and you want to make changes without bringing it down. This usually involves having two or more copies of your program with a simple load balancer as a front end. Then you can temporarily suspend one of the running programs and bring it back on-line as a new version of the program. In the mean time the other running copies are handling the load. Repeat until all running copies have been updated.
 
Campbell Ritchie
Marshal
Posts: 75719
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ooooooooooh! Is that what bringing down means? Sorry, I misunderstood that bit.
 
Karthick Pattabiraman
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:But in both those approaches the changes to code are minimal. If your CustomerX class is a true subclass of your plain simple Customer, then won't it work if you add a new customer type like that.

You can have configuration files which you add customer types too. Or you can have databases which you add customer types to. But you will have to write some code somewhere whichever approach you take.



Sorry for going back and forth on this. All my life I have been a PL/SQL programmer. So this is kind of new.

So if I have the configuration stored in a DB table and I load the HashMap from that. I actually don't have to change the existing code. All I have to do is create a new class CustomerF. And in the DB add entry for this. Good so far. But if the current application is running do I have to bring down it to deploy the new class?

 
Karthick Pattabiraman
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:

Karthick Pattabiraman wrote:Consider I need to build a process to add client details. Today the application has 5 different type of customer.
The process is up and running
Tomorrow a new type of customer is added by the business. Now how should I have written the process so that I can implement the new change without bringing down the existing process?
But this look to be error prone as it’s depending on the runtime input. And also can the new class added to the application can be implemented without stopping the running process. I tried but could not do it.


My take on this is that you have a process that is up and running 24/7 and you want to make changes without bringing it down. This usually involves having two or more copies of your program with a simple load balancer as a front end. Then you can temporarily suspend one of the running programs and bring it back on-line as a new version of the program. In the mean time the other running copies are handling the load. Repeat until all running copies have been updated.



Thanks. Yes that's exactly what I am trying to figure out. So does that mean there is no approach to deploy a code change to a running application (I don't even know if that's a stupid question :-)).
 
Carey Brown
Saloon Keeper
Posts: 9285
78
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
 
Campbell Ritchie
Marshal
Posts: 75719
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:This is no longer a "beginner" thread.

Agree. Moving discussion.

Yes, I think it is possible to recompile code on the fly. And it is possible to load new classes onto a running application. But I don't know how to do it. I am sure it is something you have to do very carefully.
 
I like tacos! And this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic