/** {@inheritDoc} */
  protected void getNewMonitors(Map<String, Monitor> map) throws MonitorException {
    assert Thread.holdsLock(this);

    int used = prologue.getUsed();
    long modificationTime = prologue.getModificationTimeStamp();

    if ((used > lastUsed) || (lastModificationTime > modificationTime)) {

      lastUsed = used;
      lastModificationTime = modificationTime;

      Monitor monitor = getNextMonitorEntry();
      while (monitor != null) {
        String name = monitor.getName();

        // guard against duplicate entries
        if (!map.containsKey(name)) {
          map.put(name, monitor);

          /*
           * insertedMonitors is null when called from pollFor()
           * via buildMonitorMap(). Since we update insertedMonitors
           * at the end of buildMonitorMap(), it's ok to skip the
           * add here.
           */
          if (insertedMonitors != null) {
            insertedMonitors.add(monitor);
          }
        }
        monitor = getNextMonitorEntry();
      }
    }
  }
 public JilterStatus eom(JilterEOMActions eomActions, Properties properties) {
   logger.debug("jilter eom()");
   try {
     bos.close(); // close stream
   } catch (IOException io) {
     logger.error("jilter failed to close io stream during eom", io);
   }
   byte[] messageBytes = bos.toByteArray();
   bos = new ByteArrayOutputStream();
   ByteArrayInputStream bis = new ByteArrayInputStream(messageBytes);
   try {
     logger.debug("jilter store callback execute");
     Config.getStopBlockFactory()
         .detectBlock("milter server", Thread.currentThread(), this, IDLE_TIMEOUT);
     callback.store(bis, host);
     logger.debug("jilter store callback finished");
   } catch (ArchiveException e) {
     logger.error("failed to store the message via milter", e);
     if (e.getRecoveryDirective() == ArchiveException.RecoveryDirective.REJECT) {
       logger.debug("jilter reject");
       return JilterStatus.SMFIS_REJECT;
     } else if (e.getRecoveryDirective() == ArchiveException.RecoveryDirective.RETRYLATER) {
       logger.debug("jilter temp fail");
       return JilterStatus.SMFIS_TEMPFAIL;
     }
   } catch (Throwable oome) {
     logger.error("failed to store message:" + oome.getMessage(), oome);
     return JilterStatus.SMFIS_REJECT;
   } finally {
     Config.getStopBlockFactory().endDetectBlock(Thread.currentThread());
   }
   return JilterStatus.SMFIS_CONTINUE;
 }
  /**
   * Method to provide a gross level of synchronization with the target monitored jvm.
   *
   * <p>gross synchronization works by polling for the hotspot.rt.hrt.ticks counter, which is the
   * last counter created by the StatSampler initialization code. The counter is updated when the
   * watcher thread starts scheduling tasks, which is the last thing done in vm initialization.
   */
  protected void synchWithTarget(Map<String, Monitor> map) throws MonitorException {
    /*
     * synch must happen with syncWaitMs from now. Default is 5 seconds,
     * which is reasonabally generous and should provide for extreme
     * situations like startup delays due to allocation of large ISM heaps.
     */
    long timeLimit = System.currentTimeMillis() + syncWaitMs;

    String name = "hotspot.rt.hrt.ticks";
    LongMonitor ticks = (LongMonitor) pollFor(map, name, timeLimit);

    /*
     * loop waiting for the ticks counter to be non zero. This is
     * an indication that the jvm is initialized.
     */
    log("synchWithTarget: " + lvmid + " ");
    while (ticks.longValue() == 0) {
      log(".");

      try {
        Thread.sleep(20);
      } catch (InterruptedException e) {
      }

      if (System.currentTimeMillis() > timeLimit) {
        lognl("failed: " + lvmid);
        throw new MonitorException("Could Not Synchronize with target");
      }
    }
    lognl("success: " + lvmid);
  }
  @Override
  public synchronized void run() {
    while (!quit) {
      //			filter_input();
      try {
        Thread.sleep(1); // poll at 1kHz
        // grab data from shared buffer and move it the local one
        ourBuffer.append(sharedBuffer.take());
        // System.out.print(ourBuffer);
        // create a matcher to find an open tag in the buffer
        int endCloseTag;
        int startOpenTag;
        Matcher closeTagMatcher = closeTagPattern.matcher(ourBuffer);

        // look or a closing tag in our buffer
        if (closeTagMatcher.find()) {
          endCloseTag = closeTagMatcher.end();
          openTag = "<" + ourBuffer.charAt(closeTagMatcher.start() + 2) + ">";
          // find corresponding opening tag
          startOpenTag = ourBuffer.indexOf(openTag);
          // send the input string to the GUI for processing
          if (startOpenTag >= 0 && startOpenTag < endCloseTag) {
            gui.incoming(ourBuffer.substring(startOpenTag, endCloseTag));
            // clear our buffer
            ourBuffer.delete(startOpenTag, endCloseTag);
          } else {
            ourBuffer.delete(0, endCloseTag);
          }
        }
      } catch (Exception e) {
        System.out.print(e + "\n");
      }
    }
  }
  @Override
  public synchronized void run() {
    try {
      for (int i = 0; i < NUM_PIPES; i++) {
        while (Thread.currentThread() == reader[i]) {
          try {
            this.wait(100);
          } catch (InterruptedException ie) {
          }
          if (pin[i].available() != 0) {
            String input = this.readLine(pin[i]);
            appendMsg(htmlize(input));
            if (textArea.getDocument().getLength() > 0) {
              textArea.setCaretPosition(textArea.getDocument().getLength() - 1);
            }
          }
          if (quit) {
            return;
          }
        }
      }

    } catch (Exception e) {
      Debug.error(me + "Console reports an internal error:\n%s", e.getMessage());
    }
  }
  /**
   * Method to poll the instrumentation memory for a counter with the given name. The polling period
   * is bounded by the timeLimit argument.
   */
  protected Monitor pollFor(Map<String, Monitor> map, String name, long timeLimit)
      throws MonitorException {
    Monitor monitor = null;

    log("polling for: " + lvmid + "," + name + " ");

    pollForEntry = nextEntry;
    while ((monitor = map.get(name)) == null) {
      log(".");

      try {
        Thread.sleep(20);
      } catch (InterruptedException e) {
      }

      long t = System.currentTimeMillis();
      if ((t > timeLimit) || (overflow.intValue() > 0)) {
        lognl("failed: " + lvmid + "," + name);
        dumpAll(map, lvmid);
        throw new MonitorException("Could not find expected counter");
      }

      getNewMonitors(map);
    }
    lognl("success: " + lvmid + "," + name);
    return monitor;
  }
Esempio n. 7
0
 /**
  * Create a Thread that will retrieve and display any output. Needs to be high priority, else
  * debugger may exit before it can be displayed.
  */
 private void displayRemoteOutput(final InputStream stream) {
   Thread thr =
       new Thread("output reader") {
         @Override
         public void run() {
           try {
             dumpStream(stream);
           } catch (IOException ex) {
             MessageOutput.fatalError("Failed reading output");
           } finally {
             notifyOutputComplete();
           }
         }
       };
   thr.setPriority(Thread.MAX_PRIORITY - 1);
   thr.start();
 }
Esempio n. 8
0
  /**
   * This is called when JPM runs in the background to start jobs
   *
   * @throws Exception
   */
  public void daemon() throws Exception {
    Runtime.getRuntime()
        .addShutdownHook(
            new Thread("Daemon shutdown") {
              public void run() {

                for (Service service : startedByDaemon) {
                  try {
                    reporter.error("Stopping " + service);
                    service.stop();
                    reporter.error("Stopped " + service);
                  } catch (Exception e) {
                    // Ignore
                  }
                }
              }
            });
    List<ServiceData> services = getServices();
    Map<String, ServiceData> map = new HashMap<String, ServiceData>();
    for (ServiceData d : services) {
      map.put(d.name, d);
    }
    List<ServiceData> start = new ArrayList<ServiceData>();
    Set<ServiceData> set = new HashSet<ServiceData>();
    for (ServiceData sd : services) {
      checkStartup(map, start, sd, set);
    }

    if (start.isEmpty()) reporter.warning("No services to start");

    for (ServiceData sd : start) {
      try {
        Service service = getService(sd.name);
        reporter.trace("Starting " + service);
        String result = service.start();
        if (result != null) reporter.error("Started error " + result);
        else startedByDaemon.add(service);
        reporter.trace("Started " + service);
      } catch (Exception e) {
        reporter.error("Cannot start daemon %s, due to %s", sd.name, e);
      }
    }

    while (true) {
      for (Service sd : startedByDaemon) {
        try {
          if (!sd.isRunning()) {
            reporter.error("Starting due to failure " + sd);
            String result = sd.start();
            if (result != null) reporter.error("Started error " + result);
          }
        } catch (Exception e) {
          reporter.error("Cannot start daemon %s, due to %s", sd, e);
        }
      }
      Thread.sleep(10000);
    }
  }
Esempio n. 9
0
  public ShowComp() throws InterruptedException, IOException {
    super("CONNECTED COMPUTERS");
    int x = 0, d = 20;
    mb = new JMenuBar();
    File = new JMenu("File");
    mb.add(File);
    exit = new JMenuItem("Exit");
    exit.addActionListener(this);
    File.add(exit);
    ta = new JTextArea();
    ta.setBounds(20, 30, 315, 470);
    ta.setEditable(false);
    add(ta);

    setJMenuBar(mb);

    sel = new JLabel("The connected computers are..");
    sel.setBounds(15, 5, 300, 30);
    add(sel);
    b1 = new JButton("<< BACK");
    b1.setBounds(140, 510, 100, 30);
    b1.setToolTipText("Back to main page");
    b1.addActionListener(this);
    add(b1);
    setLayout(null);
    while (x < 360) {
      x = x + d;
      setBounds(675, 50, x, 600);
      this.show();
    }
    // setVisible(true);
    String s = "192.168.0.", temp = null;
    Printer printer = new Printer();
    printer.start();
    Connector connector = new Connector(printer);
    connector.start();

    LinkedList targets = new LinkedList();
    for (int i = 1; i <= 255; i++) {
      temp = s + Integer.toString(i);
      Target t = new Target(temp);
      targets.add(t);
      connector.add(t);
    }
    Thread.sleep(2000);
    connector.shutdown();
    connector.join();

    for (Iterator i = targets.iterator(); i.hasNext(); ) {
      Target t = (Target) i.next();
      if (!t.shown) t.show();
    }

    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  }
Esempio n. 10
0
 // To be called exactly twice by the child process
 public static void rendezvousChild() {
   try {
     for (int i = 0; i < 100; i++) {
       System.gc();
       System.runFinalization();
       Thread.sleep(50);
     }
     System.out.write((byte) '\n');
     System.out.flush();
     System.in.read();
   } catch (Throwable t) {
     throw new Error(t);
   }
 }
  /** {@inheritDoc} */
  protected MonitorStatus getMonitorStatus(Map<String, Monitor> map) throws MonitorException {
    assert Thread.holdsLock(this);
    assert insertedMonitors != null;

    // load any new monitors
    getNewMonitors(map);

    // current implementation doesn't support deletion or reuse of entries
    ArrayList removed = EMPTY_LIST;
    ArrayList inserted = insertedMonitors;

    insertedMonitors = new ArrayList<Monitor>();
    return new MonitorStatus(inserted, removed);
  }
Esempio n. 12
0
  public void run() {
    Map read;
    boolean shouldRead = go_read;
    String command = null;
    long last = 0;

    try {
      /* swallow the banner if requested to do so */
      if (swallow) {
        readResponse();
      }

      while (shouldRead) {
        synchronized (listeners) {
          if (commands.size() > 0) {
            command = (String) commands.removeFirst();
          }
        }

        if (command != null) {
          _sendString(command);
          command = null;
          lastRead = System.currentTimeMillis();
        }

        long now = System.currentTimeMillis();
        if (this.window != null && !this.window.isShowing() && (now - last) < 1500) {
          /* check if our window is not showing... if not, then we're going to switch to a very reduced
          read schedule. */
        } else {
          read = readResponse();
          if (read == null || "failure".equals(read.get("result") + "")) {
            break;
          }

          processRead(read);
          last = System.currentTimeMillis();
        }

        Thread.sleep(100);

        synchronized (listeners) {
          shouldRead = go_read;
        }
      }
    } catch (Exception javaSucksBecauseItMakesMeCatchEverythingFuckingThing) {
      javaSucksBecauseItMakesMeCatchEverythingFuckingThing.printStackTrace();
    }
  }
  /**
   * Stops this <tt>ContactSourceService</tt> implementation and prepares it for garbage collection.
   *
   * @see AsyncContactSourceService#stop()
   */
  public void stop() {
    boolean interrupted = false;

    synchronized (queries) {
      while (!queries.isEmpty()) {
        queries.get(0).cancel();
        try {
          queries.wait();
        } catch (InterruptedException iex) {
          interrupted = true;
        }
      }
    }
    if (interrupted) Thread.currentThread().interrupt();
  }
  public void startThread() {

    if (!connected) return;

    // Use this inner class to hide the public run method
    Runnable r =
        new Runnable() {
          public void run() {
            runWork();
          }
        };
    runit = true;
    fetchDataThread = new Thread(r, "DataVideoGather");
    fetchDataThread.start();
    System.out.println("DataVideoGather: Started thread.");
  }
  public void handleBlock(Thread thread) {

    try {
      if (socket != null) {
        logger.debug("close socket()");
        socket.close();
      }
    } catch (Exception e) {
      // ignored
    }
    synchronized (this) {
      if (thread != null) {
        logger.debug("interrupt thread()");
        thread.interrupt();
      }
    }
  }
Esempio n. 16
0
 /**
  * Returns the current file cache.
  *
  * @param root root directory
  * @return id, or {@code null} if newer file cache exists
  * @throws InterruptedException interruption
  */
 ProjectCache cache(final IOFile root) throws InterruptedException {
   final ProjectCache pc = cache;
   if (pc == null) {
     // no file cache available: create and return new one
     cache = new ProjectCache();
     add(root, cache);
     cache.finish();
   } else {
     // wait until file cache is initialized
     while (!pc.valid()) {
       Thread.yield();
       // file cache was replaced with newer version
       if (pc != cache) throw new InterruptedException();
     }
   }
   // return existing file cache
   return cache;
 }
  /** {@inheritDoc} */
  protected void buildMonitorMap(Map<String, Monitor> map) throws MonitorException {
    assert Thread.holdsLock(this);

    // start at the beginning of the buffer
    buffer.rewind();

    // create pseudo monitors
    buildPseudoMonitors(map);

    // position buffer to start of the data section
    buffer.position(prologue.getSize());
    nextEntry = buffer.position();
    perfDataItem = 0;

    int used = prologue.getUsed();
    long modificationTime = prologue.getModificationTimeStamp();

    Monitor m = getNextMonitorEntry();
    while (m != null) {
      map.put(m.getName(), m);
      m = getNextMonitorEntry();
    }

    /*
     * set the last modification data. These are set to the values
     * recorded before parsing the data structure. This allows the
     * the data structure to be modified while the Map is being built.
     * The Map may contain more entries than indicated based on the
     * time stamp, but this is handled by ignoring duplicate entries
     * when the Map is updated in getNewMonitors().
     */
    lastUsed = used;
    lastModificationTime = modificationTime;

    // synchronize with the target jvm
    synchWithTarget(map);

    // work around 1.4.2 counter inititization bugs
    kludge(map);

    insertedMonitors = new ArrayList<Monitor>(map.values());
  }
Esempio n. 18
0
File: ZCM.java Progetto: ZeroCM/zcm
  /** Minimalist test code. */
  public static void main(String args[]) {
    ZCM zcm;

    try {
      zcm = new ZCM();
    } catch (IOException ex) {
      System.err.println("ex: " + ex);
      return;
    }

    zcm.subscribe(".*", new SimpleSubscriber());

    while (true) {
      try {
        Thread.sleep(100);
        zcm.publish("TEST", "foobar");
      } catch (Exception ex) {
        System.err.println("ex: " + ex);
      }
    }
  }
Esempio n. 19
0
  public static void main(String[] args) throws Exception {

    Properties configFile = new Properties();
    configFile.load(new FileInputStream("my_config.properties"));
    myConnString = configFile.getProperty("MYCONN");

    try {
      mysqlConn = DriverManager.getConnection(myConnString);
      myStm = mysqlConn.createStatement();
      myStm.executeQuery("set wait_timeout = 7200");
    } catch (Exception e) {
      System.out.println("MySQL Offline.");
      System.exit(1);
    }

    getBlogs();

    Thread.sleep(1000); // For cleaning mongo cursos

    myStm.close();
  }
Esempio n. 20
0
 public static void sleep(int ms) {
   try {
     Thread.sleep(ms);
   } catch (Exception e) {
   }
 }
Esempio n. 21
0
  @Override
  public void onTick() {
    if (!bot.hasSpawned() || !bot.isConnected()) return;
    if (ticksToGo > 0) {
      ticksToGo--;
      return;
    }

    MainPlayerEntity player = bot.getPlayer();
    if (player == null) return;
    if (firstStart) {
      bot.say("/tpa DarkStorm_");
      ticksToGo = 15;
      firstStart = false;
      return;
    } else if (asdfasdfasdf) {
      bot.say("/warp arena");
      ticksToGo = 200;
      asdfasdfasdf = false;
      return;
    } else if (asdfasdf) {
      bot.say("/pay DarkStorm_ 1000");
      try {
        Thread.sleep(500);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      /*try {
      	PlayerInventory inventory = player.getInventory();
      	for(int i = 0; i < 44; i++) {
      		ItemStack item = inventory.getItemAt(i);
      		if(item != null) {
      			inventory.selectItemAt(i);
      			inventory.dropSelectedItem();
      		}
      	}
      } catch(Exception exception) {}*/
      bot.say("\247bai");
      asdfasdf = false;
      return;
    }
    // connectionHandler.disconnect("");
    // return;
    // } else if("".equals(""))
    // return;
    // if(player.getDistanceTo(spawn) < 7 && player.getZ() < 589.5) {
    // player.setZ(player.getZ() + 0.12);
    // bot.updateMovement();
    // } else
    // canSpam = true;

    // if(player.getDistanceTo(spawn) < 10 && player.getY() < 72) {
    // if(player.getZ() < -37.6)
    // player.setZ(player.getZ() + 0.1);
    // else if(player.getX() < 232.4)
    // player.setX(player.getX() + 0.1);
    // else
    // player.setY(player.getY() + 0.1);
    // bot.updateMovement();
    // } else if(player.getZ() > -38 && player.getZ() < -36.6
    // && player.getX() > 232 && player.getX() < 233) {
    // player.setZ(player.getZ() + 0.1);
    // bot.updateMovement();
    // } else

    // if(player.getDistanceToSquared(spawn) > 49)
    // mode = 3;
    // if(mode == 0)
    // mode = player.getZ() > 295 ? 2 : 1;
    // switch(mode) {
    // case -1:
    // canSpam = true;
    // break;
    // case 1:
    // canSpam = false;
    // if(player.getZ() < 296.3) {
    // player.setZ(player.getZ() + 0.1);
    // bot.updateMovement();
    // } else
    // mode = -1;
    // break;
    // case 2:
    // canSpam = false;
    // if(player.getZ() > 286.6) {
    // player.setZ(player.getZ() - 0.1);
    // bot.updateMovement();
    // } else
    // mode = -1;
    // break;
    // default:
    // connectionHandler.disconnect("Bad location!");
    // break;
    // }

    canSpam = true;
  }
Esempio n. 22
0
  private DarkBotMCSpambot(
      DarkBot darkBot,
      String server,
      String username,
      String password,
      String sessionId,
      String loginProxy,
      String proxy,
      String owner) {
    synchronized (bots) {
      bots.add(this);
      // slotsTaken.incrementAndGet();
      synchronized (slotsTaken) {
        slotsTaken.notifyAll();
      }
    }
    MinecraftBotData.Builder builder = MinecraftBotData.builder();
    // botData.nickname = "";
    // for(int i = 0; i < 10; i++)
    // botData.nickname += alphas[random.nextInt(alphas.length)];
    if (proxy != null && !proxy.isEmpty()) {
      int port = 80;
      ProxyType type = ProxyType.SOCKS;
      if (proxy.contains(":")) {
        String[] parts = proxy.split(":");
        proxy = parts[0];
        port = Integer.parseInt(parts[1]);
        if (parts.length > 2) type = ProxyType.values()[Integer.parseInt(parts[2]) - 1];
      }
      builder.withSocksProxy(new ProxyData(proxy, port, type));
      this.proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(proxy, port));
    }
    if (loginProxy != null && !loginProxy.isEmpty()) {
      int port = 80;
      if (loginProxy.contains(":")) {
        String[] parts = loginProxy.split(":");
        loginProxy = parts[0];
        port = Integer.parseInt(parts[1]);
      }
      builder.withHttpProxy(new ProxyData(loginProxy, port, ProxyType.HTTP));
      this.loginProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(loginProxy, port));
    }
    builder.withUsername(username);
    if (sessionId != null) builder.withSessionId(sessionId);
    else builder.withPassword(password);
    if (server != null && !server.isEmpty()) {
      int port = 25565;
      if (server.contains(":")) {
        String[] parts = server.split(":");
        server = parts[0];
        port = Integer.parseInt(parts[1]);
      }
      builder.withServer(server).withPort(port);
    } else throw new IllegalArgumentException("Unknown server!");

    this.owner = owner;
    MinecraftBotData botData = builder.build();
    System.setProperty("socksProxyHost", "");
    System.setProperty("socksProxyPort", "");
    System.out.println("[" + username + "] Connecting...");
    bot = new MinecraftBot(darkBot, botData);
    bot.setMovementDisabled(true);
    connectionHandler = bot.getConnectionHandler();
    Session session = bot.getSession();
    // System.gc();
    System.out.println("[" + username + "] Done! (" + amountJoined.incrementAndGet() + ")");
    bot.getEventManager().registerListener(this);
    bot.getGameHandler().registerListener(this);

    long lastShoutTime = System.currentTimeMillis();
    while (bot.isConnected()) {
      if (die) {
        connectionHandler.sendPacket(new Packet255KickDisconnect("Goodbye"));
        return;
      }
      try {
        Thread.sleep(3000 + random.nextInt(1000));
      } catch (InterruptedException exception) {
        exception.printStackTrace();
      }
      if (!bot.hasSpawned()) continue;
      connectionHandler.sendPacket(new Packet0KeepAlive(random.nextInt()));
      if (spamMessage == null || !canSpam) continue;
      String message = spamMessage;
      if (message.contains("%skill")) message = message.replace("%skill", skills[nextSkill++]);
      if (nextSkill >= skills.length) nextSkill = 0;
      if (message.contains("%bot")) {
        synchronized (bots) {
          message =
              message.replace(
                  "%bot",
                  bots.get(nextBot > bots.size() ? (nextBot = 0) * 0 : nextBot++)
                      .bot
                      .getSession()
                      .getUsername());
        }
      }
      if (message.contains("%spamlist"))
        message = message.replace("%spamlist", spamList[nextSpamList++]);
      if (nextSpamList >= spamList.length) nextSpamList = 0;
      if (message.contains("%rnd")) {
        int length = 1;
        int index = message.indexOf("%rnd") + "%rnd".length();
        int lastIndex;
        for (lastIndex = index; lastIndex < message.length(); lastIndex++)
          if (Character.isDigit(message.charAt(lastIndex))) lastIndex++;
          else break;
        if (lastIndex > message.length()) lastIndex--;
        try {
          System.out.println(index + "," + lastIndex + "," + message.length());
          length = Integer.parseInt(message.substring(index, lastIndex));
        } catch (Exception exception) {
        }

        String randomChars = "";
        for (int i = 0; i < length; i++) randomChars += alphas[random.nextInt(alphas.length)];
        message = message.replace("%rnd", randomChars);
      }
      if (message.contains("%msg"))
        message = "/msg " + msgChars[nextMsgChar++] + " " + message.replace("%msg", "");
      if (message.contains("%ernd")) {
        message = message.replace("%ernd", "");
        int extraMessageLength = 15 + random.nextInt(6);
        message = message.substring(0, Math.min(100 - extraMessageLength, message.length())) + " [";
        extraMessageLength -= 3;
        for (int i = 0; i < extraMessageLength; i++)
          message += alphas[random.nextInt(alphas.length)];
        message += "]";
      } else message = message.substring(0, Math.min(100, message.length()));
      connectionHandler.sendPacket(new Packet3Chat(message));
    }
    synchronized (bots) {
      bots.remove(this);
    }
    amountJoined.decrementAndGet();
    slotsTaken.decrementAndGet();
    synchronized (slotsTaken) {
      slotsTaken.notifyAll();
    }
  }
  /**
   * Method to move files from HDFS to local filesystem
   *
   * <p>localPath: Path on the machines filesystem fs:FileSystem object from HDFS pathList:List of
   * paths for files that might need to be backed up size:max size in bytes to be backed up
   *
   * <p>ReturnsDate of the last files backed up if reached size limit, else, zero
   */
  public long backupFiles(
      String localPath, String preservePath, FileSystem fs, ArrayList<Path> pathList, long size) {
    Path fsPath;
    long tmpSize = 0;
    long tmpDate = 0;

    // Start iterating over all paths
    for (Path hdfsPath : pathList) {
      try {
        long nFileSize = fs.getContentSummary(hdfsPath).getLength();
        tmpSize = tmpSize + nFileSize;

        if ((tmpSize <= size) || (size == 0)) {
          FileStatus stat = fs.getFileStatus(hdfsPath);

          System.err.println(
              "File "
                  + hdfsPath.toUri().getPath()
                  + " "
                  + nFileSize
                  + " bytes, "
                  + "perms: "
                  + stat.getOwner()
                  + "/"
                  + stat.getGroup()
                  + ", "
                  + stat.getPermission().toString());

          tmpDate = stat.getModificationTime() / 1000;

          String sFsPath = localPath + hdfsPath.toUri().getPath();
          fsPath = new Path(sFsPath);

          File f = new File(sFsPath);

          // COMMENTED OUT: until a few backup cycles run
          // and the mtime gets in fact set on all copied
          // files.
          //
          // ignore it if the file exists and has the same mtime
          // if (f.exists() && f.isFile() && f.lastModified() == stat.getModificationTime())
          // {
          // System.out.println("no need to backup " + f.toString() + ", mtime matches hdfs");
          // continue;
          // }

          if (false == m_bDryRun) {
            // check if we need to back up the local file
            // (not directory), if it already exists.
            if (f.exists() && f.isFile()) {
              // ignore files with substrings in the
              // no-preserve file
              if (true == doPreserveFile(sFsPath)) {
                // move it to the backup path
                String sNewPath = preservePath + hdfsPath.toUri().getPath();
                File newFile = new File(sNewPath);

                // create directory structure for new file?
                if (false == newFile.getParentFile().exists()) {
                  if (false == newFile.getParentFile().mkdirs()) {
                    System.err.println("Failed to mkdirs " + newFile.getParentFile().toString());
                    System.exit(1);
                  }
                }

                // rename existing file to new location
                if (false == f.renameTo(newFile)) {
                  System.err.println(
                      "Failed to renameTo " + f.toString() + " to " + newFile.toString());
                  System.exit(1);
                }

                System.out.println("preserved " + f.toString() + " into " + newFile.toString());
              } else {
                System.out.println("skipped preservation of " + f.toString());
              }
            }

            // copy from hdfs to local filesystem
            fs.copyToLocalFile(hdfsPath, fsPath);

            // set the mtime to match hdfs file
            f.setLastModified(stat.getModificationTime());

            // compare checksums on both files
            compareChecksums(fs, hdfsPath, sFsPath);
          }

          // don't print the progress after every file -- go
          // by at least 1% increments
          long nPercentDone = (long) (100 * tmpSize / m_nTotalBytes);
          if (nPercentDone > m_nLastPercentBytesDone) {
            System.out.println(
                "progress: copied "
                    + prettyPrintBytes(tmpSize)
                    + ", "
                    + nPercentDone
                    + "% done"
                    + ", tstamp="
                    + tmpDate);

            m_nLastPercentBytesDone = nPercentDone;
          }

          if (m_nSleepSeconds > 0) {
            try {
              Thread.sleep(1000 * m_nSleepSeconds);
            } catch (Exception e2) {
              // ignore
            }
          }
        } else {
          return tmpDate;
        }
      } catch (IOException e) {
        System.err.println("FATAL ERROR: Something wrong with the file");
        System.err.println(e);
        System.out.println(tmpDate);
        System.exit(1);

        return 0;
      }
    }

    return 0;
  }
Esempio n. 24
0
 static void fail() {
   failed++;
   Thread.dumpStack();
 }
 public void stopThread() {
   runit = false;
   fetchDataThread.interrupt();
   System.out.println("DataVideoGather: Stopped thread.");
 }
Esempio n. 26
0
  @Test
  public void testVip7day() throws Exception {

    driver
        .manage()
        .timeouts()
        .implicitlyWait(30, TimeUnit.SECONDS); // неявное ожидание при каждом поиске элементов
    driver.get("http://mylove.ru");

    driver.findElement(By.id("mprofile_link")).click();
    driver.findElement(By.cssSelector("#isvip")).click();

    if (isElementPresent(By.xpath("//*[@id='settings']"))) {
      driver.findElement(By.xpath("//*[@id='settings']//a[contains(@class,'techbutton')]")).click();
    }
    Pattern pat = Pattern.compile("[-]?[0-9]+(.[0-9]+)?");
    // String Str1= driver.findElement(By.cssSelector("div.vipend > i")).getText();
    String Str1 =
        driver
            .findElement(
                By.cssSelector("#body > div.window.pay_window > div > div.paymay > div.vipend > i"))
            .getText();

    Matcher matcher1 = pat.matcher(Str1);
    while (matcher1.find()) Str1 = matcher1.group(); // что-то происходит

    Str1 = Str1.replaceAll(" ", "");
    Integer i1 = Integer.valueOf(Str1);
    // driver.findElement(By.xpath("//*[@id=\"vip_settings\"]/div[2]/a[1]")).click(); тоже верно

    driver.findElement(By.cssSelector("#vip_settings  div.pcols > a")).click();

    Thread.sleep(
        1000); /// без ожидания не успевает измениться выбранное значение дней, потом заменить на
               // явное ожидание с условием
    driver
        .findElement(By.cssSelector("div.pay_variant.pay_bill.pay_variant_cash > a"))
        .click(); // Платим со счета

    WebDriverWait wait = new WebDriverWait(driver, 20);
    wait.until(
        ExpectedConditions.stalenessOf(
            driver.findElement(
                By.cssSelector(
                    "#isvip")))); // подождем когда какой то DOM исчезнет(( чтобы посмотреть сколько
                                  // теперь дней до окончания випа, долго работает

    driver.findElement(By.cssSelector("#isvip")).click();
    driver.findElement(By.xpath("//*[@id='settings']//a[contains(@class,'techbutton')]")).click();
    String Str2 = driver.findElement(By.cssSelector("div.vipend > i")).getText();

    Matcher matcher2 = pat.matcher(Str2);

    while (matcher2.find()) Str2 = matcher2.group();
    Str2 = Str2.replaceAll(" ", ""); // если дней больше 1000 то строка с пробелами
    Integer i2 = Integer.valueOf(Str2);
    i1 = i1 + 7;

    // Проверим что количество дней випа увеличилось на 7
    assertEquals(i2, i1);
  };
Esempio n. 27
0
 // Overriding "start()"
 public void start() {
   running = true;
   super.start();
 }