コード例 #1
0
  public void pushSRI(StreamSRI header) {

    if (logger != null) {
      logger.trace("bulkio.InPort pushSRI  ENTER (port=" + name + ")");
    }
    synchronized (sriUpdateLock) {
      if (!currentHs.containsKey(header.streamID)) {
        if (logger != null) {
          logger.debug("pushSRI PORT:" + name + " NEW SRI:" + header.streamID);
        }
        if (sriCallback != null) {
          sriCallback.newSRI(header);
        }
        currentHs.put(header.streamID, new sriState(header, true));
        if (header.blocking) {
          // If switching to blocking we have to set the semaphore
          synchronized (dataBufferLock) {
            if (!blocking) {
              try {
                queueSem.acquire(workQueue.size());
              } catch (InterruptedException e) {
                e.printStackTrace();
              }
            }
            blocking = true;
          }
        }
      } else {
        StreamSRI oldSri = currentHs.get(header.streamID).getSRI();
        boolean cval = false;
        if (sri_cmp != null) {
          cval = sri_cmp.compare(header, oldSri);
        }
        if (cval == false) {
          if (sriCallback != null) {
            sriCallback.changedSRI(header);
          }
          this.currentHs.put(header.streamID, new sriState(header, true));
          if (header.blocking) {
            // If switching to blocking we have to set the semaphore
            synchronized (dataBufferLock) {
              if (!blocking) {
                try {
                  queueSem.acquire(workQueue.size());
                } catch (InterruptedException e) {
                  e.printStackTrace();
                }
              }
              blocking = true;
            }
          }
        }
      }
    }
    if (logger != null) {
      logger.trace("bulkio.InPort pushSRI  EXIT (port=" + name + ")");
    }
  }
コード例 #2
0
  public void pushPacket(short[] data, PrecisionUTCTime time, boolean eos, String streamID) {
    if (logger != null) {
      logger.trace("bulkio.InPort pushPacket ENTER (port=" + name + ")");
    }
    synchronized (this.dataBufferLock) {
      if (this.maxQueueDepth == 0) {
        return;
      }
    }

    boolean portBlocking = false;
    StreamSRI tmpH = null;
    boolean sriChanged = false;
    synchronized (this.sriUpdateLock) {
      if (this.currentHs.containsKey(streamID)) {
        tmpH = this.currentHs.get(streamID).getSRI();
        sriChanged = this.currentHs.get(streamID).isChanged();
        if (eos == false) {
          this.currentHs.get(streamID).setChanged(false);
        }
        portBlocking = blocking;
      } else {
        if (logger != null) {
          logger.warn(
              "bulkio.InPort pushPacket received data from stream '" + streamID + "' with no SRI");
        }
        tmpH =
            new StreamSRI(
                1,
                0.0,
                1.0,
                (short) 1,
                0,
                0.0,
                0.0,
                (short) 0,
                (short) 0,
                streamID,
                false,
                new DataType[0]);
        if (sriCallback != null) {
          sriCallback.newSRI(tmpH);
        }
        sriChanged = true;
        currentHs.put(streamID, new sriState(tmpH, false));
      }
    }

    // determine whether to block and wait for an empty space in the queue
    Packet p = null;

    if (portBlocking) {
      p = new Packet(data, time, eos, streamID, tmpH, sriChanged, false);

      try {
        queueSem.acquire();
      } catch (InterruptedException e) {
        e.printStackTrace();
      }

      synchronized (this.dataBufferLock) {
        this.stats.update(
            data.length, this.workQueue.size() / (float) this.maxQueueDepth, eos, streamID, false);
        this.workQueue.add(p);
        this.dataSem.release();
      }
    } else {
      synchronized (this.dataBufferLock) {
        if (this.workQueue.size() == this.maxQueueDepth) {
          if (logger != null) {
            logger.debug(
                "bulkio::InPort pushPacket PURGE INPUT QUEUE (SIZE" + this.workQueue.size() + ")");
          }
          boolean sriChangedHappened = false;
          boolean flagEOS = false;
          for (Iterator<Packet> itr = this.workQueue.iterator(); itr.hasNext(); ) {
            if (sriChangedHappened && flagEOS) {
              break;
            }
            Packet currentPacket = itr.next();
            if (currentPacket.sriChanged) {
              sriChangedHappened = true;
            }
            if (currentPacket.EOS) {
              flagEOS = true;
            }
          }
          if (sriChangedHappened) {
            sriChanged = true;
          }
          if (flagEOS) {
            eos = true;
          }
          this.workQueue.clear();
          p = new Packet(data, time, eos, streamID, tmpH, sriChanged, true);
          this.stats.update(data.length, 0, eos, streamID, true);
        } else {
          p = new Packet(data, time, eos, streamID, tmpH, sriChanged, false);
          this.stats.update(
              data.length,
              this.workQueue.size() / (float) this.maxQueueDepth,
              eos,
              streamID,
              false);
        }
        if (logger != null) {
          logger.trace("bulkio::InPort pushPacket NEW Packet (QUEUE=" + workQueue.size() + ")");
        }
        this.workQueue.add(p);
        this.dataSem.release();
      }
    }

    if (logger != null) {
      logger.trace("bulkio.InPort pushPacket EXIT (port=" + name + ")");
    }
    return;
  }