/** * Copy event handler from current class configuration into runtime injector. * This is a helper method called from initializeInjector() only. * @param runtimeInjector Runtime injector to copy event handler to. * @param param Class that identifies the event handler parameter. * @param <T> Type of the event handler. * @throws InjectionException If configuration error occurs. */ private <T extends EventHandler<?>> void copyEventHandler( final Injector runtimeInjector, final Class<? extends Name<T>> param) throws InjectionException { runtimeInjector.bindVolatileParameter(param, this.originalInjector.getNamedInstance(param)); }
/** * Instantiates a new CommunicationGroupDriver instance. * @param groupName specified name of the communication group * @param topologyClass topology implementation * @param numberOfTasks minimum number of tasks needed in this group before start * @param customFanOut fanOut for TreeTopology * @return CommunicationGroupDriver instance * @throws InjectionException */ public CommunicationGroupDriver getNewInstance( final Class<? extends Name<String>> groupName, final Class<? extends Topology> topologyClass, final int numberOfTasks, final int customFanOut) throws InjectionException { final Injector newInjector = injector.forkInjector(); newInjector.bindVolatileParameter(CommGroupNameClass.class, groupName); newInjector.bindVolatileParameter(TopologyClass.class, topologyClass); newInjector.bindVolatileParameter(CommGroupNumTask.class, numberOfTasks); newInjector.bindVolatileParameter(TreeTopologyFanOut.class, customFanOut); return newInjector.getInstance(CommunicationGroupDriver.class); } }
/** * @param jobIdentifier * @param remoteIdentifier * @return * @throws BindException * @throws InjectionException */ private synchronized RunningJobImpl newRunningJob(final String jobIdentifier, final String remoteIdentifier) throws BindException, InjectionException { final Injector child = this.injector.forkInjector(); child.bindVolatileParameter(REEFImplementation.DriverRemoteIdentifier.class, remoteIdentifier); child.bindVolatileParameter(DriverIdentifier.class, jobIdentifier); return child.getInstance(RunningJobImpl.class); } }
@Inject private TopologyFactory(@Parameter(GroupCommSenderStage.class) final EStage<GroupCommunicationMessage> senderStage, @Parameter(CommGroupNameClass.class) final Class<? extends Name<String>> groupName, @Parameter(DriverIdentifier.class) final String driverId, @Parameter(CommGroupNumTask.class) final int numberOfTasks, @Parameter(TreeTopologyFanOut.class) final int fanOut) { injector = Tang.Factory.getTang().newInjector(); injector.bindVolatileParameter(GroupCommSenderStage.class, senderStage); injector.bindVolatileParameter(CommGroupNameClass.class, groupName); injector.bindVolatileParameter(DriverIdentifier.class, driverId); injector.bindVolatileParameter(CommGroupNumTask.class, numberOfTasks); injector.bindVolatileParameter(TreeTopologyFanOut.class, fanOut); }
/** * Helper method to create a new EvaluatorManager instance. * * @param id identifier of the Evaluator * @param desc NodeDescriptor on which the Evaluator executes. * @return a new EvaluatorManager instance. */ private EvaluatorManager getNewEvaluatorManagerInstance(final String id, final EvaluatorDescriptorImpl desc) { LOG.log(Level.FINEST, "Creating Evaluator Manager for Evaluator ID {0}", id); final Injector child = this.injector.forkInjector(); try { child.bindVolatileParameter(EvaluatorManager.EvaluatorIdentifier.class, id); child.bindVolatileParameter(EvaluatorManager.EvaluatorDescriptorName.class, desc); } catch (final BindException e) { throw new RuntimeException("Unable to bind evaluator identifier and name.", e); } final EvaluatorManager result; try { result = child.getInstance(EvaluatorManager.class); } catch (final InjectionException e) { throw new RuntimeException("Unable to instantiate a new EvaluatorManager for Evaluator ID: " + id, e); } return result; }
@Inject private CommunicationGroupDriverFactory( @Parameter(DriverIdentifier.class) final String driverId, @Parameter(GroupCommSenderStage.class) final EStage<GroupCommunicationMessage> senderStage, @Parameter(GroupCommRunningTaskHandler.class) final BroadcastingEventHandler<RunningTask> groupCommRunningTaskHandler, @Parameter(GroupCommFailedTaskHandler.class) final BroadcastingEventHandler<FailedTask> groupCommFailedTaskHandler, @Parameter(GroupCommFailedEvalHandler.class) final BroadcastingEventHandler<FailedEvaluator> groupCommFailedEvaluatorHandler, final GroupCommMessageHandler groupCommMessageHandler) { injector = Tang.Factory.getTang().newInjector(); injector.bindVolatileParameter(GroupCommSenderStage.class, senderStage); injector.bindVolatileParameter(DriverIdentifier.class, driverId); injector.bindVolatileParameter(GroupCommRunningTaskHandler.class, groupCommRunningTaskHandler); injector.bindVolatileParameter(GroupCommFailedTaskHandler.class, groupCommFailedTaskHandler); injector.bindVolatileParameter(GroupCommFailedEvalHandler.class, groupCommFailedEvaluatorHandler); injector.bindVolatileInstance(GroupCommMessageHandler.class, groupCommMessageHandler); }
/** * Instantiates a new Topology instance. * @param operatorName specified name of the operator * @param topologyClass specified topology type * @return Topology instance * @throws InjectionException */ public Topology getNewInstance(final Class<? extends Name<String>> operatorName, final Class<? extends Topology> topologyClass) throws InjectionException { final Injector newInjector = injector.forkInjector(); newInjector.bindVolatileParameter(OperatorNameClass.class, operatorName); return newInjector.getInstance(topologyClass); } }
/** * Runs the RPC server. * Specifically, creates a {@link NettyMessagingTransport} and binds it to a listening port. */ public void run() { // Calling 'run' multiple times is considered invalid, since it will override state variables like // 'transport', and 'host'. ensureServerState(false); try { final Injector injector = Tang.Factory.getTang().newInjector(); final LocalAddressProvider localAddressProvider = injector.getInstance(LocalAddressProvider.class); host = localAddressProvider.getLocalAddress(); injector.bindVolatileParameter(RemoteConfiguration.HostAddress.class, host); injector.bindVolatileParameter(RemoteConfiguration.Port.class, 0); injector.bindVolatileParameter(RemoteConfiguration.RemoteServerStage.class, new SyncStage<>(new ServerEventHandler())); transport = injector.getInstance(NettyMessagingTransport.class); LOG.info("DriverRPCServer running at {}", transport.getListeningPort()); isRunning = true; } catch (final InjectionException e) { throw new RuntimeException(e); } }
commGroupMessageHandler.addHandler(new TopologyMessageHandler(this)); final Injector injector = Tang.Factory.getTang().newInjector(); injector.bindVolatileParameter(CommGroupNameClass.class, groupName); injector.bindVolatileParameter(GroupCommSenderStage.class, senderStage); injector.bindVolatileParameter(DriverIdentifier.class, driverId); injector.bindVolatileParameter(CommGroupNumTask.class, numberOfTasks); injector.bindVolatileParameter(TreeTopologyFanOut.class, fanOut); try { topologyFactory = injector.getInstance(TopologyFactory.class);
/** * @param port a listening port number * @param factory an identifier factory * @param localAddressProvider a local address provider * Constructs a name server */ @Inject private NameServerImpl( @Parameter(NameServerParameters.NameServerPort.class) final int port, @Parameter(NameServerParameters.NameServerIdentifierFactory.class) final IdentifierFactory factory, final LocalAddressProvider localAddressProvider) { final Injector injector = Tang.Factory.getTang().newInjector(); this.localAddressProvider = localAddressProvider; this.reefEventStateManager = null; final Codec<NamingMessage> codec = NamingCodecFactory.createFullCodec(factory); final EventHandler<NamingMessage> handler = createEventHandler(codec); injector.bindVolatileParameter(RemoteConfiguration.HostAddress.class, localAddressProvider.getLocalAddress()); injector.bindVolatileParameter(RemoteConfiguration.Port.class, port); injector.bindVolatileParameter(RemoteConfiguration.RemoteServerStage.class, new SyncStage<>(new NamingServerHandler(handler, codec))); try { this.transport = injector.getInstance(NettyMessagingTransport.class); } catch (final InjectionException e) { throw new RuntimeException(e); } this.port = transport.getListeningPort(); this.idToAddrMap = Collections.synchronizedMap(new HashMap<Identifier, InetSocketAddress>()); LOG.log(Level.FINE, "NameServer starting, listening at port {0}", this.port); }
/** * Constructs a naming registry client. * * @param serverAddr a name server address * @param serverPort a name server port * @param timeout timeout in ms * @param factory an identifier factory */ NameRegistryClient(final String serverAddr, final int serverPort, final long timeout, final IdentifierFactory factory, final LocalAddressProvider localAddressProvider) { this.serverSocketAddr = new InetSocketAddress(serverAddr, serverPort); this.timeout = timeout; this.codec = NamingCodecFactory.createRegistryCodec(factory); this.replyQueue = new LinkedBlockingQueue<>(); final Injector injector = Tang.Factory.getTang().newInjector(); injector.bindVolatileParameter(RemoteConfiguration.HostAddress.class, localAddressProvider.getLocalAddress()); injector.bindVolatileParameter(RemoteConfiguration.RemoteClientStage.class, new SyncStage<>(new NamingRegistryClientHandler(new NamingRegistryResponseHandler(replyQueue), codec))); try { this.transport = injector.getInstance(NettyMessagingTransport.class); } catch (final InjectionException e) { throw new RuntimeException(e); } }
injector.bindVolatileParameter(NetworkServiceParameters.NetworkServiceIdentifierFactory.class, idFac); injector.bindVolatileInstance(NameResolver.class, nameResolver); injector.bindVolatileParameter(NetworkServiceParameters.NetworkServiceCodec.class, new GroupCommunicationMessageCodec()); injector.bindVolatileParameter(NetworkServiceParameters.NetworkServiceTransportFactory.class, tpFactory); injector.bindVolatileParameter(NetworkServiceParameters.NetworkServiceHandler.class, new EventHandler<Message<GroupCommunicationMessage>>() { @Override injector.bindVolatileParameter(NetworkServiceParameters.NetworkServiceExceptionHandler.class, new LoggingEventHandler<Exception>()); this.netService = injector.getInstance(NetworkService.class); injector.bindVolatileParameter(GroupCommSenderStage.class, senderStage); injector.bindVolatileParameter(DriverIdentifier.class, driverId); injector.bindVolatileParameter(GroupCommRunningTaskHandler.class, groupCommRunningTaskHandler); injector.bindVolatileParameter(GroupCommFailedTaskHandler.class, groupCommFailedTaskHandler); injector.bindVolatileParameter(GroupCommFailedEvalHandler.class, groupCommFailedEvaluatorHandler); injector.bindVolatileInstance(GroupCommMessageHandler.class, groupCommMessageHandler);