use of org.apache.plc4x.java.spi.model.DefaultPlcConsumerRegistration in project plc4x by apache.
the class FirmataProtocolLogic method register.
@Override
public PlcConsumerRegistration register(Consumer<PlcSubscriptionEvent> consumer, Collection<PlcSubscriptionHandle> collection) {
final DefaultPlcConsumerRegistration consumerRegistration = new DefaultPlcConsumerRegistration(this, consumer, collection.toArray(new PlcSubscriptionHandle[0]));
consumers.put(consumerRegistration, consumer);
return consumerRegistration;
}
use of org.apache.plc4x.java.spi.model.DefaultPlcConsumerRegistration in project plc4x by apache.
the class FirmataProtocolLogic method unregister.
@Override
public void unregister(PlcConsumerRegistration plcConsumerRegistration) {
DefaultPlcConsumerRegistration consumerRegistration = (DefaultPlcConsumerRegistration) plcConsumerRegistration;
consumers.remove(consumerRegistration);
}
use of org.apache.plc4x.java.spi.model.DefaultPlcConsumerRegistration in project plc4x by apache.
the class FirmataProtocolLogic method publishDigitalEvents.
protected void publishDigitalEvents(BitSet changedBits, BitSet bitValues) {
// If nothing changed, no need to do anything.
if (changedBits.cardinality() == 0) {
return;
}
// Try sending the subscription event to all listeners.
for (Map.Entry<DefaultPlcConsumerRegistration, Consumer<PlcSubscriptionEvent>> entry : consumers.entrySet()) {
final DefaultPlcConsumerRegistration registration = entry.getKey();
final Consumer<PlcSubscriptionEvent> consumer = entry.getValue();
// Only if the current data point matches the subscription, publish the event to it.
for (PlcSubscriptionHandle handle : registration.getSubscriptionHandles()) {
if (handle instanceof FirmataSubscriptionHandle) {
FirmataSubscriptionHandle subscriptionHandle = (FirmataSubscriptionHandle) handle;
// (The bit subscribed to in this field actually changed).
if (subscriptionHandle.getField() instanceof FirmataFieldDigital) {
FirmataFieldDigital digitalField = (FirmataFieldDigital) subscriptionHandle.getField();
// send out an update event with all of its current values.
if (digitalField.getBitSet().intersects(changedBits)) {
List<PlcValue> values = new ArrayList<>(digitalField.getBitSet().cardinality());
for (int i = 0; i < digitalField.getBitSet().length(); i++) {
values.add(new PlcBOOL(bitValues.get(i)));
}
sendUpdateEvents(consumer, subscriptionHandle.getName(), values);
}
}
}
}
}
}
use of org.apache.plc4x.java.spi.model.DefaultPlcConsumerRegistration in project plc4x by apache.
the class S7ProtocolEventLogic method register.
@Override
public PlcConsumerRegistration register(Consumer<PlcSubscriptionEvent> consumer, Collection<PlcSubscriptionHandle> handles) {
Map<PlcConsumerRegistration, Consumer> mapConsumers = null;
S7PlcSubscriptionHandle handle = (S7PlcSubscriptionHandle) handles.toArray()[0];
if (!mapIndex.containsKey(handle.getEventType())) {
mapConsumers = new HashMap();
mapIndex.put(handle.getEventType(), mapConsumers);
}
mapConsumers = mapIndex.get(handle.getEventType());
// TODO: Check the implementation of "DefaultPlcConsumerRegistration". List<> vs Collection<>
DefaultPlcConsumerRegistration registro = new DefaultPlcConsumerRegistration(this, consumer, handles.toArray(new PlcSubscriptionHandle[handles.size()]));
mapConsumers.put(registro, consumer);
return registro;
}
Aggregations