コード例 #1
0
  /**
   * Create a PerfDataBuffer instance for accessing the specified instrumentation buffer.
   *
   * @param vmid the <em>file:</em> URI to the instrumentation buffer file
   * @throws MonitorException
   */
  public PerfDataBuffer(VmIdentifier vmid) throws MonitorException {
    File f = new File(vmid.getURI());
    String mode = vmid.getMode();

    try {
      FileChannel fc = new RandomAccessFile(f, mode).getChannel();
      ByteBuffer bb = null;

      if (mode.compareTo("r") == 0) {
        bb = fc.map(FileChannel.MapMode.READ_ONLY, 0L, (int) fc.size());
      } else if (mode.compareTo("rw") == 0) {
        bb = fc.map(FileChannel.MapMode.READ_WRITE, 0L, (int) fc.size());
      } else {
        throw new IllegalArgumentException("Invalid mode: " + mode);
      }

      fc.close(); // doesn't need to remain open

      createPerfDataBuffer(bb, 0);
    } catch (FileNotFoundException e) {
      throw new MonitorException("Could not find " + vmid.toString());
    } catch (IOException e) {
      throw new MonitorException("Could not read " + vmid.toString());
    }
  }
コード例 #2
0
  /** {@inheritDoc} */
  public MonitoredVm getMonitoredVm(VmIdentifier vmid, int interval) throws MonitorException {
    VmIdentifier nvmid = null;
    try {
      nvmid = hostId.resolve(vmid);
      RemoteVm rvm = remoteHost.attachVm(vmid.getLocalVmId(), vmid.getMode());
      RemoteMonitoredVm rmvm = new RemoteMonitoredVm(rvm, nvmid, timer, interval);
      rmvm.attach();
      return rmvm;

    } catch (RemoteException e) {
      throw new MonitorException("Remote Exception attaching to " + nvmid.toString(), e);
    } catch (URISyntaxException e) {
      /*
       * the VmIdentifier is expected to be a valid and should resolve
       * easonably against the host identifier. A URISyntaxException
       * here is most likely a programming error.
       */
      throw new IllegalArgumentException("Malformed URI: " + vmid.toString(), e);
    }
  }