use of com.ociweb.gl.api.PubSubListener in project GreenLightning by oci-pronghorn.
the class MQTTApp method declareBehavior.
@Override
public void declareBehavior(final GreenRuntime runtime) {
// optional 2 topics, optional transform lambda
runtime.bridgeSubscription("topic/ingress", mqttConfig);
// optional 2 topics, optional transform lambda
runtime.bridgeTransmission("topic/egress", mqttConfig);
final MsgCommandChannel cmdChnl = runtime.newCommandChannel();
final PubSubService pubSubService = cmdChnl.newPubSubService();
TimeListener timeListener = new TimeListener() {
@Override
public void timeEvent(long time, int iteration) {
Writable writable = new Writable() {
@Override
public void write(ChannelWriter writer) {
Date d = new Date(System.currentTimeMillis());
System.err.println("sent " + d);
writer.writeUTF8Text("egress body " + d);
}
};
pubSubService.publishTopic("topic/egress", writable);
}
};
runtime.addTimePulseListener(timeListener);
final MsgCommandChannel cmd = runtime.newCommandChannel();
final PubSubService pubSubService2 = cmd.newPubSubService();
PubSubListener listener = new PubSubListener() {
@Override
public boolean message(CharSequence topic, ChannelReader payload) {
System.out.print("\ningress body: ");
payload.readUTFOfLength(payload.available(), System.out);
System.out.println();
Writable writable = new Writable() {
@Override
public void write(ChannelWriter writer) {
writer.writeUTF("second step test message");
}
};
pubSubService2.publishTopic("localtest", writable);
return true;
}
};
runtime.addPubSubListener(listener).addSubscription("topic/ingress");
PubSubListener localTest = new PubSubListener() {
@Override
public boolean message(CharSequence topic, ChannelReader payload) {
System.out.println("got topic " + topic + " payload " + payload.readUTF());
return true;
}
};
runtime.addPubSubListener(localTest).addSubscription("localtest");
}
use of com.ociweb.gl.api.PubSubListener in project GreenLightning by oci-pronghorn.
the class MassiveBehavior method declareBehavior.
@Override
public void declareBehavior(GreenRuntime runtime) {
// runtime.addTimePulseListener(new stopperBehavior(runtime));
int i = 7;
while (--i >= 0) {
final GreenCommandChannel cmd = runtime.newCommandChannel();
final PubSubService pubSubServce = cmd.newPubSubService();
final String topic = "topic" + i;
final int value = i;
final Writable writable = new Writable() {
@Override
public void write(ChannelWriter writer) {
writer.writePackedInt(value);
}
};
TimeListener pubs = new TimeListener() {
@Override
public void timeEvent(long time, int iteration) {
if (!pubSubServce.publishTopic(topic, writable)) {
System.out.println("overloaded can not publish " + value);
}
}
};
runtime.addTimePulseListener(pubs);
PubSubListener subs = new PubSubListener() {
public boolean message(CharSequence topic, ChannelReader payload) {
return true;
}
};
runtime.addPubSubListener(subs).addSubscription(topic);
}
}
Aggregations