/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Base implementation of background poller thread used in watch service
* implementations. A poller thread waits on events from the file system and
* also services "requests" from clients to register for new events or cancel
* existing registrations.
*/
// list of requests pending to the poller thread
// set to true when shutdown
private boolean shutdown;
protected AbstractPoller() {
this.shutdown = false;
}
/**
* Starts the poller thread
*/
public void start() {
final Runnable thisRunnable = this;
return null;
}
});
}
/**
* Wakeup poller thread so that it can service pending requests
*/
/**
* Executed by poller thread to register directory for changes
*/
/**
* Executed by poller thread to cancel key
*/
/**
* Executed by poller thread to shutdown and cancel all keys
*/
abstract void implCloseAll();
/**
* Requests, and waits on, poller thread to register given file.
*/
throws IOException
{
// validate arguments before request to poller
throw new NullPointerException();
throw new IllegalArgumentException("No events to register");
// standard events
{
continue;
}
// OVERFLOW is ignored
throw new IllegalArgumentException("No events to register");
continue;
}
// null/unsupported
throw new NullPointerException("An element in event set is 'null'");
}
}
/**
* Cancels, and waits on, poller thread to cancel given key.
*/
try {
} catch (IOException x) {
// should not happen
throw new AssertionError(x.getMessage());
}
}
/**
* Shutdown poller thread
*/
}
/**
* Types of request that the poller thread must handle
*/
private static enum RequestType {
}
/**
* Encapsulates a request (command) to the poller thread.
*/
private static class Request {
private boolean completed = false;
}
return type;
}
return params;
}
synchronized (this) {
this.completed = true;
notifyAll();
}
}
/**
* Await completion of the request. The return value is the result of
* the request.
*/
synchronized (this) {
while (!completed) {
try {
wait();
} catch (InterruptedException x) {
// ignore
}
}
return result;
}
}
}
/**
* Enqueues request to poller thread and waits for result
*/
// submit request
synchronized (requestList) {
if (shutdown) {
throw new ClosedWatchServiceException();
}
}
// wakeup thread
wakeup();
// wait for result
if (result instanceof RuntimeException)
throw (RuntimeException)result;
if (result instanceof IOException )
throw (IOException)result;
return result;
}
/**
* Invoked by poller thread to process all pending requests
*
* @return true if poller thread should shutdown
*/
@SuppressWarnings("unchecked")
boolean processRequests() {
synchronized (requestList) {
// if in process of shutdown then reject request
if (shutdown) {
}
/**
* Register directory
*/
case REGISTER: {
break;
}
/**
* Cancel existing key
*/
case CANCEL : {
break;
}
/**
* Close watch service
*/
case CLOSE: {
implCloseAll();
shutdown = true;
break;
}
default:
}
}
}
return shutdown;
}
}