01: package org.cougaar.demo.mandelbrot.v2;
02:
03: import org.cougaar.core.component.ComponentSupport;
04: import org.cougaar.core.component.ServiceBroker;
05: import org.cougaar.core.component.ServiceProvider;
06:
07: /**
08: * This component is a base class that advertises the {@link FractalService}.
09: */
10: public abstract class CalculatorBase extends ComponentSupport {
11:
12: private ServiceProvider sp;
13:
14: public void load() {
15: super .load();
16:
17: // wrap our "calculate" method as a service
18: FractalService svc = new FractalService() {
19: public byte[] calculate(int width, int height,
20: double min_x, double max_x, double min_y,
21: double max_y) {
22: return CalculatorBase.this .calculate(width, height,
23: min_x, max_x, min_y, max_y);
24: }
25: };
26:
27: // advertise our service
28: sp = new TrivialServiceProvider(svc);
29: sb.addService(FractalService.class, sp);
30: }
31:
32: public void unload() {
33: // shutting down, revoke our service
34: if (sp != null) {
35: sb.revokeService(FractalService.class, sp);
36: sp = null;
37: }
38:
39: super .unload();
40: }
41:
42: /** Implement this method. */
43: protected abstract byte[] calculate(int width, int height,
44: double min_x, double max_x, double min_y, double max_y);
45:
46: private static final class TrivialServiceProvider implements
47: ServiceProvider {
48: private final Object svc;
49:
50: public TrivialServiceProvider(Object svc) {
51: this .svc = svc;
52: }
53:
54: public Object getService(ServiceBroker sb, Object requestor,
55: Class serviceClass) {
56: return svc;
57: }
58:
59: public void releaseService(ServiceBroker sb, Object requestor,
60: Class serviceClass, Object service) {
61: }
62: }
63: }
|