@Test public void testMonitor() { final Reachability r = new SystemConfigurationReachability(); final Reachability.Monitor monitor = r.monitor(new Host(new TestProtocol(), "cyberduck.ch", 80), new Reachability.Callback() { @Override public void change() { } } ).start(); assertSame(monitor, monitor.stop()); }
@Override public Monitor monitor(final Host bookmark, final Callback callback) { final String url = this.toURL(bookmark); return new Reachability.Monitor() { private final CDReachabilityMonitor monitor = CDReachabilityMonitor.monitorForUrl(url); private final NotificationFilterCallback listener = new NotificationFilterCallback(callback); @Override public Monitor start() { notificationCenter.addObserver(listener.id(), Foundation.selector("notify:"), "kNetworkReachabilityChangedNotification", monitor.id()); monitor.startReachabilityMonitor(); return this; } @Override public Monitor stop() { monitor.stopReachabilityMonitor(); notificationCenter.removeObserver(listener.id()); return this; } }; }
SystemConfigurationReachability implements Reachability { @Override public Monitor monitor(final Host bookmark, final Callback callback) { final String url = this.toURL(bookmark); return new Reachability.Monitor() { private final CDReachabilityMonitor monitor = CDReachabilityMonitor.monitorForUrl(url); private final NotificationFilterCallback listener = new NotificationFilterCallback(callback); @Override public Monitor start() { notificationCenter.addObserver(listener.id(), Foundation.selector("notify:"), "kNetworkReachabilityChangedNotification", monitor.id()); monitor.startReachabilityMonitor(); return this; } @Override public Monitor stop() { monitor.stopReachabilityMonitor(); notificationCenter.removeObserver(listener.id()); return this; } }; } }
SystemConfigurationReachability implements Reachability { @Override public Monitor monitor(final Host bookmark, final Callback callback) { final String url = this.toURL(bookmark); return new Reachability.Monitor() { private final CDReachabilityMonitor monitor = CDReachabilityMonitor.monitorForUrl(url); private final NotificationFilterCallback listener = new NotificationFilterCallback(callback); @Override public Monitor start() { notificationCenter.addObserver(listener.id(), Foundation.selector("notify:"), "kNetworkReachabilityChangedNotification", monitor.id()); monitor.startReachabilityMonitor(); return this; } @Override public Monitor stop() { monitor.stopReachabilityMonitor(); notificationCenter.removeObserver(listener.id()); return this; } }; } SystemConfigurationReachability(); }
SystemConfigurationReachability implements Reachability { @Override public Monitor monitor(final Host bookmark, final Callback callback) { final String url = this.toURL(bookmark); return new Reachability.Monitor() { private final CDReachabilityMonitor monitor = CDReachabilityMonitor.monitorForUrl(url); private final NotificationFilterCallback listener = new NotificationFilterCallback(callback); @Override public Monitor start() { notificationCenter.addObserver(listener.id(), Foundation.selector("notify:"), "kNetworkReachabilityChangedNotification", monitor.id()); monitor.startReachabilityMonitor(); return this; } @Override public Monitor stop() { monitor.stopReachabilityMonitor(); notificationCenter.removeObserver(listener.id()); return this; } }; } SystemConfigurationReachability(); @Override Monitor monitor(final Host bookmark, final Callback callback); @Override boolean isReachable(final Host bookmark); @Override void diagnose(final Host bookmark); }
SystemConfigurationReachability implements Reachability { @Override public Monitor monitor(final Host bookmark, final Callback callback) { final String url = this.toURL(bookmark); return new Reachability.Monitor() { private final CDReachabilityMonitor monitor = CDReachabilityMonitor.monitorForUrl(url); private final NotificationFilterCallback listener = new NotificationFilterCallback(callback); @Override public Monitor start() { notificationCenter.addObserver(listener.id(), Foundation.selector("notify:"), "kNetworkReachabilityChangedNotification", monitor.id()); monitor.startReachabilityMonitor(); return this; } @Override public Monitor stop() { monitor.stopReachabilityMonitor(); notificationCenter.removeObserver(listener.id()); return this; } }; } SystemConfigurationReachability(); @Override Monitor monitor(final Host bookmark, final Callback callback); @Override boolean isReachable(final Host bookmark); @Override void diagnose(final Host bookmark);  }