use of org.olat.core.util.event.MultiUserEvent in project OpenOLAT by OpenOLAT.
the class NotificationsManagerImpl method markPublisherNews.
@Override
public void markPublisherNews(String publisherType, String data, Identity ignoreNewsFor, boolean sendEvents) {
// to make sure: ignore if no subscriptionContext
if (!StringHelper.containsNonWhitespace(publisherType) || !StringHelper.containsNonWhitespace(data))
return;
List<Publisher> publisherToUpdates = getPublishers(publisherType, data);
if (publisherToUpdates == null || publisherToUpdates.isEmpty()) {
return;
}
List<Publisher> updatedPublishers = new ArrayList<>(publisherToUpdates.size());
for (Publisher toUpdate : publisherToUpdates) {
toUpdate = getPublisherForUpdate(toUpdate);
toUpdate.setLatestNewsDate(new Date());
Publisher publisher = dbInstance.getCurrentEntityManager().merge(toUpdate);
// commit the select for update
dbInstance.commit();
updatedPublishers.add(publisher);
}
// user
if (ignoreNewsFor != null) {
for (Publisher publisher : updatedPublishers) {
markSubscriberRead(ignoreNewsFor, publisher);
}
}
if (sendEvents) {
// commit all things on the database
dbInstance.commit();
// channel-notify all interested listeners (e.g. the pnotificationsportletruncontroller)
// 1. find all subscribers which can be affected
List<Subscriber> subscribers = getValidSubscribersOf(publisherType, data);
Set<Long> subsKeys = new HashSet<Long>();
// 2. collect all keys of the affected subscribers
for (Subscriber subscriber : subscribers) {
subsKeys.add(subscriber.getKey());
}
// fire the event
MultiUserEvent mue = EventFactory.createAffectedEvent(subsKeys);
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(mue, oresMyself);
}
}
use of org.olat.core.util.event.MultiUserEvent in project OpenOLAT by OpenOLAT.
the class NotificationsManagerImpl method markPublisherNews.
/**
* call this method to indicate that there is news for the given
* subscriptionContext
*
* @param subscriptionContext
* @param ignoreNewsFor
*/
@Override
public void markPublisherNews(final SubscriptionContext subscriptionContext, Identity ignoreNewsFor, boolean sendEvents) {
// to make sure: ignore if no subscriptionContext
if (subscriptionContext == null)
return;
Publisher toUpdate = getPublisherForUpdate(subscriptionContext);
if (toUpdate == null) {
return;
}
toUpdate.setLatestNewsDate(new Date());
Publisher publisher = dbInstance.getCurrentEntityManager().merge(toUpdate);
// commit the select for update
dbInstance.commit();
// user
if (ignoreNewsFor != null) {
markSubscriberRead(ignoreNewsFor, publisher);
}
if (sendEvents) {
// commit all things on the database
dbInstance.commit();
// channel-notify all interested listeners (e.g. the pnotificationsportletruncontroller)
// 1. find all subscribers which can be affected
List<Subscriber> subscribers = getValidSubscribersOf(publisher);
Set<Long> subsKeys = new HashSet<Long>();
// 2. collect all keys of the affected subscribers
for (Subscriber subscriber : subscribers) {
subsKeys.add(subscriber.getKey());
}
// fire the event
MultiUserEvent mue = EventFactory.createAffectedEvent(subsKeys);
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(mue, oresMyself);
}
}
use of org.olat.core.util.event.MultiUserEvent in project OpenOLAT by OpenOLAT.
the class LockController method event.
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
* org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
*/
public void event(UserRequest ureq, Controller source, Event event) {
if (source == tableCtr) {
if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
TableEvent te = (TableEvent) event;
LockEntry lockToRelease = locksTableModel.getObject(te.getRowId());
dialogController = activateYesNoDialog(ureq, null, translate("lock.release.sure"), dialogController);
dialogController.setUserObject(lockToRelease);
}
} else if (source == dialogController) {
if (DialogBoxUIFactory.isYesEvent(event)) {
LockEntry lockToRelease = (LockEntry) dialogController.getUserObject();
MultiUserEvent mue = new LockRemovedEvent(lockToRelease);
OLATResourceable lockEntryOres = OresHelper.createOLATResourceableInstance(LockEntry.class, 0l);
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(mue, lockEntryOres);
CoordinatorManager.getInstance().getCoordinator().getLocker().releaseLockEntry(lockToRelease);
lockToRelease = null;
resetTableModel();
}
}
}
use of org.olat.core.util.event.MultiUserEvent in project OpenOLAT by OpenOLAT.
the class InfoMessageManager method event.
public void event(Event event) {
if (event instanceof MultiUserEvent) {
MultiUserEvent mue = (MultiUserEvent) event;
// do not use setInfoMessage(..) this event comes in from another node, where the infomessage was set.
InfoMessageManager.infoMessage = mue.getCommand();
}
}
use of org.olat.core.util.event.MultiUserEvent in project OpenOLAT by OpenOLAT.
the class ClusterEventBus method serveMessage.
void serveMessage(Message message, long receiveEnqueueTime) {
// stats
final long receiveTime = System.currentTimeMillis();
if (receiveEnqueueTime > 0) {
final long diff = receiveTime - receiveEnqueueTime;
mrtgProbeJMSEnqueueTime_.addMeasurement(diff);
}
if (lastOnMessageFinishTime_ != -1) {
final long waitingTime = receiveTime - lastOnMessageFinishTime_;
// the waiting time is inverted to represent more like a frequency
// the values it translates to are the following:
// 0ms -> 100
// 1ms -> 66
// 2ms -> 50
// 4ms -> 33
// 6ms -> 25
// 8ms -> 20
// 18ms -> 10
// 20ms -> 9
// 23ms -> 8
// 26.5ms -> 7
// 31ms -> 6
// 38ms -> 5
mrtgProbeJMSLoad_.addMeasurement((long) (100.0 / ((waitingTime / 2.0) + 1.0)));
lastOnMessageFinishTime_ = -1;
}
ObjectMessage om = (ObjectMessage) message;
try {
// unpack
JMSWrapper jmsWrapper = (JMSWrapper) om.getObject();
Integer nodeId = jmsWrapper.getNodeId();
MultiUserEvent event = jmsWrapper.getMultiUserEvent();
OLATResourceable ores = jmsWrapper.getOres();
boolean fromSameNode = clusterConfig.getNodeId().equals(nodeId);
String recMsg = "received msg: " + (fromSameNode ? "[same node]" : "") + " from node:" + nodeId + ", olat-id:" + jmsWrapper.getMsgId() + ", ores:" + ores.getResourceableTypeName() + ":" + ores.getResourceableId() + ", event:" + event + "}";
// stats
final long jmsTimestamp = om.getJMSTimestamp();
if (jmsTimestamp != 0) {
final long deliveryTime = receiveTime - jmsTimestamp;
if (deliveryTime > 1500) {
// then issue a log statement
log.warn("message received with long delivery time (longer than 1500ms: " + deliveryTime + "): " + recMsg);
}
mrtgProbeJMSDeliveryTime_.addMeasurement(deliveryTime);
}
addToReceivedScreen(recMsg);
if (log.isDebug())
log.debug(recMsg);
// message with destination and source both having this vm are ignored here, since they were already
// "inline routed" when having been sent (direct call within the vm).
// TODO jms if (!fromSameNode) {
// distribute the unmarshalled event to all JVM wide listeners for this channel.
doFire(event, ores);
// TODO jms } // else message already sent "in-vm"
// stats
final long doneTime = System.currentTimeMillis();
final long processingTime = doneTime - receiveTime;
if (processingTime > 500) {
// then issue a log statement
log.warn("message received with long processing time (longer than 500ms: " + processingTime + "): " + recMsg);
}
mrtgProbeJMSProcessingTime_.addMeasurement(processingTime);
} catch (Error er) {
log.error("Uncaught Error in ClusterEventBus.onMessage!", er);
throw er;
} catch (RuntimeException re) {
log.error("Uncaught RuntimeException in ClusterEventBus.onMessage!", re);
throw re;
} catch (JMSException e) {
log.warn("JMSException in ClusterEventBus.onMessage", e);
throw new OLATRuntimeException("error when receiving jms messages", e);
} catch (Throwable th) {
log.error("Uncaught Throwable in ClusterEventBus.onMessage!", th);
} finally {
lastOnMessageFinishTime_ = System.currentTimeMillis();
}
}
Aggregations