Package java.nio.channels

Examples of java.nio.channels.FileChannel.lock()


        FileChannel channel = null;
        FileLock lock = null;
        try
        {
            channel = new RandomAccessFile( f, "rw" ).getChannel();
            lock = channel.lock();

            mojo.execute();

            assertTrue( true );
        }
View Full Code Here


                        case LOCK_EX:
                            if (currentLock != null) {
                                currentLock.release();
                                currentLock = null;
                            }
                            currentLock = fileChannel.lock();
                            if (currentLock != null) {
                                return RubyFixnum.zero(context.getRuntime());
                            }

                            break;
View Full Code Here

                            if (currentLock != null) {
                                currentLock.release();
                                currentLock = null;
                            }

                            currentLock = fileChannel.lock(0L, Long.MAX_VALUE, true);
                            if (currentLock != null) {
                                return RubyFixnum.zero(context.getRuntime());
                            }

                            break;
View Full Code Here

                }

                // get the lock using either try lock or not depending on if we are using timeout or not
                FileLock lock = null;
                try {
                    lock = timeout > 0 ? channel.tryLock() : channel.lock();
                } catch (IllegalStateException ex) {
                    // Also catch the OverlappingFileLockException here. Do nothing here                   
                }
                if (lock != null) {
                    if (LOG.isTraceEnabled()) {
View Full Code Here

      LOCK_FILES_DIR.mkdirs();
      try {
        RandomAccessFile raf = new RandomAccessFile(GLOBAL_LOCK_FILE,
            "rw");
        FileChannel channel = raf.getChannel();
        FileLock lock = channel.lock();
        globalFileChannel = channel;
        globalFileLock = lock;
        break;
      } catch (Throwable t) {
        ;
View Full Code Here

                    }
                }

                // get the lock using either try lock or not depending on if we are using timeout or not
                try {
                    lock = timeout > 0 ? channel.tryLock() : channel.lock();
                } catch (IllegalStateException ex) {
                    // Also catch the OverlappingFileLockException here. Do nothing here                   
                }
                if (lock != null) {
                    if (LOG.isTraceEnabled()) {
View Full Code Here

        f.createNewFile();
        RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "r");
        FileChannel fcr = raf.getChannel();

        try {
            fcr.lock(0L, Long.MAX_VALUE, false);
            fail("NonWritableChannelException expected!");
        } catch (NonWritableChannelException e) {}
        raf.close();
    }
View Full Code Here

    private synchronized void writeToFile(String action) {
        Date date = new Date();
        try {
            FileOutputStream out = new FileOutputStream(logFile, true);
            FileChannel channel = out.getChannel();
            FileLock lock = channel.lock(0, Long.MAX_VALUE, false);
            PrintWriter writer = new PrintWriter(out, false);
            writer.println(DATE_FORMAT.format(date)+" - "+action+" - "+username);
            writer.flush();
            writer.close();
            if(lock.isValid()) {
View Full Code Here

    private synchronized void writeToFile(String action) {
        Date date = new Date();
        try {
            FileOutputStream out = new FileOutputStream(logFile, true);
            FileChannel channel = out.getChannel();
            FileLock lock = channel.lock(0, Long.MAX_VALUE, false);
            PrintWriter writer = new PrintWriter(out, false);
            writer.println(DATE_FORMAT.format(date)+" - "+action+" - "+username);
            writer.flush();
            writer.close();
            if(lock.isValid()) {
View Full Code Here

    if (fileChannel == null) {
      return;
    }
    FileLock fileLock = null;
    try {
      fileLock = fileChannel.lock();
      long position = fileChannel.position();
      long size = fileChannel.size();
      if (size != position) {
        fileChannel.position(size);
      }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.