Java Code Examples for org.apache.reef.io.network.Connection#open()

The following examples show how to use org.apache.reef.io.network.Connection#open() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NcsMessageEnvironment.java    From incubator-nemo with Apache License 2.0 6 votes vote down vote up
@Override
public <T> Future<MessageSender<T>> asyncConnect(final String receiverId, final String listenerId) {
  // If the connection toward the receiver exists already, reuses it.
  final Connection connection;

  if (receiverToConnectionMap.containsKey(receiverId)) {
    connection = receiverToConnectionMap.get(receiverId);
  } else {
    connection = connectionFactory.newConnection(idFactory.getNewInstance(receiverId));
    try {
      connection.open();
    } catch (final NetworkException e) {
      try {
        connection.close();
      } catch (final NetworkException exceptionToIgnore) {
        LOG.info("Can't close the broken connection.", exceptionToIgnore);
      }

      final CompletableFuture<MessageSender<T>> failedFuture = new CompletableFuture<>();
      failedFuture.completeExceptionally(e);
      return failedFuture;
    }
  }

  return CompletableFuture.completedFuture((MessageSender) new NcsMessageSender(connection, replyFutureMap));
}
 
Example 2
Source File: NcsMessageContext.java    From incubator-nemo with Apache License 2.0 5 votes vote down vote up
@Override
public <U> void reply(final U replyMessage) {
  final Connection connection = connectionFactory.newConnection(idFactory.getNewInstance(senderId));
  try {
    connection.open();
    connection.write(replyMessage);
    // We do not call connection.close since NCS caches connection.
  } catch (final NetworkException e) {
    // TODO #140: Properly classify and handle each RPC failure
    // Not logging the stacktrace here, as it's not very useful.
    LOG.error("NCS Exception");
  }
}
 
Example 3
Source File: NcsMessageContext.java    From nemo with Apache License 2.0 5 votes vote down vote up
@Override
public <U> void reply(final U replyMessage) {
  LOG.debug("[REPLY]: {}", replyMessage);
  final Connection connection = connectionFactory.newConnection(idFactory.getNewInstance(senderId));
  try {
    connection.open();
  } catch (final NetworkException e) {
    throw new RuntimeException("Cannot connect to " + senderId, e);
  }

  connection.write(replyMessage);
}
 
Example 4
Source File: CtrlMsgSender.java    From reef with Apache License 2.0 5 votes vote down vote up
@Override
public void onNext(final GroupCommunicationMessage srcCtrlMsg) {
  LOG.entering("CtrlMsgSender", "onNext", srcCtrlMsg);
  final Identifier id = idFac.getNewInstance(srcCtrlMsg.getDestid());
  final Connection<GroupCommunicationMessage> link = netService.newConnection(id);
  try {
    link.open();
    link.write(srcCtrlMsg);
  } catch (final NetworkException e) {
    throw new RuntimeException("Unable to send ctrl task msg to parent " + id, e);
  }
  LOG.exiting("CtrlMsgSender", "onNext", srcCtrlMsg);
}
 
Example 5
Source File: Sender.java    From reef with Apache License 2.0 5 votes vote down vote up
public void send(final GroupCommunicationMessage msg, final String dest) throws NetworkException {
  LOG.entering("Sender", "send", msg);
  final Identifier destId = idFac.getNewInstance(dest);
  final Connection<GroupCommunicationMessage> link = netService.newConnection(destId);
  link.open();
  link.write(msg);
  LOG.exiting("Sender", "send", msg);
}