示例#1
0
  public ConnectLoop(
      @Nonnull URI wsUri,
      @Nonnull ResourceDB resourceDB,
      @Nonnull TickedEventLoop loop,
      @Nonnull String nickname)
      throws MalformedURLException {
    this.wsUri = wsUri;
    this.resourceDB = resourceDB;
    this.loop = loop;
    this.nickname = nickname;

    this.httpUrl = SwissArmyKnife.websocketURItoHTTP(wsUri);
  }
示例#2
0
    @Override
    public void run() {
      Iterator<TickedEventLoop> it;
      TickedEventLoop eventLoop;

      setName("Deadlock-" + this.getId());

      while (true) {
        it = eventLoops.iterator();
        while (it.hasNext()) {
          eventLoop = it.next();

          if (eventLoop.deadlock_tick != eventLoop.deadlock_tick_lastseen) {
            eventLoop.deadlock_tick_lastseen = eventLoop.deadlock_tick;
            continue;
          }

          eventLoops.remove(eventLoop);
          String trace = "";
          Thread thread = eventLoop.myThread;

          for (StackTraceElement stack : thread.getStackTrace()) {
            trace += stack.toString() + "\n";
          }

          boolean kill = true;

          if (listener != null) {
            kill = listener.deadlockDetected(eventLoop, thread);
          }

          if (kill) {
            log.log(
                Level.SEVERE,
                "Deadlock or infinite loop detected in thread {0}, attemping to stop ... Stack trace: \n{1}",
                new Object[] {thread.getName(), trace});

            SwissArmyKnife.logTraceOfAllThreads(log);

            thread.interrupt();

            try {
              Thread.sleep(1000);
            } catch (InterruptedException ex) {
              return;
            }

            log.log(Level.SEVERE, "Attemping stop of thread {0}", thread.getName());
            thread.stop();

            if (listener != null) {
              listener.deadlockAfterStop(eventLoop, thread);
            }

            if (gui) {
              ErrorDialog diag;
              diag = new ErrorDialog();
              diag.setTitle("Deadlock: " + thread.getName());
              diag.setErrorText(trace);
            }
          } else {
            log.log(
                Level.SEVERE,
                "Deadlock or infinite loop detected in thread {0} (no action). Stack trace: \n{1}",
                new Object[] {thread.getName(), trace});
          }
        }

        try {
          Thread.sleep(CHECK_INTERVAL_MILLIS);
        } catch (InterruptedException ex) {
          return;
        }
      }
    }