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.wake.remote; 020 021 022import org.apache.reef.tang.annotations.DefaultImplementation; 023import org.apache.reef.wake.EventHandler; 024import org.apache.reef.wake.Stage; 025import org.apache.reef.wake.remote.impl.DefaultRemoteManagerImplementation; 026 027/** 028 * Represents all remote connections to and from one process to another. 029 */ 030@DefaultImplementation(DefaultRemoteManagerImplementation.class) 031public interface RemoteManager extends Stage { 032 /** 033 * Constructor that takes a Codec<T> 034 */ 035 036 /** 037 * Returns an event handler that can be used to send messages of type T to the 038 * given destination. 039 * 040 * @param <T> type of message 041 * @param destinationIdentifier a destination identifier 042 * @param messageType a message class type 043 * @return an event handler 044 */ 045 <T> EventHandler<T> getHandler(final RemoteIdentifier destinationIdentifier, final Class<? extends T> messageType); 046 047 /** 048 * Registers the given EventHandler to be invoked when messages of Type T 049 * arrive from sourceIdentifier. 050 * <p> 051 * Calling this method twice overrides the initial registration. 052 * 053 * @param <T> type of event 054 * @param <U> type of message 055 * @param sourceIdentifier a source identifier 056 * @param messageType a message class type 057 * @param theHandler the event handler 058 * @return the subscription that can be used to unsubscribe later 059 */ 060 <T, U extends T> AutoCloseable registerHandler(final RemoteIdentifier sourceIdentifier, 061 final Class<U> messageType, 062 final EventHandler<T> theHandler); 063 064 /** 065 * Registers the given EventHandler to be called for the given message type 066 * from any source. 067 * <p> 068 * If there is an EventHandler registered for this EventType 069 * 070 * @param <T> a type of remote message of event 071 * @param <U> a type of message 072 * @param messageType a message class type 073 * @param theHandler the event handler 074 * @return the subscription that can be used to unsubscribe later 075 */ 076 <T, U extends T> AutoCloseable registerHandler(final Class<U> messageType, 077 final EventHandler<RemoteMessage<T>> theHandler); 078 079 /** 080 * Register an EventHandler that gets called by Wake in the presence of 081 * errors. Note that user-level errors that need to cross the network need 082 * to be handled as standard messages. 083 * 084 * @param theHandler the exception event handler 085 * @return the subscription that can be used to unsubscribe later 086 * @deprecated before 0.14, will be deleted in 0.15 087 */ 088 @Deprecated 089 AutoCloseable registerErrorHandler(final EventHandler<Exception> theHandler); 090 091 /** 092 * Access the Identifier of this. 093 * 094 * @return the Identifier of this. 095 */ 096 RemoteIdentifier getMyIdentifier(); 097}