Esempio n. 1
0
 /** Private constructor */
 private ProtocolManager() {
   super();
   conf = FileConfigService.getService();
   ev = EventDispatcher.getInstance();
   ev.addProducer(Constants.PROTOCOL_MANAGER_PRODUCER_ID);
   ev.addProducer(Constants.SENSOR_STATE_PRODUCER_ID);
 }
Esempio n. 2
0
  /* (non-Javadoc)
   * @see jcu.sal.managers.ManagerFactory#build(org.w3c.dom.Document)
   */
  @Override
  protected AbstractProtocol build(ProtocolConfiguration config, Identifier id)
      throws ComponentInstantiationException {
    AbstractProtocol p = null;
    String type = config.getType();
    ProtocolID i = (ProtocolID) id;
    try {

      // logger.debug("building AbstractProtocol type: " + type);
      String className = PluginList.getProtocolClassName(type);

      Class<?>[] params = {ProtocolID.class, ProtocolConfiguration.class};
      Constructor<?> c = Class.forName(className).getConstructor(params);
      Object[] o = new Object[2];
      o[0] = i;
      o[1] = config;
      // logger.debug("AbstractProtocol config: " + XMLhelper.toString(config));
      p = (AbstractProtocol) c.newInstance(o);
      // logger.debug("done building protocol "+p.toString());
    } catch (Throwable e) {
      logger.error("Error in new protocol instanciation.");
      e.printStackTrace();
      logger.error("XML doc:\n");
      logger.error(config.getXMLString());
      throw new ComponentInstantiationException("Unable to instantiate component", e);
    }

    // check if there are other instances of the same type
    try {
      if (!p.supportsMultipleInstances() && getComponentsOfType(type).size() != 0) {
        logger.debug(
            "Found another instance of type '"
                + type
                + "' which doesnt support multiple instance, deleting this protocol");
        throw new ComponentInstantiationException(
            "Found another instance of type '"
                + type
                + "' which doesnt support multiple instances");
      }
    } catch (NotFoundException e) {
    } // no other instances

    // Parse the protocol's configuration
    try {
      p.parseConfig();
    } catch (ConfigurationException e1) {
      logger.error("Error in the protocol configuration:\n" + e1.getMessage());
      // e1.printStackTrace();
      throw new ComponentInstantiationException();
    }

    // save protocol config
    conf.addProtocol(config);

    ev.queueEvent(
        new ProtocolListEvent(
            ProtocolListEvent.PROTOCOL_ADDED, i.getName(), Constants.PROTOCOL_MANAGER_PRODUCER_ID));
    logger.debug("Created protocol '" + config.getID() + "' - type: " + type);
    return p;
  }
Esempio n. 3
0
 /* (non-Javadoc)
  * @see jcu.sal.managers.ManagerFactory#remove(java.lang.Object)
  */
 @Override
 protected void remove(AbstractProtocol component) {
   ProtocolID pid = component.getID();
   // logger.debug("Removing protocol " + pid.toString());
   component.remove(this);
   /**
    * the sensors associated with the protocol must be removed AFTER the protocol otherwise the
    * autodetection could try and create them again between the moment we remove them and the
    * moment we remove the protocol
    */
   SensorManager.getSensorManager().destroyComponents(component.getSensors());
   componentRemovable(pid);
   ev.queueEvent(
       new ProtocolListEvent(
           ProtocolListEvent.PROTOCOL_REMOVED,
           component.getID().getName(),
           Constants.PROTOCOL_MANAGER_PRODUCER_ID));
   logger.debug(
       "Removed protocol '" + component.getID().getName() + "' - type: " + component.getType());
 }