org.apache.reef.io.network.Message Java Examples

The following examples show how to use org.apache.reef.io.network.Message. 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 nemo with Apache License 2.0 6 votes vote down vote up
private MessageType getMsgType(final ControlMessage.Message controlMessage) {
  switch (controlMessage.getType()) {
    case TaskGroupStateChanged:
    case ScheduleTaskGroup:
    case BlockStateChanged:
    case ExecutorFailed:
    case DataSizeMetric:
    case ContainerFailed:
    case MetricMessageReceived:
      return MessageType.Send;
    case RequestBlockLocation:
      return MessageType.Request;
    case BlockLocationInfo:
      return MessageType.Reply;
    default:
      throw new IllegalArgumentException(controlMessage.toString());
  }
}
 
Example #2
Source File: GroupCommNetworkHandlerImpl.java    From reef with Apache License 2.0 6 votes vote down vote up
@Override
public void onNext(final Message<GroupCommunicationMessage> mesg) {
  LOG.entering("GroupCommNetworkHandlerImpl", "onNext", mesg);
  final Iterator<GroupCommunicationMessage> iter = mesg.getData().iterator();
  final GroupCommunicationMessage msg = iter.hasNext() ? iter.next() : null;
  if (msg != null) {
    try {
      final Class<? extends Name<String>> groupName =
          (Class<? extends Name<String>>) Class.forName(msg.getGroupname());
      commGroupHandlers.get(groupName).onNext(msg);
    } catch (final ClassNotFoundException e) {
      throw new RuntimeException("GroupName not found", e);
    }
  }
  LOG.exiting("GroupCommNetworkHandlerImpl", "onNext", mesg);
}
 
Example #3
Source File: NcsMessageEnvironment.java    From incubator-nemo with Apache License 2.0 6 votes vote down vote up
public void onNext(final Message<ControlMessage.Message> messages) {
  final ControlMessage.Message controlMessage = extractSingleMessage(messages);
  final MessageType messageType = getMsgType(controlMessage);
  switch (messageType) {
    case Send:
      processSendMessage(controlMessage);
      break;
    case Request:
      processRequestMessage(controlMessage);
      break;
    case Reply:
      processReplyMessage(controlMessage);
      break;
    default:
      throw new IllegalArgumentException(controlMessage.toString());
  }
}
 
Example #4
Source File: NcsMessageEnvironment.java    From incubator-nemo with Apache License 2.0 6 votes vote down vote up
private MessageType getMsgType(final ControlMessage.Message controlMessage) {
  switch (controlMessage.getType()) {
    case TaskStateChanged:
    case ScheduleTask:
    case BlockStateChanged:
    case ExecutorFailed:
    case RunTimePassMessage:
    case ExecutorDataCollected:
    case MetricMessageReceived:
    case RequestMetricFlush:
    case MetricFlushed:
    case PipeInit:
      return MessageType.Send;
    case RequestBlockLocation:
    case RequestBroadcastVariable:
    case RequestPipeLoc:
      return MessageType.Request;
    case BlockLocationInfo:
    case InMasterBroadcastVariable:
    case PipeLocInfo:
      return MessageType.Reply;
    default:
      throw new IllegalArgumentException(controlMessage.toString());
  }
}
 
Example #5
Source File: NetworkConnectionServiceImpl.java    From reef with Apache License 2.0 6 votes vote down vote up
@Override
public <T> ConnectionFactory<T> registerConnectionFactory(
    final Identifier connectionFactoryId,
    final Codec<T> codec,
    final EventHandler<Message<T>> eventHandler,
    final LinkListener<Message<T>> linkListener,
    final Identifier localEndPointId) {
  final String id = connectionFactoryId.toString();
  checkBeforeRegistration(id);

  final NetworkConnectionFactory<T> connectionFactory = new NetworkConnectionFactory<>(
      this, connectionFactoryId, codec, eventHandler, linkListener, localEndPointId);
  final Identifier localId = getEndPointIdWithConnectionFactoryId(connectionFactoryId, localEndPointId);
  nameServiceRegisteringStage.onNext(new Tuple<>(localId, (InetSocketAddress) transport.getLocalAddress()));

  if (connFactoryMap.putIfAbsent(id, connectionFactory) != null) {
    throw new NetworkRuntimeException("ConnectionFactory " + connectionFactoryId + " was already registered.");
  }

  LOG.log(Level.INFO, "ConnectionFactory {0} was registered", id);

  return connectionFactory;
}
 
Example #6
Source File: NcsMessageEnvironment.java    From nemo with Apache License 2.0 6 votes vote down vote up
public void onNext(final Message<ControlMessage.Message> messages) {
  final ControlMessage.Message controlMessage = extractSingleMessage(messages);
  LOG.debug("[RECEIVED]: msg={}", controlMessage);
  final MessageType messageType = getMsgType(controlMessage);
  switch (messageType) {
    case Send:
      processSendMessage(controlMessage);
      break;
    case Request:
      processRequestMessage(controlMessage);
      break;
    case Reply:
      processReplyMessage(controlMessage);
      break;
    default:
      throw new IllegalArgumentException(controlMessage.toString());
  }
}
 
Example #7
Source File: Utils.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Extract a group communication message object from a message.
 * @param msg
 * @return
 */
public static GroupCommunicationMessage getGCM(final Message<GroupCommunicationMessage> msg) {
  final Iterator<GroupCommunicationMessage> gcmIterator = msg.getData().iterator();
  if (gcmIterator.hasNext()) {
    final GroupCommunicationMessage gcm = gcmIterator.next();
    if (gcmIterator.hasNext()) {
      throw new RuntimeException("Expecting exactly one GCM object inside Message but found more");
    }
    return gcm;
  } else {
    throw new RuntimeException("Expecting exactly one GCM object inside Message but found none");
  }
}
 
Example #8
Source File: NcsMessageEnvironment.java    From nemo with Apache License 2.0 5 votes vote down vote up
private long getRequestId(final ControlMessage.Message controlMessage) {
  switch (controlMessage.getType()) {
    case BlockLocationInfo:
      return controlMessage.getBlockLocationInfoMsg().getRequestId();
    default:
      throw new IllegalArgumentException(controlMessage.toString());
  }
}
 
Example #9
Source File: NcsMessageEnvironment.java    From nemo with Apache License 2.0 5 votes vote down vote up
private String getExecutorId(final ControlMessage.Message controlMessage) {
  switch (controlMessage.getType()) {
    case RequestBlockLocation:
      return controlMessage.getRequestBlockLocationMsg().getExecutorId();
    default:
      throw new IllegalArgumentException(controlMessage.toString());
  }
}
 
Example #10
Source File: NetworkConnectionFactory.java    From reef with Apache License 2.0 5 votes vote down vote up
NetworkConnectionFactory(
    final NetworkConnectionServiceImpl networkService,
    final Identifier connectionFactoryId,
    final Codec<T> eventCodec,
    final EventHandler<Message<T>> eventHandler,
    final LinkListener<Message<T>> eventListener,
    final Identifier localEndPointId) {
  this.networkService = networkService;
  this.connectionMap = new ConcurrentHashMap<>();
  this.connectionFactoryId = connectionFactoryId;
  this.eventCodec = eventCodec;
  this.eventHandler = eventHandler;
  this.eventListener = eventListener;
  this.localEndPointId = localEndPointId;
}
 
Example #11
Source File: NcsMessageEnvironment.java    From incubator-nemo with Apache License 2.0 5 votes vote down vote up
private long getRequestId(final ControlMessage.Message controlMessage) {
  switch (controlMessage.getType()) {
    case BlockLocationInfo:
      return controlMessage.getBlockLocationInfoMsg().getRequestId();
    case InMasterBroadcastVariable:
      return controlMessage.getBroadcastVariableMsg().getRequestId();
    case PipeLocInfo:
      return controlMessage.getPipeLocInfoMsg().getRequestId();
    default:
      throw new IllegalArgumentException(controlMessage.toString());
  }
}
 
Example #12
Source File: NcsMessageEnvironment.java    From incubator-nemo with Apache License 2.0 5 votes vote down vote up
private String getExecutorId(final ControlMessage.Message controlMessage) {
  switch (controlMessage.getType()) {
    case RequestBlockLocation:
      return controlMessage.getRequestBlockLocationMsg().getExecutorId();
    case RequestBroadcastVariable:
      return controlMessage.getRequestbroadcastVariableMsg().getExecutorId();
    case RequestPipeLoc:
      return controlMessage.getRequestPipeLocMsg().getExecutorId();
    default:
      throw new IllegalArgumentException(controlMessage.toString());
  }
}
 
Example #13
Source File: NcsMessageEnvironment.java    From incubator-nemo with Apache License 2.0 5 votes vote down vote up
public void onException(final Throwable throwable,
                        final SocketAddress socketAddress,
                        final Message<ControlMessage.Message> messages) {
  // 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 #14
Source File: NetworkMessagingTestService.java    From reef with Apache License 2.0 5 votes vote down vote up
@Override
public void onNext(final Message<T> value) {

  final int currentCount = count.incrementAndGet();
  LOG.log(Level.FINER, "Message {0}/{1} :: {2}", new Object[] {currentCount, expected, value});

  Assert.assertEquals(expectedSrcId, value.getSrcId());
  Assert.assertEquals(expectedDestId, value.getDestId());
  Assert.assertTrue(currentCount <= expected);

  if (currentCount >= expected) {
    monitor.mnotify();
  }
}
 
Example #15
Source File: NetworkConnectionFactory.java    From reef with Apache License 2.0 4 votes vote down vote up
LinkListener<Message<T>> getLinkListener() {
  return eventListener;
}
 
Example #16
Source File: NetworkConnectionFactory.java    From reef with Apache License 2.0 4 votes vote down vote up
EventHandler<Message<T>> getEventHandler() {
  return eventHandler;
}
 
Example #17
Source File: NetworkService.java    From reef with Apache License 2.0 4 votes vote down vote up
@Inject
private NetworkService(
    @Parameter(NetworkServiceParameters.NetworkServiceIdentifierFactory.class) final IdentifierFactory factory,
    @Parameter(NetworkServiceParameters.NetworkServicePort.class) final int nsPort,
    final NameResolver nameResolver,
    @Parameter(NetworkServiceParameters.NetworkServiceCodec.class) final Codec<T> codec,
    @Parameter(NetworkServiceParameters.NetworkServiceTransportFactory.class) final TransportFactory tpFactory,
    @Parameter(NetworkServiceParameters.NetworkServiceHandler.class) final EventHandler<Message<T>> recvHandler,
    @Parameter(NetworkServiceParameters.NetworkServiceExceptionHandler.class)
    final EventHandler<Exception> exHandler) {
  this.factory = factory;
  this.codec = codec;
  this.transport = tpFactory.newInstance(nsPort,
      new LoggingEventHandler<TransportEvent>(),
      new MessageHandler<T>(recvHandler, codec, factory), exHandler);

  this.nameResolver = nameResolver;

  this.nameServiceRegisteringStage = new SingleThreadStage<>(
      "NameServiceRegisterer", new EventHandler<Tuple<Identifier, InetSocketAddress>>() {
        @Override
        public void onNext(final Tuple<Identifier, InetSocketAddress> tuple) {
          try {
            nameResolver.register(tuple.getKey(), tuple.getValue());
            LOG.log(Level.FINEST, "Registered {0} with nameservice", tuple.getKey());
          } catch (final Exception ex) {
            final String msg = "Unable to register " + tuple.getKey() + "with name service";
            LOG.log(Level.WARNING, msg, ex);
            throw new RuntimeException(msg, ex);
          }
        }
      }, 5);

  this.nameServiceUnregisteringStage = new SingleThreadStage<>(
      "NameServiceRegisterer", new EventHandler<Identifier>() {
        @Override
        public void onNext(final Identifier id) {
          try {
            nameResolver.unregister(id);
            LOG.log(Level.FINEST, "Unregistered {0} with nameservice", id);
          } catch (final Exception ex) {
            final String msg = "Unable to unregister " + id + " with name service";
            LOG.log(Level.WARNING, msg, ex);
            throw new RuntimeException(msg, ex);
          }
        }
      }, 5);
}
 
Example #18
Source File: NetworkService.java    From reef with Apache License 2.0 4 votes vote down vote up
MessageHandler(final EventHandler<Message<T>> handler,
               final Codec<T> codec, final IdentifierFactory factory) {
  this.handler = handler;
  this.codec = new NSMessageCodec<>(codec, factory);
}
 
Example #19
Source File: NetworkMessagingTestService.java    From reef with Apache License 2.0 4 votes vote down vote up
@Override
public void onSuccess(final Message<T> message) {
  LOG.log(Level.FINER, "Success: message {0}", message);
}
 
Example #20
Source File: NetworkMessagingTestService.java    From reef with Apache License 2.0 4 votes vote down vote up
@Override
public void onException(final Throwable cause, final SocketAddress remoteAddress, final Message<T> message) {
  LOG.log(Level.WARNING, "Exception: message " + message, cause);
  throw new RuntimeException(cause);
}
 
Example #21
Source File: NcsMessageEnvironment.java    From nemo with Apache License 2.0 4 votes vote down vote up
public void onException(final Throwable throwable,
                        final SocketAddress socketAddress,
                        final Message<ControlMessage.Message> messages) {
  final ControlMessage.Message controlMessage = extractSingleMessage(messages);
  throw new RuntimeException(controlMessage.toString(), throwable);
}
 
Example #22
Source File: NcsMessageEnvironment.java    From nemo with Apache License 2.0 4 votes vote down vote up
private ControlMessage.Message extractSingleMessage(final Message<ControlMessage.Message> messages) {
  return messages.getData().iterator().next();
}
 
Example #23
Source File: NcsMessageEnvironment.java    From nemo with Apache License 2.0 4 votes vote down vote up
public void onSuccess(final Message<ControlMessage.Message> messages) {
  // No-ops.
}
 
Example #24
Source File: NcsMessageEnvironment.java    From nemo with Apache License 2.0 4 votes vote down vote up
private void processReplyMessage(final ControlMessage.Message controlMessage) {
  final long requestId = getRequestId(controlMessage);
  replyFutureMap.onSuccessMessage(requestId, controlMessage);
}
 
Example #25
Source File: NcsMessageEnvironment.java    From nemo with Apache License 2.0 4 votes vote down vote up
private void processRequestMessage(final ControlMessage.Message controlMessage) {
  final String listenerId = controlMessage.getListenerId();
  final String executorId = getExecutorId(controlMessage);
  final MessageContext messageContext = new NcsMessageContext(executorId, connectionFactory, idFactory);
  listenerConcurrentMap.get(listenerId).onMessageWithContext(controlMessage, messageContext);
}
 
Example #26
Source File: NcsMessageEnvironment.java    From nemo with Apache License 2.0 4 votes vote down vote up
private void processSendMessage(final ControlMessage.Message controlMessage) {
  final String listenerId = controlMessage.getListenerId();
  listenerConcurrentMap.get(listenerId).onMessage(controlMessage);
}
 
Example #27
Source File: NcsMessageEnvironment.java    From incubator-nemo with Apache License 2.0 4 votes vote down vote up
private ControlMessage.Message extractSingleMessage(final Message<ControlMessage.Message> messages) {
  return messages.getData().iterator().next();
}
 
Example #28
Source File: NcsMessageEnvironment.java    From incubator-nemo with Apache License 2.0 4 votes vote down vote up
public void onSuccess(final Message<ControlMessage.Message> messages) {
  // No-ops.
}
 
Example #29
Source File: NcsMessageEnvironment.java    From incubator-nemo with Apache License 2.0 4 votes vote down vote up
private void processReplyMessage(final ControlMessage.Message controlMessage) {
  final long requestId = getRequestId(controlMessage);
  replyFutureMap.onSuccessMessage(requestId, controlMessage);
}
 
Example #30
Source File: NcsMessageEnvironment.java    From incubator-nemo with Apache License 2.0 4 votes vote down vote up
private void processRequestMessage(final ControlMessage.Message controlMessage) {
  final String listenerId = controlMessage.getListenerId();
  final String executorId = getExecutorId(controlMessage);
  final MessageContext messageContext = new NcsMessageContext(executorId, connectionFactory, idFactory);
  listenerConcurrentMap.get(listenerId).onMessageWithContext(controlMessage, messageContext);
}