Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/metacosm/framework/event/RemoteEventLogger.java


1   /*
2       Metacosm, an object-oriented network game framework
3       Copyright (C) 1999-2001 Metacosm Development Team
4   
5       This program is free software; you can redistribute it and/or modify
6       it under the terms of the GNU General Public License as published by
7       the Free Software Foundation; either version 2 of the License, or
8       (at your option) any later version.
9   
10      This program 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
13      GNU General Public License for more details.
14  
15      You should have received a copy of the GNU General Public License
16      along with this program; if not, write to the Free Software
17      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19  
20  package org.metacosm.framework.event;
21  
22  import org.metacosm.util.StringKey;
23  import org.metacosm.util.MCEventDispatcher;
24  import org.metacosm.util.MCEventListener;
25  import org.metacosm.util.MCEvent;
26  import org.metacosm.util.AdminMessage;
27  
28  import org.metacosm.framework.server.AdminConsoleConnection;
29  
30  /**
31   * An RemoteEventLogger can be created on an AdminConsoleConnection
32   * to forward all or some debug messages to the remote administration ui.
33   * Later should be extended to forward a subset of messages.
34   */
35  final public class RemoteEventLogger implements MCEventListener {
36  
37    /**
38     * Public constructor, an adminConnection as parameter
39     * is mandatory.
40     */
41    public RemoteEventLogger(AdminConsoleConnection adminConnection) {
42      eventManager = EventManager.getInstance();
43      this.adminConnection = adminConnection;
44    }
45  
46    public void startEventForwarding() {
47      // For now, subscribe to "debug" events
48      eventManager.addListener(this, "all");
49    }
50  
51    public void stopEventForwarding() {
52      // For now, unsubscribe to "debug" events
53      eventManager.removeListener(this, "all");
54    }
55  
56    // TODO Not implemented
57    public void forwardEventType() {
58      // not implemented
59    }
60  
61    // TODO Not implemented
62    public void blockEventType() {
63      // not implemented
64    }
65  
66    public void adminMessageReceived(AdminMessage msg) {
67  
68      String str = EventManager.STRING_TYPE+ "=\"" + msg.getType()
69                 + "\" " + EventManager.STRING_TIMESTAMP + "=\""
70                 + msg.getAttribute(EventManager.STRING_TIMESTAMP)
71                 + "\" " + EventManager.STRING_SUBTYPE + "=\""
72                 + msg.getAttribute(EventManager.STRING_SUBTYPE)
73                 + "\" " + EventManager.STRING_DESCRIPTION + "=\""
74                 + msg.getAttribute(EventManager.STRING_DESCRIPTION) +"\"";
75      adminConnection.sendAdminMessage(str);
76    }
77  
78    public void MCEventReceived(MCEvent msg) {
79      if (msg instanceof AdminMessage) {
80        adminMessageReceived((AdminMessage) msg);
81      }
82    } 
83  
84    /**
85     * EventManager instance
86     */
87    private static EventManager eventManager;
88  
89    /**
90     * Reference to the connection to which the logs are forwarded.
91     */
92    private AdminConsoleConnection adminConnection;
93  }