public void addBuffer(Buffer buf) {
   synchronized (buffers) {
     buffers.add(buf);
     // System.out.println("Adding buffer: size = " + buffers.size());
     buffers.notify();
   }
 }
  public void read(Buffer buf) {
    synchronized (buffers) {
      while (buffers.size() == 0 && notDone) {
        try {
          buffers.wait();
        } catch (InterruptedException ex) {
          ex.printStackTrace();
        }
      }

      if (buffers.size() > 0) {
        Buffer newBuf = (Buffer) buffers.get(0);
        int[] newData = (int[]) newBuf.getData();
        buf.setData(newData);
        buf.setLength(newBuf.getLength());
        buf.setOffset(0);
        buf.setFormat(vFormat);
        buf.setFlags(Buffer.FLAG_KEY_FRAME | Buffer.FLAG_NO_DROP);
        buffers.remove(0);
        // System.out.println("Removing buffer: size = " + buffers.size());
      } else {
        buf.setEOM(true);
        buf.setOffset(0);
        buf.setLength(0);
        synchronized (buffers) {
          buffers.notify();
        }
      }
    }
  }
示例#3
1
  public boolean addTooltipText(String tooltip, Object tooltipObject) {
    _tooltipObject = tooltipObject;
    synchronized (queue) {
      if (!quit) {
        queue.addElement(tooltip);
        counter = 10;
        queue.notify();
        return true;
      }

      return false;
    }
  }
    public void send(byte[] buf, int off, int len) throws IOException {
      if (len > mtu) {
        // TODO Simulate rejection?
      }

      byte[] copy = new byte[len];
      System.arraycopy(buf, off, copy, 0, len);
      DatagramPacket packet = new DatagramPacket(copy, len);

      synchronized (sendQueue) {
        sendQueue.addElement(packet);
        sendQueue.notify();
      }
    }
  public void waitForDone() {

    synchronized (buffers) {
      notDone = false;
      while (buffers.size() != 0) {
        try {
          buffers.wait();
        } catch (InterruptedException ex) {
        }
      }
      buffers.notify();
    }
    finished = true;
  }
示例#6
1
  public static WeiboHeadImage SearchHeadImage(
      Vector _imageList, String _imageID, byte _style, int _hashCode, boolean _isWeiboOrIM)
      throws Exception {
    synchronized (_imageList) {
      for (int i = 0; i < _imageList.size(); i++) {
        WeiboHeadImage t_image = (WeiboHeadImage) _imageList.elementAt(i);

        if (_style == t_image.m_weiboStyle && t_image.m_userID.equals(_imageID)) {

          if ((t_image.m_dataHash != _hashCode && _hashCode != 0)) {

            // change the new hash code and request head image
            //
            t_image.m_dataHash = _hashCode;

            // the head image has been changed
            // must request image
            //
            SendHeadImageQueryMsg(_imageID, _style, _isWeiboOrIM);
          }

          return t_image;
        }
      }

      WeiboHeadImage t_image = new WeiboHeadImage();

      t_image.m_isWeiboOrIM = _isWeiboOrIM;
      t_image.m_userID = _imageID;
      t_image.m_headImage = getDefaultHeadImage();
      t_image.m_dataHash = _hashCode;
      t_image.m_weiboStyle = _style;

      _imageList.addElement(t_image);

      if (recvMain.isSDCardSupport()) {

        if (sm_loadImageThread == null) {

          sm_loadImageThread =
              new Thread() {

                public void run() {

                  while (true) {

                    try {
                      synchronized (sm_loadImageQueue) {
                        while (sm_loadImageQueue.isEmpty()) {
                          try {
                            sm_loadImageQueue.wait();
                          } catch (Exception e) {
                            exceptionOutput("WHI0", e);
                          }
                        }
                      }

                      WeiboHeadImage t_image = (WeiboHeadImage) sm_loadImageQueue.elementAt(0);

                      if (!LoadWeiboImage(t_image)) {
                        SendHeadImageQueryMsg(
                            t_image.m_userID, t_image.m_weiboStyle, t_image.m_isWeiboOrIM);
                      }

                      sm_loadImageQueue.removeElementAt(0);

                    } catch (Exception e) {
                      exceptionOutput("WHI1", e);
                    }
                  }
                }
              };

          sm_loadImageThread.start();
        }

        if (t_image.m_dataHash != 0) {

          // has image hash code (has head image, maybe some weibo or IM has not set image)
          //
          synchronized (sm_loadImageQueue) {
            sm_loadImageQueue.addElement(t_image);

            try {
              sm_loadImageQueue.notify();
            } catch (Exception e) {
              exceptionOutput("WHI2", e);
            }
          }
        }
      }

      return t_image;
    }
  }
 public void add(ChargeResultInfo item) {
   synchronized (queue) {
     queue.addElement(item);
     queue.notify();
   }
 }
示例#8
1
 public void quit() {
   synchronized (queue) {
     quit = true;
     queue.notify();
   }
 }