private static void startSync() { RemoteException rex; Properties serverList = null; if (serverPortal != null) { while (true) { try { System.out.println(serverPortal.hello()); serverList = serverPortal.getServerList(); try { PropertyHandler.save(SERVER_LIST_FILE, serverList); ClientConnection.getInstance().reload(); } catch (Exception ex) { System.out.println("server list save failed"); } sync.setServerPortal(serverPortal); sync.start(); wait(syncInterval); } catch (RemoteException ex) { rex = ex; break; } } System.out.println("Disconnected, trying to reconnect..."); reconnect(rex); startSync(); } else { System.out.println("No ative server"); } }
public void run() { BackingStore graphics = this.graphics; Sync sync = this.sync; Aut.Animation aut = this.aut; try { while (this.running) { try { sync.waitfor(); graphics.reinit(); aut.enter(); graphics.paint(); } catch (InterruptedException aux) { interrupted(); // (clear interrupt) } catch (Exception exc) { exc.printStackTrace(); } finally { aut.exit(); } } } finally { aut.halt(); } }
/** * @param key Key to lock. * @return Sync object that should be passed to {@link #unlock(Object, Object)} method. */ public <T> Object lock(T key) { assert key != null; boolean interrupted = false; Sync t = new Sync(); try { while (true) { Sync old = locks.putIfAbsent(key, t); if (old != null) { while (true) { try { old.await(); break; } catch (InterruptedException ignored) { interrupted = true; } } } else return t; } } finally { if (interrupted) Thread.currentThread().interrupt(); } }
/** * 重新设置对应的Boolean mutex * * @param mutex */ public void set(Boolean mutex) { if (mutex) { sync.innerSetTrue(); } else { sync.innerSetFalse(); } }
/** * Resets the counter to zero. But waiting threads won't be released somehow. So this interrupts * the threads so that they escape from their waiting state. */ public void resetAndInterrupt() { sync.reset(); for (int i = 0; i < 3; i++) // Because it is a best effort thing, do it three times and hope for the best. for (Thread t : sync.getQueuedThreads()) t.interrupt(); sync.reset(); // Just in case a thread would've incremented the counter again. }
/** Execute the given command directly in the current thread, within the supplied lock. */ public void execute(Runnable command) throws InterruptedException { mutex_.acquire(); try { command.run(); } finally { mutex_.release(); } }
public static Sync create(boolean withChilds) { Sync xml = new Sync(); xml.setClientId(123); xml.setServerId(345); if (withChilds) { xml.setStatus(TestXmlStatus.create(false)); xml.setResult(net.sf.ahtutils.xml.status.TestXmlResult.create(false)); } return xml; }
/** * @param key Key to lock. * @return Sync object that should be passed to {@link #unlock(Object, Object)} method. * @throws InterruptedException If interrupted while acquiring lock. */ public <T> Object lockInterruptibly(T key) throws InterruptedException { assert key != null; Sync t = new Sync(); while (true) { Sync old = locks.putIfAbsent(key, t); if (old != null) old.await(); else return t; } }
public Object remove(Object key) { try { wr_.acquire(); try { return c_.remove(key); } finally { wr_.release(); } } catch (InterruptedException ex) { Thread.currentThread().interrupt(); throw new UnsupportedOperationException(); } }
public void clear() { try { wr_.acquire(); try { c_.clear(); } finally { wr_.release(); } } catch (InterruptedException ex) { Thread.currentThread().interrupt(); throw new UnsupportedOperationException(); } }
/** * Subclasses should invoke this method to mark the future as cancelled. This will set the state * of the future to {@link AbstractFuture.Sync#CANCELLED} and call {@link #done()} if the state * was successfully changed. * * @return true if the state was successfully changed. */ protected final boolean cancel() { boolean result = sync.cancel(); if (result) { done(); } return result; }
/** * Subclasses should invoke this method to set the result of the computation to {@code value}. * This will set the state of the future to {@link AbstractFuture.Sync#COMPLETED} and call {@link * #done()} if the state was successfully changed. * * @param value the value that was the result of the task. * @return true if the state was successfully changed. */ protected boolean set(@Nullable V value) { boolean result = sync.set(value); if (result) { done(); } return result; }
@Override public void decodeContent(XMLTokenizer tokenizer) throws IOException { while (tokenizer.atSTag()) { String tag = tokenizer.getTagName(); if (tag.equals(Sync.xmlTag())) syncs.add(new Sync(bmlId, tokenizer)); ensureDecodeProgress(tokenizer); } }
/** Try to acquire sync before a reader operation; record failure * */ protected boolean beforeRead() { try { rd_.acquire(); return false; } catch (InterruptedException ex) { syncFailures_.increment(); return true; } }
public static void init() { Add.init(); Address.init(); Align.init(); Alloc.init(); Anchor.init(); And.init(); Bad.init(); Bitcast.init(); Block.init(); Builtin.init(); Call.init(); Cmp.init(); Cond.init(); Confirm.init(); Const.init(); Conv.init(); CopyB.init(); Deleted.init(); Div.init(); Dummy.init(); End.init(); Eor.init(); Free.init(); IJmp.init(); Id.init(); Jmp.init(); Load.init(); Member.init(); Minus.init(); Mod.init(); Mul.init(); Mulh.init(); Mux.init(); NoMem.init(); Not.init(); Offset.init(); Or.init(); Phi.init(); Pin.init(); Proj.init(); Raise.init(); Return.init(); Sel.init(); Shl.init(); Shr.init(); Shrs.init(); Size.init(); Start.init(); Store.init(); Sub.init(); Switch.init(); Sync.init(); Tuple.init(); Unknown.init(); }
/** * Subclasses should invoke this method to set the result of the computation to an error, {@code * throwable}. This will set the state of the future to {@link AbstractFuture.Sync#COMPLETED} and * call {@link #done()} if the state was successfully changed. * * @param throwable the exception that the task failed with. * @return true if the state was successfully changed. * @throws Error if the throwable was an {@link Error}. */ protected boolean setException(Throwable throwable) { boolean result = sync.setException(checkNotNull(throwable)); if (result) { done(); } // If it's an Error, we want to make sure it reaches the top of the // call stack, so we rethrow it. if (throwable instanceof Error) { throw (Error) throwable; } return result; }
public void run() { while (true) { // System.out.println("Running stitchthread"); t1 = null; t2 = null; Sync.Take(q1, q2); bi1 = t1.getImage(); bi2 = t2.getImage(); if (bi1 != null && bi2 != null) { // System.out.println("can stitch pic "+ bi1.toString() + " and " + bi2.toString()); // System.out.println("can stitch pic "+ 1 + " and " + 2); // synchronized(this) { // System.err.println("bi1: "+bi1+" bi2: "+bi2); BufferedImage stitched = ImageStitching.stitch(bi1, bi2, ImageFloat32.class); long min = Math.min(t1.getTime(), t2.getTime()); Tuple tuple = new Tuple(stitched, min); try { q3.put(tuple); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } // } bi1 = null; bi2 = null; if (!flag) Sync.openJavaWindow(stitched.getWidth(), stitched.getHeight()); updateJavaWindow(stitched); // System.err.println("stitched"); } // else if (bi1 == null && bi2 == null){ // break; // } } }
public static void main(String[] args) { System.out.println("hello client"); init(); System.out.println("Connecting to server..."); connect(); if (serverPortal == null) { System.out.println("did not find active server"); System.exit(1); } boolean connected = false; do { try { userSession = new Login(serverPortal); connected = userSession.login(); } catch (RemoteException ex) { reconnect(ex); } } while (!connected); String localPath = userSession.getSyncPath(); String tempPath = userSession.getMetaPath(); String userName = userSession.getUserName(); String device = userSession.getDeviceID(); String dataPath = tempPath + "filelist.obj"; try { boolean recursive = false; watchService = new WatchDir(localPath, recursive, userName, device, dataPath); } catch (IOException ex) { System.out.println("HI IO"); System.out.println(ex.getMessage()); } new Thread(watchService).start(); sync = new Sync(userName, device, serverPortal, localPath, tempPath, dataPath); sync.setClientFileList(watchService.loadFileList()); startSync(); }
/** * Returns a string identifying this latch, as well as its state. The state, in brackets, includes * the String {@code "Count ="} followed by the current count. * * @return a string identifying this latch, as well as its state */ public String toString() { return super.toString() + "[Count = " + sync.getCount() + "]"; }
/** * An accurate sync method that will attempt to run at a constant frame rate. It should be called * once every frame. * * @param fps - the desired frame rate, in frames per second */ public static void sync(int fps) { Sync.sync(fps); }
@Override public void run() { sync.test(); }
/** * Acquires a shared latch if one is available or waits for one if no shared latch is current * available. */ public void countUpOrAwait() throws InterruptedException { sync.acquireSharedInterruptibly(1); }
/** Provide access to the list of threads waiting to acquire this limited shared latch. */ public Collection<Thread> getQueuedThreads() { return sync.getQueuedThreads(); }
/** * Returns <code>true</code> if there is at least one thread waiting to acquire the shared lock, * otherwise returns <code>false</code>. */ public boolean hasQueuedThreads() { return sync.hasQueuedThreads(); }
/** * Releases all waiting threads and causes the {@link #limit} to be ignored until {@link #reset()} * is called. */ public boolean releaseAll() { released = true; return sync.releaseShared(0); }
/** * Releases a shared latch, making it available for another thread to use. * * @return the previous counter value */ public long countDown() { sync.releaseShared(0); return count.get(); }
/** * Causes the current thread to wait until the latch has counted down to zero, unless the thread * is {@linkplain Thread#interrupt interrupted}, or the specified waiting time elapses. * * <p>If the current count is zero then this method returns immediately with the value {@code * true}. * * <p>If the current count is greater than zero then the current thread becomes disabled for * thread scheduling purposes and lies dormant until one of three things happen: * * <ul> * <li>The count reaches zero due to invocations of the {@link #countDown} method; or * <li>Some other thread {@linkplain Thread#interrupt interrupts} the current thread; or * <li>The specified waiting time elapses. * </ul> * * <p>If the count reaches zero then the method returns with the value {@code true}. * * <p>If the current thread: * * <ul> * <li>has its interrupted status set on entry to this method; or * <li>is {@linkplain Thread#interrupt interrupted} while waiting, * </ul> * * then {@link InterruptedException} is thrown and the current thread's interrupted status is * cleared. * * <p>If the specified waiting time elapses then the value {@code false} is returned. If the time * is less than or equal to zero, the method will not wait at all. * * @param timeout the maximum time to wait * @param unit the time unit of the {@code timeout} argument * @return {@code true} if the count reached zero and {@code false} if the waiting time elapsed * before the count reached zero * @throws InterruptedException if the current thread is interrupted while waiting */ public boolean await(long timeout, TimeUnit unit) throws InterruptedException { return sync.tryAcquireSharedNanos(1, unit.toNanos(timeout)); }
/** Clean up after a reader operation * */ protected void afterRead(boolean wasInterrupted) { if (wasInterrupted) { Thread.currentThread().interrupt(); } else rd_.release(); }
/** * Decrements the count of the latch, releasing all waiting threads if the count reaches zero. * * <p>If the current count is greater than zero then it is decremented. If the new count is zero * then all waiting threads are re-enabled for thread scheduling purposes. * * <p>If the current count equals zero then nothing happens. */ public void countDown() { sync.releaseShared(1); }
/** * Returns the current count. * * <p>This method is typically used for debugging and testing purposes. * * @return the current count */ public long getCount() { return sync.getCount(); }