Search in sources :

Example 1 with IServerListener

use of org.eclipse.wst.server.core.IServerListener 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) {
        }
    });
}
Also used : IServer(org.eclipse.wst.server.core.IServer) IViewPart(org.eclipse.ui.IViewPart) CommonViewer(org.eclipse.ui.navigator.CommonViewer) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IServerLifecycleListener(org.eclipse.wst.server.core.IServerLifecycleListener) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ServerEvent(org.eclipse.wst.server.core.ServerEvent) IServerListener(org.eclipse.wst.server.core.IServerListener)

Example 2 with IServerListener

use of org.eclipse.wst.server.core.IServerListener 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);
}
Also used : ServerEvent(org.eclipse.wst.server.core.ServerEvent) IServerListener(org.eclipse.wst.server.core.IServerListener)

Example 3 with IServerListener

use of org.eclipse.wst.server.core.IServerListener 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);
    }
}
Also used : ServerEvent(org.eclipse.wst.server.core.ServerEvent) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IServerListener(org.eclipse.wst.server.core.IServerListener) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 4 with IServerListener

use of org.eclipse.wst.server.core.IServerListener 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();
    }
}
Also used : IVMRunner(org.eclipse.jdt.launching.IVMRunner) VMRunnerConfiguration(org.eclipse.jdt.launching.VMRunnerConfiguration) CoreException(org.eclipse.core.runtime.CoreException) ServerEvent(org.eclipse.wst.server.core.ServerEvent) AbstractSourceLookupDirector(org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector) IVMInstall(org.eclipse.jdt.launching.IVMInstall) CoreException(org.eclipse.core.runtime.CoreException) ExecutionArguments(org.eclipse.jdt.launching.ExecutionArguments) IServerListener(org.eclipse.wst.server.core.IServerListener) File(java.io.File)

Example 5 with IServerListener

use of org.eclipse.wst.server.core.IServerListener 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);
}
Also used : ServerEvent(org.eclipse.wst.server.core.ServerEvent) LiferayTomcatServerBehavior(com.liferay.ide.server.tomcat.core.LiferayTomcatServerBehavior) IServerListener(org.eclipse.wst.server.core.IServerListener)

Aggregations

IServerListener (org.eclipse.wst.server.core.IServerListener)5 ServerEvent (org.eclipse.wst.server.core.ServerEvent)5 CoreException (org.eclipse.core.runtime.CoreException)2 LiferayTomcatServerBehavior (com.liferay.ide.server.tomcat.core.LiferayTomcatServerBehavior)1 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 AbstractSourceLookupDirector (org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector)1 ExecutionArguments (org.eclipse.jdt.launching.ExecutionArguments)1 IVMInstall (org.eclipse.jdt.launching.IVMInstall)1 IVMRunner (org.eclipse.jdt.launching.IVMRunner)1 VMRunnerConfiguration (org.eclipse.jdt.launching.VMRunnerConfiguration)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 IViewPart (org.eclipse.ui.IViewPart)1 CommonViewer (org.eclipse.ui.navigator.CommonViewer)1 IServer (org.eclipse.wst.server.core.IServer)1 IServerLifecycleListener (org.eclipse.wst.server.core.IServerLifecycleListener)1