org.imca_cat.pollingwatchservice.EventingWatchService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of concourse-driver-java Show documentation
Show all versions of concourse-driver-java Show documentation
Concourse is a self-tuning database that is designed for both ad hoc analytics and high volume transactions at scale. Developers use Concourse to quickly build mission critical software while also benefiting from real time insight into their most important data. With Concourse, end-to-end data management requires no extra infrastructure, no prior configuration and no additional coding–all of which greatly reduce costs and allow developers to focus on core business problems.
/*
* Copyright (c) 2013-2019 Cinchapi Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.imca_cat.pollingwatchservice;
import java.io.IOException;
import java.nio.file.ClosedWatchServiceException;
import java.nio.file.Path;
import java.nio.file.WatchEvent.Kind;
import java.nio.file.WatchEvent.Modifier;
import java.nio.file.WatchKey;
import java.nio.file.WatchService;
import java.util.concurrent.TimeUnit;
/**
* An Adapter that
* adapts the {@code WatchService} interface to a {@link PathWatchService}.
* Since the idea of a {@code WatchService} for a {@code FileSystem} is that it
* maps onto the native event notification facility where available, this class
* is considered to be an "eventing" implementation of the
* {@code PathWatchService} interface.
*
* Example:
*
*
* FileSystem fs = FileSystems.getDefault();
* PathWatchService s = new EventingWatchService(fs.newWatchService());
* s.register(fs.getPath("/home/luke"),
* StandardWatchEventKinds.ENTRY_CREATE,
* StandardWatchEventKinds.ENTRY_DELETE,
* StandardWatchEventKinds.ENTRY_MODIFY);
* s.start();
* for (;;) {
* WatchKey k = s.take();
* ...
* }
*
*/
public class EventingWatchService implements PathWatchService {
private final WatchService service;
/**
* Constructs an instance on the specified watch service.
*
* @param service the watch service to be adapted
*/
public EventingWatchService(WatchService service) {
super();
this.service = service;
}
@Override
public void start() {
/* IGNORED */
}
/**
* @throws ClosedWatchServiceException {@inheritDoc}
*/
@Override
public WatchKey register(Path dir, Kind>... kinds) throws IOException {
return dir.register(service, kinds);
}
/**
* @throws ClosedWatchServiceException {@inheritDoc}
*/
@Override
public WatchKey register(Path dir, Kind>[] kinds, Modifier... modifiers)
throws IOException {
return dir.register(service, kinds, modifiers);
}
@Override
public void close() throws IOException {
service.close();
}
/**
* @throws ClosedWatchServiceException {@inheritDoc}
*/
@Override
public WatchKey poll() {
return service.poll();
}
/**
* @throws ClosedWatchServiceException {@inheritDoc}
*/
@Override
public WatchKey poll(long timeout, TimeUnit unit)
throws InterruptedException {
return service.poll(timeout, unit);
}
/**
* @throws ClosedWatchServiceException {@inheritDoc}
*/
@Override
public WatchKey take() throws InterruptedException {
return service.take();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy