use of org.talend.designer.runtime.visualization.JvmModelEvent in project tdi-studio-se by Talend.
the class MBeanServer method dump.
/**
* Dumps the profile data into file.
*
* @param type The snapshot type
* @param dumpFileName The dump file name
* @param monitor The progress monitor
* @return The file store
* @throws JvmCoreException
*/
private IFileStore dump(SnapshotType type, String dumpFileName, IProgressMonitor monitor) throws JvmCoreException {
String simpleFileName;
if (dumpFileName == null) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(new Date().getTime()).append('.').append(type.getExtension());
simpleFileName = stringBuffer.toString();
} else {
simpleFileName = new File(dumpFileName).getName();
}
IFileStore fileStore = Util.getFileStore(simpleFileName, jvm.getBaseDirectory());
// restore the terminated JVM if already removed
AbstractJvm abstractJvm = jvm;
if (!((Host) jvm.getHost()).getJvms().contains(jvm)) {
jvm.saveJvmProperties();
abstractJvm = (AbstractJvm) ((Host) jvm.getHost()).addTerminatedJvm(jvm.getPid(), jvm.getPort(), jvm.getMainClass());
}
OutputStream os = null;
try {
if (type == SnapshotType.Heap || type == SnapshotType.Thread) {
String dump = getDumpString(type);
os = fileStore.openOutputStream(EFS.NONE, null);
os.write(dump.getBytes());
} else if (type == SnapshotType.Hprof && jvm.isRemote()) {
ObjectName objectName = getObjectName(DATA_TRANSFER_MXBEAN_NAME);
os = fileStore.openOutputStream(EFS.NONE, null);
byte[] bytes;
int offset = 0;
final int SIZE = 4096;
//$NON-NLS-1$ //$NON-NLS-2$
final String[] SIGNATURES = new String[] { String.class.getCanonicalName(), "int", "int" };
do {
bytes = (byte[]) invoke(objectName, "read", new Object[] { //$NON-NLS-1$
dumpFileName, offset, SIZE }, SIGNATURES);
os.write(bytes);
offset += SIZE;
if (monitor != null && monitor.isCanceled()) {
break;
}
} while (bytes.length > 0);
}
if (monitor != null && monitor.isCanceled()) {
return null;
}
Snapshot snapshot = new Snapshot(fileStore, abstractJvm);
abstractJvm.addSnapshot(snapshot);
JvmModel.getInstance().fireJvmModelChangeEvent(new JvmModelEvent(State.ShapshotTaken, abstractJvm, snapshot));
} catch (CoreException e) {
throw new JvmCoreException(IStatus.ERROR, NLS.bind(Messages.openOutputStreamFailedMsg, fileStore.toURI().getPath()), e);
} catch (IOException e) {
try {
fileStore.delete(EFS.NONE, null);
} catch (CoreException e1) {
// do nothing
}
throw new JvmCoreException(IStatus.ERROR, NLS.bind(Messages.dumpFailedMsg, fileStore.toURI().getPath()), e);
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
// do nothing
}
}
}
return fileStore;
}
use of org.talend.designer.runtime.visualization.JvmModelEvent in project tdi-studio-se by Talend.
the class MBeanServer method refresh.
/**
* Refreshes the MBean model.
*
* @throws JvmCoreException
*/
protected void refresh() throws JvmCoreException {
if (!checkReachability()) {
return;
}
for (IMonitoredMXBeanGroup group : monitoredAttributeGroups) {
for (IMonitoredMXBeanAttribute attribute : group.getAttributes()) {
String attributeName = attribute.getAttributeName();
Object attributeObject = getAttribute(attribute.getObjectName(), attributeName);
Number value = getAttributeValue(attributeObject, attributeName);
if (value == null) {
continue;
}
// exceptional handling for process CPU time
if (MonitorAttributeName.CPU_TIME.equals(attribute.getAttributeName())) {
if (previousProcessCpuTime == 0) {
previousProcessCpuTime = (Long) value;
continue;
}
Double percent = ((Long) value - previousProcessCpuTime) / 1000000000d;
previousProcessCpuTime = (Long) value;
value = percent > 1 ? 1 : percent;
}
((MonitoredMXBeanAttribute) attribute).add(value, new Date());
}
}
JvmModel.getInstance().fireJvmModelChangeEvent(new JvmModelEvent(State.JvmModified, jvm));
}
use of org.talend.designer.runtime.visualization.JvmModelEvent in project tdi-studio-se by Talend.
the class RefreshAction method run.
/*
* @see Action#run()
*/
@Override
public void run() {
boolean isChecked = isChecked();
section.suspendRefresh(!isChecked);
if (isChecked) {
section.jvmModelChanged(new JvmModelEvent(State.JvmModified, section.getJvm()));
}
}
use of org.talend.designer.runtime.visualization.JvmModelEvent in project tdi-studio-se by Talend.
the class AbstractJvm method deleteSnapshot.
/*
* @see IJvm#deleteSnapshot(ISnapshot)
*/
@Override
public void deleteSnapshot(ISnapshot snapshot) {
snapshots.remove(snapshot);
try {
snapshot.getFileStore().delete(EFS.NONE, null);
} catch (CoreException e) {
Activator.log(IStatus.ERROR, NLS.bind(Messages.deleteFileFailedMsg, snapshot.getFileStore().getName()), e);
}
JvmModel.getInstance().fireJvmModelChangeEvent(new JvmModelEvent(State.ShapshotRemoved, this));
}
use of org.talend.designer.runtime.visualization.JvmModelEvent in project tdi-studio-se by Talend.
the class CpuProfiler method setProfiledPackages.
/*
* @see ICpuProfiler#setProfiledPackages(Set<String>)
*/
@Override
public void setProfiledPackages(Set<String> packages) throws JvmCoreException {
if (type == ProfilerType.BCI) {
validateAgent();
ProfilerState state = getState();
if (state != ProfilerState.READY && state != ProfilerState.RUNNING) {
return;
}
StringBuffer buffer = new StringBuffer();
for (String item : packages) {
if (buffer.length() > 0) {
buffer.append(',');
}
buffer.append(item);
}
invokeCpuProfilerMXBeanMethod(SET_FILTER, new String[] { PROFILED_PACKAGES_PROP_KEY, buffer.toString() }, new String[] { String.class.getName(), String.class.getName() });
} else {
this.profiledPackages = packages;
}
JvmModel.getInstance().fireJvmModelChangeEvent(new JvmModelEvent(State.CpuProfilerConfigChanged, jvm));
}
Aggregations