当前位置: 首页>>代码示例>>Java>>正文


Java Request类代码示例

本文整理汇总了Java中org.jetlang.channels.Request的典型用法代码示例。如果您正苦于以下问题:Java Request类的具体用法?Java Request怎么用?Java Request使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Request类属于org.jetlang.channels包,在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onIncomingMessage

import org.jetlang.channels.Request; //导入依赖的package包/类
@FiberOnly
private void onIncomingMessage(Request<RpcWireRequest, RpcReply> message) {
  try {
    RpcWireRequest req = message.getRequest();
    if (req.isPreElectionPollMessage()) {
      doPreElectionPollMessage(message);

    } else if (req.isRequestVoteMessage()) {
      doRequestVote(message);

    } else if (req.isAppendMessage()) {
      doAppendMessage(message);

    } else {
      logger.warn("got a message of protobuf type I don't know: {}", req);
    }
  } catch (Exception e) {
    logger.error("Uncaught exception while processing message {}: {}", message, e);
    throw e;
  }
}
 
开发者ID:cloud-software-foundation,项目名称:c5-replicator,代码行数:22,代码来源:ReplicatorInstance.java

示例2: doPreElectionPollMessage

import org.jetlang.channels.Request; //导入依赖的package包/类
@FiberOnly
private void doPreElectionPollMessage(Request<RpcWireRequest, RpcReply> message) {
  final RpcWireRequest request = message.getRequest();
  final PreElectionPoll msg = request.getPreElectionPollMessage();
  final long msgLastLogTerm = msg.getLastLogTerm();
  final long msgLastLogIndex = msg.getLastLogIndex();

  final boolean wouldVote =
      msg.getTerm() >= currentTerm
          && atLeastAsUpToDateAsLocalLog(msgLastLogTerm, msgLastLogIndex)
          && !rejectPollFromOldConfiguration(request.from, msgLastLogTerm, msgLastLogIndex);

  logger.debug("sending pre-election reply to {} wouldVote = {}", message.getRequest().from, wouldVote);
  PreElectionReply m = new PreElectionReply(currentTerm, wouldVote);
  RpcReply reply = new RpcReply(m);
  message.reply(reply);
}
 
开发者ID:cloud-software-foundation,项目名称:c5-replicator,代码行数:18,代码来源:ReplicatorInstance.java

示例3: handleWireInboundMessage

import org.jetlang.channels.Request; //导入依赖的package包/类
@FiberOnly
private void handleWireInboundMessage(Channel channel, ReplicationWireMessage msg) {
  long messageId = msg.getMessageId();
  if (msg.getReceiverId() != nodeId) {
    LOG.debug("Got messageId {} for {} but I am {}, ignoring!", messageId, msg.getReceiverId(), nodeId);
    return;
  }

  if (msg.getInReply()) {
    Request<RpcRequest, RpcWireReply> request = outstandingRPCs.get(messageId);
    if (request == null) {
      LOG.debug("Got a reply message_id {} which we don't track", messageId);
      return;
    }

    outstandingRPCs.remove(messageId);
    outstandingRPCbySession.remove(request.getSession());
    request.reply(new RpcWireReply(msg));
  } else {
    handleWireRequestMessage(channel, msg);
  }
}
 
开发者ID:cloud-software-foundation,项目名称:c5-replicator,代码行数:23,代码来源:ReplicatorService.java

示例4: sendMessageAsync

import org.jetlang.channels.Request; //导入依赖的package包/类
private void sendMessageAsync(final Request<RpcRequest, RpcWireReply> message, final Channel channel) {
  fiber.execute(() -> {
    RpcRequest request = message.getRequest();
    long to = request.to;
    long messageId = messageIdGen++;

    outstandingRPCs.put(messageId, message);
    outstandingRPCbySession.put(message.getSession(), messageId);

    LOG.trace("Sending message id {} to {} / {}", messageId, to, request.quorumId);

    ReplicationWireMessage wireMessage = request.getWireMessage(
        messageId,
        nodeId,
        to,
        false
    );

    channel.writeAndFlush(wireMessage).addListener(
        future -> {
          if (!future.isSuccess()) {
            LOG.warn("Error sending from node {} request {}: {}", nodeId, request, future.cause());
          }
        });
  });
}
 
开发者ID:cloud-software-foundation,项目名称:c5-replicator,代码行数:27,代码来源:ReplicatorService.java

示例5: handleLoopBackMessage

import org.jetlang.channels.Request; //导入依赖的package包/类
private void handleLoopBackMessage(final Request<RpcRequest, RpcWireReply> origMessage) {
  final long toFrom = nodeId; // I am me.
  final RpcRequest request = origMessage.getRequest();
  final String quorumId = request.quorumId;

  // Funny thing we don't have a direct handle on who sent us this message, so we have to do this. Sok though.
  final ReplicatorInstance repl = replicatorInstances.get(quorumId);
  if (repl == null) {
    // rare failure condition, whereby the replicator died AFTER it send messages.
    return; // ignore the message.
  }

  final RpcWireRequest newRequest = new RpcWireRequest(toFrom, quorumId, request.message);
  AsyncRequest.withOneReply(fiber, repl.getIncomingChannel(), newRequest, msg -> {
    assert msg.message != null;
    RpcWireReply newReply = new RpcWireReply(toFrom, toFrom, quorumId, msg.message);
    origMessage.reply(newReply);
  });
}
 
开发者ID:cloud-software-foundation,项目名称:c5-replicator,代码行数:20,代码来源:ReplicatorService.java

示例6: handleNodeInfoRequest

import org.jetlang.channels.Request; //导入依赖的package包/类
@FiberOnly
private void handleNodeInfoRequest(Request<NodeInfoRequest, NodeInfoReply> message) {
  NodeInfoRequest req = message.getRequest();
  NodeInfo peer = peerNodeInfoMap.get(req.nodeId);
  if (peer == null) {
    message.reply(NodeInfoReply.NO_REPLY);
    return;
  }

  Integer servicePort = peer.modules.get(req.moduleType);
  if (servicePort == null) {
    message.reply(NodeInfoReply.NO_REPLY);
    return;
  }

  List<String> peerAddresses = peer.availability.getAddressesList();
  if (peerAddresses == null || peerAddresses.isEmpty()) {
    message.reply(NodeInfoReply.NO_REPLY);
    return;
  }

  // does this module run on that peer?
  message.reply(new NodeInfoReply(true, peerAddresses, servicePort));
}
 
开发者ID:cloud-software-foundation,项目名称:c5-replicator,代码行数:25,代码来源:BeaconService.java

示例7: prepareRequest

import org.jetlang.channels.Request; //导入依赖的package包/类
private Request<CommandRpcRequest<?>, CommandReply>
prepareRequest(long peer, ModuleSubCommand moduleSubCommand) {
  CommandRpcRequest<ModuleSubCommand> commandRpcRequest = new CommandRpcRequest<>(peer, moduleSubCommand);
  return new Request<CommandRpcRequest<?>, CommandReply>() {

    @Override
    public Session getSession() {
      return null;
    }

    @Override
    public CommandRpcRequest<?> getRequest() {
      return commandRpcRequest;
    }

    @Override
    public void reply(CommandReply i) {
    }
  };
}
 
开发者ID:cloud-software-foundation,项目名称:c5,代码行数:21,代码来源:TabletService.java

示例8: sendRequest

import org.jetlang.channels.Request; //导入依赖的package包/类
static void sendRequest(CommandRpcRequest<ModuleSubCommand> commandCommandRpcRequest,
                        ModuleInformationProvider moduleInformationProvider)
    throws ExecutionException, InterruptedException {

  Request<CommandRpcRequest<?>, CommandReply> request = new Request<CommandRpcRequest<?>, CommandReply>() {
    @Override
    public Session getSession() {
      return null;
    }

    @Override
    public CommandRpcRequest<ModuleSubCommand> getRequest() {
      return commandCommandRpcRequest;
    }

    @Override
    public void reply(CommandReply i) {

    }
  };
  ListenableFuture<C5Module> f = moduleInformationProvider.getModule(ModuleType.ControlRpc);
  ControlModule controlService;
  controlService = (ControlModule) f.get();
  controlService.doMessage(request);
}
 
开发者ID:cloud-software-foundation,项目名称:c5,代码行数:26,代码来源:TabletLeaderBehaviorHelper.java

示例9: receiveWrite

import org.jetlang.channels.Request; //导入依赖的package包/类
private void receiveWrite(Request<IncomingRpcRequest, OutgoingRpcReply> message) {
    BallotNumber k = message.getRequest().getBallotNumber();
    // If write > k or read > k THEN
    if (write.compareTo(k, info) > 0
            || read.compareTo(k, info) > 0) {
        // send nackWRITE, k
        LOG.debug("{} sending nackWRITE, rejected ballot {} because I already have (r;w) {} ; {}", getId(), k, read, write);
        message.reply(OutgoingRpcReply.getNackWriteMessage(message.getRequest(), k));
    } else {
        write = k;
        lease = message.getRequest().getLease();
        LOG.info("{} new lease value written [{}] with k {}", getId(), lease, write);

        // send ackWRITE, k
        message.reply(OutgoingRpcReply.getAckWriteMessage(message.getRequest(), k));
    }
}
 
开发者ID:cloud-software-foundation,项目名称:c5,代码行数:18,代码来源:FleaseLease.java

示例10: receiveRead

import org.jetlang.channels.Request; //导入依赖的package包/类
private void receiveRead(Request<IncomingRpcRequest, OutgoingRpcReply> message) {
    BallotNumber k = message.getRequest().getBallotNumber();
    // If write >= k or read >= k
    if (write.compareTo(k, info) >= 0
            || read.compareTo(k, info) >= 0) {
        // send (nackREAD, k) to p(j)
        LOG.debug("{} Sending nackREAD, rejecting ballot {} because I already have (r;w) {} ; {}", getId(), k, read, write);
        message.reply(OutgoingRpcReply.getNackReadMessage(message.getRequest(), k));
    } else {
        LOG.debug("{} onRead, setting 'read' to : {} (was: {})", getId(), k, read);
        read = k;
        // send (ackREAD,k,write(i),v(i)) to p(j)
        message.reply(OutgoingRpcReply.getAckReadMessage(message.getRequest(),
                k, write, lease));
    }
}
 
开发者ID:cloud-software-foundation,项目名称:c5,代码行数:17,代码来源:FleaseLease.java

示例11: JetlangPonger

import org.jetlang.channels.Request; //导入依赖的package包/类
/** Creates a JetlangPonger. */
public JetlangPonger(final Fiber _fiber) {
    fiber = _fiber;
    channel = new MemoryRequestChannel();
    final Callback<Request> onReq = new Callback<Request>() {
        @Override
        public void onMessage(final Request message) {
            final Object request = message.getRequest();
            if (request instanceof PingRequest) {
                final PingRequest ping = (PingRequest) request;
                message.reply(ping.processRequest(JetlangPonger.this));
            } else {
                throw new IllegalStateException(
                        "Expected PingRequest but got "
                                + request.getClass());
            }
        }
    };
    fiber.start();
    channel.subscribe(fiber, onReq);
}
 
开发者ID:skunkiferous,项目名称:PingPong,代码行数:22,代码来源:JetlangPonger.java

示例12: ping

import org.jetlang.channels.Request; //导入依赖的package包/类
/** Send a ping, unless we're done, in which case tell caller we are done. */
private void ping(final Request hammerRequest) throws Exception {
    final Callback<Integer> onReply = new Callback<Integer>() {
        @Override
        public void onMessage(final Integer response) {
            pongs++;
            if (response.intValue() != pongs) {
                throw new IllegalStateException("Expected " + pongs
                        + " but got " + response);
            }
            if (pongs < count) {
                try {
                    ping(hammerRequest);
                } catch (final Exception e) {
                    e.printStackTrace();
                    hammerRequest.reply(pongs);
                }
            } else {
                hammerRequest.reply(pongs);
            }
        }
    };
    ponger.ping(pongs, onReply);
}
 
开发者ID:skunkiferous,项目名称:PingPong,代码行数:25,代码来源:JetlangPinger.java

示例13: messageForwarder

import org.jetlang.channels.Request; //导入依赖的package包/类
private void messageForwarder(final Request<RpcRequest, RpcWireReply> origMsg) {

    final RpcRequest request = origMsg.getRequest();
    final long destination = request.to;
    final ReplicatorInstance repl = replicators.get(destination);
    if (repl == null) {
      // boo
      LOG.info("Request to nonexistent peer {}", destination);
      // Do nothing and allow request to timeout.
      return;
    }

    LOG.debug("Request {}", request);
    if (shouldDropMessage(request)) {
      LOG.debug("Request dropped: {}", request);
      return;
    }

    final RpcWireRequest newRequest = new RpcWireRequest(request.from, request.quorumId, request.message);
    AsyncRequest.withOneReply(rpcFiber, repl.getIncomingChannel(), newRequest, msg -> {
      // Note that 'RpcReply' has an empty from/to/messageId.  We must know from our context (and so we do)
      RpcWireReply newReply = new RpcWireReply(request.from, request.to, request.quorumId, msg.message);
      LOG.debug("Reply {}", newReply);
      if (shouldDropMessage(newReply)) {
        LOG.debug("Reply dropped: {}", newReply);
        return;
      }
      replyChannel.publish(newReply);
      origMsg.reply(newReply);
    });
  }
 
开发者ID:cloud-software-foundation,项目名称:c5-replicator,代码行数:32,代码来源:InRamSim.java

示例14: routeOutboundRequests

import org.jetlang.channels.Request; //导入依赖的package包/类
/**
 * Either route an outbound request to a callback, or queue it, depending on destination peer
 */
private void routeOutboundRequests(Request<RpcRequest, RpcWireReply> request) {
  long to = request.getRequest().to;
  if (peerBehavioralCallbacks.containsKey(to)) {
    peerBehavioralCallbacks.get(to).onMessage(request);
  } else {
    if (!requests.containsKey(to)) {
      requests.put(to, new LinkedBlockingQueue<>());
    }
    requests.get(to).add(request);
  }
}
 
开发者ID:cloud-software-foundation,项目名称:c5-replicator,代码行数:15,代码来源:ReplicatorLeaderTest.java

示例15: createRequestRule

import org.jetlang.channels.Request; //导入依赖的package包/类
/**
 * Execute a callback on all pending requests to a given peer, and any requests hereafter
 */
private void createRequestRule(long peerId, Callback<Request<RpcRequest, RpcWireReply>> handler) {
  peerBehavioralCallbacks.put(peerId, handler);
  if (requests.containsKey(peerId)) {
    List<Request<RpcRequest, RpcWireReply>> pendingRequests = new LinkedList<>();
    requests.get(peerId).drainTo(pendingRequests);
    pendingRequests.forEach(handler::onMessage);
  }
}
 
开发者ID:cloud-software-foundation,项目名称:c5-replicator,代码行数:12,代码来源:ReplicatorLeaderTest.java


注:本文中的org.jetlang.channels.Request类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。