1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.talika.tarsis.service;
24
25 import org.talika.tarsis.context.Context;
26 import org.talika.tarsis.log.Logger;
27
28 /**
29 * Base implementation of <code>Service</code> interface.
30 *
31 * @author Jose M. Palomar
32 * @version $Revision: 269 $
33 */
34 public abstract class AbstractService implements Service {
35
36
37
38
39 /**
40 * Tarsis context.
41 */
42 private Context context;
43
44 /**
45 * Tarsis logger.
46 */
47 private Logger logger;
48
49
50 /**
51 * Creates a new <code>AbstractService</code> object.
52 */
53 public AbstractService() {
54 }
55
56
57 /**
58 * Called by the framework to indicate that is being placed into service.
59 *
60 * @param context Context context that initialized service.
61 * @throws ServiceException if an exception has occurred that interferes with the
62 * services's normal operation
63 * @see org.talika.tarsis.service.Service#init(Context)
64 */
65 public void init(Context context) throws ServiceException {
66 this.context = context;
67 this.logger = context.getLogger();
68
69 if (this.logger.isInfoEnabled()) {
70 this.logger.logInfo(getName() + ": init");
71 }
72 }
73
74 /**
75 * Called by the framework to indicate that is being placed out of service.
76 *
77 * @see org.talika.tarsis.service.Service#destroy()
78 */
79 public void destroy() {
80 if (this.logger.isInfoEnabled()) {
81 this.logger.logInfo(getName() + ": destroy");
82 }
83
84 this.logger = null;
85 this.context = null;
86 }
87
88 /**
89 * Returns name of service.
90 *
91 * @return String name of service.
92 * @see org.talika.tarsis.service.Service#getName()
93 */
94 public abstract String getName();
95
96 /**
97 * Returns the Tarsis context.
98 *
99 * @return Context the Tarsis context.
100 */
101 protected final Context getContext() {
102 return context;
103 }
104
105 /**
106 * Returns the Tarsis logger.
107 *
108 * @return Logger the Tarsis logger.
109 */
110 protected final Logger getLogger() {
111 return logger;
112 }
113
114 }