Esempio n. 1
0
 public String getTitle() {
   LinkedList<Throwable> stack = getStack();
   if (stack.isEmpty()) {
     return "NO EXCEPTION";
   } else {
     return getTitle(stack.removeFirst());
   }
 }
Esempio n. 2
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. 3
0
 public void run() {
   try {
     for (; ; ) {
       Target t = null;
       synchronized (pending) {
         while (pending.size() == 0) pending.wait();
         t = (Target) pending.removeFirst();
       }
       t.show();
     }
   } catch (InterruptedException x) {
     return;
   }
 }
Esempio n. 4
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();
    }
  }
 public int bfs() {
   int[] record = new int[n];
   Arrays.fill(record, Integer.MAX_VALUE);
   LinkedList<Integer> queue = new LinkedList<Integer>();
   queue.addLast(0);
   int distance = 0;
   int count = 1;
   while (queue.size() > 0) {
     int newCount = 0;
     while (count > 0) {
       int tempPoint = queue.pollFirst();
       ArrayList<Road> tempRoads = roads[tempPoint];
     }
     distance++;
   }
 }
Esempio n. 6
0
    void add(Target t) {
      SocketChannel sc = null;
      try {

        sc = SocketChannel.open();
        sc.configureBlocking(false);

        boolean connected = sc.connect(t.address);

        t.channel = sc;
        t.connectStart = System.currentTimeMillis();

        if (connected) {
          t.connectFinish = t.connectStart;
          sc.close();
          printer.add(t);
        } else {
          synchronized (pending) {
            pending.add(t);
          }

          sel.wakeup();
        }
      } catch (IOException x) {
        if (sc != null) {
          try {
            sc.close();
          } catch (IOException xx) {
          }
        }
        t.failure = x;
        printer.add(t);
      }
    }
Esempio n. 7
0
    void processPendingTargets() throws IOException {
      synchronized (pending) {
        while (pending.size() > 0) {
          Target t = (Target) pending.removeFirst();
          try {

            t.channel.register(sel, SelectionKey.OP_CONNECT, t);

          } catch (IOException x) {

            t.channel.close();
            t.failure = x;
            printer.add(t);
          }
        }
      }
    }
Esempio n. 8
0
 protected LinkedList<Throwable> getStack() {
   Throwable e = exception;
   LinkedList<Throwable> stack = new LinkedList<Throwable>();
   while (e != null) {
     stack.addFirst(e);
     if (e instanceof NotFoundException) {
       status = HttpServletResponse.SC_NOT_FOUND;
     }
     if (e instanceof ServletException) {
       Throwable t = ((ServletException) e).getRootCause();
       if (t == null) t = e.getCause();
       e = t;
     } else if (e instanceof javax.servlet.jsp.JspException) {
       Throwable t = ((JspException) e).getRootCause();
       if (t == null) t = e.getCause();
       e = t;
     } else {
       e = e.getCause();
     }
   }
   return stack;
 }
 public void search(Vertex[] nodes, int start) {
   LinkedList<Vertex> queue = new LinkedList<>();
   nodes[start].numPaths = 1;
   nodes[start].minDistance = 0;
   queue.addLast(nodes[start]);
   while (!queue.isEmpty()) {
     Vertex curr = queue.removeFirst();
     for (Edge e : curr.edges) {
       Vertex other = e.end;
       if (!other.checked) {
         other.checked = true;
         queue.addLast(other);
       }
       if (curr.minDistance + e.weight < other.minDistance) {
         other.minDistance = curr.minDistance + e.weight;
         other.numPaths = curr.numPaths;
       } else if (curr.minDistance + e.weight == other.minDistance) {
         other.numPaths += curr.numPaths;
       }
     }
   }
 }
Esempio n. 10
0
  public Collection<NamedRegion> parseProbes() throws IOException {
    double ethreshold = 1.0e-3;
    Parser<BlastTabEntry> parser =
        new Parser<BlastTabEntry>(blasttab, new BlastTabEntry.ParsingMapper());
    Iterator<BlastTabEntry> itr =
        new FilterIterator<BlastTabEntry, BlastTabEntry>(
            new BlastTabEntry.ExpectedScoreFilter(ethreshold), parser);

    Map<String, Set<Region>> primerHits = new TreeMap<String, Set<Region>>();
    Set<String> primerNames = new TreeSet<String>();

    while (itr.hasNext()) {
      BlastTabEntry entry = itr.next();
      NamedRegion r = createNamedRegion(entry);
      if (!primerHits.containsKey(entry.getQuery())) {
        primerHits.put(entry.getQuery(), new HashSet<Region>());
      }
      primerHits.get(entry.getQuery()).add(r);
      primerNames.add(removePrimerLR(entry.getQuery()));
    }

    LinkedList<NamedRegion> probes = new LinkedList<NamedRegion>();

    for (String primerName : primerNames) {
      Pair<Region, Region> hits = findProbePair(primerName, primerHits);
      if (hits != null) {
        Region left = hits.getFirst(), right = hits.getLast();
        int start = Math.min(left.getStart(), right.getStart());
        int end = Math.max(left.getEnd(), right.getEnd());

        NamedRegion probe = new NamedRegion(genome, left.getChrom(), start, end, primerName);
        probes.addLast(probe);
      }
    }

    return probes;
  }
Esempio n. 11
0
  public void drawsmall(GOut g, Coord br, int h) {
    Coord c;
    if (qline != null) {
      if ((rqline == null) || !rqline.text.equals(qline.line)) {
        String pre = String.format("%s> ", qline.chan.name());
        rqline = qfnd.render(pre + qline.line);
        rqpre = pre.length();
      }
      c = br.sub(0, 20);
      g.chcolor(24, 24, 16, 200);
      g.frect(c, rqline.tex().sz());
      g.chcolor();
      g.image(rqline.tex(), c);
      int lx = rqline.advance(qline.point + rqpre);
      g.line(new Coord(br.x + lx + 1, br.y - 18), new Coord(br.x + lx + 1, br.y - 6), 1);
    } else {
      c = br.sub(0, 5);
    }
    long now = System.currentTimeMillis();
    synchronized (notifs) {
      for (Iterator<Notification> i = notifs.iterator(); i.hasNext(); ) {
        Notification n = i.next();
        if (now - n.time > 5000) {
          i.remove();
          continue;
        }
        if ((c.y -= n.msg.sz().y) < br.y - h) break;

        g.chcolor(24, 24, 16, 200);
        g.frect(c, n.chnm.tex().sz().add(n.msg.tex().sz().x + selw, 0));
        g.chcolor();
        g.image(n.chnm.tex(), c, br.sub(0, h), br.add(selw - 10, 0));
        g.image(n.msg.tex(), c.add(selw, 0));
      }
    }
  }
Esempio n. 12
0
 public void sendString(String text) {
   synchronized (listeners) {
     commands.add(text);
   }
 }
Esempio n. 13
0
    public Writer getErrorReport(
        Writer to, final HttpServletRequest request, CharTransformer escape) throws IOException {
      final Writer logMsg = new StringWriter();
      final Writer tee = new org.mmbase.util.ChainedWriter(to, logMsg);
      Writer msg = tee;

      LinkedList<Throwable> stack = getStack();
      String ticket = new Date().toString();

      Map<String, String> props;
      try {
        props = org.mmbase.util.ApplicationContextReader.getProperties("mmbase_errorpage");
      } catch (javax.naming.NamingException ne) {
        props = Collections.emptyMap();
        log.info(ne);
      }

      if (request != null) {
        {
          msg.append("Headers\n----------\n");
          // request properties
          for (Object name : Collections.list(request.getHeaderNames())) {
            msg.append(
                escape.transform(
                    name + ": " + escape.transform(request.getHeader((String) name)) + "\n"));
          }
        }
        {
          msg.append("\nAttributes\n----------\n");
          Pattern p = requestIgnore;
          if (p == null && props.get("request_ignore") != null) {
            p = Pattern.compile(props.get("request_ignore"));
          }
          for (Object name : Collections.list(request.getAttributeNames())) {
            if (p == null || !p.matcher((String) name).matches()) {
              msg.append(
                  escape.transform(name + ": " + request.getAttribute((String) name) + "\n"));
            }
          }
        }
        if (Boolean.TRUE.equals(showSession)
            || (showSession == null && !"false".equals(props.get("show_session")))) {
          HttpSession ses = request.getSession(false);
          if (ses != null) {
            msg.append("\nSession\n----------\n");
            Pattern p = sessionIgnore;
            if (p == null && props.get("session_ignore") != null) {
              p = Pattern.compile(props.get("session_ignore"));
            }
            for (Object name : Collections.list(ses.getAttributeNames())) {
              if (p == null || !p.matcher((String) name).matches()) {
                msg.append(escape.transform(name + ": " + ses.getAttribute((String) name) + "\n"));
              }
            }
          }
        }
      }
      msg.append("\n");
      msg.append("Misc. properties\n----------\n");

      if (request != null) {
        msg.append("method: ").append(escape.transform(request.getMethod())).append("\n");
        msg.append("querystring: ").append(escape.transform(request.getQueryString())).append("\n");
        msg.append("requesturl: ")
            .append(escape.transform(request.getRequestURL().toString()))
            .append("\n");
      }
      if (Boolean.TRUE.equals(showMMBaseVersion)
          || (showMMBaseVersion == null && !"false".equals(props.get("show_mmbase_version")))) {
        msg.append("mmbase version: ").append(org.mmbase.Version.get()).append("\n");
      }
      msg.append("status: ").append("").append(String.valueOf(status)).append("\n\n");

      if (request != null) {
        msg.append("Parameters\n----------\n");
        // request parameters
        Enumeration en = request.getParameterNames();
        while (en.hasMoreElements()) {
          String name = (String) en.nextElement();
          msg.append(name)
              .append(": ")
              .append(escape.transform(request.getParameter(name)))
              .append("\n");
        }
      }
      msg.append("\nException ")
          .append(ticket)
          .append("\n----------\n\n")
          .append(
              exception != null
                  ? (escape.transform(exception.getClass().getName()))
                  : "NO EXCEPTION")
          .append(": ");

      int wroteCauses = 0;
      while (!stack.isEmpty()) {

        Throwable t = stack.removeFirst();
        // add stack stacktraces
        if (t != null) {
          if (stack.isEmpty()) { // write last message always
            msg = tee;
          }
          String message = t.getMessage();
          if (msg != tee) {
            to.append("\n=== skipped(see log)  : ")
                .append(escape.transform(t.getClass().getName()))
                .append(": ")
                .append(message)
                .append("\n");
          }

          msg.append("\n\n").append(escape.transform(t.getClass().getName() + ": " + message));
          StackTraceElement[] stackTrace = t.getStackTrace();
          for (StackTraceElement e : stackTrace) {
            msg.append("\n        at ").append(escape.transform(e.toString()));
          }
          if (!stack.isEmpty()) {
            msg.append("\n-------caused:\n");
          }
          wroteCauses++;
          if (wroteCauses >= MAX_CAUSES) {
            msg = logMsg;
          }
        }
      }
      // write errors to  log
      if (status == 500) {
        try {
          if (props.get("to") != null && props.get("to").length() > 0) {
            javax.naming.Context initCtx = new javax.naming.InitialContext();
            javax.naming.Context envCtx = (javax.naming.Context) initCtx.lookup("java:comp/env");
            Object mailSession = envCtx.lookup("mail/Session");
            Class sessionClass = Class.forName("javax.mail.Session");
            Class recipientTypeClass = Class.forName("javax.mail.Message$RecipientType");
            Class messageClass = Class.forName("javax.mail.internet.MimeMessage");
            Object mail = messageClass.getConstructor(sessionClass).newInstance(mailSession);
            messageClass
                .getMethod("addRecipients", recipientTypeClass, String.class)
                .invoke(mail, recipientTypeClass.getDeclaredField("TO").get(null), props.get("to"));
            messageClass.getMethod("setSubject", String.class).invoke(mail, ticket);
            mail.getClass().getMethod("setText", String.class).invoke(mail, logMsg.toString());
            Class.forName("javax.mail.Transport")
                .getMethod("send", Class.forName("javax.mail.Message"))
                .invoke(null, mail);
            tee.append("\nmailed to (").append(String.valueOf(props)).append(")");
          }

        } catch (Exception nnfe) {
          tee.append("\nnot mailed (").append(String.valueOf(nnfe)).append(")");
          if (log.isDebugEnabled()) {
            log.debug(nnfe.getMessage(), nnfe);
          }
        }
        log.error("TICKET " + ticket + ":\n" + logMsg);
      }
      return to;
    }
Esempio n. 14
0
 public void addSessionListener(ConsoleCallback l) {
   listeners.add(l);
 }
Esempio n. 15
0
 public void fireSessionWroteEvent(String text) {
   Iterator i = listeners.iterator();
   while (i.hasNext()) {
     ((ConsoleCallback) i.next()).sessionWrote(session, text);
   }
 }
Esempio n. 16
0
 void add(Target t) {
   synchronized (pending) {
     pending.add(t);
     pending.notify();
   }
 }
Esempio n. 17
0
 public void notify(Channel chan, Channel.Message msg) {
   synchronized (notifs) {
     notifs.addFirst(new Notification(chan, msg));
   }
   Audio.play(notifsfx);
 }