use of services.moleculer.config.ServiceBrokerConfig in project moleculer-java by moleculer-java.
the class DefaultEventbus method started.
// --- START EVENT BUS ---
/**
* Initializes default EventBus instance.
*
* @param broker
* parent ServiceBroker
* @param config
* optional configuration of the current component
*/
@Override
public void started(ServiceBroker broker) throws Exception {
super.started(broker);
// Set nodeID
this.nodeID = broker.getNodeID();
// Set components
ServiceBrokerConfig cfg = broker.getConfig();
this.strategy = cfg.getStrategyFactory();
this.transporter = cfg.getTransporter();
this.executor = cfg.getExecutor();
}
use of services.moleculer.config.ServiceBrokerConfig in project moleculer-java by moleculer-java.
the class DefaultCircuitBreaker method started.
// --- START BREAKER ---
@Override
public void started(ServiceBroker broker) throws Exception {
super.started(broker);
// Set components
ServiceBrokerConfig cfg = broker.getConfig();
this.serviceRegistry = cfg.getServiceRegistry();
this.contextFactory = cfg.getContextFactory();
}
use of services.moleculer.config.ServiceBrokerConfig in project moleculer-java by moleculer-java.
the class RedisCacher method started.
/**
* Initializes cacher instance.
*
* @param broker
* parent ServiceBroker
* @param config
* optional configuration of the current component
*/
@Override
public void started(ServiceBroker broker) throws Exception {
super.started(broker);
logger.info(nameOf(this, true) + " will use " + nameOf(serializer, true) + '.');
// Get components
ServiceBrokerConfig cfg = broker.getConfig();
executor = cfg.getExecutor();
scheduler = cfg.getScheduler();
// Connect to Redis server
connect();
}
use of services.moleculer.config.ServiceBrokerConfig in project moleculer-java by moleculer-java.
the class NodeService method started.
// --- START SERVICE ---
@Override
public void started(ServiceBroker broker) throws Exception {
super.started(broker);
// Set components
ServiceBrokerConfig cfg = broker.getConfig();
this.transporter = cfg.getTransporter();
this.monitor = cfg.getMonitor();
this.localNodeID = broker.getNodeID();
}
use of services.moleculer.config.ServiceBrokerConfig in project moleculer-java by moleculer-java.
the class ClusterTest method run.
public void run() {
System.out.println("START");
try {
// Load Sigar DLLs
String nativeDir = "./native";
System.setProperty("java.library.path", nativeDir);
ExecutorService executor = Executors.newFixedThreadPool(Math.min(NODES, 100));
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(Math.min(NODES, 100));
String[] urls = new String[NODES];
for (int i = 0; i < NODES; i++) {
int port = 6000 + i;
urls[i] = "tcp://127.0.0.1:" + port + "/node-" + i;
}
ServiceBroker[] brokers = new ServiceBroker[NODES];
for (int i = 0; i < NODES; i++) {
// urls
TcpTransporter transporter = new TcpTransporter();
transporter.setGossipPeriod(3);
transporter.setDebug(false);
transporter.setOfflineTimeout(0);
ServiceBrokerConfig settings = new ServiceBrokerConfig();
settings.setShutDownThreadPools(false);
settings.setExecutor(executor);
settings.setScheduler(scheduler);
settings.setTransporter(transporter);
settings.setNodeID("node-" + i);
ServiceBroker broker = new ServiceBroker(settings);
brokers[i] = broker;
}
for (int i = 0; i < NODES; i++) {
brokers[i].start();
System.out.println("node-" + i + " started.");
}
boolean turnOn = true;
HashMap<String, Long> maxSeqs = new HashMap<>();
ServiceBroker broker;
TcpTransporter transporter;
int counter = 0;
while (true) {
Thread.sleep(1000);
counter++;
if (counter % 70 == 0) {
if (turnOn) {
for (int n = 0; n < NODES / 3; n++) {
int i = rnd.nextInt(NODES);
broker = brokers[i];
transporter = (TcpTransporter) broker.getConfig().getTransporter();
if (transporter.writer == null) {
transporter.connect();
}
}
}
int i = rnd.nextInt(NODES);
broker = brokers[i];
transporter = (TcpTransporter) broker.getConfig().getTransporter();
if (transporter.writer != null) {
transporter.nodes.clear();
transporter.disconnect();
}
}
maxSeqs.clear();
for (int i = 0; i < NODES; i++) {
broker = brokers[i];
transporter = (TcpTransporter) broker.getConfig().getTransporter();
maxSeqs.put(broker.getNodeID(), transporter.getDescriptor().cpuSeq);
}
for (int i = 0; i < NODES; i++) {
broker = brokers[i];
transporter = (TcpTransporter) broker.getConfig().getTransporter();
for (int n = 0; n < NODES; n++) {
NodeDescriptor d = transporter.nodes.get("node-" + n);
boolean online = transporter.isOnline("node-" + n);
Color color;
Long seq = null;
if (online) {
if (d != null) {
long cpuSeq = d.cpuSeq;
long maxSeq = maxSeqs.get("node-" + n);
if (maxSeq > 0) {
if (maxSeq < cpuSeq) {
maxSeq = cpuSeq;
maxSeqs.put("node-" + n, maxSeq);
}
long c = Math.max(0, 255 - 20 * (maxSeq - cpuSeq));
color = new Color(0, (int) c, 0);
} else {
color = Color.WHITE;
}
seq = d.seq;
} else {
color = Color.YELLOW;
}
} else {
color = Color.RED;
if (d != null) {
seq = d.seq;
}
}
image.draw(n, i, color, seq);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("STOP");
System.exit(0);
}
Aggregations