All Downloads are FREE. Search and download functionalities are using the official Maven repository.

rpc.turbo.discover.DirectConnectDiscover Maven / Gradle / Ivy

There is a newer version: 0.0.9
Show newest version
package rpc.turbo.discover;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import rpc.turbo.annotation.TurboService;
import rpc.turbo.config.HostPort;
import rpc.turbo.config.server.Protocol;

public class DirectConnectDiscover implements Discover {

	private List hostPorts;

	@Override
	public void init(List hostPorts) {
		this.hostPorts = hostPorts;
	}

	@Override
	public void addListener(String group, String app, Protocol protocol, DiscoverListener listener) {
		Map providerWithWeight = hostPorts.stream()
				.collect(Collectors.toMap(item -> item, item -> TurboService.DEFAULT_WEIGHT));

		listener.onChange(providerWithWeight);

		new Thread(() -> {
			while (true) {
				try {
					Thread.sleep(5000);
				} catch (InterruptedException e) {
					break;
				}

				System.out.println("DirectConnectDiscover onChange");
				listener.onChange(providerWithWeight);
			}
		}).start();
	}

	@Override
	public void close() throws IOException {
		System.out.println("DirectConnectDiscover close");
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy