Пример #1
0
 public Response callSherpaAndRetry(SAMPMessage message) throws SEDException, SampException {
   String id = null;
   for (int i = 0; i < RETRY; i++) {
     try {
       Response response =
           getSampClient().callAndWait(findSherpa(message.get().getMType()), message.get(), 10);
       if (isException(response)) {
         throw getException(response);
       }
       return response;
     } catch (SampException ex) {
       try {
         Thread.sleep(RETRY_INTERVAL);
       } catch (InterruptedException e) {
       }
       continue;
     }
   }
   String action = "calling";
   String msg =
       "Tried "
           + action
           + " Sherpa for "
           + RETRY
           + " times every "
           + RETRY_INTERVAL
           + " milliseconds. Giving up";
   throw new SEDException(msg);
 }
Пример #2
0
  /** Test of createMessage method, of class SAMPFactory. */
  public void testCreateMessage() throws Exception {
    String mtype = "test";
    Object instance = getInstance();

    SAMPMessage result = SAMPFactory.createMessage(mtype, instance, TestInterface.class);
    Message message = result.get();
    assertEquals("test", message.getMType());
    Map obj = message.getParams();
    assertEquals("Test Name", obj.get("name"));
    assertEquals(
        EncodeDoubleArray.encodeBase64(new double[] {1., 2., 3.}, false), obj.get("array"));
    Map nested = (Map) obj.get("nested");
    assertEquals("Test Something", nested.get("something"));
  }
Пример #3
0
  /** Test of get method, of class SAMPFactory. */
  public void testGet_Map_Class() throws Exception {

    String mtype = "test";
    Object instance = getInstance();

    SAMPMessage message = SAMPFactory.createMessage(mtype, instance, TestInterface.class);

    Map map = message.get().getParams();

    TestInterface result = (TestInterface) SAMPFactory.get(map, TestInterface.class);

    assertEquals("Test Name", result.getName());
    assertTrue(Arrays.equals(new double[] {1., 2., 3.}, result.getArray()));
    assertEquals("Test Something", result.getNested().getSomething());
  }
Пример #4
0
  public void sendMessage(SAMPMessage message) throws SampException {
    if (sampClient.getConnection().getSubscribedClients(message.get().getMType()).isEmpty())
      throw new SampException("No clients can receive the SAMP Message");

    sampClient.callAll(message.get(), new LogResultHandler(message.get()), DEFAULT_TIMEOUT);
  }