KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > server > Service


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2002 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.server;
20
21 import java.lang.reflect.InvocationTargetException JavaDoc;
22 import java.lang.reflect.Method JavaDoc;
23
24 import org.lucane.common.Message;
25 import org.lucane.common.net.ObjectConnection;
26
27 /**
28  * This interface has to be implemented by a service in order to run
29  * inside the server as an internal service and not requiring opening a new port
30  * and running a distinct processus.
31  */

32 public abstract class Service
33 {
34   /**
35    * Get a service class name
36    *
37    * @return the class name
38    */

39   public String JavaDoc getName()
40   {
41     return this.getClass().getPackage().getName();
42   }
43
44   /**
45    * Return the service base directory
46    *
47    * @return the service directory
48    */

49   public String JavaDoc getDirectory()
50   {
51     String JavaDoc pack = this.getClass().getPackage().getName();
52     String JavaDoc url = "jar:file:///" + Server.getInstance().getWorkingDirectory()
53                 + Server.APPLICATIONS_DIRECTORY + pack + ".jar!/";
54     return url.replace('\\', '/');
55   }
56
57   /**
58    * Invoke a method
59    *
60    * @param method the method name
61    * @param types the params types
62    * @param params the params
63    * @return the method result
64    */

65   public Object JavaDoc invoke(String JavaDoc method, Class JavaDoc[] types, Object JavaDoc[] params)
66   throws SecurityException JavaDoc, NoSuchMethodException JavaDoc, IllegalArgumentException JavaDoc, IllegalAccessException JavaDoc, InvocationTargetException JavaDoc
67   {
68     Method JavaDoc m = this.getClass().getDeclaredMethod(method, types);
69     return m.invoke(this, params);
70   }
71   
72   /**
73    * Called each time a request for this service has to be treated.
74    *
75    * @param oc the connection
76    * @param message the message
77    */

78   public abstract void process(ObjectConnection oc, Message message);
79
80   /**
81    * Initialize the service.
82    * Called every time the server is started.
83    *
84    * @param parent the Server
85    */

86   public void init(Server parent) {}
87
88   /**
89    * Install the service.
90    * Only called the first time a service is initialized.
91    */

92   public void install() {}
93   
94   /**
95    * Shutdown the service.
96    * Called at server shutdown
97    */

98   public void shutdown() {}
99 }
100
Popular Tags