Package org.apache.activemq.apollo.util.os

Examples of org.apache.activemq.apollo.util.os.Kernel32Library


    } else if( os.toLowerCase().startsWith("windows") ) {
            // We will gracefully fall back to default JDK file sync behavior
            // if the JNA library is not in the path, and we can't set the
            // FileDescriptor.fd field accessible.
            try {
                final Kernel32Library lib = getKernel32Library();
                return new SyncStrategy() {
                    public void sync(FileDescriptor fd) throws IOException {
                        fd.sync();
                    }
                    public void hardlink(File source, File target) throws IOException {
                        int rc = lib.CreateHardLink(target.getCanonicalPath(), source.getCanonicalPath(), 0);
                        if( rc == 0 ){
                            throw new IOException("Hard link failed with result code="+lib.GetLastError());
                        }
                    }
                };
            } catch (Throwable ignore) {
                // Perhaps we should issue a warning here so folks know that
                // the disk syncs are not going to be of very good quality.
            }
        }


        // We will gracefully fall back to default JDK file sync behavior
        // if the JNA library is not in the path, and we can't set the
        // FileDescriptor.fd field accessible.
        try {
            final CLibrary lib = getCLibrary();
            return new SyncStrategy() {
                public void sync(FileDescriptor fd) throws IOException {
                    fd.sync();
                }

                public void hardlink(File source, File target) throws IOException {
                    int rc = lib.link(source.getCanonicalPath(), target.getCanonicalPath());
                    if( rc != 0 ){
                        throw new IOException("Hard link failed with result code="+rc);
                    }
                }
            };
View Full Code Here


    private static HardLinkStrategy createHardLinkStrategy() {

        String os = System.getProperty("os.name");
        if( os.toLowerCase().startsWith("windows") ) {
            try {
                final Kernel32Library lib = getKernel32Library();
                return new HardLinkStrategy() {
                    public void hardlink(File source, File target) throws IOException {
                        int rc = lib.CreateHardLink(target.getCanonicalPath(), source.getCanonicalPath(), 0);
                        if( rc == 0 ){
                            throw new IOException("Hard link failed with result code="+lib.GetLastError());
                        }
                    }
                };
            } catch (Throwable ignore) {
            }
        }

        try {
            final CLibrary lib = getCLibrary();
            return new HardLinkStrategy() {
                public void hardlink(File source, File target) throws IOException {
                    int rc = lib.link(source.getCanonicalPath(), target.getCanonicalPath());
                    if( rc != 0 ){
                        throw new IOException("Hard link failed with result code="+rc);
                    }
                }
            };
View Full Code Here

  }

    @SuppressWarnings("unchecked")
    public static Kernel32Library getKernel32Library() throws ClassNotFoundException, IllegalAccessException, NoSuchFieldException {
        Class clazz = IOHelper.class.getClassLoader().loadClass("org.apache.activemq.apollo.util.os.Kernel32JnaLibrary");
        final Kernel32Library lib = (Kernel32Library) clazz.getField("INSTANCE").get(null);
        return lib;
    }
View Full Code Here

TOP

Related Classes of org.apache.activemq.apollo.util.os.Kernel32Library

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.