use of java.util.function.Consumer in project kylo by Teradata.
the class JcrFeedProvider method addPostFeedChangeAction.
/**
* Registers an action that produces a feed change event upon a successful transaction commit.
*
* @param feed the feed to being created
*/
private void addPostFeedChangeAction(Feed feed, ChangeType changeType) {
Feed.State state = feed.getState();
Feed.ID id = feed.getId();
String feedName = feed.getQualifiedName();
final Principal principal = SecurityContextHolder.getContext().getAuthentication();
Consumer<Boolean> action = (success) -> {
if (success) {
FeedChange change = new FeedChange(changeType, feedName, feedName, id, state);
FeedChangeEvent event = new FeedChangeEvent(change, DateTime.now(), principal);
metadataEventService.notify(event);
}
};
JcrMetadataAccess.addPostTransactionAction(action);
}
use of java.util.function.Consumer in project felix by apache.
the class FELIX3057_EmptyServiceReferenceArray method testWithoutIndex.
@SuppressWarnings("unchecked")
public void testWithoutIndex() throws Exception {
// backup currently configured filter index
BundleContext context = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
m_systemConf = context.getProperty(DependencyManager.SERVICEREGISTRY_CACHE_INDICES);
// Reset filter indices
Consumer<String> reset = (Consumer<String>) System.getProperties().get("org.apache.felix.dependencymanager.filterindex.reset");
// clear filter index
reset.accept(null);
// no filter index used
executeTest(context);
// reset filer index configured in our bnd.bnd
reset.accept(m_systemConf);
}
use of java.util.function.Consumer in project openremote by openremote.
the class KNXConnection method connect.
public synchronized void connect() {
if (connectionStatus == ConnectionStatus.CONNECTED || connectionStatus == ConnectionStatus.CONNECTING) {
LOG.finest("Already connected or connection in progress");
return;
}
onConnectionStatusChanged(ConnectionStatus.CONNECTING);
InetSocketAddress localEndPoint;
InetSocketAddress remoteEndPoint = new InetSocketAddress(this.gatewayIp, this.remotePort);
try {
TPSettings tpSettings = new TPSettings(new IndividualAddress(this.localKNXAddress));
if (StringUtils.isNotBlank(this.localIp)) {
localEndPoint = new InetSocketAddress(this.localIp, 0);
} else {
InetAddress localHost = InetAddress.getLocalHost();
localEndPoint = new InetSocketAddress(localHost, 0);
}
if (this.connectionType.equals("TUNNELLING")) {
knxLink = KNXNetworkLinkIP.newTunnelingLink(localEndPoint, remoteEndPoint, this.useNat, tpSettings);
} else {
knxLink = KNXNetworkLinkIP.newRoutingLink(localEndPoint.getAddress(), remoteEndPoint.getAddress(), tpSettings);
}
if (knxLink.isOpen()) {
LOG.fine("Successfully connected to: " + gatewayIp + ":" + port);
processCommunicator = new ProcessCommunicatorImpl(knxLink);
processCommunicator.addProcessListener(this);
knxLink.addLinkListener(this);
reconnectTask = null;
reconnectDelayMilliseconds = INITIAL_RECONNECT_DELAY_MILLIS;
onConnectionStatusChanged(ConnectionStatus.CONNECTED);
// Get the values of all registered group addresses
LOG.fine("Initialising group address values");
synchronized (groupAddressConsumerMap) {
groupAddressConsumerMap.forEach((groupAddress, datapointConsumerList) -> {
if (!datapointConsumerList.isEmpty()) {
// Take first data point for the group address and request the value
Pair<StateDP, Consumer<Value>> datapointConsumer = datapointConsumerList.get(0);
getGroupAddressValue(datapointConsumer.key.getMainAddress(), datapointConsumer.key.getPriority());
}
});
}
} else {
LOG.log(Level.INFO, "Connection error");
// Failed to connect so schedule reconnection attempt
scheduleReconnect();
}
} catch (final KNXException | InterruptedException e) {
LOG.log(Level.INFO, "Connection error", e.getMessage());
scheduleReconnect();
} catch (final UnknownHostException e) {
LOG.log(Level.INFO, "Connection error", e.getMessage());
}
}
use of java.util.function.Consumer in project openremote by openremote.
the class UsersFacade method query.
@Override
public Users.RestrictedQuery query() {
Users.RestrictedQuery query = new Users.RestrictedQuery() {
@Override
public Users.RestrictedQuery tenant(UserQuery.TenantPredicate tenantPredicate) {
if (GlobalRuleset.class.isAssignableFrom(rulesEngineId.getScope()))
return super.tenant(tenantPredicate);
throw new IllegalArgumentException("Overriding query restriction is not allowed in this rules scope");
}
@Override
public Users.RestrictedQuery asset(UserQuery.AssetPredicate assetPredicate) {
if (GlobalRuleset.class.isAssignableFrom(rulesEngineId.getScope()))
return super.asset(assetPredicate);
if (TenantRuleset.class.isAssignableFrom(rulesEngineId.getScope())) {
return super.asset(assetPredicate);
// TODO: should only be allowed if asset belongs to tenant
}
if (AssetRuleset.class.isAssignableFrom(rulesEngineId.getScope())) {
return super.asset(assetPredicate);
// TODO: should only be allowed if restricted asset is descendant of scope's asset
}
throw new IllegalArgumentException("Overriding query restriction is not allowed in this rules scope");
}
@Override
public List<String> getResults() {
return notificationService.findAllUsersWithToken(this);
}
@Override
public void applyResults(Consumer<List<String>> usersIdListConsumer) {
usersIdListConsumer.accept(getResults());
}
};
if (TenantRuleset.class.isAssignableFrom(rulesEngineId.getScope())) {
query.tenantPredicate = new UserQuery.TenantPredicate(rulesEngineId.getRealmId().orElseThrow(() -> new IllegalArgumentException("Realm ID missing: " + rulesEngineId)));
}
if (AssetRuleset.class.isAssignableFrom(rulesEngineId.getScope())) {
String assetId = rulesEngineId.getAssetId().orElseThrow(() -> new IllegalStateException("Asset ID missing: " + rulesEngineId));
ServerAsset restrictedAsset = assetStorageService.find(assetId, true);
if (restrictedAsset == null) {
// deployment is removed and the problem resolved.
throw new IllegalStateException("Asset is no longer available: " + rulesEngineId);
}
query.assetPredicate = new UserQuery.AssetPredicate(assetId);
}
return query;
}
use of java.util.function.Consumer in project nifi by apache.
the class AsyncRequestManager method submitRequest.
@Override
public void submitRequest(final String type, final String requestId, final AsynchronousWebRequest<T> request, final Consumer<AsynchronousWebRequest<T>> task) {
Objects.requireNonNull(type);
Objects.requireNonNull(requestId);
Objects.requireNonNull(request);
Objects.requireNonNull(task);
// before adding to the request map, purge any old requests. Must do this by creating a List of ID's
// and then removing those ID's one-at-a-time in order to avoid ConcurrentModificationException.
final Date oneMinuteAgo = new Date(System.currentTimeMillis() - requestExpirationMillis);
final List<String> completedRequestIds = requests.entrySet().stream().filter(entry -> entry.getValue().isComplete()).filter(entry -> entry.getValue().getLastUpdated().before(oneMinuteAgo)).map(Map.Entry::getKey).collect(Collectors.toList());
completedRequestIds.stream().forEach(id -> requests.remove(id));
final int requestCount = requests.size();
if (requestCount > maxConcurrentRequests) {
throw new IllegalStateException("There are already " + requestCount + " update requests for variable registries. " + "Cannot issue any more requests until the older ones are deleted or expire");
}
final String key = getKey(type, requestId);
final AsynchronousWebRequest<T> existing = this.requests.putIfAbsent(key, request);
if (existing != null) {
throw new IllegalArgumentException("A requests already exists with this ID and type");
}
threadPool.submit(new Runnable() {
@Override
public void run() {
try {
task.accept(request);
} catch (final Exception e) {
logger.error("Failed to perform asynchronous task", e);
request.setFailureReason("Encountered unexpected error when performing asynchronous task: " + e);
}
}
});
}
Aggregations