@Override public Observable<Void> asLifecycleObservable() { return delegate.asLifecycleObservable(); } }
@Override public Observable<Void> call() throws Exception { return delegate.register(instanceInfo); } });
@Override public Observable<Void> call() throws Exception { return delegate.unregister(); } });
@Override public Observable<Void> register(InstanceInfo instanceInfo) { if (shutdown) { return Observable.error(new IllegalStateException("Registration handler is already shutdown.")); } final RegistrationChannel newChannel = channelFactory.newRegistrationChannel(); final RegistrationChannel existing = instanceIdVsChannel.putIfAbsent(instanceInfo.getId(), newChannel); if (null != existing) { return existing.update(instanceInfo); // Be more acceptable to failure in contract adherence from the user. // If it is the same instance as existing, the server should not // generate unnecessary notifications. } return newChannel.register(instanceInfo); }
@Override public void call() { // Since we do not reuse the channel, we must shut it down with the underlying connection. registrationChannel.close(); } });
@Override public Observable<Void> call() throws Exception { return delegate.update(newInfo); } });
@Override public void call() { entry.getValue().close(); } }).subscribe();
@Override public Observable<Void> update(InstanceInfo instanceInfo) { if (shutdown) { return Observable.error(new IllegalStateException("Registration handler is already shutdown.")); } final RegistrationChannel registrationChannel = instanceIdVsChannel.get(instanceInfo.getId()); if (null == registrationChannel) { logger.info("Instance: %s is not registered. Relaying update as register.", instanceInfo); return register(instanceInfo); // Be more acceptable to errors from user. } return registrationChannel.update(instanceInfo); }
@Override public Observable<Void> asLifecycleObservable() { return delegate.asLifecycleObservable(); } }
@Override public Observable<Void> unregister() { hasUnregistered = true; return delegate.unregister(); } }
@Override public Observable<Void> call(RegistrationChannel channel, InstanceInfo instanceInfo) { return channel.register(instanceInfo); } };
@Override public void close(Throwable error) { try { shutdown(); } finally { delegate.close(error); } }
@Override public Observable<Void> update(final InstanceInfo newInfo) { this.instanceInfo = newInfo; return getStateWithChannel().getChannel().update(newInfo); }
@Override public Observable<Void> handle(ObservableConnection<Object, Object> connection) { MessageConnection broker = new HeartBeatConnection( new BaseMessageConnection("registration", connection, metricFactory.getRegistrationConnectionMetrics()), HEARTBEAT_INTERVAL_MILLIS, 3, Schedulers.computation() ); final ServerChannelFactory service = new ServerChannelFactoryImpl(registry, null, evictionQueue, broker, metricFactory); return service.newRegistrationChannel() .asLifecycleObservable(); // Since this is a discovery handler which only handles interest subscriptions, // the channel is created on connection accept. } }
@Override public Observable<Void> call() throws Exception { return delegate.unregister(); }
@Override public Observable<Void> call() throws Exception { return delegate.register(instanceInfo); }
@Override public void close() { try { shutdown(); } finally { delegate.close(); } }
@Override public Observable<Void> handle(ObservableConnection<Object, Object> connection) { MessageConnection broker = new HeartBeatConnection( new BaseMessageConnection("registration", connection, metricFactory.getRegistrationConnectionMetrics()), config.getHeartbeatIntervalMs(), 3, Schedulers.computation() ); final ServerChannelFactory<RegistrationChannel> channelFactory = new RegistrationChannelFactory(registry, broker, evictionQueue, metricFactory); return channelFactory.newChannel() .asLifecycleObservable(); // Since this is a discovery handler which only handles interest subscriptions, // the channel is created on connection accept. } }
@Override public void shutdown() { shutdown = true; channelFactory.shutdown(); Set<Map.Entry<String, RegistrationChannel>> entries = instanceIdVsChannel.entrySet(); for (final Map.Entry<String, RegistrationChannel> entry : entries) { String instanceId = entry.getKey(); logger.info("Shutting down registration handler. Unregister instance Id: " + instanceId); entry.getValue().unregister().doOnTerminate(new Action0() { @Override public void call() { entry.getValue().close(); } }).subscribe(); } } }
@Override public Observable<Void> register(InstanceInfo instanceInfo) { operations.add(instanceInfo); return delegate.register(instanceInfo); }