use of org.talend.designer.runtime.visualization.JvmCoreException in project tdi-studio-se by Talend.
the class MBeanServer method getAttribute.
/*
* @see IMBeanServer#getAttribute(ObjectName, String)
*/
@Override
public Object getAttribute(ObjectName objectName, String qualifiedAttributeName) throws JvmCoreException {
Assert.isNotNull(objectName);
Assert.isNotNull(qualifiedAttributeName);
if (!checkReachability()) {
return null;
}
String attributeName = qualifiedAttributeName;
if (attributeName.contains(".")) {
//$NON-NLS-1$
//$NON-NLS-1$
attributeName = attributeName.split("\\.")[0];
}
try {
return connection.getAttribute(objectName, attributeName);
} catch (JMException e) {
throw new JvmCoreException(IStatus.ERROR, NLS.bind(Messages.getAttributeFailedMsg, attributeName), e);
} catch (IOException e) {
throw new JvmCoreException(IStatus.ERROR, NLS.bind(Messages.getAttributeFailedMsg, attributeName), e);
}
}
use of org.talend.designer.runtime.visualization.JvmCoreException in project tdi-studio-se by Talend.
the class MBeanServer method dumpHprof.
/*
* @see IMBeanServer#dumpHprof(String, boolean, IProgressMonitor)
*/
@Override
public IFileStore dumpHprof(String hprofFileName, boolean transfer, IProgressMonitor monitor) throws JvmCoreException {
if (!checkReachability()) {
throw new JvmCoreException(IStatus.WARNING, Messages.jvmNotReachableMsg, null);
}
IFileStore fileStore = null;
String fileName;
if (jvm.isRemote()) {
fileName = hprofFileName;
} else {
fileStore = dump(SnapshotType.Hprof, null, null);
fileName = fileStore.toString();
}
if (monitor.isCanceled()) {
return null;
}
//$NON-NLS-1$
ObjectName objectName = jvm.getMBeanServer().getObjectName("com.sun.management:type=HotSpotDiagnostic");
invoke(//$NON-NLS-1$
objectName, //$NON-NLS-1$
"dumpHeap", //$NON-NLS-1$
new Object[] { fileName, Boolean.TRUE }, //$NON-NLS-1$
new String[] { String.class.getCanonicalName(), "boolean" });
if (jvm.isRemote() && transfer) {
fileStore = dump(SnapshotType.Hprof, hprofFileName, monitor);
}
return fileStore;
}
use of org.talend.designer.runtime.visualization.JvmCoreException in project tdi-studio-se by Talend.
the class MBeanServer method refreshThreadCache.
/*
* @see IMBeanServer#refreshThreadCache()
*/
@Override
public void refreshThreadCache() throws JvmCoreException {
if (!checkReachability()) {
return;
}
ThreadMXBean threadMXBean;
try {
threadMXBean = (ThreadMXBean) getMXBean(ThreadMXBean.class, ManagementFactory.THREAD_MXBEAN_NAME);
} catch (IOException e) {
throw new JvmCoreException(IStatus.ERROR, NLS.bind(Messages.getMBeanFailedMsg, ManagementFactory.THREAD_MXBEAN_NAME), e);
}
if (threadMXBean == null) {
throw new JvmCoreException(IStatus.ERROR, NLS.bind(Messages.getMBeanFailedMsg, ManagementFactory.THREAD_MXBEAN_NAME), null);
}
long[] ids = threadMXBean.findDeadlockedThreads();
LinkedHashMap<String, ThreadElement> newThreadListElements = new LinkedHashMap<String, ThreadElement>();
List<ThreadInfo> allThreads = Arrays.asList(threadMXBean.dumpAllThreads(true, false));
Collections.reverse(allThreads);
for (ThreadInfo threadInfo : allThreads) {
String threadName = threadInfo.getThreadName();
long threadId = threadInfo.getThreadId();
if (//$NON-NLS-1$
threadInfo.getStackTrace().length == 0 || threadName.startsWith("RMI ") || threadName.startsWith("JMX ")) {
//$NON-NLS-1$
continue;
}
boolean isDeadlocked = false;
if (ids != null) {
Arrays.sort(ids);
if (Arrays.binarySearch(ids, threadId) >= 0) {
isDeadlocked = true;
}
}
ThreadElement oldElement = threadListElements.get(threadName);
long processCpuTime = threadMXBean.getThreadCpuTime(threadId);
Long previousCpuTime = previousThreadProcessCpuTime.get(threadId);
double cpuUsage = 0;
previousThreadProcessCpuTime.put(threadId, processCpuTime);
if (previousCpuTime != null) {
cpuUsage = Math.min((processCpuTime - previousCpuTime) / 10000000d, 100);
}
previousThreadProcessCpuTime.put(threadId, processCpuTime);
if (oldElement == null) {
newThreadListElements.put(threadName, new ThreadElement(threadInfo, isDeadlocked, cpuUsage));
} else {
oldElement.setThreadInfo(threadInfo);
oldElement.setDeadlocked(isDeadlocked);
oldElement.setCpuUsage(cpuUsage);
newThreadListElements.put(threadName, oldElement);
}
}
threadListElements = newThreadListElements;
}
use of org.talend.designer.runtime.visualization.JvmCoreException in project tdi-studio-se by Talend.
the class MBeanServer method resumeSampling.
/**
* Resumes the sampling.
*/
public void resumeSampling() {
if (samplingTimer != null) {
samplingTimer.cancel();
}
samplingTimer = new Timer(true);
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
try {
sampleProfilingData();
} catch (JvmCoreException e) {
Activator.log(IStatus.ERROR, e.getMessage(), e);
suspendSampling();
} catch (Throwable t) {
suspendSampling();
}
}
};
samplingTimer.schedule(timerTask, 0, samplingPeriod);
}
use of org.talend.designer.runtime.visualization.JvmCoreException in project tdi-studio-se by Talend.
the class ActiveJvm method saveJvmProperties.
/**
* Saves the JVM properties.
*/
public void saveJvmProperties() {
IFileStore fileStore;
try {
fileStore = Util.getFileStore(IJvm.PROPERTIES_FILE, getBaseDirectory());
if (fileStore.fetchInfo().exists()) {
return;
}
} catch (JvmCoreException e) {
Activator.log(IStatus.ERROR, Messages.savePropertiesFileFailedMsg, e);
return;
}
Properties props = new Properties();
OutputStream os = null;
try {
os = fileStore.openOutputStream(EFS.NONE, null);
int pid = getPid();
int port = getPort();
String mainClass = getMainClass();
props.setProperty(IJvm.PID_PROP_KEY, String.valueOf(pid));
props.setProperty(IJvm.PORT_PROP_KEY, String.valueOf(port));
if (mainClass != null) {
props.setProperty(IJvm.MAIN_CLASS_PROP_KEY, mainClass);
}
props.setProperty(IJvm.HOST_PROP_KEY, getHost().getName());
//$NON-NLS-1$
props.storeToXML(os, "JVM Properties");
} catch (CoreException e) {
Activator.log(IStatus.ERROR, NLS.bind(Messages.openOutputStreamFailedMsg, fileStore.toURI().getPath()), e);
} catch (IOException e) {
try {
fileStore.delete(EFS.NONE, null);
} catch (CoreException e1) {
// do nothing
}
Activator.log(IStatus.ERROR, NLS.bind(Messages.writePropertiesFileFailedMsg, fileStore.toURI().getPath()), e);
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
// do nothing
}
}
}
}
Aggregations