private EventRegistration registerListenerInternal(String serviceName, String topic, EventFilter filter, Object listener,
                                                       boolean localOnly) {
        if (listener == null) {
            throw new IllegalArgumentException("Listener required!");
        }
        if (filter == null) {
            throw new IllegalArgumentException("EventFilter required!");
        }
        EventServiceSegment segment = getSegment(serviceName, true);
        String id = UuidUtil.newUnsecureUuidString();
        Registration reg = new Registration(id, serviceName, topic, filter, nodeEngine.getThisAddress(), listener, localOnly);
        if (!segment.addRegistration(topic, reg)) {
            return null;
        }

        if (!localOnly) {
            Supplier<Operation> supplier = new RegistrationOperationSupplier(reg, nodeEngine.getClusterService());
            invokeOnAllMembers(supplier);
        }
        return reg;
    }
private EventRegistration registerListenerInternal ( String serviceName , String topic , EventFilter filter , Object listener , boolean localOnly ) { if ( listener == null ) { throw new IllegalArgumentException ( "Listener required!" ) ; } if ( filter == null ) { throw new IllegalArgumentException ( "EventFilter required!" ) ; } EventServiceSegment segment = getSegment ( serviceName , true ) ; String id = UuidUtil . newUnsecureUuidString ( ) ; Registration reg = new Registration ( id , serviceName , topic , filter , nodeEngine . getThisAddress ( ) , listener , localOnly ) ; if ( ! segment . addRegistration ( topic , reg ) ) { return null ; } if ( ! localOnly ) { Supplier < Operation > supplier = new RegistrationOperationSupplier ( reg , nodeEngine . getClusterService ( ) ) ; invokeOnAllMembers ( supplier ) ; } return reg ; }
Registers the listener for events matching the service name, topic and filter.
If {@code localOnly} is {@code true}, it will register only for events published on this node,
otherwise, the registration is sent to other nodes and the listener will listen for
events on all cluster members.

@param serviceName the service name for which we are registering
@param topic       the event topic for which we are registering
@param filter      the filter for the listened events
@param listener    the event listener
@param localOnly   whether to register on local events or on events on all cluster members
@return the event registration
@throws IllegalArgumentException if the listener or filter is null