private void publishNotification(Notification notification) { final ListenableFuture<? extends Object> offerNotification = notificationPublishService.offerNotification(notification); if (NotificationPublishService.REJECTED.equals(offerNotification)) { LOG.debug("notification offer rejected"); return; } Futures.addCallback(offerNotification, new FutureCallback<Object>() { @Override public void onSuccess(final Object result) { } @Override public void onFailure(final Throwable t) { LOG.debug("notification offer failed: {}", t.getMessage()); LOG.trace("notification offer failed..", t); } }); }
/** * {@inheritDoc} */ @Override public void publish(final Notification n) { try { ListenableFuture<? extends Object> f = publishService. offerNotification(n, PUBLISH_TIMEOUT, TimeUnit.SECONDS); Futures.addCallback(f, new FutureCallback<Object>() { @Override public void onSuccess(Object result) { } @Override public void onFailure(Throwable cause) { LOG.error("Failed to publish notification: " + n, cause); } }); } catch (InterruptedException e) { LOG.error("Interrupted while sending notification: " + n, e); } }
@Override public void run() { int ntfOk = 0; int ntfError = 0; ListenableFuture<? extends Object> lastOkFuture = null; for (int i = 0; i < this.iterations; i++) { try { final ListenableFuture<? extends Object> result = this.publishService.offerNotification(this.ntf); if (NotificationPublishService.REJECTED == result) { ntfError++; } else { ntfOk++; lastOkFuture = result; } } catch (final Exception e) { ntfError++; } } this.ntfOk = ntfOk; this.ntfError = ntfError; // We wait for last notification to be delivered to listeners. if (lastOkFuture != null) { try { lastOkFuture.get(); } catch (InterruptedException | ExecutionException e) { throw Throwables.propagate(e); } } }
@Override public void run() { int ntfOk = 0; int ntfError = 0; ListenableFuture<? extends Object> lastOkFuture = null; for (int i = 0; i < this.iterations; i++) { try { final ListenableFuture<? extends Object> result = this.publishService.offerNotification(this.ntf); if (NotificationPublishService.REJECTED == result) { ntfError++; } else { ntfOk++; lastOkFuture = result; } } catch (final Exception e) { ntfError++; } } this.ntfOk = ntfOk; this.ntfError = ntfError; // We wait for last notification to be delivered to listeners. if (lastOkFuture != null) { try { lastOkFuture.get(); } catch (InterruptedException | ExecutionException e) { throw Throwables.propagate(e); } } }
private void sendNotification(OfHeader message, String messageClass) { TranslatorKey key = new TranslatorKey(message.getVersion(), messageClass); if (messageTranslators.containsKey(key)) { for (IMDMessageTranslator<OfHeader, List<DataObject>> translator : messageTranslators.get(key)) { List<DataObject> list = translator.translate(null, sc, message); for (DataObject dataObj : list) { notificationProviderService.offerNotification((Notification) dataObj); } } } }
@Override public void onDeviceContextClosed(final DeviceContext deviceContext) { deviceContexts.remove(deviceContext); DeviceDisconnectedBuilder builder = new DeviceDisconnectedBuilder(); builder.setNodeId(deviceContext.getConnectionContext().getNodeId()); final ListenableFuture<? extends Object> offerNotification = notificationPublishService.offerNotification(builder.build()); if (NotificationPublishService.REJECTED.equals(offerNotification)) { LOG.debug("notification offer rejected"); return; } Futures.addCallback(offerNotification, new FutureCallback<Object>() { @Override public void onSuccess(final Object result) { LOG.trace("notification offer success..", result); } @Override public void onFailure(final Throwable t) { LOG.debug("notification offer failed: {}", t.getMessage()); LOG.trace("notification offer failed..", t); } }); }
/** * RestConf RPC call implemented from the ToasterService interface. * Restocks the bread for the toaster, resets the toastsMade counter to 0, and sends a * ToasterRestocked notification. */ @Override public Future<RpcResult<java.lang.Void>> restockToaster(final RestockToasterInput input) { LOG.info( "restockToaster: " + input ); amountOfBreadInStock.set( input.getAmountOfBreadToStock() ); if( amountOfBreadInStock.get() > 0 ) { ToasterRestocked reStockedNotification = new ToasterRestockedBuilder() .setAmountOfBread( input.getAmountOfBreadToStock() ).build(); notificationProvider.offerNotification( reStockedNotification ); } return Futures.immediateFuture( RpcResultBuilder.<Void> success().build() ); }
@Override public Void call() { try { // make toast just sleeps for n seconds per doneness level. long darknessFactor = OpendaylightToaster.this.darknessFactor.get(); Thread.sleep(darknessFactor * toastRequest.getToasterDoneness()); } catch( InterruptedException e ) { LOG.info( "Interrupted while making the toast" ); } toastsMade.incrementAndGet(); amountOfBreadInStock.getAndDecrement(); if( outOfBread() ) { LOG.info( "Toaster is out of bread!" ); notificationProvider.offerNotification( new ToasterOutOfBreadBuilder().build() ); } // Set the Toaster status back to up - this essentially releases the toasting lock. // We can't clear the current toast task nor set the Future result until the // update has been committed so we pass a callback to be notified on completion. setToasterStatusUp( result -> { currentMakeToastTask.set( null ); LOG.debug("Toast done"); futureResult.set( RpcResultBuilder.<Void>success().build() ); return null; } ); return null; } }
@Override public void onSwitchDisconnected(ConnectionAdapter connectionAdapter) { BigInteger datapathId = connectionRegistry.getDatapathID(connectionAdapter); InstanceIdentifier<Node> identifier = identifierFromDatapathId(datapathId); NodeRef nodeRef = new NodeRef(identifier); NodeRemoved nodeRemoved = nodeRemoved(nodeRef); notificationProviderService.offerNotification(nodeRemoved); connectionRegistry.removeConnectionAdapter(connectionAdapter); }
private void publishNotification(final Long monitorId, final LivenessState state) { LOG.debug("Sending notification for id {} - state {}", monitorId, state); EventData data = new EventDataBuilder().setMonitorId(monitorId) .setMonitorState(state).build(); MonitorEvent event = new MonitorEventBuilder().setEventData(data).build();; final ListenableFuture<? extends Object> eventFuture = notificationPublishService.offerNotification(event); Futures.addCallback(eventFuture, new FutureCallback<Object>() { @Override public void onFailure(Throwable error) { LOG.warn("Error in notifying listeners for id {} - state {}", monitorId, state, error); } @Override public void onSuccess(Object arg) { LOG.trace("Successful in notifying listeners for id {} - state {}", monitorId, state); } }); }
void publishAddNotification(final BigInteger dpnId, final String vpnName, final String rd) { LOG.debug("Sending notification for add dpn {} in vpn {} event ", dpnId, vpnName); AddEventData data = new AddEventDataBuilder().setVpnName(vpnName).setRd(rd).setDpnId(dpnId).build(); AddDpnEvent event = new AddDpnEventBuilder().setAddEventData(data).build(); final ListenableFuture<? extends Object> eventFuture = notificationPublishService.offerNotification(event); Futures.addCallback(eventFuture, new FutureCallback<Object>() { @Override public void onFailure(Throwable error) { LOG.warn("Error in notifying listeners for add dpn {} in vpn {} event ", dpnId, vpnName, error); } @Override public void onSuccess(Object arg) { LOG.trace("Successful in notifying listeners for add dpn {} in vpn {} event ", dpnId, vpnName); } }); }
void publishRemoveNotification(final BigInteger dpnId, final String vpnName, final String rd) { LOG.debug("Sending notification for remove dpn {} in vpn {} event ", dpnId, vpnName); RemoveEventData data = new RemoveEventDataBuilder().setVpnName(vpnName).setRd(rd).setDpnId(dpnId).build(); RemoveDpnEvent event = new RemoveDpnEventBuilder().setRemoveEventData(data).build(); final ListenableFuture<? extends Object> eventFuture = notificationPublishService.offerNotification(event); Futures.addCallback(eventFuture, new FutureCallback<Object>() { @Override public void onFailure(Throwable error) { LOG.warn("Error in notifying listeners for remove dpn {} in vpn {} event ", dpnId, vpnName, error); } @Override public void onSuccess(Object arg) { LOG.trace("Successful in notifying listeners for remove dpn {} in vpn {} event ", dpnId, vpnName); } }); }
@Override public void onSuccess(RpcResult<GetFeaturesOutput> rpcFeatures) { if (rpcFeatures.isSuccessful()) { GetFeaturesOutput featureOutput = rpcFeatures.getResult(); // Register Switch connection/DatapathId to registry connectionRegistry.registerConnectionAdapter(connectionAdapter, featureOutput); NodeUpdated nodeUpdated = nodeAdded(connectionAdapter); notificationProviderService.offerNotification(nodeUpdated); } else { // Handshake failed for (RpcError rpcError : rpcFeatures.getErrors()) { LOG.info("handshake - features failure [{}]: i:{} | m:{} | s:{}", rpcError.getInfo(), rpcError.getMessage(), rpcError.getSeverity(), rpcError.getCause()); } } }
builder.setReIpAddr(new Ipv4Address(connectionContext.getConnectionAdapter().getRemoteAddress().getAddress().toString().replace("/", ""))); final ListenableFuture<? extends Object> offerNotification = notificationPublishService.offerNotification(builder.build()); if (NotificationPublishService.REJECTED.equals(offerNotification)) { LOG.debug("notification offer rejected");
InterVpnLinkCreationError notif = new InterVpnLinkCreationErrorBuilder().setInterVpnLinkCreationErrorMessage(errMsg).build(); final ListenableFuture<? extends Object> eventFuture = this.notificationsService.offerNotification(notif); Futures.addCallback(eventFuture, new FutureCallback<Object>() { @Override