Exemplo n.º 1
0
  public void callData() {
    workingDir = System.getProperty("user.dir");
    String fileName =
        workingDir
            + File.separator
            + "data"
            + File.separator
            + "log"
            + File.separator
            + "karaf.log";
    WatchedDir = workingDir + File.separator + "data" + File.separator + "log";
    try {

      LOG.info("log enabled ...");
      Thread.sleep(10000);
      infile = new File(theNewestFile.toString());
      LOG.info("karaf file ..." + theNewestFile);
      Thread.sleep(1000);
      LOG.info("parsing karaf file ...");
      Thread.sleep(9000);
      Scanner scanner = new Scanner(infile);

      while (scanner.hasNext()) {
        line = scanner.nextLine();
        if (line.contains("DEBUG") && line.contains("from")) {

          String phrase1 = line;
          String delims = "[,]+";
          String[] tokens = phrase1.split(delims);
          String phrase2 = line;
          String delims2 = "[|]+";
          String[] tokens2 = phrase2.split(delims2);
          time = tokens[0];
          attempt = tokens2[5];
          String phrase3 = line;
          String[] parts = phrase3.split(" ");
          srcIP = parts[parts.length - 1];
          usecpluginAAAstore.addData(time, srcIP, attempt);
          LOG.info("Information stored in datastore is" + time + " " + srcIP + " " + attempt);
        }
      }
      PublishNotif publishNotif = new PublishNotif();
      publishNotif.setdataBroker(dataBroker);
      publishNotif.Notify();

    } catch (Exception e) {

      e.printStackTrace();
    }
  }
Exemplo n.º 2
0
  public File getTheNewestFile() {

    workingDir = System.getProperty("user.dir");
    String fileName =
        workingDir
            + File.separator
            + "data"
            + File.separator
            + "log"
            + File.separator
            + "karaf.log";
    WatchedDir = workingDir + File.separator + "data" + File.separator + "log";

    try {
      LOG.info("log enabled ...");
      File dir = new File(WatchedDir);
      Thread.sleep(10000);
      files = dir.listFiles();
      Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR);
      for (int i = 0; i < files.length; i++) {
        file = files[i];
        karafFiles += file.getName();
      }
      LOG.info("karaf files:" + karafFiles);
      Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_REVERSE);
      for (int i = 0; i < files.length; i++) {
        file = files[i];
        RevOrder_ofFiles += file.getName();
      }
      LOG.info("list of karaf File in reverse order" + " " + RevOrder_ofFiles);
      theNewestFile = files[0];
      LOG.info("Latest karaf File" + theNewestFile);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return theNewestFile;
  }
  void scanDirectory(String path) throws IOException, InterruptedException {

    watcher = FileSystems.getDefault().newWatchService();

    Path directoryName = null;
    Path dir = Paths.get(path);
    // dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
    registerAll(dir);

    System.out.println("er i path");

    for (; ; ) {
      WatchKey key;
      try {
        key = watcher.take();
      } catch (InterruptedException e) {
        e.printStackTrace();
        return;
      }

      //            System.out.println("er i while");

      for (WatchEvent<?> event : key.pollEvents()) {
        WatchEvent.Kind kind = event.kind();

        WatchEvent<Path> ev = (WatchEvent<Path>) event;
        Path filename = ev.context();
        Path directory;

        if (filename != null) {
          //  System.out.println("filename != null.");
          directory = dir.resolve(filename);
        } else {
          continue;
        }

        // System.out.println("filename er "+filename);
        if (kind == OVERFLOW) {
          //     System.out.println("fikk en overflow. ");
          continue;
        } else if (kind == ENTRY_MODIFY) {

          //  System.out.println(kind.name() + " for path/directory " + directory);

        } else if (kind == ENTRY_CREATE) {

          System.out.println(kind.name() + " for path/directory " + directory);
          //  System.out.println("suffix length er "+suffix[1]);
          System.out.println(kind.name() + " for path/directory " + directory);
          // System.out.println("filnavn er" + filename);
          String suffix[] = (directory.toString()).split("\\.");
          if ((suffix.length > 1) && (suffix[1].endsWith("evt"))) {
            System.out.println("Laget fil.");
            String adress =
                (directory.getParent().toAbsolutePath() + "/" + directoryName + "/" + filename);
            convertToSimpleEvent(adress);

          } else if (Files.isDirectory(directory, LinkOption.NOFOLLOW_LINKS)) {
            directoryName = filename;
            registerAll(directory);
            //   System.out.println("Laget fil og venter i 6 sec.");
            Thread.sleep(6000);
            // traverseDirectories(directory.toString());
            //  System.out.println("Ny mappe er laget på lokajson."+directory);
          }

        } else if (kind == ENTRY_DELETE) {

          System.out.println(kind.name() + " " + directory);
        }
      }

      boolean valid = key.reset();
      if (!valid) {
        System.out.println("ble ikke valid " + valid);
        keys.remove(key);

        // all directories are inaccessible
        if (keys.isEmpty()) {
          break;
        }
      }
    }
  }
Exemplo n.º 4
0
  // void processEvents() {
  public void run() {
    System.out.println("WatchDir Thread INFO: priority=" + Thread.currentThread().getPriority());
    for (; ; ) {
      // wait for key to be signalled
      System.out.println("WatchDir INFO: restarting loop...acquiring new key");
      WatchKey key;
      try {
        key = watcher.take();
      } catch (InterruptedException x) {
        return;
      }

      Path dir = keys.get(key);
      if (dir == null) {
        System.err.println("WatchKey not recognized!!");
        continue;
      }

      for (WatchEvent<?> event : key.pollEvents()) {
        WatchEvent.Kind kind = event.kind();
        // TBD - provide example of how OVERFLOW event is handled
        if (kind == OVERFLOW) {
          System.out.println("Encountered OVERFLOW Event - " + event);
          continue;
        }

        // Context for directory entry event is the file name of entry
        WatchEvent<Path> ev = cast(event);
        Path name = ev.context();
        Path child = dir.resolve(name);

        // print out event
        System.out.format("[WatchDir] %s: %s\n", event.kind().name(), child);

        // if directory is created, and watching recursively, then
        // register it and its sub-directories
        if (recursive && (kind == ENTRY_CREATE)) {
          try {
            if (Files.isDirectory(child, NOFOLLOW_LINKS)) {
              registerAll(child);
            }
          } catch (IOException x) {
            // ignore to keep sample readbale
          }
        }

        long t = System.currentTimeMillis();
        if (!Folder.dontWatch.contains(Folder.getInternalPath(child))) {
          Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
          System.out.println(
              "WatchDir#"
                  + key
                  + " INFO: path="
                  + child
                  + ", internal="
                  + Folder.getInternalPath(child)
                  + " is NOT in don't watch list. Forwarding it to other peers. @"
                  + Main.timeToString(t)); // DEBUG
          forwardToItopic(kind, child);
        } else {
          Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
          System.out.println(
              "WatchDir#"
                  + key
                  + " INFO: path="
                  + child
                  + ", internal="
                  + Folder.getInternalPath(child)
                  + " IS in the don't watch list. NOT forwarding. @"
                  + Main.timeToString(t)); // DEBUG
          // try{
          //     Thread.sleep(minDelayBtwnWatchEvents);
          // } catch(InterruptedException ex) {
          //     System.err.println("Exception:"+ex+" while trying to sleep WatchDir thread");
          //     ex.printStackTrace();
          // }
        }
      }

      // reset key and remove from set if directory no longer accessible
      boolean valid = key.reset();
      if (!valid) {
        keys.remove(key);

        // all directories are inaccessible
        if (keys.isEmpty()) {
          break;
        }
      }
    }
  }
Exemplo n.º 5
0
  @Override
  public void start(Stage primaryStage) {
    // Create four buttons, for each of the read/writing ways.
    Button btnTextNoBuffer = new Button();
    btnTextNoBuffer.setText("Save and load to text file, no buffer.");
    Button btnTextWithBuffer = new Button();
    btnTextWithBuffer.setText("Save and load to text file, with buffer.");
    Button btnBinaryNoBuffer = new Button();
    btnBinaryNoBuffer.setText("Save and load to Mapped file.");
    Button btnBinaryWithBuffer = new Button();
    btnBinaryWithBuffer.setText("Save and load to binary file, with buffer.");

    // Textfield to enter the number of edges + label
    TextField nrOfEdges = new TextField();
    Label lbl = new Label();
    lbl.setText("Enter your desired level.");

    // Label to present the read/write time.
    Label speed = new Label();
    speed.setText("The write speed will be shown here.");
    // New canvas
    kochPanel = new Canvas(kpWidth, kpHeight);
    kochPanel.setTranslateX(100);

    // position the elements
    btnTextNoBuffer.setTranslateY(-80);
    btnTextWithBuffer.setTranslateY(-40);
    btnBinaryWithBuffer.setTranslateY(40);
    btnTextNoBuffer.setTranslateX(-240);
    btnTextWithBuffer.setTranslateX(-240);
    btnBinaryNoBuffer.setTranslateX(-240);
    btnBinaryWithBuffer.setTranslateX(-240);
    nrOfEdges.setTranslateY(-220);
    nrOfEdges.setTranslateX(-310);
    nrOfEdges.setMaxWidth(50);
    lbl.setTranslateX(-240);
    lbl.setTranslateY(-200);
    speed.setTranslateY(-240);

    StackPane root = new StackPane();
    // root.getChildren().add(btnTextNoBuffer);
    // root.getChildren().add(btnTextWithBuffer);
    root.getChildren().add(btnBinaryNoBuffer);
    // root.getChildren().add(btnBinaryWithBuffer);
    // root.getChildren().add(nrOfEdges);
    // root.getChildren().add(lbl);
    root.getChildren().add(kochPanel);
    root.getChildren().add(speed);

    Scene scene = new Scene(root, 700, 500);

    primaryStage.setTitle("Edges and stuff");
    primaryStage.setScene(scene);
    primaryStage.show();

    // Event handlers for buttons
    //        btnTextNoBuffer.setOnMouseClicked(event -> {
    //            int i = Integer.parseInt(nrOfEdges.getText());
    //            currentLevel = i;
    //            clearKochPanel();
    //            createKochFractal(i);
    //            double x = 0;
    //            try {
    //                x = saveTextFileNoBuffer();
    //            } catch (IOException e) {
    //                e.printStackTrace();
    //            }
    //            speed.setText(String.valueOf((x / 1000000)));
    //            //drawAllEdges();
    //        });

    //        btnTextWithBuffer.setOnMouseClicked(event -> {
    //            int i = Integer.parseInt(nrOfEdges.getText());
    //            currentLevel = i;
    //            clearKochPanel();
    //            createKochFractal(i);
    //            double x = 0;
    //            try {
    //                x = saveTextFileWithBuffer();
    //            }
    //            catch (Exception ex)
    //            {
    //                ex.printStackTrace();
    //            }
    //            speed.setText(String.valueOf(x / 1000000));
    //            //drawAllEdges();
    //        });

    btnBinaryNoBuffer.setOnMouseClicked(
        event -> {
          // int i = Integer.parseInt(nrOfEdges.getText());
          // currentLevel = i;
          //            if (i > 10)
          //            {
          //                speed.setText("Too high of a level count!");
          //                throw new UnsupportedOperationException();
          //            }
          clearKochPanel();
          // createKochFractal(i);
          double x = 0;
          try {
            x = loadBinaryFile();
          } catch (Exception e) {
            e.printStackTrace();
          }
          speed.setText(String.valueOf(x / 1000000));
          // drawAllEdges();
        });

    btnBinaryWithBuffer.setOnMouseClicked(
        event -> {
          int i = Integer.parseInt(nrOfEdges.getText());
          currentLevel = i;
          clearKochPanel();
          createKochFractal(i);
          double x = 0;
          try {
            x = saveBinaryFileWithBuffer();
          } catch (Exception e) {
            e.printStackTrace();
          }
          speed.setText(String.valueOf(x / 1000000));
        });
    Thread t =
        new Thread() {
          public void run() {
            watchForNewEdges();
          }
        };
    t.start();
  }