use of com.robo4j.RoboContext in project robo4j by Robo4J.
the class RemoteContextTests method startRemoteSenderTest.
@Disabled("for individual testing")
@Test
void startRemoteSenderTest() throws Exception {
// Note that all this cludging about with local lookup service
// implementations etc would normally not be needed.
// This is just to isolate this test from other tests.
final LocalLookupServiceImpl localLookup = new LocalLookupServiceImpl();
final LookupService service = LookupServiceTests.getLookupService(localLookup);
LookupServiceProvider.setDefaultLookupService(service);
service.start();
// context has been discovered
RoboContextDescriptor descriptor = getRoboContextDescriptor(service, CONTEXT_ID_REMOTE_RECEIVER);
assertTrue(service.getDiscoveredContexts().size() > 0);
assertNotNull(descriptor);
// build the producer system
RoboContext producerEmitterSystem = buildEmitterContext(String.class, UNIT_STRING_CONSUMER, REMOTE_UNIT_EMITTER);
localLookup.addContext(producerEmitterSystem);
producerEmitterSystem.start();
RoboReference<String> remoteTestMessageProducer = producerEmitterSystem.getReference(REMOTE_UNIT_EMITTER);
for (int i = 0; i < 10; i++) {
remoteTestMessageProducer.sendMessage("REMOTE MESSAGE :" + i);
}
System.in.read();
}
use of com.robo4j.RoboContext in project robo4j by Robo4J.
the class RemoteTestMessageProducer method sendRandomMessage.
public void sendRandomMessage() {
final int number = TestToolkit.getRND().nextInt() % 100;
final String text = StringToolkit.getRandomMessage(10);
// We're sending a reference to ourself for getting the acks...
final TestMessageType message = new TestMessageType(number, text, getContext().getReference(getId()));
RoboContext ctx = LookupServiceProvider.getDefaultLookupService().getContext(targetContext);
ctx.getReference(target).sendMessage(message);
}
use of com.robo4j.RoboContext in project robo4j by Robo4J.
the class VectorEventListenerUnit method onMessage.
@Override
public void onMessage(VectorEvent message) {
SimpleLoggingUtil.info(getClass(), "received:" + message);
RoboContext remoteContext = LookupServiceProvider.getDefaultLookupService().getContext(targetContext);
if (remoteContext != null) {
RoboReference<VectorEvent> roboReference = remoteContext.getReference(remoteUnit);
if (roboReference != null) {
roboReference.sendMessage(message);
}
} else {
SimpleLoggingUtil.info(getClass(), String.format("context not found: %s", targetContext));
}
}
use of com.robo4j.RoboContext in project robo4j by Robo4J.
the class AdafruitBiColor24BackpackExample method main.
public static void main(String[] args) throws Exception {
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
InputStream settings = AdafruitBiColor24BackpackExample.class.getClassLoader().getResourceAsStream("bargraph24example.xml");
RoboContext ctx = new RoboBuilder().add(settings).build();
ctx.start();
RoboReference<DrawMessage> barUnit = ctx.getReference("bargraph");
DrawMessage clearMessage = new DrawMessage(BackpackMessageCommand.CLEAR);
AtomicInteger position = new AtomicInteger();
executor.scheduleAtFixedRate(() -> {
if (position.get() > BiColor24BarDevice.MAX_BARS - 1) {
position.set(0);
}
barUnit.sendMessage(clearMessage);
barUnit.sendMessage(new DrawMessage(BackpackMessageCommand.PAINT, new short[] { (short) position.getAndIncrement() }, new short[] { 0 }, new BiColor[] { BiColor.getByValue(position.get() % 3 + 1) }));
}, 2, 1, TimeUnit.SECONDS);
System.out.println("Press enter to quit\n");
System.in.read();
executor.shutdown();
ctx.shutdown();
}
use of com.robo4j.RoboContext in project robo4j by Robo4J.
the class ColorDemo method runDemo.
@Override
public void runDemo() {
String prefix = "Color changes:\n";
lcd.sendMessage(LcdMessage.MESSAGE_CLEAR);
int delay = 0;
int i = 0;
for (; i < Color.values().length - 1; i++) {
Color c = Color.values()[i];
scheduler.schedule(lcd, getColorMessage(prefix, c), delay += 1, 1, TimeUnit.SECONDS, 1);
}
scheduler.schedule(lcd, getColorMessage(prefix, Color.values()[i]), delay += 1, 1, TimeUnit.SECONDS, 1, (RoboContext context) -> {
lcd.sendMessage(new LcdMessage(getName() + " Demo:\nDone!", Color.ON));
setDone();
});
}
Aggregations