public long getFreeMemorySpace() throws JIException {
    System.gc();

    JIVariant results[] =
        service_dispatch.callMethodA(
            "ExecQuery",
            new Object[] {
              new JIString("select * from Win32_PerfRawData_PerfOS_Memory"),
              JIVariant.OPTIONAL_PARAM(),
              JIVariant.OPTIONAL_PARAM(),
              JIVariant.OPTIONAL_PARAM()
            });
    IJIDispatch wbemObjectSet_dispatch =
        (IJIDispatch) JIObjectFactory.narrowObject((results[0]).getObjectAsComObject());
    JIVariant variant = wbemObjectSet_dispatch.get("_NewEnum");
    IJIComObject object2 = variant.getObjectAsComObject();

    IJIEnumVariant enumVARIANT =
        (IJIEnumVariant) JIObjectFactory.narrowObject(object2.queryInterface(IJIEnumVariant.IID));
    if (wbemObjectSet_dispatch.get("Count").getObjectAsInt() != 1)
      return -1; // there should be 1 hint

    JIArray array = (JIArray) enumVARIANT.next(1)[0];
    JIVariant item = ((JIVariant[]) array.getArrayInstance())[0];
    IJIDispatch wbemObject_dispatch =
        (IJIDispatch) JIObjectFactory.narrowObject(item.getObjectAsComObject());
    return Long.parseLong(
        wbemObject_dispatch.get("AvailableKBytes").getObjectAsString().getString());
  }
  public LinkedList<IJIDispatch> getDiskDrives() throws JIException {
    System.gc();

    // get all local disks
    JIVariant results[] =
        service_dispatch.callMethodA(
            "ExecQuery",
            new Object[] {
              new JIString("select * from Win32_LogicalDisk where DriveType = 3"),
              JIVariant.OPTIONAL_PARAM(),
              JIVariant.OPTIONAL_PARAM(),
              JIVariant.OPTIONAL_PARAM()
            });
    IJIDispatch wbemObjectSet_dispatch =
        (IJIDispatch) JIObjectFactory.narrowObject((results[0]).getObjectAsComObject());
    JIVariant variant = wbemObjectSet_dispatch.get("_NewEnum");
    IJIComObject object2 = variant.getObjectAsComObject();

    IJIEnumVariant enumVARIANT =
        (IJIEnumVariant) JIObjectFactory.narrowObject(object2.queryInterface(IJIEnumVariant.IID));

    LinkedList<IJIDispatch> drives = new LinkedList<IJIDispatch>();

    int count = wbemObjectSet_dispatch.get("Count").getObjectAsInt();
    for (int i = 0; i < count; i++) {
      Object[] values = enumVARIANT.next(1);
      JIArray array = (JIArray) values[0];
      JIVariant[] variants = (JIVariant[]) array.getArrayInstance();
      for (JIVariant item : variants) {
        drives.add((IJIDispatch) JIObjectFactory.narrowObject(item.getObjectAsComObject()));
      }
    }
    return drives;
  }
Ejemplo n.º 3
0
 public void OnWriteComplete(
     int dwTransid,
     int hGroup,
     int hrMasterError,
     int dwCount,
     JIArray pClientHandles,
     JIArray pErrors) {
   Logger.getLogger(OPCDataCallbackImpl.class.getName())
       .finest("OnWriteComplete, transid=" + dwTransid);
   Integer[] clientHandles = (Integer[]) pClientHandles.getArrayInstance();
   Integer[] errors = (Integer[]) pErrors.getArrayInstance();
   listener.writeCompleted(dwTransid, hGroup, hrMasterError, clientHandles, errors);
 }
Ejemplo n.º 4
0
  public void getTCharArray() throws JIException, InterruptedException, UnknownHostException {
    System.gc();
    JICallBuilder callObject = new JICallBuilder(true);
    callObject.setOpnum(6);
    Object results[];

    callObject.addOutParamAsObject(
        new JIArray(Byte.class, new int[] {50}, 1, false), JIFlags.FLAG_NULL);
    results = comObject.call(callObject);

    JIArray arrayOfResults = (JIArray) results[0];
    Byte[] arrayOfBytes = (Byte[]) arrayOfResults.getArrayInstance();
    int length = 50;
    for (int i = 0; i < length; i++) {
      System.out.println(arrayOfBytes[i].byteValue());
    }
  }
Ejemplo n.º 5
0
  FuncDesc(JIStruct filledStruct) {
    if (filledStruct == null) {
      values = null;
      memberId = -1;
      lprgscode = null;
      lprgelemdescParam = null;
      funcKind = -1;
      invokeKind = -1;
      callConv = -1;
      cParams = -1;
      cParamsOpt = -1;
      oVft = -1;
      cScodes = -1;
      elemdescFunc = null;
      wFuncFlags = -1;
      return;
    }
    values = filledStruct;
    memberId = ((Integer) values.getMember(0)).intValue();
    lprgscode = (JIPointer) values.getMember(1);
    JIPointer ptr = (JIPointer) values.getMember(2);
    JIArray arrayOfElemDesc = null;
    if (!ptr.isNull()) {
      JIArray arry = (JIArray) ptr.getReferent();
      Object[] obj = (Object[]) arry.getArrayInstance();
      //			ElemDesc[] arry2 = new ElemDesc[obj.length];
      //			for (int i = 0; i < obj.length; i++)
      //			{
      //				arry2[i] = new ElemDesc((JIStruct)obj[i]);
      //			}

      //			arrayOfElemDesc = new JIArray(arry2);
      arrayOfElemDesc = new JIArray(obj);
    }

    lprgelemdescParam = new JIPointer(arrayOfElemDesc);
    funcKind = ((Integer) values.getMember(3)).intValue();
    invokeKind = ((Integer) values.getMember(4)).intValue();
    callConv = ((Integer) values.getMember(5)).intValue();
    cParams = ((Short) values.getMember(6)).shortValue();
    cParamsOpt = ((Short) values.getMember(7)).shortValue();
    oVft = ((Short) values.getMember(8)).shortValue();
    cScodes = ((Short) values.getMember(9)).shortValue();
    elemdescFunc = new ElemDesc(((JIStruct) values.getMember(10)));
    wFuncFlags = ((Short) values.getMember(11)).shortValue();
  }
Ejemplo n.º 6
0
  public void getConformantIntArray()
      throws JIException, InterruptedException, UnknownHostException {

    JICallBuilder callObject = new JICallBuilder(true);
    callObject.setOpnum(8);
    Object results[];

    callObject.addOutParamAsType(Integer.class, JIFlags.FLAG_NULL);
    callObject.addOutParamAsObject(
        new JIPointer(new JIArray(Integer.class, null, 1, true)), JIFlags.FLAG_NULL);
    results = comObject.call(callObject);

    JIArray arrayOfResults = (JIArray) ((JIPointer) results[1]).getReferent();
    Integer[] arrayOfIntegers = (Integer[]) arrayOfResults.getArrayInstance();
    int length = ((Integer) results[0]).intValue();
    for (int i = 0; i < length; i++) {
      System.out.println(arrayOfIntegers[i].intValue());
    }
  }
Ejemplo n.º 7
0
    public T next() {
      try {
        if (hasNext()) {
          count--;
          Object[] values = this.enumerator.next(1);
          JIArray array = (JIArray) values[0];
          Object[] arrayObj = (Object[]) array.getArrayInstance();
          IJIComObject co = ((JIVariant) arrayObj[0]).getObjectAsComObject();
          IJIDispatch dispatch = (IJIDispatch) JIObjectFactory.narrowObject(co);

          // Create a new SWbemSetItem from the result.
          final Constructor<T> ctor = clazz.getConstructor(IJIDispatch.class, SWbemServices.class);
          final T item = ctor.newInstance(dispatch, this.service);
          return item;
        } else {
          throw new NoSuchElementException();
        }
      } catch (Exception ex) {
        return null;
      }
    }
Ejemplo n.º 8
0
  public void OnReadComplete(
      int dwTransid,
      int hGroup,
      int hrMasterQuality,
      int hrMasterError,
      int dwCount,
      JIArray phClientItems,
      JIArray pvValues,
      JIArray pwQualities,
      JIArray pftTimeStamps,
      JIArray pErrors)
      throws JIException {
    Logger.getLogger(OPCDataCallbackImpl.class.getName())
        .finest("OnReadComplete, transid=" + dwTransid);
    Integer[] clientHandles = (Integer[]) phClientItems.getArrayInstance();
    Object[] values = new Object[dwCount];
    Short[] qualities = (Short[]) pwQualities.getArrayInstance();
    Date[] timeStamps = new Date[dwCount];
    Integer[] errors = (Integer[]) pErrors.getArrayInstance();

    JIStruct[] fileTimeStructs = (JIStruct[]) pftTimeStamps.getArrayInstance();
    for (int i = 0; i < fileTimeStructs.length; i++)
      timeStamps[i] = new FileTime(fileTimeStructs[i]).getTime();

    JIVariant[] valueVariants = (JIVariant[]) pvValues.getArrayInstance();
    for (int i = 0; i < valueVariants.length; i++) values[i] = valueVariants[i].getObject();

    listener.readCompleted(
        dwTransid,
        hGroup,
        hrMasterQuality,
        hrMasterError,
        clientHandles,
        values,
        qualities,
        timeStamps,
        errors);
  }
  public LinkedList<IJIDispatch> getServices() throws JIException {
    System.gc();

    // get all services which should start automatically but are not running
    JIVariant results[] =
        service_dispatch.callMethodA(
            "ExecQuery",
            new Object[] {
              new JIString(
                  "select * from Win32_Service where StartMode = 'Auto' and Started = FALSE"),
              JIVariant.OPTIONAL_PARAM(),
              JIVariant.OPTIONAL_PARAM(),
              JIVariant.OPTIONAL_PARAM()
            });

    IJIDispatch wbemObjectSet_dispatch =
        (IJIDispatch) JIObjectFactory.narrowObject((results[0]).getObjectAsComObject());
    JIVariant variant = wbemObjectSet_dispatch.get("_NewEnum");
    IJIComObject object2 = variant.getObjectAsComObject();
    IJIEnumVariant enumVARIANT =
        (IJIEnumVariant) JIObjectFactory.narrowObject(object2.queryInterface(IJIEnumVariant.IID));

    LinkedList<IJIDispatch> services = new LinkedList<IJIDispatch>();

    int count = wbemObjectSet_dispatch.get("Count").getObjectAsInt();
    for (int i = 0; i < count; i++) {
      Object[] values = enumVARIANT.next(1);
      JIArray array = (JIArray) values[0];
      JIVariant[] variants = (JIVariant[]) array.getArrayInstance();
      for (JIVariant item : variants) {
        IJIDispatch wbemObject_dispatch =
            (IJIDispatch) JIObjectFactory.narrowObject(item.getObjectAsComObject());
        services.add(wbemObject_dispatch);
      }
    }
    return services;
  }
  /**
   * Add resources to an existing virtual computer system
   *
   * @param vmDispatch A reference to the computer system instance to which the resource is to be
   *     added.
   * @param newResourceAllocationDispatch the new resource allocation setting data reference to be
   *     added.
   * @return the resource allocation setting data path of the added resource
   * @deprecated
   * @throws JIException
   */
  @Deprecated
  public String addVirtualSystemResources2(
      final IJIDispatch vmDispatch, final IJIDispatch newResourceAllocationDispatch)
      throws JIException {
    if (this.addVirtualSystemResources == null) {
      for (final SWbemMethod m : super.getMethods()) {
        if (m.getName().equals("AddVirtualSystemResources")) {
          this.addVirtualSystemResources = m;
        }
      }
    }

    // Getting the dispatcher of the VM Path
    IJIDispatch vmPathDispatcher =
        (IJIDispatch)
            JIObjectFactory.narrowObject(
                vmDispatch.get("Path_").getObjectAsComObject().queryInterface(IJIDispatch.IID));

    // Getting the virtual machine path
    String vmPath = vmPathDispatcher.get("Path").getObjectAsString2();

    // Getting the dispatcher of the resource path

    String resourceText =
        newResourceAllocationDispatch.callMethodA("GetText_", new Object[] {new Integer(1)})[0]
            .getObjectAsString2();

    SWbemObject inParams = this.addVirtualSystemResources.getInParameters();

    inParams.getObjectDispatcher().put("TargetSystem", new JIVariant(new JIString(vmPath)));

    inParams
        .getObjectDispatcher()
        .put(
            "ResourceSettingData",
            new JIVariant(new JIArray(new JIString[] {new JIString(resourceText)})));

    Object[] methodParams =
        new Object[] {
          new JIString("AddVirtualSystemResources"),
          new JIVariant(inParams.getObjectDispatcher()),
          new Integer(0),
          JIVariant.NULL(),
        };

    // Execute the method.
    JIVariant[] results = super.objectDispatcher.callMethodA("ExecMethod_", methodParams);

    // Get the out parameters.
    JIVariant outParamsVar = results[0];
    IJIComObject co = outParamsVar.getObjectAsComObject();
    IJIDispatch outParamsDisp = (IJIDispatch) JIObjectFactory.narrowObject(co);

    // Get the out parameter virtualSystemResources and convert it into an
    // array of JIVariants.
    JIVariant newResourcesVars = outParamsDisp.get("NewResources");
    JIArray newResourcesVarsJIArr = newResourcesVars.getObjectAsArray();
    JIVariant[] newResourcesVarsJIVarArr = (JIVariant[]) newResourcesVarsJIArr.getArrayInstance();

    String newResourceCoString = newResourcesVarsJIVarArr[0].getObjectAsString2();

    return newResourceCoString;
  }
  /**
   * Add resources to an existing virtual computer system
   *
   * @param vmDispatch A reference to the computer system instance to which the resource is to be
   *     added.
   * @param newResourceAllocationDispatch the new resource allocation setting data reference to be
   *     added.
   * @return the resource allocation setting data path of the added resource
   * @throws JIException
   */
  public String addVirtualSystemResources(
      final IJIDispatch vmDispatch, final IJIDispatch newResourceAllocationDispatch)
      throws JIException {
    // Getting the dispatcher of the VM Path
    IJIDispatch vmPathDispatcher =
        (IJIDispatch)
            JIObjectFactory.narrowObject(
                vmDispatch.get("Path_").getObjectAsComObject().queryInterface(IJIDispatch.IID));

    // Getting the virtual machine path
    String vmPath = vmPathDispatcher.get("Path").getObjectAsString2();

    // Getting the dispatcher of the resource path

    String resourceText =
        newResourceAllocationDispatch.callMethodA("GetText_", new Object[] {new Integer(1)})[0]
            .getObjectAsString2();

    JIVariant[] tmp =
        dispatch.callMethodA(
            "AddVirtualSystemResources",
            new Object[] {
              new JIString(vmPath),
              new JIArray(new JIString[] {new JIString(resourceText)}),
              JIVariant.EMPTY_BYREF(),
              JIVariant.EMPTY_BYREF()
            });

    int result = tmp[0].getObjectAsInt();

    JIVariant resultVariant = tmp[2];

    JIVariant variant2 = resultVariant.getObjectAsVariant();

    JIArray newResourcesArr = variant2.getObjectAsArray();

    if (newResourcesArr == null) {
      throw new JIException(32768, "The resource could not be added");
    }

    JIVariant[] newResourcesVarArr = (JIVariant[]) newResourcesArr.getArrayInstance();

    String newResourcePath = newResourcesVarArr[0].getObjectAsString2();

    String name = newResourceAllocationDispatch.get("ElementName").getObjectAsString2();
    if (result == 0) {
      logger.debug(name + " added to " + vmPath);
    } else {
      if (result == 4096) {
        logger.debug("Addind resources...");
        String jobPath = tmp[1].getObjectAsVariant().getObjectAsString2();
        HyperVUtils.monitorJob(jobPath, service.getObjectDispatcher());
      } else {
        logger.error(name + " addition to " + vmPath + " failed with error code " + result);
        throw new IllegalStateException(
            "Cannot add resource "
                + name
                + " to "
                + vmDispatch.get("ElementName").getObjectAsString2());
      }
    }

    return newResourcePath;
  }