@Override
 @XmlTransient
 public IPacketFilter getInstance() {
   LocationFilter locFilter = new LocationFilter();
   for (GeometryConfiguration geo : geometries) {
     locFilter.addFilterGeometry(geo.getPredicate());
   }
   return locFilter;
 }
Exemple #2
0
  @Override
  protected void run(Injector injector) throws Exception {
    if (filename == null && hostPort == null && (dir == null || name == null)) {
      usage();
      System.exit(-1);
    }

    // Create reader
    AisReader aisReader;
    if (filename != null) {
      aisReader = AisReaders.createReaderFromFile(filename);
    } else if (hostPort != null) {
      AisTcpReader rrAisReader = AisReaders.createReader(hostPort);
      rrAisReader.setTimeout(timeout);
      aisReader = rrAisReader;
    } else {
      aisReader = AisReaders.createDirectoryReader(dir, name, recursive);
    }

    runtime *= 1000;

    // Add times
    filter.parseStartAndEnd(starttimeStr, endtimeStr);

    // Add base stations
    filter.parseBaseStations(baseStations);

    // Add countries
    filter.parseCountries(countries);

    // Add regions
    filter.parseRegions(regions);

    // Output stream
    if (outFile == null) {
      out = System.out;
    }

    // Message handler
    // Add filters
    // Maybe insert downsampling filter
    if (downsampleRate > 0) {
      filters.add(new ReplayDownSampleFilter(downsampleRate));
    }
    if (doubletFiltering) {
      filters.add(new ReplayDuplicateFilter());
    }
    if (expression != null) {
      filters.add(new ExpressionFilter(expression));
    }
    if (geometry != null) {
      LocationFilter locationFilter = new LocationFilter();
      Area a = getGeometry(geometry);
      locationFilter.addFilterGeometry(e -> a.contains(e));
      filters.add(locationFilter);
    }

    // Register handler
    aisReader.registerPacketHandler(this);

    // Start reader thread
    long start = System.currentTimeMillis();
    aisReader.start();

    while (true) {
      Thread.sleep(500);
      if (aisReader.getStatus() == Status.DISCONNECTED) {
        break;
      }
      if (runtime > 0 && System.currentTimeMillis() - start > runtime) {
        stop = true;
        aisReader.stopReader();
        break;
      }
    }
  }