List of usage examples for java.lang Thread holdsLock
public static native boolean holdsLock(Object obj);
From source file:org.openconcerto.sql.model.graph.DatabaseGraph.java
boolean save(final DBRoot r) { final String rootName = r.getName(); final File rootFile = this.getRootFile(rootName); if (rootFile == null) { return false; } else {//from w ww . ja v a 2 s . co m assert Thread .holdsLock(this.base.getTreeMutex()) : "Might save garbage if two threads open the same file"; BufferedWriter pWriter = null; try { FileUtils.mkdir_p(rootFile.getParentFile()); pWriter = FileUtils.createXMLWriter(rootFile); pWriter.write("<root codecVersion=\""); pWriter.write(XML_VERSION); pWriter.write("\""); SQLSchema.getVersionAttr(r.getSchema(), pWriter); pWriter.write(" >\n"); for (final SQLTable t : r.getDescs(SQLTable.class)) { final Set<Link> flinks = this.getForeignLinks(t); // now that the atomic level is the table we must explicitly record which tables // have no links (to differentiate from tables which we don't know of) pWriter.write("<table name=\""); pWriter.write(OUTPUTTER.escapeAttributeEntities(t.getName())); pWriter.write("\">\n"); for (final Link l : flinks) { l.toXML(pWriter); } pWriter.write("</table>\n"); } pWriter.write("\n</root>\n"); return true; } catch (Exception e) { Log.get().log(Level.WARNING, "unable to save files in " + rootFile, e); return false; } finally { if (pWriter != null) { try { pWriter.close(); } catch (IOException e) { e.printStackTrace(); } } } } }
From source file:org.openconcerto.sql.model.SQLDataSource.java
private Connection getRawConnection() { assert !Thread.holdsLock( this) : "super.getConnection() might block (see setWhenExhaustedAction()), and since return/closeConnection() need this lock, this method cannot wait while holding the lock"; Connection result = null;/*from www.j a va 2s .c o m*/ try { result = super.getConnection(); } catch (SQLException e1) { // try to know if interrupt, TODO cleanup : patch pg Driver.java to fill the cause if (e1.getCause() instanceof InterruptedException || (e1 instanceof PSQLException && e1.getMessage().equals(pgInterrupted))) { throw new RTInterruptedException(e1); } final int retryWait = this.retryWait; if (retryWait == 0) throw new IllegalStateException("Impossible d'obtenir une connexion sur " + this, e1); try { // on attend un petit peu Thread.sleep(retryWait * 1000); // avant de ressayer result = super.getConnection(); } catch (InterruptedException e) { throw new RTInterruptedException("interrupted while waiting for a second try", e); } catch (Exception e) { throw new IllegalStateException( "Impossible d'obtenir une connexion sur " + this + ": " + e.getLocalizedMessage(), e1); } } if (State.DEBUG) State.INSTANCE.connectionCreated(); return result; }
From source file:org.openconcerto.sql.model.SQLSchema.java
void mutateTo(SQLSchema newSchema) { assert Thread.holdsLock(this.getDBSystemRoot().getTreeMutex()); synchronized (this) { this.version = newSchema.version; this.clearNonPersistent(); this.putProcedures(newSchema.procedures); // since one can refresh only some tables, newSchema is a subset of this for (final SQLTable t : newSchema.getTables()) { this.getTable(t.getName()).mutateTo(t); }//from w w w . ja va 2 s. c o m } }
From source file:org.openconcerto.sql.preferences.SQLPreferences.java
private final LinkedList<SQLPreferences> findAncestors() { // parent() and node() take lock on root, so we have no way of finding our ancestor while we // hold this.lock assert !Thread.holdsLock(this.lock) : "Deadlock possible since we access parent()"; final LinkedList<SQLPreferences> res = new LinkedList<SQLPreferences>(); res.add(this); SQLPreferences current = this; SQLPreferences p;//from w w w .java 2s . c o m while ((p = (SQLPreferences) current.parent()) != null) { res.addFirst(p); current = p; } return res; }
From source file:org.openconcerto.sql.preferences.SQLPreferences.java
protected final void flushTxn() throws SQLException { assert Thread.holdsLock(this.lock); // create node even if there's no values nor any children boolean masterChanged = createNode(); if (this.removedKeys.size() > 0 || this.changedValues.size() > 0) { // also delete changed, so we can insert afterwards this.deleteValues(CollectionUtils.union(this.removedKeys, this.changedValues.keySet())); // MAYBE remove and clear after transaction commit if (this.values != null) this.values.keySet().removeAll(this.removedKeys); this.removedKeys.clear(); if (this.changedValues.size() > 0) { final int nodeID = getNode().getID(); final List<String> insValues = new ArrayList<String>(this.changedValues.size()); for (final Entry<String, String> e : this.changedValues.entrySet()) { insValues.add("(" + nodeID + ", " + this.getPrefWT().getBase().quoteString(e.getKey()) + ", " + this.getPrefWT().getBase().quoteString(e.getValue()) + ")"); // MAYBE put after transaction commit if (this.values != null) this.values.put(e.getKey(), e.getValue()); }/*from www. j a va2 s .com*/ SQLRowValues.insertCount(this.getPrefWT(), "(\"ID_NODE\", \"NAME\", \"VALUE\") VALUES" + CollectionUtils.join(insValues, ", ")); this.changedValues.clear(); } masterChanged = true; } if (masterChanged) replicate(); }
From source file:raptor.engine.uci.UCIEngine.java
/** * the engine wants to send infos to the GUI. This should be done whenever * one of the info has changed. The engine can send only selected infos and * multiple infos can be send with one info command, e.g. * "info currmove e2e4 currmovenumber 1" or * "info depth 12 nodes 123456 nps 100000". Also all infos belonging to the * pv should be sent together e.g.// w w w . j a va2 s. c om * "info depth 2 score cp 214 time 1242 nodes 2124 nps 34928 pv e2e4 e7e5 g1f3" * I suggest to start sending "currmove", "currmovenumber", "currline" and * "refutation" only after one second to avoid too much traffic. * * <pre> * Additional info: * depth * search depth in plies * seldepth * selective search depth in plies, * if the engine sends seldepth there must also a "depth" be present in the same string. * time * the time searched in ms, this should be sent together with the pv. * nodes * x nodes searched, the engine should send this info regularly * pv ... * the best line found * multipv * this for the multi pv mode. * for the best move/pv add "multipv 1" in the string when you send the pv. * in k-best mode always send all k variants in k strings together. * score * cp * the score from the engine's point of view in centipawns. * mate * mate in y moves, not plies. * If the engine is getting mated use negativ values for y. * lowerbound * the score is just a lower bound. * upperbound * the score is just an upper bound. * currmove * currently searching this move * currmovenumber * currently searching move number x, for the first move x should be 1 not 0. * hashfull * the hash is x permill full, the engine should send this info regularly * nps * x nodes per second searched, the engine should send this info regularly * tbhits * x positions where found in the endgame table bases * cpuload * the cpu usage of the engine is x permill. * string * any string str which will be displayed be the engine, * if there is a string command the rest of the line will be interpreted as . * refutation ... * move is refuted by the line ... , i can be any number >= 1. * Example: after move d1h5 is searched, the engine can send * "info refutation d1h5 g6h5" * if g6h5 is the best answer after d1h5 or if g6h5 refutes the move d1h5. * if there is norefutation for d1h5 found, the engine should just send * "info refutation d1h5" * The engine should only send this if the option "UCI_ShowRefutations" is set to true. * currline ... * this is the current line the engine is calculating. is the number of the cpu if * the engine is running on more than one cpu. = 1,2,3.... * if the engine is just using one cpu, can be omitted. * If is greater than 1, always send all k lines in k strings together. * The engine should only send this if the option "UCI_ShowCurrLine" is set to true. * </pre> * * Examples: * * <pre> * go infinite * info depth 1 seldepth 0 time 34 nodes 0 nps 151466 score cp 1 pv c7c5 * info nps 151466 nodes 0 cpuload 0 hashfull 0 time 35 * bestmove c7c5 * stop * </pre> */ protected void parseInfoLine(String info, UCIInfoListener listener) { if (!isProcessingGo() || Thread.holdsLock(stopSynch)) return; if (LOG.isDebugEnabled()) LOG.debug("Entering parseInfoLine(" + info + ",...)"); RaptorStringTokenizer tok = new RaptorStringTokenizer(info, " ", true); tok.nextToken(); int currentMoveNumber = 0; List<UCIInfo> infos = new ArrayList<UCIInfo>(10); String nextType = null; while (tok.hasMoreTokens()) { String type = null; if (nextType != null) { type = nextType; nextType = null; } else { type = tok.nextToken(); } while (!isSupportedInfoType(type) && tok.hasMoreTokens()) { type = tok.nextToken(); } if (!isSupportedInfoType(type)) { break; } if (type.equalsIgnoreCase("depth")) { DepthInfo depthInfo = new DepthInfo(); depthInfo.setSearchDepthPlies(Integer.parseInt(tok.nextToken())); infos.add(depthInfo); } else if (type.equalsIgnoreCase("seldepth")) { SelectiveSearchDepthInfo ssDepthInfo = new SelectiveSearchDepthInfo(); ssDepthInfo.setDepthInPlies(Integer.parseInt(tok.nextToken())); infos.add(ssDepthInfo); } else if (type.equalsIgnoreCase("time")) { TimeInfo timeInfo = new TimeInfo(); timeInfo.setTimeMillis(Integer.parseInt(tok.nextToken())); infos.add(timeInfo); } else if (type.equalsIgnoreCase("nodes")) { NodesSearchedInfo nodesSearched = new NodesSearchedInfo(); nodesSearched.setNodesSearched(Long.parseLong(tok.nextToken())); infos.add(nodesSearched); } else if (type.equalsIgnoreCase("pv")) { BestLineFoundInfo bestLineFoundInfo = new BestLineFoundInfo(); String currentMove = tok.nextToken(); List<UCIMove> currentLine = new ArrayList<UCIMove>(10); while (true) { currentLine.add(new UCIMove(currentMove)); if (tok.hasMoreTokens()) { currentMove = tok.nextToken(); if (isSupportedInfoType(currentMove)) { nextType = currentMove; break; } } else { break; } } bestLineFoundInfo.setMoves(currentLine.toArray(new UCIMove[0])); infos.add(bestLineFoundInfo); } else if (type.equalsIgnoreCase("multipv")) { infos.add(new MultiPV(tok.nextToken())); } else if (type.equalsIgnoreCase("score")) { ScoreInfo scoreInfo = new ScoreInfo(); String nextToken = tok.nextToken(); while (true) { if (nextToken.equalsIgnoreCase("cp")) { scoreInfo.setValueInCentipawns(Integer.parseInt(tok.nextToken())); } else if (nextToken.equalsIgnoreCase("mate")) { scoreInfo.setMateInMoves(Integer.parseInt(tok.nextToken())); } else if (nextToken.equalsIgnoreCase("lowerbound")) { scoreInfo.setLowerBoundScore(true); } else if (nextToken.equalsIgnoreCase("upperbound")) { scoreInfo.setUpperBoundScore(true); } else { nextType = nextToken; break; } if (tok.hasMoreTokens()) { nextToken = tok.nextToken(); } else { break; } } infos.add(scoreInfo); } else if (type.equalsIgnoreCase("currmove")) { CurrentMoveInfo currentMoveInfo = new CurrentMoveInfo(); currentMoveInfo.setMove(parseUCIMove(tok.nextToken())); currentMoveInfo.setMoveNumber(currentMoveNumber); infos.add(currentMoveInfo); } else if (type.equalsIgnoreCase("currentmovenumber")) { currentMoveNumber = Integer.parseInt(tok.nextToken()); } else if (type.equalsIgnoreCase("hashfull")) { tok.nextToken(); } else if (type.equalsIgnoreCase("nps")) { NodesPerSecondInfo nodesPerSecInfo = new NodesPerSecondInfo(); nodesPerSecInfo.setNodesPerSecond(Long.parseLong(tok.nextToken())); infos.add(nodesPerSecInfo); } else if (type.equalsIgnoreCase("tbhits")) { TableBaseHitsInfo tbInfo = new TableBaseHitsInfo(); tbInfo.setNumberOfHits(Integer.parseInt(tok.nextToken())); infos.add(tbInfo); } else if (type.equalsIgnoreCase("cpuload")) { CPULoadInfo cpuInfo = new CPULoadInfo(); cpuInfo.setCpuUsage(Integer.parseInt(tok.nextToken())); infos.add(cpuInfo); } else if (type.equalsIgnoreCase("string")) { StringInfo stringInfo = new StringInfo(); stringInfo.setValue(tok.getWhatsLeft().trim()); infos.add(stringInfo); } else { LOG.warn("Unkown type: " + type); } } listener.engineSentInfo(infos.toArray(new UCIInfo[0])); }