creating reusable modules
Asked Answered
D

1

7

I'm writing a big Red5 Java application for the web. Red5 a Flash Media Server alternative that is java based and is written with the spring framework.

I want to have many versions of my application online, each with different behaviors and different classes enabled or disabled.

I'm looking for a way to convert my code into modules based code that will allow me to remove/add modules/features from the main application.

I know about OSGI http://www.springsource.org/osgi but it says that it needs a SpringSource dm server and I have no idea how it's gonna work together in red5 and it's seems very complicated to fully understand.

I don't have a good knowledge of spring framework in general, i work with it db-related and that's it. red5 uses it more extensively.

so can anyone please make any sense from this information ? is there something that can be done to divide my code to modules ?

any information regarding the issue would be greatly appreciated.

Driskell answered 26/7, 2012 at 12:30 Comment(0)
L
4

My preferred method of dealing with this kind of situation is Dependancy Injection (DI). Spring has a DI capability built in, for which a tutorial is easy to find online. However, Spring's DI is not as good, for many reasons, as that provided by Guice, which I would highly recommend. (The main advantage of Guice over Spring's DI in my opinion is type safety.)

DI is basically a mechanism for replacing class implementations at runtime. Rather than hard code dependancies into classes (by having a class construct other classes directly for example) you code them to have their dependant classes passed to them in their constructors. The DI framework will then pass the correct instances at runtime according to the configuration. Spring configuration can be done via annotations or an XML file, Guice uses a subclass of com.google.inject.AbstractModule.

So you could use different configuration files for the different instances of your application, and have them provide different sets of features for activation, or indeed different implementations of the same feature. If you set up the application to use this technique then the only thing that need differ between instances is a single configuration file.

Lyautey answered 30/7, 2012 at 16:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.