/** * Handles a pages/mirror service request. Places a page in the file2copy queue, so it will be * sent to a mirror site by the FileCopier. * * @param filenode the filenet node that contains the service request * @param status the current status of the node * @param ctype the type of change on that node ("c" : node was changed) * @return <code>true</code> */ public boolean handleMirror(MMObjectNode filenode, int status, String ctype) { switch (status) { case Netfiles.STATUS_REQUEST: // Request // register the node as being On Its Way filenode.setValue("status", Netfiles.STATUS_ON_ITS_WAY); filenode.commit(); String filename = filenode.getStringValue("filename"); String dstserver = filenode.getStringValue("mmserver"); // recover the correct source/dest properties for this mirror // // why does it say "demoserver" ?? // String sshpath = getProperty("demoserver", "sshpath"); log.debug("sshpath=" + sshpath); String srcpath = getProperty("demoserver", "path"); log.debug("srcpath=" + srcpath); String dstuser = getProperty(dstserver, "user"); log.debug("dstuser="******"host"); log.debug("dsthost=" + dsthost); String dstpath = getProperty(dstserver, "path"); log.debug("dstpath=" + dstpath); /* this code can be dropped as it is handled in FileCopier SCPcopy scpcopy=new SCPcopy(sshpath,dstuser,dsthost,dstpath); synchronized(syncobj) { scpcopy.copy(srcpath,filename); } */ // create a new file2copy object and add it to the queue, // so the FileCopier thread will handle it. files2copy.append(new aFile2Copy(dstuser, dsthost, dstpath, srcpath, filename, sshpath)); // register the node as being Done filenode.setValue("status", Netfiles.STATUS_DONE); filenode.commit(); break; case Netfiles.STATUS_ON_ITS_WAY: // On its way break; case Netfiles.STATUS_DONE: // Done break; } return true; }
/** * Schedules a service-request on a file. Only "pages/main" services are handled. The * service-request is later handled through the {@link #probeCall} method. * * @param service the service to be performed * @param subservice the subservice to be performed * @param filename the filename to service * @return <code>true</code> if maintenance was performed, <code>false</code> otherwise */ public boolean fileChange(String service, String subservice, String filename) { log.debug("frontend change -> " + filename); log.service("s=" + service + " sub=" + subservice + "file=" + filename); // jump to correct subhandles based on the subservice if (subservice.equals("main")) { handleMainCheck(service, subservice, filename); } return true; }
@Override public CloseableIterator<JdbcEntry> getSubCursor(String identifier) { if (isSub) { log.debug("Using getSubCursor for " + identifier); return getSqlCursor(getSql(identifier)); } else { return getSqlCursor(getFindSql(identifier)); } }
/** * Recalculate a page. Invokes the SCAN parser (which will re-cache the page through the scancache * module) Only works for SCAN. * * @param url of the page to cache */ public void calcPage(String url) { scanparser m = (scanparser) Vwms.getMMBase().getModule("SCANPARSER"); url = url.substring(0, url.length() - 5); url = url.replace(':', '?'); log.debug("getPage=" + url); if (m != null) { scanpage sp = new scanpage(); m.calcPage(url, sp, 0); } }
@Override public org.mmbase.bridge.Node getNode(final Cloud userCloud, final Document doc) { String docId = doc.get("number"); if (docId == null) { throw new IllegalArgumentException("No number found in " + doc); } LazyMap m = nodeCache.get(docId); // if (m == null) { Map<String, String> keys = new HashMap<String, String>(); for (String keyWord : keyWords) { keys.put(keyWord, doc.get(keyWord)); } m = new LazyMap(docId, keys); nodeCache.put(docId, m); } org.mmbase.bridge.Node node = new MapNode<String>( m, new MapNodeManager(userCloud, m) { @Override public boolean hasField(String name) { if (JdbcIndexDefinition.this.key.equals(name)) return true; return super.hasField(name); } @Override public org.mmbase.bridge.Field getField(String name) { if (map == null && JdbcIndexDefinition.this.key.equals(name)) { org.mmbase.core.CoreField fd = org.mmbase.core.util.Fields.createField( name, org.mmbase.core.util.Fields.classToType(Object.class), org.mmbase.bridge.Field.TYPE_UNKNOWN, org.mmbase.bridge.Field.STATE_VIRTUAL, null); return new org.mmbase.bridge.implementation.BasicField(fd, this); } else { return super.getField(name); } } }); if (log.isDebugEnabled()) { log.debug("Returning node for " + node); } return node; }
/** * Schedules a netfile object to be send to its mirror sites. The routine searches the appropriate * netfile node, and sets its status to 'request'. If a node does not exits, a new node is * created. In the latter case, the system also creates mirrornodes for each mirrorsite associated * with this service. * * @param service the service to be performed * @param subservice the subservice to be performed * @param filename the filename to service */ public void handleMainCheck(String service, String subservice, String filename) { log.debug("Reached handleMainCheck"); Netfiles bul = (Netfiles) Vwms.getMMBase().getMMObject("netfiles"); Enumeration e = bul.search( "WHERE filename='" + filename + "' AND service='" + service + "' AND subservice='" + subservice + "'"); if (e.hasMoreElements()) { MMObjectNode mainnode = (MMObjectNode) e.nextElement(); mainnode.setValue("status", Netfiles.STATUS_REQUEST); mainnode.commit(); } else { MMObjectNode mainnode = bul.getNewNode("system"); mainnode.setValue("filename", filename); mainnode.setValue("mmserver", Vwms.getMMBase().getMachineName()); mainnode.setValue("service", service); mainnode.setValue("subservice", subservice); mainnode.setValue("status", Netfiles.STATUS_REQUEST); mainnode.setValue("filesize", -1); bul.insert("system", mainnode); Enumeration f = getMirrorNodes(service).elements(); while (f.hasMoreElements()) { MMObjectNode n2 = (MMObjectNode) f.nextElement(); // hack hack also have to create mirror nodes ! mainnode = bul.getNewNode("system"); mainnode.setValue("filename", filename); mainnode.setValue("mmserver", n2.getStringValue("name")); mainnode.setValue("service", service); mainnode.setValue("subservice", "mirror"); mainnode.setValue("status", Netfiles.STATUS_DONE); mainnode.setValue("filesize", -1); bul.insert("system", mainnode); } } }
/** Constructor for the PageMaster VWM. */ public PageMaster() { log.debug("ready for action"); }
CloseableIterator<JdbcEntry> getSqlCursor(final String sql) { try { long start = System.currentTimeMillis(); final Connection con = getDirectConnection(); log.debug("About to execute " + sql + " (" + directConnections + ")"); final Statement statement = con.createStatement(); final ResultSet results = statement.executeQuery(sql); if (log.isDebugEnabled()) { log.debug("Executed " + sql + " in " + (System.currentTimeMillis() - start) + " ms"); } final ResultSetMetaData meta = results.getMetaData(); return new CloseableIterator<JdbcEntry>() { boolean hasNext = results.isBeforeFirst(); int i = 0; @Override public boolean hasNext() { return hasNext; } @Override public JdbcEntry next() { if (!hasNext) { throw new NoSuchElementException(); } try { results.next(); hasNext = !results.isLast(); } catch (java.sql.SQLException sqe) { log.error(sqe); hasNext = false; } JdbcEntry entry = new JdbcEntry(meta, results, sql); i++; if (log.isServiceEnabled()) { if (i % 100 == 0) { log.service("jdbc cursor " + i + " (now at id=" + entry.getIdentifier() + ")"); } else if (log.isDebugEnabled()) { log.trace("jdbc cursor " + i + " (now at id=" + entry.getIdentifier() + ")"); } } return entry; } @Override public void remove() { throw new UnsupportedOperationException(); } @Override public void close() { log.debug("Closing " + con); try { if (results != null) results.close(); if (statement != null) statement.close(); if (con != null) con.close(); } catch (Exception e) { log.error(e); } } }; } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }