Package org.hyperic.sigar

Examples of org.hyperic.sigar.FileWatcherThread


    public static void main(String[] args) throws SigarException {
        boolean recurse = false;
        Sigar sigar = new Sigar();

        FileWatcherThread watcherThread =
            FileWatcherThread.getInstance();

        watcherThread.setInterval(1000);

        FileWatcher watcher =
            new FileWatcher(sigar) {
                public void onChange(FileInfo info) {
                    System.out.println(info.getName() +
                                       " Changed:\n" +
                                       info.diff());
                }

                public void onNotFound(FileInfo info) {
                    System.out.println(info.getName() + " no longer exists");
                    remove(info.getName());
                }

                public void onException(FileInfo info, SigarException e) {
                    System.out.println("Error checking " + info.getName() + ":");
                    e.printStackTrace();
                }
            };

        ProcFileMirror mirror =
            new ProcFileMirror(sigar, "./proc");

        watcher.setInterval(watcherThread.getInterval());
        mirror.setInterval(watcherThread.getInterval());
        mirror.setExpire(60);

        for (int i=0; i<args.length; i++) {
            String arg = args[i];
            if (arg.startsWith("/proc/")) {
                mirror.add(arg);

                arg = mirror.getProcFile(arg);
                add(sigar, watcher, arg, false);
            }
            else if (arg.equals("-r")) {
                recurse = true;
            }
            else {
                add(sigar, watcher, arg, recurse);
            }
        }

        watcherThread.add(mirror);
        watcherThread.add(watcher);

        watcherThread.doStart();

        System.out.println("Press any key to stop");
        try {
            System.in.read();
        } catch (IOException e) { }

        watcherThread.doStop();
    }
View Full Code Here


    }

    public static void main(String[] args) throws SigarException {
        Sigar sigar = new Sigar();

        FileWatcherThread watcherThread =
            FileWatcherThread.getInstance();

        watcherThread.doStart();

        watcherThread.setInterval(1000);

        FileTail watcher =
            new FileTail(sigar) {
                public void tail(FileInfo info, Reader reader) {
                    String line;
                    BufferedReader buffer =
                        new BufferedReader(reader);

                    if (getFiles().size() > 1) {
                        System.out.println("==> " +
                                           info.getName() +
                                           " <==");
                    }

                    try {
                        while ((line = buffer.readLine()) != null) {
                            System.out.println(line);
                        }
                    } catch (IOException e) {
                        System.out.println(e);                   
                    }
                }
            };

        for (int i=0; i<args.length; i++) {
            watcher.add(args[i]);
        }

        watcherThread.add(watcher);

        try {
            System.in.read();
        } catch (IOException e) { }

        watcherThread.doStop();
    }
View Full Code Here

    public static void main(String[] args) throws SigarException {
        boolean recurse = false;
        Sigar sigar = new Sigar();

        FileWatcherThread watcherThread =
            FileWatcherThread.getInstance();

        watcherThread.setInterval(1000);

        FileWatcher watcher =
            new FileWatcher(sigar) {
                public void onChange(FileInfo info) {
                    System.out.println(info.getName() +
                                       " Changed:\n" +
                                       info.diff());
                }

                public void onNotFound(FileInfo info) {
                    System.out.println(info.getName() + " no longer exists");
                    remove(info.getName());
                }

                public void onException(FileInfo info, SigarException e) {
                    System.out.println("Error checking " + info.getName() + ":");
                    e.printStackTrace();
                }
            };

        ProcFileMirror mirror =
            new ProcFileMirror(sigar, "./proc");

        watcher.setInterval(watcherThread.getInterval());
        mirror.setInterval(watcherThread.getInterval());
        mirror.setExpire(60);

        for (int i=0; i<args.length; i++) {
            String arg = args[i];
            if (arg.startsWith("/proc/")) {
                mirror.add(arg);

                arg = mirror.getProcFile(arg);
                add(sigar, watcher, arg, false);
            }
            else if (arg.equals("-r")) {
                recurse = true;
            }
            else {
                add(sigar, watcher, arg, recurse);
            }
        }

        watcherThread.add(mirror);
        watcherThread.add(watcher);

        watcherThread.doStart();

        System.out.println("Press any key to stop");
        try {
            System.in.read();
        } catch (IOException e) { }

        watcherThread.doStop();
    }
View Full Code Here

    }

    public static void main(String[] args) throws SigarException {
        Sigar sigar = new Sigar();

        FileWatcherThread watcherThread =
            FileWatcherThread.getInstance();

        watcherThread.doStart();

        watcherThread.setInterval(1000);

        FileTail watcher =
            new FileTail(sigar) {
                public void tail(FileInfo info, Reader reader) {
                    String line;
                    BufferedReader buffer =
                        new BufferedReader(reader);

                    if (getFiles().size() > 1) {
                        System.out.println("==> " +
                                           info.getName() +
                                           " <==");
                    }

                    try {
                        while ((line = buffer.readLine()) != null) {
                            System.out.println(line);
                        }
                    } catch (IOException e) {
                        System.out.println(e);                   
                    }
                }
            };

        for (int i=0; i<args.length; i++) {
            watcher.add(args[i]);
        }

        watcherThread.add(watcher);

        try {
            System.in.read();
        } catch (IOException e) { }

        watcherThread.doStop();
    }
View Full Code Here

TOP

Related Classes of org.hyperic.sigar.FileWatcherThread

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.