Esempio n. 1
0
  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");
    }
  }
Esempio n. 2
0
  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();
    }
  }
Esempio n. 3
0
  /**
   * @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();
    }
  }
Esempio n. 4
0
 /**
  * 重新设置对应的Boolean mutex
  *
  * @param mutex
  */
 public void set(Boolean mutex) {
   if (mutex) {
     sync.innerSetTrue();
   } else {
     sync.innerSetFalse();
   }
 }
Esempio n. 5
0
 /**
  * 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.
 }
Esempio n. 6
0
 /** 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();
   }
 }
Esempio n. 7
0
  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;
  }
Esempio n. 8
0
  /**
   * @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;
    }
  }
Esempio n. 9
0
 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();
   }
 }
Esempio n. 10
0
 public void clear() {
   try {
     wr_.acquire();
     try {
       c_.clear();
     } finally {
       wr_.release();
     }
   } catch (InterruptedException ex) {
     Thread.currentThread().interrupt();
     throw new UnsupportedOperationException();
   }
 }
Esempio n. 11
0
 /**
  * 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;
 }
Esempio n. 12
0
 /**
  * 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;
 }
Esempio n. 13
0
 @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);
   }
 }
Esempio n. 14
0
 /** 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;
   }
 }
Esempio n. 15
0
 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();
 }
Esempio n. 16
0
  /**
   * 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;
  }
Esempio n. 17
0
  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;
      // }

    }
  }
Esempio n. 18
0
  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();
  }
Esempio n. 19
0
 /**
  * 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() + "]";
 }
Esempio n. 20
0
 /**
  * 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);
 }
Esempio n. 21
0
 @Override
 public void run() {
   sync.test();
 }
Esempio n. 22
0
 /**
  * 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);
 }
Esempio n. 23
0
 /** Provide access to the list of threads waiting to acquire this limited shared latch. */
 public Collection<Thread> getQueuedThreads() {
   return sync.getQueuedThreads();
 }
Esempio n. 24
0
 /**
  * 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();
 }
Esempio n. 25
0
 /**
  * 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);
 }
Esempio n. 26
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();
 }
Esempio n. 27
0
 /**
  * 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));
 }
Esempio n. 28
0
 /** Clean up after a reader operation * */
 protected void afterRead(boolean wasInterrupted) {
   if (wasInterrupted) {
     Thread.currentThread().interrupt();
   } else rd_.release();
 }
Esempio n. 29
0
 /**
  * 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);
 }
Esempio n. 30
0
 /**
  * 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();
 }