コード例 #1
0
ファイル: SegmentFileManager.java プロジェクト: imace/zava
 @Override
 public ByteBuffer readPage(File file, long position, ByteBuffer pageBuffer)
     throws IOException, InterruptedException {
   long start = System.currentTimeMillis();
   RandomAccessFile randomAccessFile = randomAccessFile(file);
   try {
     randomAccessFile.seek(position);
     randomAccessFile.readFully(pageBuffer.array(), pageBuffer.arrayOffset(), pageSizeBytes);
     if (Thread.interrupted()) {
       throw new InterruptedException();
     }
     long stop = System.currentTimeMillis();
     if (LOG.isLoggable(Level.FINE)) {
       LOG.log(
           Level.FINE,
           "Read page at {0} of {1}: {2} msec",
           new Object[] {position, file, stop - start});
     }
   } catch (EOFException e) {
     LOG.log(
         Level.SEVERE,
         "Caught EOFException while reading {0}, position {1}",
         new Object[] {file, position});
     LOG.log(Level.SEVERE, "stack", e);
     throw e;
   } finally {
     randomAccessFile.close();
   }
   return pageBuffer;
 }
コード例 #2
0
ファイル: WatchDir.java プロジェクト: juhnowski/sbertech
  /** Обработчик всех событий помещенных в очередь */
  void processEvents() {
    for (; ; ) {

      WatchKey key;
      try {
        key = watcher.take();
      } catch (InterruptedException x) {
        LOG.log(Level.SEVERE, x.getMessage());
        return;
      }

      Path dir = keys.get(key);
      if (dir == null) {
        LOG.log(Level.SEVERE, "Входной каталог не найден!");
        continue;
      }

      for (WatchEvent<?> event : key.pollEvents()) {
        WatchEvent.Kind kind = event.kind();

        // TODO - подумать над обработчиком события OVERFLOW
        if (kind == OVERFLOW) {
          continue;
        }

        WatchEvent<Path> ev = cast(event);
        Path name = ev.context();
        Path child = dir.resolve(name);

        // логируем событие
        if (kind == ENTRY_CREATE) {
          LOG.log(Level.FINEST, "{0}: {1}", new Object[] {event.kind().name(), child});
          Runnable worker = new WorkerThread(child);
          executor.execute(worker);
        }
      }

      boolean valid = key.reset();
      if (!valid) {
        keys.remove(key);
        if (keys.isEmpty()) {
          break;
        }
      }
    }
  }
コード例 #3
0
ファイル: SegmentFileManager.java プロジェクト: imace/zava
 @Override
 public void flush(File file) throws IOException {
   long start = System.currentTimeMillis();
   RandomAccessFile randomAccessFile = randomAccessFile(file);
   try {
     FileChannel channel = randomAccessFile.getChannel();
     channel.force(true);
     if (LOG.isLoggable(Level.FINE)) {
       long stop = System.currentTimeMillis();
       LOG.log(Level.FINE, "Flushed {0}: {1} msec", new Object[] {file, stop - start});
     }
   } finally {
     randomAccessFile.close();
   }
 }
コード例 #4
0
ファイル: SegmentFileManager.java プロジェクト: imace/zava
 @Override
 public void write(File file, long position, ByteBuffer buffer)
     throws IOException, InterruptedException {
   long start = System.currentTimeMillis();
   RandomAccessFile randomAccessFile = randomAccessFile(file);
   try {
     FileChannel channel = randomAccessFile.getChannel();
     channel.position(position);
     channel.write(buffer);
     if (Thread.interrupted()) {
       throw new InterruptedException();
     }
     long stop = System.currentTimeMillis();
     if (LOG.isLoggable(Level.FINE)) {
       LOG.log(
           Level.FINE,
           "Wrote page at {0} of {1}: {2} msec",
           new Object[] {position, file, stop - start});
     }
   } finally {
     randomAccessFile.close();
   }
 }
コード例 #5
0
ファイル: JobTracker.java プロジェクト: bruthe/hadoop-0.1r
 public void run() {
   while (shouldRun) {
     JobInProgress job = null;
     synchronized (jobInitQueue) {
       if (jobInitQueue.size() > 0) {
         job = (JobInProgress) jobInitQueue.elementAt(0);
         jobInitQueue.remove(job);
       } else {
         try {
           jobInitQueue.wait(JOBINIT_SLEEP_INTERVAL);
         } catch (InterruptedException iex) {
         }
       }
     }
     try {
       if (job != null) {
         job.initTasks();
       }
     } catch (Exception e) {
       LOG.log(Level.WARNING, "job init failed", e);
       job.kill();
     }
   }
 }