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> 041 * @param destinationIdentifier a destination identifier 042 * @param messageType a message class type 043 * @return an event handler 044 */ 045 public <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, U extends T> 054 * @param sourceIdentifier a source identifier 055 * @param messageType a message class type 056 * @param theHandler the event handler 057 * @return the subscription that can be used to unsubscribe later 058 */ 059 public <T, U extends T> AutoCloseable registerHandler(final RemoteIdentifier sourceIdentifier, final Class<U> messageType, final EventHandler<T> theHandler); 060 061 /** 062 * Registers the given EventHandler to be called for the given message type 063 * from any source. 064 * <p/> 065 * If there is an EventHandler registered for this EventType 066 * 067 * @param <T, U extends T> 068 * @param messageType a message class type 069 * @param theHandler the event handler 070 * @return the subscription that can be used to unsubscribe later 071 */ 072 public <T, U extends T> AutoCloseable registerHandler(final Class<U> messageType, final EventHandler<RemoteMessage<T>> theHandler); 073 074 /** 075 * Register an EventHandler that gets called by Wake in the presence of 076 * errors. Note that user-level errors that need to cross the network need 077 * to be handled as standard messages. 078 * 079 * @param theHandler the exception event handler 080 * @return the subscription that can be used to unsubscribe later 081 */ 082 @Deprecated 083 public AutoCloseable registerErrorHandler(final EventHandler<Exception> theHandler); 084 085 /** 086 * Access the Identifier of this. 087 * 088 * @return the Identifier of this. 089 */ 090 public RemoteIdentifier getMyIdentifier(); 091}