1 /*------------------------------------------------------------------------------
  2 Name:      NotificationHandler.java
  3 Project:   xmlBlaster.org
  4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
  5 ------------------------------------------------------------------------------*/
  6 
  7 package org.xmlBlaster.client.jmx;
  8 import javax.management. *;
  9 import org.xmlBlaster.client.I_Callback;
 10 import org.xmlBlaster.util.admin.extern. *;
 11 import org.xmlBlaster.client.I_XmlBlasterAccess;
 12 import org.xmlBlaster.client.qos. *;
 13 import org.xmlBlaster.client.key. *;
 14 import org.xmlBlaster.util.Global;
 15 import java.util.Properties;
 16 import org.xmlBlaster.util.qos.address.Address;
 17 import javax.swing.JPanel;
 18 import java.util.logging.Logger;
 19 import java.util.logging.Level;
 20 import java.io. *;
 21 import org.xmlBlaster.jmxgui.JmxPlugin;
 22 
 23 /**
 24  * Client-sided NotificationHandler<br>
 25  * Takes subscribtions to Notifications from clients. Invokes a server-sided<br>
 26  * subscription<p>
 27  * Update is called, whenever a Notification-event is sent back from the server
 28  */
 29 public class NotificationHandler implements I_Callback {
 30    private static Logger log = Logger.getLogger(NotificationHandler.class.getName());
 31    private static int port = 3424;
 32    private I_XmlBlasterAccess returnCon;
 33    private Global glob;
 34    private SerializeHelper serHelp;
 35 
 36    private String ME = "NotificationHandler";
 37    private JmxPlugin panel;
 38 
 39    private String beanSource = "";
 40    private AsyncMBeanServer server;
 41    private ObjectName objectName;
 42 
 43    public NotificationHandler(String strObjectName, String className, JmxPlugin panel, AsyncMBeanServer server) {
 44       this.server = server;
 45       this.beanSource = strObjectName;
 46       try {
 47          this.glob = Global.instance();
 48 
 49          if (log.isLoggable(Level.FINER))
 50             log.severe("Constructor for '" + strObjectName + "' of class '" + className + "'");
 51 
 52          this.objectName = new ObjectName(strObjectName);
 53 //      this.glob = Global.instance().getClone(null);
 54 
 55          serHelp = new SerializeHelper(glob);
 56          this.panel = panel;
 57          //connect to embedded xmlBlaster
 58 /*      Address addr = new Address(glob);
 59       addr.setPort(port);*/
 60 
 61 //      Properties prop = new Properties();
 62 //      prop.setProperty("bootstrapHostname","127.0.0.1");
 63 //      prop.setProperty("bootstrapPort","3424");
 64 
 65 //      this.glob.init(prop);
 66 
 67 //      glob.setBootstrapAddress(addr);
 68          returnCon = glob.getXmlBlasterAccess();
 69          SubscribeKey subKey = new SubscribeKey(this.glob, "xmlBlasterMBeans_Notification");
 70          log.info("NotificationHandler... Trying to connect to service...");
 71          SubscribeQos    sQos = new SubscribeQos(this.glob);
 72 
 73          sQos.setWantLocal(false);
 74 //      if (!returnCon.isConnected()) {
 75 //         ConnectQos qos = new ConnectQos(this.glob, "InternalConnector", "connector");
 76 //         ConnectReturnQos rQos = returnCon.connect(qos, this);
 77 
 78 //         ConnectReturnQos rQos = returnCon.connect(qos, null);
 79 //      }
 80 //      returnCon.subscribe(subKey, sQos, this);
 81          returnCon.subscribe(subKey, sQos, this);
 82          NotificationFilter filter = new UserFilter();
 83 
 84          server.addNotificationListener(objectName, className, filter);
 85       }
 86       catch (Exception ex) {
 87          log.severe("Error when invoking internal Server for Connector: " + ex.toString());
 88          ex.printStackTrace();
 89       }
 90    }
 91    public void unregister() {
 92       server.removeNotificationListener(this.objectName);
 93    }
 94    public String update(String cbSessionId, UpdateKey updateKey, byte [] content, UpdateQos updateQos)
 95    {
 96       Notification    notif = null;
 97 
 98       log.info("Received Notification....");
 99       try {
100          notif = (Notification) serHelp.deserializeObject(content);
101       }
102       catch (IOException ex) {
103       }
104       if (this.beanSource.equals(notif.getSource().toString())) {
105          log.info("sending update to panel: " + notif.getSource());
106          panel.update();
107       }
108       return "";
109    }
110    }


syntax highlighted by Code2HTML, v. 0.9.1