Package tahrir.tools.ByteArraySegment

Examples of tahrir.tools.ByteArraySegment.ByteArraySegmentBuilder


      received.add(x, new AtomicBoolean(false));

      final int pos = x;
      try {
        final LongPart lp = new LongPart(longMessageId, x, segments.size(), segments.get(x));
        final ByteArraySegmentBuilder builder = ByteArraySegment.builder();
        PrimitiveMessageType.SHORT.write(builder);
        final int messageId = TrUtils.rand.nextInt();
        builder.writeInt(messageId);
        ShortMessageType.LONG_PART.write(builder);
        TrSerializer.serializeTo(lp, builder);
        final Resender resender = new Resender(messageId, TrConstants.UDP_SHORT_MESSAGE_RETRY_ATTEMPTS, new TrSentReceivedListener() {

          boolean failureReported = false;

          public void failure() {
            if (!failureReported) {
              failureReported = true;
              sentListener.failure();
            }
          }

          public void received() {
            received.get(pos).set(true);
            // logger.debug("Longpart " + pos +
            // " receive confirmation: " +
            // Arrays.toString(received));
            for (final AtomicBoolean r : received) {
              if (!r.get())
                return;
            }
            sentListener.received();
          }

          public void sent() {
            sent.get(pos).set(true);
            for (final AtomicBoolean s : sent) {
              if (!s.get())
                return;
            }
            sentListener.sent();
          }
        }, encryptOutbound(builder.build()), this, priority);
        resenders.put(messageId, resender);
        resender.run();
      } catch (final TrSerializableException e) {
        throw new RuntimeException(e);
      }
View Full Code Here


        final String args = Joiner.on(",").join(Iterables.transform(Lists.newArrayList(arguments), toStringer));
        logger.debug("\tSending " + method.getName() + "(" + args
            + ")\t -> "+connection.remoteAddress);
      }
      final int methodId = TrSessionManager.hashCode(method);
      final ByteArraySegmentBuilder builder = ByteArraySegment.builder();
      MessageType.METHOD_CALL.write(builder);
      builder.writeInt(sessionId);
      builder.writeInt(methodId);
      if (arguments != null) {
        for (final Object argument : arguments) {
          TrSerializer.serializeTo(argument, builder);
        }
      }

      final Priority priority = method.getAnnotation(Priority.class);

      if (priority == null)
        throw new RuntimeException("Required @Priority annotation missing on method " + method
            + " in interface "
            + method.getDeclaringClass());

      final ByteArraySegment messageBAS = builder.build();

      connection.send(messageBAS, priority.value(), new TrSentReceivedListener() {

        public void sent() {
View Full Code Here

TOP

Related Classes of tahrir.tools.ByteArraySegment.ByteArraySegmentBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.