@Override
 public void windowClose(CloseEvent e) {
   if (okPressed) {
     if (okAction != null) {
       okAction.execute(this);
     }
   } else {
     if (cancelAction != null) {
       cancelAction.execute(this);
     }
   }
 }
示例#2
0
  public Promise all(Action... theActions) {
    return then(
        (onResult) -> {
          Object[] arr = new Object[theActions.length];
          Map<Action, Integer> actionIndexMap = new HashMap<Action, Integer>();

          // track the results, but execute them all in parallel vs serially
          Latch latch =
              new Latch(
                  theActions.length,
                  () -> {
                    onResult.done(null, arr);
                  });
          for (int i = 0; i < theActions.length; i++) {
            Action action = theActions[i];
            actionIndexMap.put(action, i);
            action.execute(
                (err, result) -> {
                  boolean success = err == null ? true : false;
                  if (!success) {
                    onResult.done(err, null);
                  } else {
                    arr[actionIndexMap.get(action)] = result;
                    latch.complete();
                  }
                });
          }
        });
  }
示例#3
0
  public void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    String dossier_prive = "/WEB-INF/";
    request.setCharacterEncoding("UTF-8");
    String param_vue = (String) request.getParameter("vue");
    String param_action = (String) request.getParameter("action");
    if (!StringUtils.estVide(param_vue)) {
      vue = dossier_prive + param_vue;
    }
    if (!StringUtils.estVide(param_action)) {
      Action classeAction = actions.get(param_action);
      String reponse_action = classeAction.execute(request);
      if (reponse_action.contains(".jsp")) {
        vue = dossier_prive + reponse_action;
      } else {
        vue = reponse_action;
      }
    }

    if (vue != null) {
      RequestDispatcher rd = request.getRequestDispatcher(vue);
      rd.forward(request, response);
    }
  }
示例#4
0
  public static void main(String[] args) {
    if (args.length < 5) {
      LOG.error("args: <fb-ip> <password> <user> <service> <action> *[key=value]");
      System.exit(1);
    } else {
      ip = args[0];
      password = args[1];
      user = args[2];
      serviceName = args[3];
      actionName = args[4];
      for (int i = 5; i < args.length; i++) {
        String[] parts = args[i].split("=");
        if (parts.length == 2) {
          if (params == null) {
            params = new HashMap<String, Object>();
          }
          try {
            Integer ipart = Integer.parseInt(parts[1]);
            params.put(parts[0], ipart);
          } catch (NumberFormatException e) {
            params.put(parts[0], parts[1]);
          }
        } else {
          LOG.error(args[i] + "not a valid parameter (key=value");
        }
      }
    }
    // Create a new FritzConnection with username and password
    FritzConnection fc = new FritzConnection(ip, user, password);
    try {
      // The connection has to be initiated. This will load the tr64desc.xml respectively
      // igddesc.xml
      // and all the defined Services and Actions.
      fc.init();
    } catch (IOException | JAXBException e) {
      LOG.error(e.getLocalizedMessage(), e);
    }

    // Get the Service. Returns null if not existing
    Service service = fc.getService(serviceName);
    if (service == null) {
      LOG.error("service " + serviceName + " does not exist");
      System.exit(1);
    }
    // Get the Action. Returns null if not existing
    Action action = service.getAction(actionName);
    if (action == null) {
      LOG.error("action " + actionName + " does not exist for service " + serviceName);
      System.exit(1);
    }
    try {
      // Execute the action without any In-Parameter.
      Response response1 = action.execute(params);
      for (String key : response1.getData().keySet()) {
        System.out.println(key + " = " + response1.getData().get(key));
      }
    } catch (UnsupportedOperationException | IOException e) {
      LOG.error(e.getLocalizedMessage(), e);
    }
  }
示例#5
0
 public static void interpretCommand(String command) {
   String[] argv = command.trim().split(" ", 2);
   Action action = actions.get(argv[0]);
   if (action == null) {
     messageIdk();
   } else {
     action.execute(argv);
   }
 }
示例#6
0
  void enqueue(Action action) {
    boolean queued = false;
    ActionQueue prior = null;
    while (!queued) {
      prior = aq.get();
      queued =
          aq.compareAndSet(
              prior, new ActionQueue((IPersistentStack) prior.q.cons(action), prior.error));
    }

    if (prior.q.count() == 0 && prior.error == null) action.execute();
  }
示例#7
0
  public String executeService(String name, String request) throws Exception {
    String result = null;
    Action action = null;

    System.out.println("executando servico " + name);

    ServiceDefinition pd = getService(name);
    String actionName = pd.getClasses().get(0).getName();
    ;

    ServiceContext ctx = new ServiceContext(repository);

    // carrega a classe e cria uma nova instancia
    Object obj = null;
    try {
      obj = ctx.getClassLoader().loadClass(actionName).newInstance();

    } catch (InstantiationException iEx) {
      throw new Exception(actionName, iEx);

    } catch (IllegalAccessException iaEx) {
      throw new Exception(actionName, iaEx);

    } catch (ClassNotFoundException cnfEx) {
      throw new Exception(actionName, cnfEx);

    } catch (NoClassDefFoundError ncdfErr) {
      throw new Exception(actionName, ncdfErr);

    } catch (Exception ncdfErr) {
      throw new Exception(actionName, ncdfErr);
    }

    action = (Action) obj;

    Object response = action.execute(request);

    if (pd.getResponse() != null && pd.getResponse().equals("json")) {

      // JSONArray jsonArray = JSONArray.fromObject( response );
      // result = jsonArray.toString();

      StringWriter out = new StringWriter();
      JSONValue.writeJSONString(response, out);
      result = out.toString();

    } else {
      result = String.valueOf(response);
    }

    return result;
  }
示例#8
0
 /**
  * Ask the specified <code>Action</code> instance to handle this request. Return the <code>
  * ActionForward</code> instance (if any) returned by the called <code>Action</code> for further
  * processing.
  *
  * @param request The servlet request we are processing
  * @param response The servlet response we are creating
  * @param action The Action instance to be used
  * @param form The ActionForm instance to pass to this Action
  * @param mapping The ActionMapping instance to pass to this Action
  * @return The <code>ActionForward</code> instance (if any) returned by the called <code>Action
  *     </code>.
  * @throws IOException if an input/output error occurs
  * @throws ServletException if a servlet exception occurs
  */
 protected ActionForward processActionPerform(
     HttpServletRequest request,
     HttpServletResponse response,
     Action action,
     ActionForm form,
     ActionMapping mapping)
     throws IOException, ServletException {
   try {
     return (action.execute(mapping, form, request, response));
   } catch (Exception e) {
     return (processException(request, response, e, form, mapping));
   }
 }
  public void testRandomized() {
    List<Action> actions =
        Arrays.asList(
            new NextAction(),
            new HasNextAction(),
            new PreviousAction(),
            new HasPreviousAction(),
            new NextIndexAction(),
            new PreviousIndexAction(),
            new RemoveAction(),
            new AddAction(),
            new SetAction());

    List<Integer> list = new ArrayList<Integer>(Arrays.asList(1, 2, 3, 4));
    Filter<Integer> filter =
        new Filter<Integer>() {
          public boolean accept(Integer element) {
            return element % 2 == 0;
          }
        };
    List<Integer> filteredList = copyFiltered(list, filter);
    ListIterator<Integer> filteringIterator =
        new FilteringListIterator<Integer>(list.listIterator(), filter);
    ListIterator<Integer> referenceIterator = filteredList.listIterator();

    Random random = new Random();
    for (int i = 0; i < 20000; i++) {
      Action next = actions.get(random.nextInt(actions.size()));

      Object o1 = next.execute(filteringIterator);
      Object o2 = next.execute(referenceIterator);

      if (!Action.equals(o1, o2) || !copyFiltered(list, filter).equals(filteredList)) {
        fail(
            copyFiltered(list, filter)
                + "\n"
                + filteredList
                + "\n"
                + next.getClass().getSimpleName()
                + "\n"
                + o1
                + "\n"
                + o2
                + "\n");
      }
    }
  }
示例#10
0
  /**
   * Pass one turn. This invokes the tick() method for all Organisms, and invokes general death and
   * replication rules.
   */
  public void tick() {
    this.time++;

    // Make time pass for Organisms
    for (O o : this.getPopulation()) o.tick(this);

    // Kill dying Organisms
    for (SelectionRule<O> rule : this.settings.getDeathRules())
      for (O o : rule.select(this)) this.new Kill(o);

    // Split splitting Organisms
    for (SelectionRule<O> rule : this.settings.getSplittingRules())
      for (O o : rule.select(this)) this.new Split(o);

    // Reproduce sexy Organisms
    for (PairSelectionRule<O> rule : this.settings.getSexyRules())
      for (Pair<O, O> p : rule.select(this)) this.new Hump(p.left, p.right);

    // Execute Actions
    for (Action a : this.actions) a.execute();
    this.actions.clear();
  }
示例#11
0
  /** Move the promise chain to the next step in the process. */
  private void internalEval(Void aVoid) {
    if (!done && pos < actions.size() && !failed) {
      Action action = actions.get(pos);
      pos++;
      try {
        action.execute(
            (err, result) -> {
              boolean success = err == null ? true : false;
              if (failed || done) {
                return;
              }

              if (!success) {
                fail(err);
              } else {
                results.add(result);
                done = pos == actions.size();
              }

              // scheduled the next action
              if (!done && !failed) {
                vertx.runOnContext(this::internalEval);
              }

              if (done && !failed) {
                cleanUp();
                // ultimate success case
                if (onComplete != null) {
                  onComplete.done(null, results);
                }
              }
            });
      } catch (Exception ex) {
        // context.put(CONTEXT_FAILURE_KEY, ex.toString());
        fail(ex);
      }
    }
  }
示例#12
0
  /** 线程启动 */
  public void run() {
    BufferedReader in = null;
    PrintWriter out = null;
    String json = null;
    Packet packet = null;

    try {
      /** 初始化读写流 */
      in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
      out = new PrintWriter(socket.getOutputStream());

      /** 长连接,在注销时断开 */
      while (!isLogout) {

        /** 读取客户端发送的JSON请求包,并转化为对象 */
        json = in.readLine();

        if (json == null) {
          break;
        }

        System.out.println("GET:\t" + json);

        if (json.equals(Action.ADMIN_LOGIN)) {
          out.println("admin login");
          out.flush();
        } else {
          packet = gson.fromJson(json, Packet.class);

          /** 根据请求包的类型做出不同响应 */
          Class<?> actionClass = actionMap.get(packet.getType());
          Action action = (Action) actionClass.newInstance();
          action.execute(packet, socket, users, session);
        }
      }

    } catch (SocketException e) {
      /** 将用户注销的信息发送给所有客户端,以更新用户在线列表 */
      Class<?> actionClass = actionMap.get(Action.LOGOUT);
      Action action;
      try {
        action = (Action) actionClass.newInstance();
        action.execute(packet, socket, users, session);
      } catch (InstantiationException | IllegalAccessException e1) {
        e1.printStackTrace();
      }

    } catch (Exception e) {
      e.printStackTrace();
    } finally {

      System.out.println("Disconnected:\t" + socket.toString() + "\tOnline num: " + session.size());

      try {
        in.close();
        out.close();
        socket.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
示例#13
0
 public void execute(Action action) {
   action.execute();
 }
示例#14
0
  @Override
  public void execute() {
    super.execute();

    // System.out.println("Czekam.");
  }
示例#15
0
 @Override
 public ICLIControleur execute() {
   super.execute();
   return this.menu;
 }