use of org.eclipse.wst.server.core.ServerEvent in project liferay-ide by liferay.
the class RemoteServerWizardFragment method performFinish.
@Override
public void performFinish(IProgressMonitor monitor) throws CoreException {
try {
this.wizard.run(false, false, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
if (lastServerStatus == null || (!lastServerStatus.isOK())) {
lastServerStatus = getRemoteServerWC().validate(monitor);
if (!lastServerStatus.isOK()) {
throw new InterruptedException(lastServerStatus.getMessage());
}
}
}
});
} catch (Exception e) {
}
ServerCore.addServerLifecycleListener(new IServerLifecycleListener() {
String id = getServerWorkingCopy().getId();
public void serverAdded(final IServer server) {
if (server.getId().equals(id)) {
UIUtil.async(new Runnable() {
public void run() {
// $NON-NLS-1$
IViewPart serversView = UIUtil.showView("org.eclipse.wst.server.ui.ServersView");
CommonViewer viewer = (CommonViewer) serversView.getAdapter(CommonViewer.class);
viewer.setSelection(new StructuredSelection(server));
}
});
ServerCore.removeServerLifecycleListener(this);
server.addServerListener(new IServerListener() {
public void serverChanged(ServerEvent event) {
if (event.getServer().getServerState() == IServer.STATE_STARTED) {
server.publish(IServer.PUBLISH_INCREMENTAL, null, null, null);
server.removeServerListener(this);
}
}
});
}
}
public void serverChanged(IServer server) {
}
public void serverRemoved(IServer server) {
}
});
}
use of org.eclipse.wst.server.core.ServerEvent in project webtools.servertools by eclipse.
the class ServerListenerTestCase method testListener.
public void testListener() {
IServerListener listener = new IServerListener() {
public void serverChanged(ServerEvent event) {
// do nothing
}
};
listener.serverChanged(null);
}
use of org.eclipse.wst.server.core.ServerEvent in project eclipse-integration-commons by spring-projects.
the class ServerHandler method restartServer.
private void restartServer(IServer server, IProgressMonitor monitor) throws CoreException {
monitor.subTask("Restarting server");
final CountDownLatch eventLatch = new CountDownLatch(1);
IServerListener serverListener = new IServerListener() {
public void serverChanged(ServerEvent event) {
if (event.getState() == IServer.STATE_STARTED) {
eventLatch.countDown();
}
}
};
try {
server.addServerListener(serverListener);
if (server.getServerState() != IServer.STATE_STARTED) {
server.start(ILaunchManager.DEBUG_MODE, monitor);
} else if (server.getServerRestartState()) {
server.restart(ILaunchManager.DEBUG_MODE, monitor);
} else {
return;
}
// wait 10 seconds
monitor.subTask("Waiting for server to start");
for (int i = 0; i < 50; i++) {
try {
if (eventLatch.await(200, TimeUnit.MILLISECONDS)) {
break;
}
} catch (InterruptedException e) {
throw new OperationCanceledException();
}
Policy.checkCancelled(monitor);
}
} finally {
server.removeServerListener(serverListener);
}
}
use of org.eclipse.wst.server.core.ServerEvent in project liferay-ide by liferay.
the class PortalServerLaunchConfigDelegate method launchServer.
private void launchServer(final IServer server, final ILaunchConfiguration config, final String mode, final ILaunch launch, final IProgressMonitor monitor) throws CoreException {
final IVMInstall vm = verifyVMInstall(config);
final IVMRunner runner = vm.getVMRunner(mode) != null ? vm.getVMRunner(mode) : vm.getVMRunner(ILaunchManager.RUN_MODE);
final File workingDir = verifyWorkingDirectory(config);
final String workingDirPath = workingDir != null ? workingDir.getAbsolutePath() : null;
final String progArgs = getProgramArguments(config);
final String vmArgs = getVMArguments(config);
final String[] envp = getEnvironment(config);
final ExecutionArguments execArgs = new ExecutionArguments(vmArgs, progArgs);
final Map<String, Object> vmAttributesMap = getVMSpecificAttributesMap(config);
final PortalServerBehavior portalServer = (PortalServerBehavior) server.loadAdapter(PortalServerBehavior.class, monitor);
final String classToLaunch = portalServer.getClassToLaunch();
final String[] classpath = getClasspath(config);
final VMRunnerConfiguration runConfig = new VMRunnerConfiguration(classToLaunch, classpath);
runConfig.setProgramArguments(execArgs.getProgramArgumentsArray());
runConfig.setVMArguments(execArgs.getVMArgumentsArray());
runConfig.setWorkingDirectory(workingDirPath);
runConfig.setEnvironment(envp);
runConfig.setVMSpecificAttributesMap(vmAttributesMap);
final String[] bootpath = getBootpath(config);
if (ListUtil.isNotEmpty(bootpath)) {
runConfig.setBootClassPath(bootpath);
}
portalServer.launchServer(launch, mode, monitor);
server.addServerListener(new IServerListener() {
@Override
public void serverChanged(ServerEvent event) {
if ((event.getKind() & ServerEvent.MODULE_CHANGE) > 0) {
AbstractSourceLookupDirector sourceLocator = (AbstractSourceLookupDirector) launch.getSourceLocator();
try {
final String memento = config.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, (String) null);
if (memento != null) {
sourceLocator.initializeFromMemento(memento);
} else {
sourceLocator.initializeDefaults(config);
}
} catch (CoreException e) {
LiferayServerCore.logError("Could not reinitialize source lookup director", e);
}
} else if ((event.getKind() & ServerEvent.SERVER_CHANGE) > 0 && event.getState() == IServer.STATE_STOPPED) {
server.removeServerListener(this);
}
}
});
try {
runner.run(runConfig, launch, monitor);
portalServer.addProcessListener(launch.getProcesses()[0]);
} catch (Exception e) {
portalServer.cleanup();
}
}
use of org.eclipse.wst.server.core.ServerEvent in project liferay-ide by liferay.
the class LiferayTomcatUtil method syncStopServer.
public static void syncStopServer(final IServer server) {
if (server.getServerState() != IServer.STATE_STARTED) {
return;
}
final LiferayTomcatServerBehavior serverBehavior = (LiferayTomcatServerBehavior) server.loadAdapter(LiferayTomcatServerBehavior.class, null);
Thread shutdownThread = new Thread() {
@Override
public void run() {
serverBehavior.stop(true);
synchronized (server) {
try {
server.wait(5000);
} catch (InterruptedException e) {
}
}
}
};
IServerListener shutdownListener = new IServerListener() {
@Override
public void serverChanged(ServerEvent event) {
if (event.getState() == IServer.STATE_STOPPED) {
synchronized (server) {
server.notifyAll();
}
}
}
};
server.addServerListener(shutdownListener);
try {
shutdownThread.start();
shutdownThread.join();
} catch (InterruptedException e) {
}
server.removeServerListener(shutdownListener);
}
Aggregations