public void publishEvent(String serviceName, Collection<EventRegistration> registrations, Object event, int orderKey) {
final Iterator<EventRegistration> iter = registrations.iterator();
Data eventData = null;
while (iter.hasNext()) {
EventRegistration registration = iter.next();
if (!(registration instanceof Registration)) {
throw new IllegalArgumentException();
}
final Registration reg = (Registration) registration;
if (isLocal(reg)) {
executeLocal(serviceName, event, reg, orderKey);
} else {
if (eventData == null) {
eventData = nodeEngine.toData(event);
}
final Address subscriber = registration.getSubscriber();
sendEventPacket(subscriber, new EventPacket(registration.getId(), serviceName, eventData), orderKey);
}
}
}