/** * Connect by tcp. * * @param host the host * @param port the port * @return the t conn */ public static synchronized TConn connectByTcp(String host, int port, long timeout) { TimeStamp t = TimeStamp.create(); try { if (tcpconnector == null) { tcpconnector = new TDCConnector(); } tcpconnector.connector.setConnectTimeoutMillis(timeout); ConnectFuture connFuture = tcpconnector.connector.connect(new InetSocketAddress(host, port)); connFuture.awaitUninterruptibly(timeout); IoSession session = connFuture.getSession(); TConn c = new TConn(session); session.setAttribute("conn", c); return c; } catch (Exception e) { log.error( "error, [" + host + ":" + port + "], cost: " + t.past() + "ms, timeout=" + timeout, e); } return null; }
public void runIt(Object td[]) { long timeNow = System.currentTimeMillis(); if (dL > 2) debug("Checking " + timeNow); int checkedCount; synchronized (managedObjs) { checkedCount = managedCount; if (checkedObjs.length < checkedCount) checkedObjs = new TimeStamp[managedLen]; System.arraycopy(managedObjs, 0, checkedObjs, 0, checkedCount); } for (int i = 0; i < checkedCount; i++) { TimeStamp ts = checkedObjs[i]; checkedObjs[i] = null; if (ts == null || !ts.isValid()) continue; long maxInactiveInterval = ts.getMaxInactiveInterval(); if (dL > 3) debug("TS: " + maxInactiveInterval + " " + ts.getLastAccessedTime()); if (maxInactiveInterval < 0) continue; long timeIdle = timeNow - ts.getLastAccessedTime(); if (timeIdle >= maxInactiveInterval) { if (expireCallback != null) { if (dL > 0) debug(ts + " " + timeIdle + " " + maxInactiveInterval); expireCallback.expired(ts); } } } }
public void drawEdges() { this.application.clearKochPanel(); // Opdracht 8 Verplaats naar Change Level /* this.kochFractal.generateLeftEdge(); this.kochFractal.generateBottomEdge(); this.kochFractal.generateRightEdge();*/ TimeStamp timeStamp = new TimeStamp(); timeStamp.setBegin("Begin met tekenen."); for (Edge edge : edgeList) { this.application.drawEdge(edge); } timeStamp.setEnd("Klaar met tekenen!"); this.application.setTextDraw(timeStamp.toString()); }
/** * set original time stamp * * @param tsTo to time stamped message * @param tsFrom from time stamped message */ private void setOriginTSMsg(TimeStamp tsTo, TimeStamp tsFrom) { if (tsTo == null || tsFrom == null) return; tsTo.setTimeStamp(tsFrom.getType(), tsFrom.getVectorClock(), tsFrom.getLogicalClock()); }
public int compare(DataBox a, DataBox b) { TimeStamp ta = a.getTargetTime(); TimeStamp tb = b.getTargetTime(); return ta.timeFormatted().compareTo(tb.timeFormatted()); }
public void changeLevel(final int nxt) { try { this.tempEdgeList = new ArrayList<>(); this.kochFractal.setLevel(nxt); timeStamp = new TimeStamp(); timeStamp.setBegin("Begin berekenen van edges."); kochManagerWorker.ChangeLevel(); // final Task leftTask = new Task() // { // @Override // protected synchronized Object call() throws Exception // { // Edge result = kochFractal.generateLeftEdge(); // return result; // } // }; //// leftThread.start(); // // final Task bottomTask = new Task() // { // @Override // protected synchronized Object call() throws Exception // { // return kochFractal.generateBottomEdge(); // } // }; //// bottomThread.start(); // // final Task rightTask = new Task() // { // @Override // protected synchronized Object call() throws Exception // { // return kochFractal.generateRightEdge(); // } // }; //// rightThread.start(); // // pool.execute(leftTask); // pool.execute(bottomTask); // pool.execute(rightTask); final Thread drawThread = new Thread() { @Override public void run() { try { timeStamp.setEnd("Edges berekend!"); application.setTextCalc(timeStamp.toString()); edgeList = tempEdgeList; application.requestDrawEdges(); application.setTextNrEdges(edgeList.size() + ""); } catch (Exception e) { } } }; drawThread.start(); } catch (Exception e) { } }