Ejemplo n.º 1
0
 @Test
 public void testProduceSender() {
   System.out.println("producing sms sender");
   Sender s1 = sf.produceSender("sms");
   s1.send();
   System.out.println("producing mail sender");
   Sender s2 = sf.produceSender("mail");
   s2.send();
   System.out.println("error producing type");
   sf.produceSender("hello");
 }
Ejemplo n.º 2
0
  @SuppressWarnings("serial")
  private void testLinker(int addressCount, int messageCount) {
    server.setMaxConnections(addressCount);
    Linker linker = new Linker();
    linker.start(reactor);
    for (int i : range(addressCount)) {
      for (int j : range(messageCount)) {
        Sender snd = linker.sender(server.address(i), null);
        assertEquals("sender per address", i + 1, linker.sendersSize());
        final int fi = i, fj = j;
        snd.send(dict("i", fi, "j", fj));
      }
    }
    linker.close();
    reactor.run();

    HashMap<Integer, ArrayList<Map<?, ?>>> by_addr = new HashMap<>();
    for (int i : range(addressCount)) {
      by_addr.put(i, new ArrayList<Map<?, ?>>());
    }
    ArrayList<Map<?, ?>> messagesDicts = sink.getMessagesDicts();
    for (Map<?, ?> m : messagesDicts) {
      assertNotNull("did not receive a dict", m);
      by_addr.get(m.get("i")).add(m);
    }
    for (int i : range(addressCount)) {
      ArrayList<Map<?, ?>> actual = by_addr.get(i);
      ArrayList<Map<?, ?>> expected = new ArrayList<>(messageCount);
      for (int j : range(messageCount)) {
        expected.add(dict("i", i, "j", j));
      }
      assertEquals(String.format("Messages for address %d", i), expected, actual);
    }
    assertEquals("total messages", addressCount * messageCount, messagesDicts.size());
  }
Ejemplo n.º 3
0
 public void send(Message message) throws CommunicationException {
   try {
     m_delegateSender.send(message);
   } finally {
     shutdown();
   }
 }
Ejemplo n.º 4
0
 public static void main(String args[]) {
   Builder builder = new Builder();
   list = builder.produceMailSender(10);
   for (Sender s : list) {
     s.send();
   }
 }
Ejemplo n.º 5
0
  public void send(int chan, byte[] data) {
    try {
      // System.out.println("data " + new String(data));
      TransportPacket tp;
      boolean last = false;
      boolean envoieTotal = false;
      int pointeurData = 0;
      short numSeq = 0;
      int actualLenght;

      while (!envoieTotal) {
        byte[] dataToSend;

        if (last || ((Protocol.HEADER_LENGTH_DATA + data.length) < Protocol.MAX_PACKET_SIZE)) {
          dataToSend = new byte[Protocol.HEADER_LENGTH_DATA + (data.length - pointeurData)];
          last = true;
          envoieTotal = true;
        } else dataToSend = new byte[Protocol.MAX_PACKET_SIZE];

        // System.out.println("datatosend 1 : " +dataToSend.length);

        actualLenght = dataToSend.length - Protocol.HEADER_LENGTH_DATA;

        byte[] fragData = new byte[dataToSend.length - Protocol.HEADER_LENGTH_DATA];
        System.arraycopy(data, pointeurData, fragData, 0, fragData.length);
        tp = new TransportPacket(data.length, actualLenght, chan, last, numSeq, fragData);
        dataToSend = tp.build();
        // System.out.println("datatosend 2 : " +dataToSend.length);
        /*
        System.out.println("header " + header.length);
        System.out.println("data " + dataToSend.length);
        System.arraycopy(header, 0, dataToSend, 0, header.length);
        System.arraycopy(data, pointeurData, dataToSend, header.length, Math.min((dataToSend.length - header.length), (data.length - pointeurData)));


         * System.out.println(" actual lenght ? " + actualLenght);
         * System.out.println("data ? "+ new String(data) + " LA taille : " + data.length);
         * System.out.println("nouveau pointeur ? "+ pointeurData);
         * System.out.println("toSend ? "+ new String(dataToSend));
         * System.out.println("taille ? "+ dataToSend.length);
         * System.out.println("tailleheader ? "+ header.length);
         // */
        // System.out.println("Paquet " + numSeq);
        pointeurData = pointeurData + actualLenght;
        numSeq++;
        if ((data.length - pointeurData)
            <= (Protocol.MAX_PACKET_SIZE - Protocol.HEADER_LENGTH_DATA)) {
          last = true;
        }

        sender.send(dataToSend);
      }
    } catch (NullPointerException e) {
      System.out.println("Ce channel n'est pas index�");
      e.printStackTrace();
    }
  }
Ejemplo n.º 6
0
  @Override
  public void call(List<MethodCall<Object>> methodCalls) {

    if (methodCalls.size() > 0) {
      String returnAddress = methodCalls.get(0).returnAddress();
      @SuppressWarnings("unchecked")
      List<Message<Object>> methods = (List<Message<Object>>) (Object) methodCalls;
      sender.send(returnAddress, encoder.encodeAsString(methods));
    }
  }
  /* (non-Javadoc)
   * @see android.widget.AdapterView.OnItemClickListener#onItemClick(android.widget.AdapterView, android.view.View, int, long)
   * the only clickable we listen to is the Compose button
   */
  public void onItemClick(android.widget.AdapterView<?> parent, View view, int position, long id) {

    Sender sender = new Sender(this);

    StringBuilder sb = new StringBuilder();
    appendBodyText(position, sb);

    sender.send(
        new HappyEmail(
            _prefs.getString("etpHerEmail1", ""),
            _prefs.getString(Util.SUBJECT_RECENT_PREF + (position + 1), ""),
            sb.toString()));
  }
Ejemplo n.º 8
0
 private void testSender(int count) {
   ArrayList<String> expected = new ArrayList<String>(count);
   for (int i = 0; i < count; i++) {
     expected.add(template.render(i));
   }
   server.setMaxConnections(1);
   Sender snd = Sender.Builder().withTarget(server.address()).create();
   reactor.getHandler().add(snd);
   snd.start(reactor);
   for (String msg : expected) {
     snd.send(msg);
   }
   snd.close();
   reactor.run();
   assertEquals("messages received", expected, sink.getMessages());
 }
  @Override
  public void lifecycleEvent(LifecycleEvent event) {

    if (Lifecycle.PERIODIC_EVENT.equals(event.getType())) {
      if (sender == null) {
        if (proxyList == null) sender = new MultiCastSender();
        else sender = new TcpSender();
      }

      /* Read busy and ready */
      if (coll == null) {
        try {
          coll = new CollectedInfo(host, port);
          this.port = coll.getPort();
          this.host = coll.getHost();
        } catch (Exception ex) {
          log.error("Unable to initialize info collection: " + ex);
          coll = null;
          return;
        }
      }

      /* Start or restart sender */
      try {
        sender.init(this);
      } catch (Exception ex) {
        log.error("Unable to initialize Sender: " + ex);
        sender = null;
        return;
      }

      /* refresh the connector information and send it */
      try {
        coll.refresh();
      } catch (Exception ex) {
        log.error("Unable to collect load information: " + ex);
        coll = null;
        return;
      }
      String output = "v=1&ready=" + coll.getReady() + "&busy=" + coll.getBusy() + "&port=" + port;
      try {
        sender.send(output);
      } catch (Exception ex) {
        log.error("Unable to send colllected load information: " + ex);
      }
    }
  }
    public void run() {
      try {
        final Sender m_sender = createSender();

        final int n = s_random.nextInt(10);

        for (int i = 0; i < n; ++i) {
          m_sender.send(new SimpleMessage(1));
          sleep(s_random.nextInt(30));
        }

        synchronized (Sender.class) {
          s_numberOfMessages += n;
        }

        m_sender.shutdown();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  /**
   * Sends the message using the Sender object to the registered device.
   *
   * @param message the message to be sent in the GCM ping to the device.
   * @param sender the Sender object to be used for ping,
   * @param deviceInfo the registration id of the device.
   * @return Result the result of the ping.
   * @throws IOException
   */
  private static Result sendViaGcm(Message msg, Sender sender, DeviceInfo deviceInfo)
      throws IOException {
    Result result = sender.send(msg, deviceInfo.getDeviceRegistrationId(), 5);
    LOG.info("Sent ping to device of user: " + deviceInfo.getUserHandle());
    if (result.getMessageId() != null) {
      String canonicalRegId = result.getCanonicalRegistrationId();
      if (canonicalRegId != null) {
        endpoint.removeDeviceInfo(deviceInfo.getDeviceRegistrationId());
        deviceInfo.setDeviceRegistrationId(canonicalRegId);
        endpoint.insertDeviceInfo(deviceInfo);
      }
    } else {
      String error = result.getErrorCodeName();
      if (error.equals(Constants.ERROR_NOT_REGISTERED)) {
        endpoint.removeDeviceInfo(deviceInfo.getDeviceRegistrationId());
      }
    }

    return result;
  }
Ejemplo n.º 12
0
  public boolean sendAlert(AlertChannel channel, AlertMessageEntity message) {
    String channelName = channel.getName();

    try {
      boolean result = true;
      String str = "nosend";

      if (m_configManager.isSendMachine()) {
        Sender sender = m_senders.get(channelName);

        result = sender.send(message);
        str = String.valueOf(result);
      }
      Cat.logEvent("Channel:" + channelName, message.getType() + ":" + str, Event.SUCCESS, null);
      return result;
    } catch (Exception e) {
      Cat.logError(e);
      return false;
    }
  }
Ejemplo n.º 13
0
  @Override
  public void flush() {

    if (methodCalls.size() > 0) {

      Message<Object> method;

      List<Message<Object>> methods;

      methods = new ArrayList<>(methodCalls.size());

      do {
        method = methodCalls.poll();
        methods.add(method);
      } while (method != null);

      if (methods.size() > 0) {
        sender.send(
            ((MethodCall<Object>) methods.get(0)).returnAddress(), encoder.encodeAsString(methods));
      }
    }
  }
Ejemplo n.º 14
0
 /**
  * Transmit the message to send to the sender
  *
  * @param msg
  */
 public void send(String msg) {
   m_sender.send(msg);
 }
Ejemplo n.º 15
0
 public static void main(String[] args) {
   System.out.println("rrr");
   Sender sender = new Sender(7654, "224.0.0.1");
   sender.send("[Kevin] Test 2");
 }
Ejemplo n.º 16
0
  public static void main(String[] args) {

    SendFactory factory = new SendFactory();
    Sender sender = factory.produceMail();
    sender.send();
  }
Ejemplo n.º 17
0
 /**
  * Send a packet.
  *
  * @param p is a packet to be sent
  */
 public void send(Packet p) {
   sndr.send(p);
 }