Revision ae1c072d
Added by Cherian Mathew over 8 years ago
- ID ae1c072d919b4a063f6b962978ff11df77e4b80f
- Parent 8c244d13
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/RemotingLoginDialog.java | ||
---|---|---|
40 | 40 |
import org.eclipse.swt.widgets.Dialog; |
41 | 41 |
import org.eclipse.swt.widgets.Display; |
42 | 42 |
import org.eclipse.swt.widgets.Label; |
43 |
import org.eclipse.swt.widgets.MessageBox; |
|
44 | 43 |
import org.eclipse.swt.widgets.Shell; |
45 | 44 |
import org.eclipse.swt.widgets.Text; |
46 | 45 |
import org.eclipse.ui.forms.events.ExpansionEvent; |
... | ... | |
66 | 65 |
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin; |
67 | 66 |
import eu.etaxonomy.taxeditor.webapp.CDMEmbeddedServerException; |
68 | 67 |
import eu.etaxonomy.taxeditor.webapp.CDMServer; |
68 |
import eu.etaxonomy.taxeditor.webapp.ICDMServerError; |
|
69 | 69 |
|
70 | 70 |
|
71 | 71 |
/** |
... | ... | |
73 | 73 |
* @date 20 Jan 2015 |
74 | 74 |
* |
75 | 75 |
*/ |
76 |
public class RemotingLoginDialog extends Dialog { |
|
76 |
public class RemotingLoginDialog extends Dialog implements ICDMServerError {
|
|
77 | 77 |
|
78 | 78 |
protected Object result; |
79 | 79 |
protected Shell shlConnect; |
... | ... | |
147 | 147 |
private boolean autoConnect = false; |
148 | 148 |
private boolean loadLoginPrefs = true; |
149 | 149 |
private boolean isDevRemoteSource = false; |
150 |
|
|
150 |
private Job serverJob; |
|
151 | 151 |
/** |
152 | 152 |
* Create the dialog. |
153 | 153 |
* @param parent |
... | ... | |
576 | 576 |
txtCdmInstanceStatus.setText(STATUS_RETRIEVING); |
577 | 577 |
txtCdmInstanceStatus.setToolTipText(""); |
578 | 578 |
|
579 |
Job job = new Job("Retrieve Server Instances") {
|
|
579 |
serverJob = new Job("Retrieve Server Instances") {
|
|
580 | 580 |
@Override |
581 | 581 |
protected IStatus run(IProgressMonitor monitor) { |
582 | 582 |
try { |
... | ... | |
633 | 633 |
|
634 | 634 |
if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE) && !isDevRemoteSource) { |
635 | 635 |
// Start the Job |
636 |
job.schedule();
|
|
636 |
serverJob.schedule();
|
|
637 | 637 |
} |
638 | 638 |
|
639 |
|
|
639 | 640 |
} |
640 | 641 |
|
641 | 642 |
private void refreshCdmInstance() { |
... | ... | |
701 | 702 |
if(CdmStore.getManagedServer().getDataSourceName().equals(selectedCdmInstance.getName())) { |
702 | 703 |
return; |
703 | 704 |
} else { |
704 |
final MessageBox messageBox = new MessageBox(shlConnect, SWT.OK | SWT.CANCEL | SWT.ICON_INFORMATION | SWT.APPLICATION_MODAL); |
|
705 |
messageBox.setMessage("A managed CDM server using data source " + CdmStore.getManagedServer().getDataSourceName() + " is already running. Would you like to stop it ?"); |
|
706 |
|
|
707 |
if(messageBox.open() == SWT.OK) { |
|
708 |
Display.getDefault().syncExec(new Runnable() { |
|
709 |
@Override |
|
710 |
public void run() { |
|
711 |
stopManagedServer(); |
|
712 |
} |
|
713 |
}); |
|
714 |
} else { |
|
715 |
return; |
|
716 |
} |
|
705 |
Display.getDefault().syncExec(new Runnable() { |
|
706 |
@Override |
|
707 |
public void run() { |
|
708 |
stopManagedServer(); |
|
709 |
} |
|
710 |
}); |
|
717 | 711 |
} |
718 | 712 |
} |
719 | 713 |
|
714 |
|
|
720 | 715 |
Job job = new Job("Managed CDM Server Launch") { |
721 | 716 |
|
722 | 717 |
@Override |
... | ... | |
732 | 727 |
monitor.worked(1); |
733 | 728 |
CdmStore.setManagedServer(new CDMServer(selectedCdmInstance.getName(), managedServerConfigFile)); |
734 | 729 |
monitor.subTask("Starting Managed CDM Server. This may take a while."); |
735 |
CdmStore.getManagedServer().start(false); |
|
730 |
CdmStore.getManagedServer().start(false, RemotingLoginDialog.this);
|
|
736 | 731 |
int serverUnits = 0; |
737 | 732 |
|
738 | 733 |
// the following loop is a 'fake' progress monitoring where the progress |
739 | 734 |
// bar is advanced by one unit every second until maxUnits -2 |
740 |
while(!CdmStore.getManagedServer().isStarted() || CdmStore.getManagedServer().getCurrentException() != null) {
|
|
735 |
while(!CdmStore.getManagedServer().isStarted()) { |
|
741 | 736 |
if(serverUnits < maxUnits - 2) { |
742 | 737 |
try { |
743 | 738 |
Thread.sleep(1000); |
... | ... | |
785 | 780 |
} |
786 | 781 |
|
787 | 782 |
private void stopManagedServer() { |
788 |
if(isActiveCdmInstanceRunningInManagedServer()) { |
|
789 |
final MessageBox messageBox = new MessageBox(shlConnect, SWT.OK | SWT.ICON_INFORMATION | SWT.APPLICATION_MODAL); |
|
790 |
messageBox.setMessage("Cannot stop managed CDM server while user is connected"); |
|
791 |
messageBox.open(); |
|
792 |
return; |
|
793 |
} |
|
794 | 783 |
try { |
795 | 784 |
CdmStore.getManagedServer().stop(); |
796 | 785 |
} catch (Exception e) { |
... | ... | |
802 | 791 |
true); |
803 | 792 |
} |
804 | 793 |
CdmStore.setManagedServer(null); |
805 |
refreshCdmInstance();
|
|
794 |
updateManagedServerControls();
|
|
806 | 795 |
} |
807 | 796 |
|
808 | 797 |
private int getManagedServerPort() { |
... | ... | |
1057 | 1046 |
txtServerCDMVersion.setText(""); |
1058 | 1047 |
} |
1059 | 1048 |
|
1049 |
/** |
|
1050 |
* {@inheritDoc} |
|
1051 |
*/ |
|
1052 |
@Override |
|
1053 |
public void handleError(final Throwable t) { |
|
1054 |
|
|
1055 |
Display.getDefault().syncExec(new Runnable() { |
|
1056 |
@Override |
|
1057 |
public void run() { |
|
1058 |
serverJob.cancel(); |
|
1059 |
|
|
1060 |
String title = "CDM Server launch error"; |
|
1061 |
String message = t.getMessage(); |
|
1062 |
|
|
1063 |
|
|
1064 |
MessagingUtils.errorDialog(title, |
|
1065 |
this, |
|
1066 |
message, |
|
1067 |
TaxeditorStorePlugin.PLUGIN_ID, |
|
1068 |
t, |
|
1069 |
true); |
|
1070 |
} |
|
1071 |
}); |
|
1072 |
} |
|
1073 |
|
|
1060 | 1074 |
|
1061 | 1075 |
} |
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/httpinvoker/CdmServerTest.java | ||
---|---|---|
24 | 24 |
import eu.etaxonomy.taxeditor.remoting.server.CDMServerUtils; |
25 | 25 |
import eu.etaxonomy.taxeditor.webapp.CDMEmbeddedServerException; |
26 | 26 |
import eu.etaxonomy.taxeditor.webapp.CDMServer; |
27 |
import eu.etaxonomy.taxeditor.webapp.ICDMServerError; |
|
27 | 28 |
|
28 | 29 |
|
29 | 30 |
/** |
... | ... | |
49 | 50 |
URL mgdDatasourcesConfigURL = bundle.getEntry("src/test/resources/.cdmLibrary/writableResources/mgd.datasources.xml"); |
50 | 51 |
File mgdDatasourcesConfigFile = new File(FileLocator.resolve(mgdDatasourcesConfigURL).toURI()); |
51 | 52 |
CDMServer cdmServer = new CDMServer("cdmTest", mgdDatasourcesConfigFile); |
52 |
cdmServer.start(); |
|
53 |
cdmServer.start(new ICDMServerError() { |
|
54 |
@Override |
|
55 |
public void handleError(Throwable t) { |
|
56 |
Assert.fail("Error starting server. Reason : " + t.getMessage()); |
|
57 |
} |
|
58 |
}); |
|
53 | 59 |
try { |
54 | 60 |
cdmServer.stop(); |
55 | 61 |
} catch (Exception e) { |
56 | 62 |
e.printStackTrace(); |
57 |
Assert.fail("Server could not be stopped. Reason : " + e.getMessage());
|
|
63 |
Assert.fail("Error stopping server. Reason : " + e.getMessage());
|
|
58 | 64 |
} |
59 | 65 |
} |
60 | 66 |
} |
eu.etaxonomy.taxeditor.webapp/src/main/java/eu/etaxonomy/taxeditor/webapp/CDMServer.java | ||
---|---|---|
31 | 31 |
import org.eclipse.core.runtime.Platform; |
32 | 32 |
import org.eclipse.jetty.server.Server; |
33 | 33 |
import org.eclipse.jetty.util.StringUtil; |
34 |
import org.eclipse.jetty.util.preventers.AppContextLeakPreventer; |
|
34 | 35 |
import org.eclipse.jetty.webapp.WebAppContext; |
35 | 36 |
import org.osgi.framework.Bundle; |
36 | 37 |
|
... | ... | |
58 | 59 |
private int httpPort = 9090; |
59 | 60 |
private final String contextPath = "/"; |
60 | 61 |
|
61 |
private static Exception serverException = null; |
|
62 |
|
|
63 | 62 |
private File warFile; |
64 | 63 |
private Server server; |
65 | 64 |
|
... | ... | |
102 | 101 |
|
103 | 102 |
server = new Server(httpPort); |
104 | 103 |
|
104 |
server.addBean(new AppContextLeakPreventer()); |
|
105 |
|
|
105 | 106 |
WebAppContext webapp = new WebAppContext(); |
106 | 107 |
webapp.setContextPath(contextPath); |
107 | 108 |
webapp.setWar(warFile.getAbsolutePath()); |
... | ... | |
148 | 149 |
throw new CDMEmbeddedServerException("Could not find a free TCP/IP port to start embedded Jetty HTTP Server on"); |
149 | 150 |
} |
150 | 151 |
|
151 |
public void start() throws CDMEmbeddedServerException { |
|
152 |
start(true); |
|
152 |
public void start(ICDMServerError cdmServerError) throws CDMEmbeddedServerException {
|
|
153 |
start(true, cdmServerError);
|
|
153 | 154 |
} |
154 | 155 |
|
155 |
public void start(boolean wait) throws CDMEmbeddedServerException { |
|
156 |
public void start(boolean wait, final ICDMServerError cdmServerError) throws CDMEmbeddedServerException {
|
|
156 | 157 |
|
157 | 158 |
if(server == null) { |
158 | 159 |
throw new CDMEmbeddedServerException("Server is already disposed"); |
... | ... | |
181 | 182 |
try { |
182 | 183 |
server.start(); |
183 | 184 |
server.join(); |
184 |
} catch (Exception e) {
|
|
185 |
serverException = e;
|
|
185 |
} catch (Throwable t) {
|
|
186 |
cdmServerError.handleError(t);
|
|
186 | 187 |
} |
187 | 188 |
} |
188 | 189 |
}; |
189 |
serverException = null; |
|
190 |
|
|
190 | 191 |
serverThread.start(); |
191 | 192 |
|
192 | 193 |
if(wait) { |
193 |
while(!server.isStarted() || serverException != null) {}
|
|
194 |
while(!server.isStarted()) {} |
|
194 | 195 |
|
195 |
if(serverException != null) { |
|
196 |
throw new CDMEmbeddedServerException(serverException); |
|
197 |
} |
|
198 | 196 |
} |
199 | 197 |
} |
200 | 198 |
|
201 |
public Exception getCurrentException() { |
|
202 |
return serverException; |
|
203 |
} |
|
204 |
|
|
205 | 199 |
public boolean isAlive() { |
206 | 200 |
return server.isRunning() || server.isStarting() || server.isStarted(); |
207 | 201 |
} |
eu.etaxonomy.taxeditor.webapp/src/main/java/eu/etaxonomy/taxeditor/webapp/ICDMServerError.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2015 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
package eu.etaxonomy.taxeditor.webapp; |
|
11 |
|
|
12 |
/** |
|
13 |
* @author cmathew |
|
14 |
* @date 16 Nov 2015 |
|
15 |
* |
|
16 |
*/ |
|
17 |
public interface ICDMServerError { |
|
18 |
|
|
19 |
public void handleError(Throwable t); |
|
20 |
|
|
21 |
} |
Also available in: Unified diff
#4073 Add error callback for CDM Server start