コード例 #1
0
ファイル: MasterDemo.java プロジェクト: prakashnsm/dnp3-1
  public static void main(String[] args) throws IOException, InterruptedException {

    // create the root class with a thread pool size of 1
    DNP3Manager manager = DNP3ManagerFactory.createManager(1);

    // You can send the log messages anywhere you want
    // but PrintingLogSubscriber just prints them to the console
    manager.addLogSubscriber(PrintingLogSubscriber.getInstance());

    // Create a tcp channel class that will connect to the loopback
    Channel channel = manager.addTCPClient("client", LogLevel.INFO, 5000, "127.0.0.1", 20000);

    // You can optionally add a listener to receive state changes on the channel
    channel.addStateListener(
        new ChannelStateListener() {
          @Override
          public void onStateChange(ChannelState state) {
            System.out.println("Client state: " + state);
          }
        });

    // You can modify the defaults to change the way the master behaves
    MasterStackConfig config = new MasterStackConfig();

    // Create a master instance, pass in a simple singleton to print received values to the console
    Master master =
        channel.addMaster("master", LogLevel.INTERPRET, PrintingDataObserver.getInstance(), config);

    // You can optionally add a listener to receive state changes on the stack
    master.addStateListener(
        new StackStateListener() {
          @Override
          public void onStateChange(StackState state) {
            System.out.println("Master state: " + state);
          }
        });

    // This sub-interface can issue command requests
    CommandProcessor processor = master.getCommandProcessor();

    // all this stuff just to read a line of text in Java. Oh the humanity.
    String line = "";
    InputStreamReader converter = new InputStreamReader(System.in);
    BufferedReader in = new BufferedReader(converter);

    while (true) {
      System.out.println("Enter something to issue a command or type <quit> to exit");
      line = in.readLine();
      if (line.equals("quit")) break;
      else {
        ControlRelayOutputBlock crob =
            new ControlRelayOutputBlock(
                ControlCode.LATCH_ON, (short) 1, 100, 100, CommandStatus.SUCCESS);
        ListenableFuture<CommandStatus> future = processor.selectAndOperate(crob, 0);
        System.out.println("Control result: " + future.get().name());
      }
    }

    manager.shutdown();
  }
コード例 #2
0
    @Override
    public void run() {

      BufferedReader in = null;
      PrintWriter out = null;

      try {
        in = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));
        OutputStream outputStream = socket.getOutputStream();
        out = new PrintWriter(outputStream);

        String line = in.readLine();
        CommandRequest request = CommandRequest.parse(line);

        out.print("HTTP/1.1 200 OK\r\n\r\n");
        out.flush();
        if (StringUtils.isEmpty(request.getCommand())) {
          out.println("Command is blank");
          out.flush();
          return;
        }

        CommandProcessor commandProcessor = getCommandProcessor(request.getCommand());
        if (commandProcessor != null) {
          commandProcessor.execute(outputStream, request);
        } else {
          out.println("Can not find the command:[" + request.getCommand() + "]");
        }
        out.flush();

      } catch (Throwable t) {
        LOGGER.error("EventRunnable error", t);

        try {
          if (out != null) {
            out.println("CommandCenter error, message is " + t.getMessage());
            out.flush();
          }
        } catch (Exception e) {
          LOGGER.error("EventRunnable error", t);
        }

      } finally {
        try {
          if (out != null) {
            out.close();
          }
          if (in != null) {
            in.close();
          }
          socket.close();
        } catch (Exception e) {
          LOGGER.error("EventRunnable close resource error", e);
        }
      }
    }
コード例 #3
0
 public void start() {
   try {
     commandProcessor.start();
   } catch (Exception e) {
     final String message = e.getMessage();
     if (message != null && message.startsWith("Connection refused")) {
       throw new RuntimeException(
           "Could not contact Selenium Server; have you started it on '"
               + commandProcessor.getRemoteControlServerLocation()
               + "' ?\nRead more at http://seleniumhq.org/projects/remote-control/not-started.html\n"
               + e.getMessage());
     }
     throw new RuntimeException("Could not start Selenium session: " + e.getMessage(), e);
   }
 }
コード例 #4
0
 public void waitForCondition(String script, String timeout) {
   commandProcessor.doCommand(
       "waitForCondition",
       new String[] {
         script, timeout,
       });
 }
コード例 #5
0
 public void assignId(String locator, String identifier) {
   commandProcessor.doCommand(
       "assignId",
       new String[] {
         locator, identifier,
       });
 }
コード例 #6
0
 public Number getXpathCount(String xpath) {
   return commandProcessor.getNumber(
       "getXpathCount",
       new String[] {
         xpath,
       });
 }
コード例 #7
0
 public Number getCursorPosition(String locator) {
   return commandProcessor.getNumber(
       "getCursorPosition",
       new String[] {
         locator,
       });
 }
コード例 #8
0
 public Number getElementPositionTop(String locator) {
   return commandProcessor.getNumber(
       "getElementPositionTop",
       new String[] {
         locator,
       });
 }
コード例 #9
0
 public String[] getSelectOptions(String selectLocator) {
   return commandProcessor.getStringArray(
       "getSelectOptions",
       new String[] {
         selectLocator,
       });
 }
コード例 #10
0
 public boolean isSomethingSelected(String selectLocator) {
   return commandProcessor.getBoolean(
       "isSomethingSelected",
       new String[] {
         selectLocator,
       });
 }
コード例 #11
0
 public String getSelectedId(String selectLocator) {
   return commandProcessor.getString(
       "getSelectedId",
       new String[] {
         selectLocator,
       });
 }
コード例 #12
0
 public String getTable(String tableCellAddress) {
   return commandProcessor.getString(
       "getTable",
       new String[] {
         tableCellAddress,
       });
 }
コード例 #13
0
 public boolean isChecked(String locator) {
   return commandProcessor.getBoolean(
       "isChecked",
       new String[] {
         locator,
       });
 }
コード例 #14
0
 public String getEval(String script) {
   return commandProcessor.getString(
       "getEval",
       new String[] {
         script,
       });
 }
コード例 #15
0
 public void highlight(String locator) {
   commandProcessor.doCommand(
       "highlight",
       new String[] {
         locator,
       });
 }
コード例 #16
0
 public void setCursorPosition(String locator, String position) {
   commandProcessor.doCommand(
       "setCursorPosition",
       new String[] {
         locator, position,
       });
 }
コード例 #17
0
 public boolean isOrdered(String locator1, String locator2) {
   return commandProcessor.getBoolean(
       "isOrdered",
       new String[] {
         locator1, locator2,
       });
 }
コード例 #18
0
 public String getAttribute(String attributeLocator) {
   return commandProcessor.getString(
       "getAttribute",
       new String[] {
         attributeLocator,
       });
 }
コード例 #19
0
 public Number getElementHeight(String locator) {
   return commandProcessor.getNumber(
       "getElementHeight",
       new String[] {
         locator,
       });
 }
コード例 #20
0
 public boolean isTextPresent(String pattern) {
   return commandProcessor.getBoolean(
       "isTextPresent",
       new String[] {
         pattern,
       });
 }
コード例 #21
0
 public String getExpression(String expression) {
   return commandProcessor.getString(
       "getExpression",
       new String[] {
         expression,
       });
 }
コード例 #22
0
 public boolean isElementPresent(String locator) {
   return commandProcessor.getBoolean(
       "isElementPresent",
       new String[] {
         locator,
       });
 }
コード例 #23
0
 public Number getCssCount(String css) {
   return commandProcessor.getNumber(
       "getCssCount",
       new String[] {
         css,
       });
 }
コード例 #24
0
 public boolean isEditable(String locator) {
   return commandProcessor.getBoolean(
       "isEditable",
       new String[] {
         locator,
       });
 }
コード例 #25
0
 public void allowNativeXpath(String allow) {
   commandProcessor.doCommand(
       "allowNativeXpath",
       new String[] {
         allow,
       });
 }
コード例 #26
0
 public String[] getAttributeFromAllWindows(String attributeName) {
   return commandProcessor.getStringArray(
       "getAttributeFromAllWindows",
       new String[] {
         attributeName,
       });
 }
コード例 #27
0
 public void ignoreAttributesWithoutValue(String ignore) {
   commandProcessor.doCommand(
       "ignoreAttributesWithoutValue",
       new String[] {
         ignore,
       });
 }
コード例 #28
0
 public void setMouseSpeed(String pixels) {
   commandProcessor.doCommand(
       "setMouseSpeed",
       new String[] {
         pixels,
       });
 }
コード例 #29
0
 public void setTimeout(String timeout) {
   commandProcessor.doCommand(
       "setTimeout",
       new String[] {
         timeout,
       });
 }
コード例 #30
0
 public void dragAndDrop(String locator, String movementsString) {
   commandProcessor.doCommand(
       "dragAndDrop",
       new String[] {
         locator, movementsString,
       });
 }