use of java.nio.file.WatchService in project j2objc by google.
the class MacOSXPathTest method test_register$WatchService$WatchEvent_Kind_Exception_NPE.
@Test
public void test_register$WatchService$WatchEvent_Kind_Exception_NPE() throws IOException {
WatchService watchService = FileSystems.getDefault().newWatchService();
Path directory = Paths.get(filesSetup.getTestDir(), "directory1");
Files.createDirectories(directory);
// When file is not a directory.
try {
directory.register(null, ENTRY_CREATE);
fail();
} catch (NullPointerException expected) {
}
try {
directory.register(watchService, (Kind<?>) null);
fail();
} catch (NullPointerException expected) {
}
}
use of java.nio.file.WatchService in project j2objc by google.
the class MacOSXPathTest method test_register$WatchService$WatchEvent_Kind$WatchEvent_Modifier_NPE.
@Test
public void test_register$WatchService$WatchEvent_Kind$WatchEvent_Modifier_NPE() throws IOException {
WatchService watchService = FileSystems.getDefault().newWatchService();
WatchEvent.Kind<?>[] events = { ENTRY_CREATE };
Path dirRoot = Paths.get(filesSetup.getTestDir(), "dir");
Files.createDirectories(dirRoot);
try {
WatchKey key = dirRoot.register(null, events, ExtendedWatchEventModifier.FILE_TREE);
fail();
} catch (NullPointerException expected) {
}
try {
WatchKey key = dirRoot.register(watchService, null, ExtendedWatchEventModifier.FILE_TREE);
fail();
} catch (NullPointerException expected) {
}
}
use of java.nio.file.WatchService in project j2objc by google.
the class MacOSXPathTest method test_register$WatchService$WatchEvent_Kind_Exception.
@Test
public void test_register$WatchService$WatchEvent_Kind_Exception() throws IOException {
WatchService watchService = FileSystems.getDefault().newWatchService();
Path directory = Paths.get(filesSetup.getTestDir(), "directory1");
Files.createFile(directory);
// When file is not a directory.
try {
directory.register(watchService, ENTRY_CREATE);
fail();
} catch (NotDirectoryException expected) {
}
// When the events are not supported.
Files.deleteIfExists(directory);
Files.createDirectories(directory);
WatchEvent.Kind<?>[] events = { new NonStandardEvent<>() };
try {
directory.register(watchService, events);
fail();
} catch (UnsupportedOperationException expected) {
}
// When the watch service is closed.
watchService.close();
try {
directory.register(watchService, ENTRY_CREATE);
fail();
} catch (ClosedWatchServiceException expected) {
}
}
use of java.nio.file.WatchService in project dubbo by alibaba.
the class FileSystemDynamicConfiguration method newWatchService.
private static Optional<WatchService> newWatchService() {
Optional<WatchService> watchService = null;
FileSystem fileSystem = FileSystems.getDefault();
try {
watchService = Optional.of(fileSystem.newWatchService());
} catch (IOException e) {
if (logger.isErrorEnabled()) {
logger.error(e.getMessage(), e);
}
watchService = Optional.empty();
}
return watchService;
}
use of java.nio.file.WatchService in project jPOS by jpos.
the class Q2 method run.
public void run() {
started = true;
Thread.currentThread().setName("Q2-" + getInstanceId().toString());
Path dir = Paths.get(deployDir.getAbsolutePath());
FileSystem fs = dir.getFileSystem();
try (WatchService service = fs.newWatchService()) {
watchServiceClassname = service.getClass().getName();
dir.register(service, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_DELETE);
/*
* The following code determines whether a MBeanServer exists
* already. If so then the first one in the list is used.
* I have not yet find a way to interrogate the server for
* information other than MBeans so to pick a specific one
* would be difficult.
*/
ArrayList mbeanServerList = MBeanServerFactory.findMBeanServer(null);
if (mbeanServerList.isEmpty()) {
server = MBeanServerFactory.createMBeanServer(JMX_NAME);
} else {
server = (MBeanServer) mbeanServerList.get(0);
}
final ObjectName loaderName = new ObjectName(Q2_CLASS_LOADER);
try {
loader = (QClassLoader) java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {
public Object run() {
return new QClassLoader(server, libDir, loaderName, mainClassLoader);
}
});
if (server.isRegistered(loaderName))
server.unregisterMBean(loaderName);
server.registerMBean(loader, loaderName);
loader = loader.scan(false);
} catch (Throwable t) {
if (log != null)
log.error("initial-scan", t);
else
t.printStackTrace();
}
factory = new QFactory(loaderName, this);
writePidFile();
initSystemLogger();
if (bundleContext == null)
addShutdownHook();
q2Thread = Thread.currentThread();
q2Thread.setContextClassLoader(loader);
if (cli != null)
cli.start();
initConfigDecorator();
if (startOSGI)
startOSGIFramework();
if (enableSsh) {
deployElement(SshService.createDescriptor(sshPort, sshUser, sshAuthorizedKeys, sshHostKeyFile), "05_sshd-" + getInstanceId() + ".xml", false, true);
}
deployInternal();
for (int i = 1; shutdown.getCount() > 0; i++) {
try {
if (i > 1 && disableDeployScan) {
shutdown.await();
break;
}
boolean forceNewClassLoader = scan() && i > 1;
QClassLoader oldClassLoader = loader;
loader = loader.scan(forceNewClassLoader);
if (loader != oldClassLoader) {
// We want this to be null so it gets GCed.
oldClassLoader = null;
// force a GC
System.gc();
log.info("new classloader [" + Integer.toString(loader.hashCode(), 16) + "] has been created");
q2Thread.setContextClassLoader(loader);
}
logVersion();
deploy();
checkModified();
ready.countDown();
if (!waitForChanges(service))
break;
} catch (InterruptedException | IllegalAccessError ignored) {
// NOPMD
} catch (Throwable t) {
log.error("start", t.getMessage());
relax();
}
}
undeploy();
try {
if (server.isRegistered(loaderName))
server.unregisterMBean(loaderName);
} catch (InstanceNotFoundException e) {
log.error(e);
}
if (decorator != null) {
decorator.uninitialize();
}
if (exit && !shuttingDown)
System.exit(0);
} catch (IllegalAccessError ignored) {
// NOPMD OK to happen
} catch (Exception e) {
if (log != null)
log.error(e);
else
e.printStackTrace();
System.exit(1);
}
}
Aggregations