Search in sources :

Example 1 with S7PlcSubscriptionHandle

use of org.apache.plc4x.java.s7.readwrite.utils.S7PlcSubscriptionHandle 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;
}
Also used : DefaultPlcConsumerRegistration(org.apache.plc4x.java.spi.model.DefaultPlcConsumerRegistration) Consumer(java.util.function.Consumer) HashMap(java.util.HashMap) PlcSubscriptionHandle(org.apache.plc4x.java.api.model.PlcSubscriptionHandle) S7PlcSubscriptionHandle(org.apache.plc4x.java.s7.readwrite.utils.S7PlcSubscriptionHandle) DefaultPlcConsumerRegistration(org.apache.plc4x.java.spi.model.DefaultPlcConsumerRegistration) PlcConsumerRegistration(org.apache.plc4x.java.api.model.PlcConsumerRegistration) S7PlcSubscriptionHandle(org.apache.plc4x.java.s7.readwrite.utils.S7PlcSubscriptionHandle)

Example 2 with S7PlcSubscriptionHandle

use of org.apache.plc4x.java.s7.readwrite.utils.S7PlcSubscriptionHandle in project plc4x by apache.

the class S7ProtocolEventLogic method unregister.

@Override
public void unregister(PlcConsumerRegistration registration) {
    S7PlcSubscriptionHandle handle = (S7PlcSubscriptionHandle) registration.getSubscriptionHandles().get(0);
    Map<PlcConsumerRegistration, Consumer> mapConsumers = mapIndex.get(handle.getEventType());
    mapConsumers.remove(registration);
}
Also used : Consumer(java.util.function.Consumer) DefaultPlcConsumerRegistration(org.apache.plc4x.java.spi.model.DefaultPlcConsumerRegistration) PlcConsumerRegistration(org.apache.plc4x.java.api.model.PlcConsumerRegistration) S7PlcSubscriptionHandle(org.apache.plc4x.java.s7.readwrite.utils.S7PlcSubscriptionHandle)

Aggregations

Consumer (java.util.function.Consumer)2 PlcConsumerRegistration (org.apache.plc4x.java.api.model.PlcConsumerRegistration)2 S7PlcSubscriptionHandle (org.apache.plc4x.java.s7.readwrite.utils.S7PlcSubscriptionHandle)2 DefaultPlcConsumerRegistration (org.apache.plc4x.java.spi.model.DefaultPlcConsumerRegistration)2 HashMap (java.util.HashMap)1 PlcSubscriptionHandle (org.apache.plc4x.java.api.model.PlcSubscriptionHandle)1