use of org.eclipse.scout.rt.shared.clientnotification.ClientNotificationMessage in project scout.rt by eclipse.
the class BridgeToServerBeanDecorator method ensureRunInServerContext.
protected Object ensureRunInServerContext(final IBeanInvocationContext<T> context) {
if (PropertyMap.isSet(PropertyMap.PROP_SERVER_SCOPE)) {
// already in a server scope
return continueCall(context);
}
// bridge to server scope
ClientNotificationCollector collector = new ClientNotificationCollector();
ServerRunContext bridgeRunContext = ServerRunContexts.copyCurrent().withClientNotificationCollector(collector).withClientNodeId(INode.ID);
ISession currentSession = ISession.CURRENT.get();
IServerSession bridgeSession = null;
if (currentSession != null) {
bridgeSession = BEANS.get(ServerSessionProviderWithCache.class).provide(currentSession.getId(), bridgeRunContext);
}
Object result = bridgeRunContext.withSession(bridgeSession).call(new Callable<Object>() {
@Override
public Object call() throws Exception {
try {
return continueCall(context);
} catch (Exception e) {
ITransaction.CURRENT.get().addFailure(e);
throw e;
}
}
});
ClientNotificationDispatcher clientNotificationDispatcher = BEANS.get(ClientNotificationDispatcher.class);
List<ClientNotificationMessage> values = collector.consume();
if (!values.isEmpty()) {
clientNotificationDispatcher.dispatchNotifications(values);
}
return result;
}
use of org.eclipse.scout.rt.shared.clientnotification.ClientNotificationMessage in project scout.rt by eclipse.
the class ClientNotificationNodeQueue method putDroppingOld.
/**
* Put notifications into queue and drop oldest ones, if capacity is reached.
*/
private void putDroppingOld(Collection<? extends ClientNotificationMessage> notifications) {
int dropCount = 0;
for (ClientNotificationMessage message : notifications) {
boolean inserted = m_notifications.offer(message);
while (!inserted) {
ClientNotificationMessage removed = m_notifications.poll();
if (removed != null) {
dropCount++;
}
inserted = m_notifications.offer(message);
}
}
if (dropCount > 0) {
LOG.warn("Notification queue capacity reached. Remove oldest {} notification messages.", dropCount);
}
}
use of org.eclipse.scout.rt.shared.clientnotification.ClientNotificationMessage in project scout.rt by eclipse.
the class ClientNotificationNodeQueue method getNotifications.
protected List<ClientNotificationMessage> getNotifications(int maxAmount, long maxWaitTime, TimeUnit unit) {
List<ClientNotificationMessage> collected = new LinkedList<>();
try {
// blocking wait to get first message
ClientNotificationMessage next = m_notifications.poll(maxWaitTime, unit);
if (next != null) {
collected.add(next);
}
// add more available notifications
// with short wait timeout to not go back with one notification when some are about to pop up.
// 0 for no reschedule
int timeout = 234;
while (next != null && collected.size() < maxAmount) {
next = m_notifications.poll(timeout, TimeUnit.MILLISECONDS);
if (next != null) {
collected.add(next);
}
}
} catch (InterruptedException e) {
LOG.info("Interrupted while waiting for client notification messages", e);
}
return collected;
}
use of org.eclipse.scout.rt.shared.clientnotification.ClientNotificationMessage in project scout.rt by eclipse.
the class ClientNotificationRegistry method publishClusterInternal.
/**
* Publish messages to other cluster nodes. Message not foreseen for cluster distributions are filtered.
*/
private void publishClusterInternal(Collection<? extends ClientNotificationMessage> messages) {
Collection<ClientNotificationMessage> filteredMessages = new LinkedList<ClientNotificationMessage>();
for (ClientNotificationMessage message : messages) {
if (message.isDistributeOverCluster()) {
filteredMessages.add(message);
}
}
// do not publish empty messages
if (filteredMessages.isEmpty()) {
return;
}
try {
IClusterSynchronizationService service = BEANS.get(IClusterSynchronizationService.class);
service.publish(new ClientNotificationClusterNotification(filteredMessages));
} catch (RuntimeException e) {
LOG.error("Failed to publish client notification", e);
}
}
Aggregations