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

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


      // FileDescriptor.fd field accessible.
      try {
        final Field field = FileDescriptor.class.getDeclaredField("fd");
        field.setAccessible(true);
        // Try to dynamically load the JNA impl of the CLibrary interface..
        final CLibrary lib = getCLibrary();
        return new SyncStrategy() {
          static final int F_FULLFSYNC = 51
          public void sync(FileDescriptor fd) throws IOException {
            try {
              int id = field.getInt(fd);
              lib.fcntl(id, F_FULLFSYNC);
            } catch (Exception e) {
              throw IOExceptionSupport.create(e);
            }
          }

                    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);
                        }
                    }
                };
      } 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.
      }
    } 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


            } 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 CLibrary getCLibrary() throws ClassNotFoundException, IllegalAccessException, NoSuchFieldException {
    Class clazz = IOHelper.class.getClassLoader().loadClass("org.apache.activemq.apollo..util.os.JnaCLibrary");
    final CLibrary lib = (CLibrary) clazz.getField("INSTANCE").get(null);
    return lib;
  }
View Full Code Here

      // FileDescriptor.fd field accessible.
      try {
        final Field field = FileDescriptor.class.getDeclaredField("fd");
        field.setAccessible(true);
        // Try to dynamically load the JNA impl of the CLibrary interface..
        final CLibrary lib = getCLibrary();
        return new IOStrategy() {
          static final int F_FULLFSYNC = 51
          public void sync(FileDescriptor fd) throws IOException {
            try {
              int id = field.getInt(fd);
              lib.fcntl(id, F_FULLFSYNC);
            } catch (Exception e) {
              throw IOExceptionSupport.create(e);
            }
          }
        };
View Full Code Here

  }

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

TOP

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

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.