KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > qfs > apps > qflog > LogServerImpl


1 // {{{ copyright
2

3 /********************************************************************
4  *
5  * $Id: LogServerImpl.java,v 1.10 2000/07/05 14:07:43 gs Exp $
6  *
7  * The contents of this file are subject to the Mozilla Public
8  * License Version 1.1 (the "License"); you may not use this file
9  * except in compliance with the License. You may obtain a copy of
10  * the License at http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS
13  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14  * implied. See the License for the specific language governing
15  * rights and limitations under the License.
16  *
17  * The Original Code is qfs.de code.
18  *
19  * The Initial Developer of the Original Code is Gregor Schmid.
20  * Portions created by Gregor Schmid are
21  * Copyright (C) 1999 Quality First Software, Gregor Schmid.
22  * All Rights Reserved.
23  *
24  * Contributor(s):
25  *
26  *******************************************************************/

27
28 // }}}
29

30 package de.qfs.apps.qflog;
31
32 // {{{ imports
33

34 import java.rmi.RemoteException JavaDoc;
35 import java.rmi.server.UnicastRemoteObject JavaDoc;
36
37 import java.util.Hashtable JavaDoc;
38
39 import de.qfs.lib.log.Log;
40 import de.qfs.lib.log.Logger;
41 import de.qfs.lib.logrmi.LogListener;
42 import de.qfs.lib.logrmi.RemoteLogLevelListener;
43 import de.qfs.lib.logrmi.LogServerImplBase;
44
45 import de.qfs.apps.qflog.logview.LogLevelTreeModel;
46
47 // }}}
48

49 /**
50  * An implementation of the LogServer interface.
51  *
52  * This particular server will bring up a window for every connected
53  * client.
54  *
55  * @author Gregor Schmid
56  * @version $Revision: 1.10 $
57  */

58 public class LogServerImpl
59     extends LogServerImplBase
60 {
61     // {{{ variables
62

63     /**
64      * The Logger used for logging.
65      */

66     private final static Logger logger = new Logger (LogServerImpl.class);
67
68     // }}}
69

70     // {{{ constructors
71

72     /**
73      * Construct a new LogServerImpl.
74      *
75      * @throws RemoteException If something RMI specific goes wrong.
76      */

77     public LogServerImpl ()
78          throws RemoteException JavaDoc
79     {
80         if (logger.level >= Log.MTD) {
81             logger.log(Log.MTD, "LogServerImpl()", "");
82         }
83     }
84
85     // }}}
86

87     //----------------------------------------------------------------------
88
// The LogServer interface
89
//----------------------------------------------------------------------
90
// {{{ getId
91

92     /**
93      * Get an Id for a new client. Different clients may connect under the same
94      * name, so this identification mechanism is required to differentiate
95      * between them.
96      *
97      * @return A unique handle identifying the client to the server.
98      */

99     public int getId(String JavaDoc clientName)
100         throws RemoteException JavaDoc
101     {
102         if (logger.level >= Log.MTD) {
103             logger.log(Log.MTD, "getId(String)",
104                        logger.level < Log.MTDDETAIL ? "" :
105                        "clientName: " + clientName);
106         }
107         return Model.instance().getNewId(clientName);
108     }
109
110     // }}}
111
// {{{ getLogListener
112

113     /**
114      * Get a LogListener for a client.
115      *
116      * @param id The client identifier obtained with {@link #getId
117      * getId}.
118      *
119      * @return The LogListener
120      *
121      * @throws RemoteException If something RMI specific goes wrong.
122      */

123     public LogListener getLogListener (int id)
124          throws RemoteException JavaDoc
125     {
126         if (logger.level >= Log.MTD) {
127             logger.log(Log.MTD, "getLogListener(int)",
128                        logger.level < Log.MTDDETAIL ? "" :
129                        "id: " + id);
130         }
131
132         LogListenerImpl listener = Model.instance().getListener(id);
133         if (listener == null) {
134             listener = new LogListenerImpl (id);
135             Model.instance().setListener(id, listener);
136         }
137         return listener;
138     }
139
140     // }}}
141
// {{{ getLogLevelListener
142

143     /**
144      * Get a LogLevelListener for a client.
145      *
146      * @param id The client identifier obtained with {@link #getId
147      * getId}.
148      *
149      * @return The LogLevelListener
150      *
151      * @throws RemoteException If something RMI specific goes wrong.
152      */

153     public RemoteLogLevelListener getLogLevelListener (int id)
154          throws RemoteException JavaDoc
155     {
156         if (logger.level >= Log.MTD) {
157             logger.log(Log.MTD, "getLogLevelListener(int)",
158                        logger.level < Log.MTDDETAIL ? "" :
159                        "id: " + id);
160         }
161
162         try {
163             LogLevelTreeModel levels = new LogLevelTreeModel ();
164             RemoteLogLevelCallbackAdapter adapter =
165                 new RemoteLogLevelCallbackAdapter (levels);
166             Model.instance().setLogLevelListener(id, adapter);
167             return adapter;
168         } catch (Exception JavaDoc ex) {
169             if (logger.level >= Log.ERR) {
170                 logger.log("getLogListener(int)", ex);
171             }
172             return null;
173         }
174     }
175
176     // }}}
177
// {{{ disconnect
178

179     /**
180      * Disconnect the client from the server.
181      *
182      * @param id The client identifier obtained with {@link #getId
183      * getId}.
184      *
185      * @throws RemoteException If something RMI specific goes wrong.
186      */

187     public void disconnect(int id)
188          throws RemoteException JavaDoc
189     {
190         if (logger.level >= Log.MTD) {
191             logger.log(Log.MTD, "disconnect(int)",
192                        logger.level < Log.MTDDETAIL ? "" :
193                        "id: " + id);
194         }
195         LogListener logListener = Model.instance().getListener(id);
196         if (logListener != null) {
197             logListener.disconnect();
198         }
199
200         RemoteLogLevelListener logLevelListener =
201             Model.instance().getLogLevelListener(id);
202         if (logLevelListener != null) {
203             logLevelListener.disconnect();
204         }
205     }
206
207     // }}}
208
}
209
210
Popular Tags