Beispiel #1
0
  @Override
  public String toString(MMObjectNode n) {
    try {
      int snumber = n.getIntValue("snumber");
      int dnumber = n.getIntValue("dnumber");
      int rnumber = n.getIntValue("rnumber");

      String sourceName = mmb.getTypeDef().getValue(snumber);
      String destName = mmb.getTypeDef().getValue(dnumber);

      if (sourceName == null) {
        sourceName = "unknown builder '" + snumber + "'";
      }
      if (destName == null) {
        destName = "unknown builder '" + dnumber + "'";
      }

      // unfilled should only happen during creation of the node.
      String source = snumber > -1 ? (sourceName + "(" + snumber + ")") : "[unfilled]";
      String destination = dnumber > -1 ? (destName + "(" + dnumber + ")") : "[unfilled]";
      MMObjectNode role = rnumber > -1 ? mmb.getRelDef().getNode(rnumber) : null;
      return source
          + "->"
          + destination
          + " ("
          + (role != null ? role.getStringValue("sname") : "???")
          + ") "
          + (isVirtual() ? "(virtual)" : "");
    } catch (Exception e) {
      log.warn(e);
    }
    return "typerel-node";
  }
Beispiel #2
0
 @Override
 public URI getUri() {
   try {
     ResourceLoader loader = ResourceLoader.Type.valueOf(resourceType.toUpperCase()).get();
     return loader.getResource(getResource()).toURI();
   } catch (URISyntaxException use) {
     log.warn(use);
     return null;
   }
 }
Beispiel #3
0
 @Override
 public boolean inIndex(String identifier) {
   CloseableIterator<JdbcEntry> i = getSqlCursor(getFindSql(identifier));
   boolean result = i.hasNext();
   try {
     i.close();
   } catch (IOException ex) {
     log.warn(ex);
   }
   return result;
 }
Beispiel #4
0
 /**
  * Returns the display string for this node It returns a commbination of objecttypes and rolename
  * : "source->destination (role)".
  *
  * @param node Node from which to retrieve the data
  * @return A <code>String</code> describing the content of the node
  */
 @Override
 public String getGUIIndicator(MMObjectNode node) {
   try {
     String source = mmb.getTypeDef().getValue(node.getIntValue("snumber"));
     String destination = mmb.getTypeDef().getValue(node.getIntValue("dnumber"));
     MMObjectNode role = mmb.getRelDef().getNode(node.getIntValue("rnumber"));
     return source
         + "->"
         + destination
         + " ("
         + (role != null ? role.getGUIIndicator() : "???")
         + ")";
   } catch (Exception e) {
     log.warn(e);
   }
   return null;
 }
Beispiel #5
0
 /**
  * Change the maximum size of the table. This may result in removal of entries in the table.
  *
  * @param size the new desired size
  */
 @Override
 public void setMaxSize(int size) {
   if (size < 0) {
     throw new IllegalArgumentException("Cannot set size to negative value " + size);
   }
   maxSize = size;
   synchronized (backing) {
     while (size() > maxSize) {
       try {
         Iterator<K> i = keySet().iterator();
         i.next();
         i.remove();
       } catch (Exception e) {
         log.warn(e);
         // ConcurentModification?
       }
     }
   }
 }
Beispiel #6
0
  /**
   * Configures the framework by reading its configuration file 'config/framework.xml' containing a
   * list with UrlConverters.
   */
  protected final void configure(Element el) {
    try {
      description.fillFromXml("description", el);

      NodeList urlconverters = el.getElementsByTagName("urlconverter");
      for (int i = 0; i < urlconverters.getLength(); i++) {
        Element element = (Element) urlconverters.item(i);
        UrlConverter uc;
        try {
          uc = (UrlConverter) Instantiator.getInstance(element, (Framework) this);
        } catch (NoSuchMethodException nsme) {
          uc = (UrlConverter) Instantiator.getInstance(element);
        } catch (ClassNotFoundException cnfe) {
          log.warn(org.mmbase.util.xml.XMLWriter.write(element) + " " + cnfe);
          continue;
        } catch (Throwable t) {
          log.error(org.mmbase.util.xml.XMLWriter.write(element) + ": " + t.getMessage(), t);
          if (t.getCause() != null) {
            log.error("Caused by: " + t.getCause().getMessage(), t.getCause());
          }
          continue;
        }
        urlConverter.add(uc);
      }
      parDef = null;

    } catch (Throwable e) {
      log.error(e.getMessage(), e);
    }
    /*
    BasicUrlConverter buc = new BasicUrlConverter(this);
    if (! urlConverter.contains(buc)) {
        urlConverter.add(buc);
    }
    */
    log.info(
        "Configured with "
            + el.getOwnerDocument().getDocumentURI()
            + " "
            + getClass()
            + " "
            + this);
  }
Beispiel #7
0
  /*
   * (non-Javadoc)
   * @see org.mmbase.module.core.MMObjectBuilder#notify(org.mmbase.core.event.NodeEvent)
   */
  @Override
  public void notify(NodeEvent event) {
    if (log.isDebugEnabled()) {
      log.debug(
          "Changed "
              + event.getMachine()
              + " "
              + event.getNodeNumber()
              + " "
              + event.getBuilderName()
              + " "
              + NodeEvent.newTypeToOldType(event.getType()));
    }
    if (tableName.equals(event.getBuilderName())) {
      if (event.getType() == Event.TYPE_NEW) {
        MMObjectNode typeRelNode = getNode(event.getNodeNumber());
        if (typeRelNode != null) {
          Set<MMObjectNode> newTypeRels = addCacheEntry(typeRelNode, true);
          log.service("Added to typerelcache: " + newTypeRels);
        } else {
          log.warn("Could not found typerel node with number " + event.getNodeNumber());
        }

      } else {
        // something else changed in a typerel node? reread the complete typeRelNodes Set
        log.service(
            "Received '" + event + "' which is about typrels. Now re-reading the entire cache");
        readCache();
      }
      // also, clear all query-caches, because result may change by this. See MMB-348
      for (Cache qc : CacheManager.getMap().values()) {
        if (qc instanceof QueryResultCache) {
          qc.clear();
        }
      }
    }
    super.notify(event);
  }
Beispiel #8
0
  /**
   * Addes one typerel cache entries, plus inherited relations (if builder are initialized)
   *
   * @return A Set with the added entries, which can be used for logging or so, or can be
   *     disregarded
   * @since MMBase-1.6.2
   */
  protected TypeRelSet addCacheEntry(
      final MMObjectNode typeRel, final boolean buildersInitialized) {

    if (typeRel == null) {
      throw new IllegalArgumentException("typeRel cannot be null");
    }

    final TypeRelSet added =
        new TypeRelSet(); // store temporary, which will enable nice logging of what happened

    // Start to add the actual definition, this is then afterwards again,
    // except if one of the builders could not be found
    added.add(typeRel);

    if (mmb == null) {
      throw new IllegalStateException("mmb is null");
    }

    final RelDef reldef = mmb.getRelDef();
    if (reldef == null) {
      throw new IllegalStateException("No reldef found");
    }

    final MMObjectNode reldefNode = reldef.getNode(typeRel.getIntValue("rnumber"));
    if (reldefNode == null) {
      throw new RuntimeException(
          "Could not find reldef-node for rnumber= " + typeRel.getIntValue("rnumber"));
    }

    final boolean bidirectional = (!InsRel.usesdir) || (reldefNode.getIntValue("dir") > 1);

    INHERITANCE:
    if (buildersInitialized) { // handle inheritance, which is
      // not possible during
      // initialization of MMBase.

      final TypeDef typeDef = mmb.getTypeDef();

      final String sourceBuilderName = typeDef.getValue(typeRel.getIntValue("snumber"));
      final MMObjectBuilder sourceBuilder =
          sourceBuilderName != null ? mmb.getBuilder(sourceBuilderName) : null;

      final String destinationBuilderName = typeDef.getValue(typeRel.getIntValue("dnumber"));
      final MMObjectBuilder destinationBuilder =
          destinationBuilderName != null ? mmb.getBuilder(destinationBuilderName) : null;

      if (sourceBuilder == null) {
        if (destinationBuilder == null) {
          log.info(
              "Both source and destination of "
                  + typeRel
                  + " are not active builders. Cannot follow descendants.");
        } else {
          log.info(
              "The source of relation type "
                  + typeRel
                  + " is not an active builder. Cannot follow descendants.");
        }
        break INHERITANCE;
      }

      if (destinationBuilder == null) {
        log.warn(
            "The destination of relation type "
                + typeRel
                + " is not an active builder. Cannot follow descendants.");
        break INHERITANCE;
      }

      final int rnumber = typeRel.getIntValue("rnumber");

      final List<MMObjectBuilder> sources =
          new ArrayList<MMObjectBuilder>(sourceBuilder.getDescendants());
      sources.add(sourceBuilder);

      final List<MMObjectBuilder> destinations =
          new ArrayList<MMObjectBuilder>(destinationBuilder.getDescendants());
      destinations.add(destinationBuilder);

      for (MMObjectBuilder s : sources) {
        for (MMObjectBuilder d : destinations) {
          MMObjectNode vnode = new VirtualTypeRelNode(s.getNumber(), d.getNumber(), rnumber);
          added.add(vnode);
        }
      }

      // seek all parents and store typerels for them
      // this cache is used by contains(INCLUDE_PARENTS /
      // INCLUDE_PARENTS_AND_DESCENDANTS));
      MMObjectBuilder sourceParent = sourceBuilder;
      while (sourceParent != null) {
        MMObjectBuilder destinationParent = destinationBuilder;
        while (destinationParent != null) {
          MMObjectNode vnode =
              new VirtualTypeRelNode(
                  sourceParent.getNumber(), destinationParent.getNumber(), rnumber);
          parentTypeRelNodes.add(vnode);
          destinationParent = destinationParent.getParentBuilder();
        }
        sourceParent = sourceParent.getParentBuilder();
      }
      added.add(typeRel); // replaces the ones added in the 'inheritance'
      // loop (so now not any more Virtual)
    }

    for (MMObjectNode node : added) {
      if (!node.isVirtual()) {
        // make sure 'real' nodes replace virtual nodes. (real and virtual nodes are equal, so will
        // not be added to set otherwise)
        // This is especially essential whey you use STRICT in contains
        typeRelNodes.remove(node);
        if (bidirectional) inverseTypeRelNodes.remove(node);
      }
      typeRelNodes.add(node);
      if (bidirectional) inverseTypeRelNodes.add(node);
    }
    if (log.isDebugEnabled()) {
      log.debug("Added to typerelcache: " + added);
    }
    return added;
  }
Beispiel #9
0
  private Boolean sendMail(HttpServletRequest req, Node node, String email) {
    boolean send = false;

    Cloud cloud = node.getCloud();
    String emailbuilder = "email";
    try {
      Module sendmail = cloud.getCloudContext().getModule("sendmail");
      emailbuilder = sendmail.getProperty("emailbuilder");
    } catch (NotFoundException nfe) {
      log.warn("No email module " + nfe);
    }

    if (cloud.hasNodeManager(emailbuilder)) {

      NodeManager nm = cloud.getNodeManager(emailbuilder);
      Node message = nm.createNode();

      String host = req.getHeader("host");
      if (host == null || "".equals(host)) {
        try {
          host = java.net.InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException uhe) {
          log.warn("No host: " + uhe);
        }
      }
      String from = "downloader@" + host;
      // do a quick check if we've got something more or less valid
      Pattern p = Pattern.compile(".+@.+\\.[a-z]+");
      Matcher m = p.matcher(from);
      if (!m.matches()) {
        from = "*****@*****.**";
      }

      String mediaTitle = node.getStringValue("title");
      String mediaUrl = getProperty(node, URL_KEY);
      StringBuilder body = new StringBuilder();

      body.append("*This is an automated message / Dit is een geautomatiseerd bericht*");
      body.append("\n\n*English*");
      body.append("\n\nDear,");
      body.append("\n\nWe have received your file belonging to media item titled '")
          .append(mediaTitle)
          .append("'. ");
      body.append("In about 1 hour, you can find your submission at: ");
      body.append("http://").append(host).append("/media/").append(node.getNumber());
      body.append("\n\nKind regards,");
      body.append("\n\n").append(host);

      body.append("\n\n\n*Nederlands*");
      body.append("\n\nBeste,");
      body.append("\n\nWe hebben je bestand voor het media item met de titel '")
          .append(mediaTitle)
          .append("' ontvangen. ");
      body.append("Je kunt je bijdrage hier over circa een uur terugvinden: ");
      body.append("http://").append(host).append("/media/").append(node.getNumber());
      body.append("\n\nMet vriendelijke groet,");
      body.append("\n\n").append(host);

      message.setValue("from", from);
      message.setValue("to", email);
      message.setValue("subject", "Download complete / Download voltooid");
      message.setValue("body", body.toString());
      message.commit();

      Function mail = message.getFunction("mail");
      Parameters mail_params = mail.createParameters();
      mail_params.set("type", "oneshot");
      mail.getFunctionValue(mail_params);

      if (log.isDebugEnabled()) {
        log.debug("Message download ready send to: " + email);
      }
      send = true;
    } else {
      log.warn("Can not send message - no emailbuilder installed.");
    }

    return send;
  }
Beispiel #10
0
        @Override
        public void onChange(String resource) {
          try {
            LOG.debug("Reading " + resource);

            HashMap<CommandExecutor.Method, Stage> newexecutorsMap =
                new HashMap<CommandExecutor.Method, Stage>();
            Document document = getResourceLoader().getDocument(resource);
            Map<Stage, Integer> totals = new EnumMap<Stage, Integer>(Stage.class);

            if (document != null) {
              org.w3c.dom.NodeList ellist = document.getDocumentElement().getChildNodes();

              Stage prevStage = Stage.RECOGNIZER;
              for (int i = 0; i <= ellist.getLength(); i++) {
                if (ellist.item(i) instanceof Element) {
                  Element el = (Element) ellist.item(i);
                  if (el.getTagName().equals("localhost")) {
                    int max = Integer.parseInt(el.getAttribute("max_simultaneous_transcoders"));
                    Stage s = Stage.valueOf(el.getAttribute("stage").toUpperCase());
                    Integer t = totals.get(s);
                    if (t == null) t = 0;
                    t += max;
                    totals.put(s, t);
                    for (int j = 1; j <= max; j++) {
                      newexecutorsMap.put(new CommandExecutor.Method(), s);
                    }
                  } else if (el.getTagName().equals("server")) {
                    int max = Integer.parseInt(el.getAttribute("max_simultaneous_transcoders"));
                    Stage s = Stage.valueOf(el.getAttribute("stage").toUpperCase());
                    Integer t = totals.get(s);
                    if (t == null) t = 0;
                    t += max;
                    totals.put(s, t);
                    String host = el.getAttribute("host");
                    int port = Integer.parseInt(el.getAttribute("port"));
                    for (int j = 1; j <= max; j++) {
                      newexecutorsMap.put(new CommandExecutor.Method(host, port), s);
                    }
                  }
                }
              }
              for (Map.Entry<Stage, Integer> e : totals.entrySet()) {
                threadPools.get(e.getKey()).setCorePoolSize(e.getValue());
                threadPools.get(e.getKey()).setMaximumPoolSize(e.getValue());
              }
            } else {
              LOG.warn("No " + resource);
            }
            synchronized (executorsMap) {
              executorsMap.clear();
              executorsMap.putAll(newexecutorsMap);
            }
            LOG.service(
                "Reading of configuration file "
                    + resource
                    + " successfull. Executors "
                    + executorsMap
                    + ". Max simultaneous transcoders: "
                    + totals);
          } catch (Exception e) {
            LOG.error(
                e.getClass()
                    + " "
                    + e.getMessage()
                    + " In "
                    + resource
                    + " Executors now "
                    + executorsMap
                    + " (not changed)",
                e);
          }
        }