Tesuji
08-26-2005, 09:38 AM
In the project I'm currently working on we have a dozen components that each run in their own thread. They communicate with each other asynchronously over a bus.
Spring seemed perfect for configuring these components (and quite a few others) and defining their relationships. At the moment I have a kind of glue component that instantiates all the components, connects them up and then starts the threads. At shutdown it is responsible for stopping the components.
Instantiating all the components and connecting them up I can do through Spring and it will clean up the code tremendously. But I don't see how to do the startup process and shutdown process through Spring, so I still need my glue component.
For example (consider ServerComponent as my glue component):
class ServerComponent
{
Component component1;
Component component2;
Component component3;
public ServerComponent()
{
component1 = new RequestHandler();
component2 = new RequestDistributor();
component3 = new OrderProcessor(component1,component2);
}
public void StartUp()
{
// The order of starting and stopping is important.
component1.Start();
component2.Start();
component3.Start();
}
public void ShutDown()
{
component3.Stop();
component2.Stop();
component1.Stop();
}
}
My question is: how can I do this using Spring so that I don't need my glue. The start-up is doable, but I don't see how I can define the shutdown process. I can't rely on the finalizers to be called. That is a pity, as the glue component doesn't have any real function itself except for the starting and stopping.
I would appreciate any ideas.
Spring seemed perfect for configuring these components (and quite a few others) and defining their relationships. At the moment I have a kind of glue component that instantiates all the components, connects them up and then starts the threads. At shutdown it is responsible for stopping the components.
Instantiating all the components and connecting them up I can do through Spring and it will clean up the code tremendously. But I don't see how to do the startup process and shutdown process through Spring, so I still need my glue component.
For example (consider ServerComponent as my glue component):
class ServerComponent
{
Component component1;
Component component2;
Component component3;
public ServerComponent()
{
component1 = new RequestHandler();
component2 = new RequestDistributor();
component3 = new OrderProcessor(component1,component2);
}
public void StartUp()
{
// The order of starting and stopping is important.
component1.Start();
component2.Start();
component3.Start();
}
public void ShutDown()
{
component3.Stop();
component2.Stop();
component1.Stop();
}
}
My question is: how can I do this using Spring so that I don't need my glue. The start-up is doable, but I don't see how I can define the shutdown process. I can't rely on the finalizers to be called. That is a pity, as the glue component doesn't have any real function itself except for the starting and stopping.
I would appreciate any ideas.