I'm trying to force my application to execute shutdown hooks when clicking the "red square terminate" button in Eclipse. I realize this question was addressed here and here.
I've implemented the following code based on this response and this comment on Eclipse.org forums:
import java.rmi.RemoteException;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.debug.core.model.IStreamsProxy;
public class JavaProcessDecorator implements IProcess {
private IProcess p;
public JavaProcessDecorator(IProcess p) {
this.p = p;
}
private boolean sigkill = false;
@SuppressWarnings("rawtypes")
@Override public Object getAdapter(Class arg)
{
return p.getAdapter(arg);
}
@Override public ILaunch getLaunch()
{
return p.getLaunch();
}
@Override public IStreamsProxy getStreamsProxy()
{
return p.getStreamsProxy();
}
@Override public void setAttribute(String s1, String s2)
{
p.setAttribute(s1, s2);
}
@Override public void terminate() throws DebugException
{
if (!sigkill) {
try {
IDebugIService cs = DirmiServer.INSTANCE.getRemote("main", IDebugIService.class);
if(cs != null) cs.modelEvent(new TerminateRequest());
} catch (RemoteException e) { }
this.sigkill = true;
} else p.terminate();
}
@Override
public boolean canTerminate() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isTerminated() {
return p.isTerminated();
}
@Override
public String getLabel() {
return p.getLabel();
}
@Override
public String getAttribute(String key) {
return p.getAttribute(key);
}
@Override
public int getExitValue() throws DebugException {
return p.getExitValue();
}
}
I've downloaded both DirmiServer and Cojen jars however Eclipse complains in the following two lines:
IDebugIService cs = DirmiServer.INSTANCE.getRemote("main", IDebugIService.class);
if(cs != null) cs.modelEvent(new TerminateRequest());
That 'IDebugIService ', 'DirmiServer', 'IDebugIService' and 'TerminateRequest'
cannot be resolved to a type?
What am I doing wrong?
Thanks