This project has retired. For details please refer to its Attic page.
Source code
001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.reef.io.network.group.impl.driver;
020
021import org.apache.reef.io.network.group.impl.GroupCommunicationMessage;
022import org.apache.reef.io.network.group.impl.utils.Utils;
023import org.apache.reef.tang.annotations.Name;
024import org.apache.reef.wake.AbstractEStage;
025import org.apache.reef.wake.EventHandler;
026import org.apache.reef.wake.impl.SingleThreadStage;
027
028import java.util.HashMap;
029import java.util.Map;
030import java.util.logging.Logger;
031
032/**
033 * The network handler for the group communication service on the driver side.
034 */
035public class GroupCommMessageHandler implements EventHandler<GroupCommunicationMessage> {
036
037  private static final Logger LOG = Logger.getLogger(GroupCommMessageHandler.class.getName());
038
039  private final Map<Class<? extends Name<String>>, AbstractEStage<GroupCommunicationMessage>>
040      commGroupMessageStages = new HashMap<>();
041
042  public void addHandler(final Class<? extends Name<String>> groupName,
043                         final SingleThreadStage<GroupCommunicationMessage> stage) {
044    LOG.entering("GroupCommMessageHandler", "addHandler", new Object[]{Utils.simpleName(groupName), stage});
045    commGroupMessageStages.put(groupName, stage);
046    LOG.exiting("GroupCommMessageHandler", "addHandler", Utils.simpleName(groupName));
047  }
048
049  @Override
050  public void onNext(final GroupCommunicationMessage msg) {
051    LOG.entering("GroupCommMessageHandler", "onNext", msg);
052    final Class<? extends Name<String>> groupName = Utils.getClass(msg.getGroupname());
053    commGroupMessageStages.get(groupName).onNext(msg);
054    LOG.exiting("GroupCommMessageHandler", "onNext", msg);
055  }
056}