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.impl; 020 021import org.apache.reef.tang.annotations.Parameter; 022import org.apache.reef.wake.EventHandler; 023import org.apache.reef.wake.remote.Codec; 024import org.apache.reef.wake.remote.RemoteConfiguration; 025import org.apache.reef.wake.remote.RemoteManager; 026import org.apache.reef.wake.remote.RemoteManagerFactory; 027import org.apache.reef.wake.remote.address.LocalAddressProvider; 028import org.apache.reef.wake.remote.ports.TcpPortProvider; 029import org.apache.reef.wake.remote.transport.TransportFactory; 030 031import javax.inject.Inject; 032 033/** 034 * Default implementation of RemoteManagerFactory. 035 */ 036public final class DefaultRemoteManagerFactory implements RemoteManagerFactory { 037 038 private final Codec<?> codec; 039 private final EventHandler<Throwable> errorHandler; 040 private final boolean orderingGuarantee; 041 private final int numberOfTries; 042 private final int retryTimeout; 043 private final LocalAddressProvider localAddressProvider; 044 private final TransportFactory tpFactory; 045 046 @Inject 047 private DefaultRemoteManagerFactory( 048 @Parameter(RemoteConfiguration.MessageCodec.class) final Codec<?> codec, 049 @Parameter(RemoteConfiguration.ErrorHandler.class) final EventHandler<Throwable> errorHandler, 050 @Parameter(RemoteConfiguration.OrderingGuarantee.class) final boolean orderingGuarantee, 051 @Parameter(RemoteConfiguration.NumberOfTries.class) final int numberOfTries, 052 @Parameter(RemoteConfiguration.RetryTimeout.class) final int retryTimeout, 053 final LocalAddressProvider localAddressProvider, 054 final TransportFactory tpFactory) { 055 this.codec = codec; 056 this.errorHandler = errorHandler; 057 this.orderingGuarantee = orderingGuarantee; 058 this.numberOfTries = numberOfTries; 059 this.retryTimeout = retryTimeout; 060 this.localAddressProvider = localAddressProvider; 061 this.tpFactory = tpFactory; 062 } 063 064 // TODO[REEF-547]: This method uses deprecated DefaultRemoteManagerImplementation constructor. 065 @Override 066 public RemoteManager getInstance(final String name) { 067 return new DefaultRemoteManagerImplementation(name, 068 DefaultRemoteManagerImplementation.UNKNOWN_HOST_NAME, // Indicate to use the localAddressProvider 069 0, // Indicate to use the tcpPortProvider 070 this.codec, 071 this.errorHandler, 072 this.orderingGuarantee, 073 this.numberOfTries, 074 this.retryTimeout, 075 this.localAddressProvider, 076 this.tpFactory); 077 } 078 079 // TODO[REEF-547]: This method uses deprecated DefaultRemoteManagerImplementation constructor. 080 @Override 081 @SuppressWarnings("checkstyle:hiddenfield") 082 public <T> RemoteManager getInstance(final String name, 083 final String hostAddress, 084 final int listeningPort, 085 final Codec<T> codec, 086 final EventHandler<Throwable> errorHandler, 087 final boolean orderingGuarantee, 088 final int numberOfTries, 089 final int retryTimeout, 090 final LocalAddressProvider localAddressProvider, 091 final TcpPortProvider tcpPortProvider) { 092 return new DefaultRemoteManagerImplementation(name, 093 hostAddress, 094 listeningPort, 095 codec, 096 errorHandler, 097 orderingGuarantee, 098 numberOfTries, 099 retryTimeout, 100 localAddressProvider, 101 tpFactory); 102 } 103 104 // TODO[REEF-547]: This method uses deprecated DefaultRemoteManagerImplementation constructor. 105 @Override 106 @SuppressWarnings("checkstyle:hiddenfield") 107 public <T> RemoteManager getInstance(final String name, 108 final String hostAddress, 109 final int listeningPort, 110 final Codec<T> codec, 111 final EventHandler<Throwable> errorHandler, 112 final boolean orderingGuarantee, 113 final int numberOfTries, 114 final int retryTimeout) { 115 return new DefaultRemoteManagerImplementation(name, 116 hostAddress, 117 listeningPort, 118 codec, 119 errorHandler, 120 orderingGuarantee, 121 numberOfTries, 122 retryTimeout, 123 this.localAddressProvider, 124 this.tpFactory); 125 126 } 127 128 // TODO[REEF-547]: This method uses deprecated DefaultRemoteManagerImplementation constructor. 129 @Override 130 @SuppressWarnings("checkstyle:hiddenfield") 131 public <T> RemoteManager getInstance( 132 final String name, final Codec<T> codec, final EventHandler<Throwable> errorHandler) { 133 return new DefaultRemoteManagerImplementation(name, 134 DefaultRemoteManagerImplementation.UNKNOWN_HOST_NAME, // Indicate to use the localAddressProvider 135 0, // Indicate to use the tcpPortProvider, 136 codec, 137 errorHandler, 138 this.orderingGuarantee, 139 this.numberOfTries, 140 this.retryTimeout, 141 this.localAddressProvider, 142 this.tpFactory); 143 } 144 145 // TODO[REEF-547]: This method uses deprecated DefaultRemoteManagerImplementation constructor. 146 @Override 147 @SuppressWarnings("checkstyle:hiddenfield") 148 public <T> RemoteManager getInstance(final String name, 149 final int listeningPort, 150 final Codec<T> codec, 151 final EventHandler<Throwable> errorHandler) { 152 return new DefaultRemoteManagerImplementation(name, 153 DefaultRemoteManagerImplementation.UNKNOWN_HOST_NAME, // Indicate to use the localAddressProvider 154 listeningPort, 155 codec, 156 errorHandler, 157 this.orderingGuarantee, 158 this.numberOfTries, 159 this.retryTimeout, 160 this.localAddressProvider, 161 this.tpFactory); 162 } 163}