Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package org.nustaq.kontraktor.services;
import com.beust.jcommander.JCommander;
import com.eclipsesource.json.WriterConfig;
import io.undertow.server.HttpServerExchange;
import io.undertow.util.HeaderMap;
import org.nustaq.kontraktor.*;
import org.nustaq.kontraktor.annotations.CallerSideMethod;
import org.nustaq.kontraktor.annotations.Local;
import org.nustaq.kontraktor.remoting.base.ServiceDescription;
import org.nustaq.kontraktor.remoting.encoding.Coding;
import org.nustaq.kontraktor.remoting.encoding.SerializerType;
import org.nustaq.kontraktor.remoting.http.undertow.Http4K;
import org.nustaq.kontraktor.remoting.tcp.TCPConnectable;
import org.nustaq.kontraktor.remoting.tcp.TCPNIOPublisher;
import org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable;
import org.nustaq.kontraktor.rest.FromQuery;
import org.nustaq.kontraktor.services.datacluster.DataShard;
import org.nustaq.kontraktor.services.datacluster.dynamic.DynDataShard;
import org.nustaq.kontraktor.services.rlserver.SingleProcessRLClusterArgs;
import org.nustaq.kontraktor.util.Log;
import org.nustaq.kontraktor.util.Pair;
import org.nustaq.reallive.api.TableDescription;
import org.nustaq.reallive.server.dynamic.DynClusterDistribution;
import org.nustaq.serialization.FSTConfiguration;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* Created by ruedi on 11.08.2015.
*
* a simple service registry. Services can be registered by name.
* They are expected to send cyclical heartbeats.
* By registering a listener (callback) remote services can listen to
* availability/unavailability of services
*
* Rationale: in cluster of services managing connectivity gets complex
* quickly. In order to simplify this, services are given a single point
* of contact: the service registry (serviceRegistry). They register themself and
* obtain address and availability from the central registry.
* Note: Downside is, this is a SPOF.
*/
public class ServiceRegistry extends Actor {
public static final String CONFIGUPDATE = "configupdate";
public static final String SERVICEDUMP = "running";
public static final String AVAILABLE = "available";
public static final String TIMEOUT = "timeout";
protected HashMap> services;
protected Map statusMap;
protected List listeners;
protected ClusterCfg config;
@Local
public void init(ClusterCfg cfg) {
services = new HashMap<>();
statusMap = new HashMap<>();
listeners = new ArrayList<>();
checkTimeout();
config = cfg == null ? ClusterCfg.read() : cfg;
serviceDumper();
}
public void serviceDumper() {
if ( ! isStopped() ) {
try {
Log.Info(this, "------");
services.forEach((k, sd) -> Log.Info(this,""+sd) );
Log.Info(this, "------");
listeners.forEach( cb -> {
cb.pipe(new Pair(SERVICEDUMP, services));
});
if ( ClusterCfg.isDirty() ) {
config = ClusterCfg.read();
listeners.forEach(cb -> cb.pipe(new Pair(CONFIGUPDATE, config)));
}
} catch (Exception e) {
Log.Error(this,e);
}
if ( options.dumpServices() )
delayed(10000, () -> serviceDumper());
}
}
public void registerService( ServiceDescription desc ) {
Log.Info(this,"registering service "+desc);
List serviceList = getServiceList(desc.getName());
serviceList.add(desc);
desc.receiveHeartbeat();
if (serviceList.size()==1)
broadcastAvailable(desc);
}
public IPromise