Ejemplo n.º 1
0
Archivo: Main.java Proyecto: hsbp/urc
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.main);
   sender = new Sender();
   sender.start();
   attachEventHandlers();
 }
Ejemplo n.º 2
0
 /** Model startuje i uruchamia wszystkie potrzebne moduły. */
 public void load() {
   if (self == null) {
     outQueue.add(new ProgramClosingEvent());
     throw new NullPointerException("Self contact nie może być null!");
   }
   server.start();
   multicast.start();
   sender.start();
 }
Ejemplo n.º 3
0
    private void start(ThreadFactory f) {
      // only start once....
      if (active.compareAndSet(false, true)) {
        connectionPeerReceiver = new ConnectionPeerReceiver(f);
        connectionPeerReceiver.start();

        if (isSenderUsed()) {
          sender = new Sender(f, getSenderQueueSize());
          sender.start();
        }
      }
    }
Ejemplo n.º 4
0
  void sendMessages() throws Exception {
    if (num_threads > 1 && num_msgs % num_threads != 0) {
      System.err.println(
          "num_msgs (" + num_msgs + " ) has to be divisible by num_threads (" + num_threads + ")");
      return;
    }

    System.out.println(
        "sending "
            + num_msgs
            + " messages ("
            + Util.printBytes(msg_size)
            + ") to "
            + remote
            + ": oob="
            + oob
            + ", "
            + num_threads
            + " sender thread(s)");
    ByteBuffer buf =
        ByteBuffer.allocate(Global.BYTE_SIZE + Global.LONG_SIZE).put(START).putLong(num_msgs);
    Message msg = new Message(null, buf.array());
    // msg.writeTo(output);

    ExposedByteArrayOutputStream out_stream = new ExposedByteArrayOutputStream((int) (msg.size()));
    ExposedDataOutputStream dos = new ExposedDataOutputStream(out_stream);
    byte flags = 0;
    dos.writeShort(Version.version); // write the version
    if (msg.getDest() == null) flags += (byte) 2;
    dos.writeByte(flags);
    msg.writeTo(dos);
    Buffer buffer = new Buffer(out_stream.getRawBuffer(), 0, out_stream.size());

    output_lock.lock(); // need to sync if we have more than 1 sender
    try {
      // msg.writeTo(output);
      output.writeInt(buffer.getLength());
      output.write(buffer.getBuf(), buffer.getOffset(), buffer.getLength());
    } finally {
      output_lock.unlock();
    }

    int msgs_per_sender = num_msgs / num_threads;
    Sender[] senders = new Sender[num_threads];
    for (int i = 0; i < senders.length; i++)
      senders[i] = new Sender(msgs_per_sender, msg_size, num_msgs / 10);
    for (Sender sender : senders) sender.start();
    for (Sender sender : senders) sender.join();
    output.flush();
    System.out.println("done sending " + num_msgs + " to " + remote);
  }
 /**
  * Send a command to the cryobay.
  *
  * @param commandMessage The string to send to the cryobay.
  * @return True if there is a connection to the cryobay
  */
 public synchronized boolean sendToCryoBay(String command) {
   if (m_sender == null) {
     m_sender = new Sender(null, m_retries, this);
     m_sender.start();
   }
   if (isConnected()) {
     m_sender.addCommand(command);
     // TODO: (Java 5) Release semaphore here
     // m_sender.interrupt(); // Wake up the run() method
     return true;
   } else {
     return false;
   }
 }
  public GenericIGTLinkClient(String hostName, int port) throws Exception {
    super(
        hostName,
        port,
        new ErrorManager() {

          @Override
          public void error(String message, Exception exception, int errorCode) {
            System.err.println(message);
          }
        });
    Log.debug("GenericIGTLinkClient started");
    s.start();
  }
Ejemplo n.º 7
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());
 }
Ejemplo n.º 8
0
  void sendMessages() throws Exception {
    Address destination = getReceiver();
    if (destination == null) {
      System.err.println("UnicastTest.sendMessages(): receiver is null, cannot send messages");
      return;
    }

    if (num_threads > 1 && num_msgs % num_threads != 0) {
      System.err.println(
          "num_msgs (" + num_msgs + " ) has to be divisible by num_threads (" + num_threads + ")");
      return;
    }

    System.out.println(
        "sending "
            + num_msgs
            + " messages ("
            + Util.printBytes(msg_size)
            + ") to "
            + destination
            + ": oob="
            + oob
            + ", "
            + num_threads
            + " sender thread(s)");
    ByteBuffer buf =
        ByteBuffer.allocate(Global.BYTE_SIZE + Global.LONG_SIZE).put(START).putLong(num_msgs);
    Message msg = new Message(destination, buf.array());
    channel.send(msg);

    long print = num_msgs / 10;
    int msgs_per_sender = num_msgs / num_threads;
    Sender[] senders = new Sender[num_threads];
    for (int i = 0; i < senders.length; i++)
      senders[i] = new Sender(msgs_per_sender, msg_size, destination, (int) print);
    for (Sender sender : senders) sender.start();
    for (Sender sender : senders) sender.join();
    System.out.println("done sending " + num_msgs + " to " + destination);
  }
Ejemplo n.º 9
0
 public static void main(String[] args) {
   Sender s = new Sender();
   Reciever r = new Reciever();
   s.start();
   r.start();
 }
Ejemplo n.º 10
0
 /** Start Substrate running. */
 public void start() {
   sndr.start();
   rcvr.start();
 }
Ejemplo n.º 11
-1
  private void testSampler(final int count, float frequency) {
    server.setMaxConnections(1);
    final ArrayList<String> expected = new ArrayList<String>(count);
    Timeout gen =
        new Timeout() {
          Tag tag = new SimpleTag(0);
          int sent = 0;

          @Override
          public void onSample(DatawireEvent e) {
            String body = template.render(sent);
            expected.add(body);
            Message message = Message.Factory.create();
            message.setBody(new AmqpValue(body));
            DatawireUtils.send(e.getLink(), tag, message);
            sent += 1;
            if (sent >= count) {
              e.getLink().close();
              cancel();
            }
          }
        };
    Sender snd =
        Sender.Builder()
            .withTarget(server.address())
            .withHandlers(new Sampler(gen, frequency))
            .create();
    reactor.getHandler().add(snd);
    gen.setTimeout(reactor, 2000);
    snd.start(reactor);
    reactor.run();
    assertTrue("Sampling timed out", gen.isCancelled());
    assertEquals("Expected messages", expected, sink.getMessages());
  }