Example #1
0
  public void register(RegPanel reg) {

    if (this.surname.trim().isEmpty()) {
      JOptionPane.showMessageDialog(reg, "Surname required", "Error", JOptionPane.ERROR_MESSAGE);
    } else if (this.names.trim().isEmpty()) {
      JOptionPane.showMessageDialog(reg, "Names required", "Error", JOptionPane.ERROR_MESSAGE);
    } else if (this.tmp_ID.trim().isEmpty()) {
      JOptionPane.showMessageDialog(reg, "ID Number required", "Error", JOptionPane.ERROR_MESSAGE);
    } else if (this.password1.trim().isEmpty()) {
      JOptionPane.showMessageDialog(reg, "Password required", "Error", JOptionPane.ERROR_MESSAGE);
    } else if (this.password2.trim().isEmpty()) {
      JOptionPane.showMessageDialog(
          reg, "Confirmation Password required", "Error", JOptionPane.ERROR_MESSAGE);
    } else if (!this.password1.trim().equals(this.password2)) {
      JOptionPane.showMessageDialog(
          reg, "Unmatching Passwords", "Error", JOptionPane.ERROR_MESSAGE);
    } else {
      this.password = Connector.hash(this.password1);

      Connection conn = Connector.createConnection();
      PreparedStatement stmt;

      int agent_id;

      try {
        this.ID = Long.parseLong(this.tmp_ID);

        String sql = "INSERT INTO agents (ID_NO,sname,names,password) VALUES (?,?,?,?)";
        stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
        stmt.setLong(1, this.ID);
        stmt.setString(2, this.surname);
        stmt.setString(3, this.names);
        stmt.setString(4, this.password);
        stmt.executeUpdate();

        ResultSet res = stmt.getGeneratedKeys();

        if (res.next()) {
          agent_id = res.getInt(1);
          Agent ag = new Agent(agent_id, conn);
          new SessionController(ag);
          reg.setVisible(false);
          new Start().setVisible(true);

        } else {
          System.out.println("Error getting insert id");
          System.exit(1);
        }

      } catch (SQLException e) {
        JOptionPane.showMessageDialog(reg, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
      } catch (NumberFormatException e) {
        JOptionPane.showMessageDialog(
            reg,
            "Please enter the ID Number in correct format",
            "Error",
            JOptionPane.ERROR_MESSAGE);
      }
    }
  }
Example #2
0
  public static void update(Dia dia) {
    Connector.connect();
    Connector.update(
        "UPDATE dia SET iddia = " + dia.getIdDia() + ", data ='" + dia.getData() + "';");

    Connector.close();
  }
  @Test
  public void testConnectorStartFromMain() throws Exception {

    System.setProperty(
        Connector.PLUGIN_CLASS, io.nats.connector.plugins.test.NATSTestPlugin.class.getName());

    try {
      Connector.main(new String[0]);
    } catch (Exception ex) {
      Assert.fail("Expected success.");
    }

    // invalid configuration, just make sure we don't crash
    String[] s = {"-config", "lksdfj"};
    Connector.main(s);

    PrintWriter pw = new PrintWriter("config.props");
    pw.write(
        Connector.PLUGIN_CLASS
            + "="
            + io.nats.connector.plugins.test.NATSTestPlugin.class.getName());
    pw.close();

    System.clearProperty(Connector.PLUGIN_CLASS);
    // make sure we don't crash, and cover code.
    s[1] = "config.props";
    Connector.main(s);
  }
Example #4
0
  @Override
  public boolean headerComplete() {
    _requests.incrementAndGet();
    switch (_version) {
      case HTTP_0_9:
        break;

      case HTTP_1_0:
        if (_configuration.getSendDateHeader())
          _response.getHttpFields().put(_connector.getServer().getDateField());
        break;

      case HTTP_1_1:
        if (_configuration.getSendDateHeader())
          _response.getHttpFields().put(_connector.getServer().getDateField());

        if (_expect) {
          badMessage(HttpStatus.EXPECTATION_FAILED_417, null);
          return true;
        }

        break;

      default:
        throw new IllegalStateException();
    }

    return true;
  }
 @Override
 public void run() {
   try {
     while (running) {
       Thread.sleep(100);
       synchronized (list) {
         for (ByteArrayOutputStream baos : list) {
           try {
             output.write(baos.toByteArray());
             output.flush();
             baos.close();
           } catch (SocketException ex) {
             Logger.getLogger(SocketSender.class.getName()).log(Level.WARNING, null, ex);
             conn.destroy();
           } catch (IOException ex) {
             Logger.getLogger(SocketSender.class.getName()).log(Level.WARNING, null, ex);
             conn.destroy();
           }
         }
         list.clear();
       }
     }
     output.close();
   } catch (InterruptedException e) {
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
 public synchronized void disconnect() {
   if (connectors != null) {
     for (Connector connector : connectors) {
       connector.disconnect();
     }
   }
 }
    private synchronized void createConnectors() {
      if (connectors != null) {
        for (Connector conn : connectors) {
          if (conn != null) {
            conn.disconnect();
          }
        }
      }
      connectors = new ArrayList<Connector>();
      for (TransportConfiguration initialConnector : initialConnectors) {
        ClientSessionFactoryInternal factory =
            new ClientSessionFactoryImpl(
                ServerLocatorImpl.this,
                initialConnector,
                callTimeout,
                callFailoverTimeout,
                clientFailureCheckPeriod,
                connectionTTL,
                retryInterval,
                retryIntervalMultiplier,
                maxRetryInterval,
                reconnectAttempts,
                threadPool,
                scheduledThreadPool,
                interceptors);

        factory.disableFinalizeCheck();

        connectors.add(new Connector(initialConnector, factory));
      }
    }
  @Test
  public void parseModel() {

    Connector connector =
        Connector.makeConnector("sbml-test-files/allCpdsMetabSmmReactionsCompounds.xml");
    Assert.assertTrue(connector.canParse());
  }
  @Test
  public void testDisconnectReconnect() throws Exception {

    System.setProperty(
        Connector.PLUGIN_CLASS, io.nats.connector.plugins.test.NATSTestPlugin.class.getName());
    Connector c = new Connector();

    ExecutorService executor = Executors.newSingleThreadExecutor();
    executor.execute(
        new Runnable() {
          @Override
          public void run() {
            try {
              Thread.sleep(500);
              System.out.println("Stopping NATS server.");
              UnitTestUtilities.stopDefaultServer();

              Thread.sleep(1000);

              System.out.println("Starting NATS server.");
              UnitTestUtilities.startDefaultServer();
            } catch (InterruptedException e) {;;
            }
          }
        });

    c.run();
  }
  /**
   * Convenience constructor Creates server and a {@link SelectChannelConnector} at the passed port.
   */
  public Server(int port) {
    setServer(this);

    Connector connector = new SelectChannelConnector();
    connector.setPort(port);
    setConnectors(new Connector[] {connector});
  }
  /**
   * Connects the figure to the new target. If there is no new target the connection reverts to its
   * original one.
   */
  public void invokeEnd(int x, int y, int anchorX, int anchorY, DrawingView view) {
    Connector target = findConnectionTarget(x, y, view.drawing());
    if (target == null) {
      target = fOriginalTarget;
    }

    setPoint(x, y);
    connect(target);
    getConnection().updateConnection();

    Connector oldConnector =
        ((ChangeConnectionHandle.UndoActivity) getUndoActivity()).getOldConnector();
    // there has been no change so there is nothing to undo
    if ((oldConnector == null)
        || (target() == null)
        || (oldConnector.owner() == target().owner())) {
      setUndoActivity(null);
    } else {
      getUndoActivity().setAffectedFigures(new SingleFigureEnumerator(getConnection()));
    }

    if (getTargetFigure() != null) {
      getTargetFigure().connectorVisibility(false);
      setTargetFigure(null);
    }
  }
 // <?|acc|last> + r
 private R pushRight(R acc, T last) {
   cur = none();
   if (right == null) return acc;
   synchronized (root) {
     Connector<T, R> r = right;
     if (r == null) return acc;
     right = null;
     r.lhs = null;
     T raleft = r.left;
     r.left = none();
     if (r.acc == NONE) {
       if (acc == NONE) {
         r.drain();
       } else {
         r.acc = acc;
         r.right = last;
       }
       return none();
     }
     if (acc == NONE) {
       return r.drainRight();
     }
     if (mergeable.test(last, raleft)) {
       r.acc = combiner.apply(acc, r.acc);
       return r.drainRight();
     }
     if (r.right == NONE) right = new Connector<>(this, r.drain(), null);
     return acc;
   }
 }
Example #13
0
  public static void create(Dia dia) {

    Connector.connect();
    Connector.update("INSERT INTO dia (data)" + " VALUES ('" + dia.getData() + "'); ");

    Connector.close();
  }
Example #14
0
  protected Connector findConnector(String connectorName) {
    //    List connectors =
    //      com.sun.jdi.Bootstrap.virtualMachineManager().allConnectors();
    List connectors = org.eclipse.jdi.Bootstrap.virtualMachineManager().allConnectors();

    //    // debug: code to list available connectors
    //    Iterator iter2 = connectors.iterator();
    //    while (iter2.hasNext()) {
    //      Connector connector = (Connector)iter2.next();
    //      System.out.println("connector name is " + connector.name());
    //    }

    for (Object c : connectors) {
      Connector connector = (Connector) c;
      //      System.out.println(connector.name());
      //    }
      //    Iterator iter = connectors.iterator();
      //    while (iter.hasNext()) {
      //      Connector connector = (Connector)iter.next();
      if (connector.name().equals(connectorName)) {
        return connector;
      }
    }
    Base.showError(
        "Compiler Error",
        "findConnector() failed to find " + connectorName + " inside Runner",
        null);
    return null; // Not reachable
  }
 /** @see Server#stop() */
 @Override
 public void stop() throws Exception {
   if (connectors != null) {
     for (Connector c : connectors) {
       c.stop();
     }
   }
 }
Example #16
0
  @Test(expected = ConnectorCommandCliException.class)
  public void testRunWithCommandAndIllegalArguments() {
    final Connector connector = new Connector(TEST_JAR);
    connector.addCommand(new ExampleCommand());

    connector.run(RunArgs.newArgs("println", "action", "wrongArg").asMainArgs());
    assertFalse(connector.isHasParsed());
  }
Example #17
0
  @Test
  public void testRunWithCommand() {
    final Connector connector = new Connector(TEST_JAR);
    connector.addCommand(new ExampleCommand());

    connector.run(RunArgs.newArgs("println", "action").asMainArgs());
    assertTrue(connector.isHasParsed());
  }
 public Statement getConnection(String name) {
   for (Connector c : connectors) {
     if (name.equals(c.getName())) {
       return c.getConnection();
     }
   }
   return null;
 }
 public PingClient() throws IOException {
   selector = Selector.open();
   Connector connector = new Connector();
   Printer printer = new Printer();
   connector.start();
   printer.start();
   receiveTarget();
 }
  /**
   * Convenience constructor Creates server and a {@link SelectChannelConnector} at the passed
   * address.
   */
  public Server(InetSocketAddress addr) {
    setServer(this);

    Connector connector = new SelectChannelConnector();
    connector.setHost(addr.getHostName());
    connector.setPort(addr.getPort());
    setConnectors(new Connector[] {connector});
  }
Example #21
0
 private Connector findConnector(String name) {
   for (Connector connector : Bootstrap.virtualMachineManager().allConnectors()) {
     if (connector.name().equals(name)) {
       return connector;
     }
   }
   return null;
 }
 public boolean hasConnection(String name) {
   for (Connector c : connectors) {
     if (name.equals(c.getName())) {
       return c.hasConnection();
     }
   }
   return false;
 }
Example #23
0
 void fireConnector() {
   if (connector == null) {
     addInfo("Starting a new connector thread.");
     connector = new Connector();
     connector.setDaemon(true);
     connector.setPriority(Thread.MIN_PRIORITY);
     connector.start();
   }
 }
Example #24
0
  @Override
  public Connector getConnector(String localId) {
    for (Connector c : connectors) {
      if (c.getLocalId().equals(localId)) {
        return c;
      }
    }

    return null;
  }
  /** Draws this handle. */
  public void draw(Graphics2D g) {
    Graphics2D gg = (Graphics2D) g.create();
    gg.transform(view.getDrawingToViewTransform());
    for (Connector c : connectors) {
      c.draw(gg);
    }

    gg.dispose();
    drawCircle(g, (getTarget() == null) ? Color.red : Color.green, Color.black);
  }
 protected void compileNext(PrintWriter out, boolean debug) throws CompileException {
   for (Connector c : connectors) {
     if (c.isOutgoing() && c.hasConnection()) {
       c.getConnection().compile(out, debug);
     } else if (c.isOutgoing()) {
       Log.i("Tern", "couldn't complete after " + this.name);
       this.LAST = true;
     }
   }
 }
 // l + <first|acc|last> + r
 private R connectOne(T first, R acc, T last) {
   synchronized (root) {
     Connector<T, R> l = left;
     if (l == null) {
       return pushRight(acc, last);
     }
     if (l.acc == NONE) {
       l.acc = acc;
       l.left = first;
       l.right = last;
       return connectEmpty();
     }
     T laright = l.right;
     if (mergeable.test(laright, first)) {
       l.acc = combiner.apply(l.acc, acc);
       l.right = last;
       return connectEmpty();
     }
     left = null;
     l.rhs = null;
     l.right = none();
     if (l.left != NONE) {
       return pushRight(acc, last);
     }
     acc = pushRight(acc, last);
     if (acc != NONE) left = new Connector<>(null, acc, this);
     return l.drain();
   }
 }
Example #28
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);
  }
Example #29
0
 /*
  * Find Connector by name
  */
 private static Connector findConnector(String name) {
   List connectors = Bootstrap.virtualMachineManager().allConnectors();
   Iterator iter = connectors.iterator();
   while (iter.hasNext()) {
     Connector connector = (Connector) iter.next();
     if (connector.name().equals(name)) {
       return connector;
     }
   }
   return null;
 }
Example #30
0
  /**
   * Updates section displayed on a diagram. Recalculates new position and size of the Section. Also
   * sets the functionality of the horizontal or vertical dragging.
   */
  public void update() {
    try {

      this.height = Math.abs(endPoint.getTop() - startPoint.getTop());
      this.width = Math.abs(endPoint.getLeft() - startPoint.getLeft());

      if (isVertical()) {

        this.setHTML(verticalLine(this.height + additionalHeight, style));

        sectionDragController.setAllowHorizontalDragging(true);
        sectionDragController.setAllowVerticalDragging(false);

        ((AbsolutePanel) this.getParent())
            .setWidgetPosition(
                this,
                this.startPoint.getLeft(),
                Math.min(this.startPoint.getTop(), this.endPoint.getTop()));

      } else if (isHorizontal()) {
        if (this.connector.isSelected) {
          this.setHTML(selectedHorizontalLine(this.width + additionalWidth, style));
        } else {
          this.setHTML(horizontalLine(this.width + additionalWidth, style));
        }

        sectionDragController.setAllowHorizontalDragging(false);
        sectionDragController.setAllowVerticalDragging(true);

        ((AbsolutePanel) this.getParent())
            .setWidgetPosition(
                this,
                Math.min(this.startPoint.getLeft(), this.endPoint.getLeft()),
                this.endPoint.getTop());
      }

      // Calculate decoration's direction and update decorations
      if (startPointDecoration != null) {
        this.startPointDecoration.update(
            calculateStartPointDecorationDirection(), startPoint.getLeft(), startPoint.getTop());
      }
      if (endPointDecoration != null) {
        this.endPointDecoration.update(
            calculateEndPointDecorationDirection(), endPoint.getLeft(), endPoint.getTop());
      }
    } catch (Exception e) {
      LOG.log(Level.SEVERE, "Error updating section", e);
      connector.calculateStandardPointsPositions();
      connector.drawSections();
    }
  }