Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2016 Javier Garcia Alonso.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jutils.jprocesses.info;
import com.profesorfalken.wmi4java.WMI4Java;
import com.profesorfalken.wmi4java.WMIClass;
import org.jutils.jprocesses.model.JProcessesResponse;
import org.jutils.jprocesses.model.ProcessInfo;
import org.jutils.jprocesses.util.ProcessesUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Service implementation for Windows
*
* @author Javier Garcia Alonso
*/
class WindowsProcessesService extends AbstractProcessesService {
//TODO: This Windows implementation works but it is not optimized by lack of time.
//For example, the filter by name or the search by pid is done retrieving
//all the processes searching in the returning list.
//Moreover, the information is dispersed and I had to get it from different sources (WMI classes, VBS scripts...)
private final Map userData = new HashMap();
private final Map cpuData = new HashMap();
private static final String LINE_BREAK_REGEX = "\\r?\\n";
private static final Map keyMap;
private Map processMap;
private static final String NAME_PROPNAME = "Name";
private static final String PROCESSID_PROPNAME = "ProcessId";
private static final String USERMODETIME_PROPNAME = "UserModeTime";
private static final String PRIORITY_PROPNAME = "Priority";
private static final String VIRTUALSIZE_PROPNAME = "VirtualSize";
private static final String WORKINGSETSIZE_PROPNAME = "WorkingSetSize";
private static final String COMMANDLINE_PROPNAME = "CommandLine";
private static final String CREATIONDATE_PROPNAME = "CreationDate";
private static final String CAPTION_PROPNAME = "Caption";
private final WMI4Java wmi4Java;
static {
Map tmpMap = new HashMap();
tmpMap.put(NAME_PROPNAME, "proc_name");
tmpMap.put(PROCESSID_PROPNAME, "pid");
tmpMap.put(USERMODETIME_PROPNAME, "proc_time");
tmpMap.put(PRIORITY_PROPNAME, "priority");
tmpMap.put(VIRTUALSIZE_PROPNAME, "virtual_memory");
tmpMap.put(WORKINGSETSIZE_PROPNAME, "physical_memory");
tmpMap.put(COMMANDLINE_PROPNAME, "command");
tmpMap.put(CREATIONDATE_PROPNAME, "start_time");
keyMap = Collections.unmodifiableMap(tmpMap);
}
public WindowsProcessesService() {
this(null);
}
WindowsProcessesService(WMI4Java wmi4Java) {
this.wmi4Java = wmi4Java;
}
public WMI4Java getWmi4Java() {
if (wmi4Java == null) {
return WMI4Java.get();
}
return wmi4Java;
}
@Override
protected List