Skip to content

Commit

Permalink
Merge pull request #33 from eclipse/bug/diagnostic_error_for_multi_in…
Browse files Browse the repository at this point in the history
…stances

Bug 552684 - [Passage] Server should show diagnostic when address in use.
ruspl-afed authored Nov 5, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 834c35a + 28e07b7 commit 990fe5f
Showing 8 changed files with 88 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
import org.eclipse.passage.lbc.api.BackendCluster;
import org.eclipse.passage.lbc.api.BackendLauncher;
import org.eclipse.passage.lbc.internal.equinox.i18n.EquinoxMessages;
import org.eclipse.passage.lic.api.LicensingResult;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
@@ -63,10 +64,21 @@ public void unbindLogger(LoggerFactory factory) {

@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
public void bindServerHandler(BackendLauncher serverHandler, Map<String, Object> context) {
if (serverHandler != null) {
logger.info(NLS.bind(EquinoxMessages.ServerRunnerImpl_i_launcher_bind, serverHandler));
serverHandler.launch(context);
logger.info(NLS.bind(EquinoxMessages.ServerRunnerImpl_i_launcher_bind, serverHandler));
LicensingResult result = serverHandler.launch(context);
switch (result.getSeverity()) {
case LicensingResult.ERROR:
logger.error(result.getMessage());
logger.error(
NLS.bind(EquinoxMessages.ServerRunnerImpl_error_launching, serverHandler.getClass().getName()));
break;
case LicensingResult.OK:
logger.info(result.getMessage());
backendLaunchers.add(serverHandler);
break;
default:
logger.warn(result.getMessage());
break;
}
}

Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@ public class EquinoxMessages extends NLS {
public static String ServerConditionArbiter_i_reserv;
public static String ServerRunnerImpl_i_launcher_bind;
public static String ServerRunnerImpl_i_launcher_unbind;
public static String ServerRunnerImpl_error_launching;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, EquinoxMessages.class);
Original file line number Diff line number Diff line change
@@ -23,3 +23,4 @@ ServerConditionArbiter_i_not_reserved=Condition was not reserved
ServerConditionArbiter_i_reserv=Condition in reserve
ServerRunnerImpl_i_launcher_bind=Bind BackendLauncher {0}
ServerRunnerImpl_i_launcher_unbind=Unbind BackendLauncher {0}
ServerRunnerImpl_error_launching=Could not start BackendLauncher instance:"{0}".
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.osgi.util.NLS;
import org.eclipse.passage.lbc.api.BackendLauncher;
import org.eclipse.passage.lbc.api.BackendRequestDispatcher;
import org.eclipse.passage.lbc.internal.jetty.i18n.JettyMessages;
@@ -55,38 +56,45 @@ public void unbindBackendRequestDispatcher(BackendRequestDispatcher dispatcher,

@Override
public LicensingResult launch(Map<String, Object> arguments) {
String source = JettyServerLauncher.class.getName();
if (server != null) {
return LicensingResults.createError(JettyMessages.JettyServerLauncher_e_start_exists, source, new IllegalStateException());
return LicensingResults.createError(JettyMessages.JettyServerLauncher_server_running_error,
LicensingResult.ERROR, new IllegalStateException());
}
// FIXME: extract from arguments
int port = JETTY_PORT_DEFAULT;
server = new Server(port);
try {
server.setHandler(new JettyRequestHandler(requestDispatchers.values()));
server.start();
logger.info(server.getState());
return LicensingResults.createOK(JettyMessages.JettyServerLauncher_ok_start, source);
return LicensingResults.createOK(JettyMessages.JettyServerLauncher_server_start_success);
} catch (Exception e) {
logger.warn(e.getMessage());
return LicensingResults.createError(JettyMessages.JettyServerLauncher_e_start, source, e);
String msg;
if (e.getCause() != null) {
msg = e.getCause().getMessage();
} else {
msg = e.getMessage();
}
return LicensingResults.createError(NLS.bind(JettyMessages.JettyServerLauncher_server_start_error, msg),
LicensingResult.ERROR, e);
}
}

@Override
public LicensingResult terminate() {
String source = JettyServerLauncher.class.getName();
if (server == null) {
return LicensingResults.createError(JettyMessages.JettyServerLauncher_e_stop_not_started, source, new IllegalStateException());
return LicensingResults.createError(JettyMessages.JettyServerLauncher_server_not_started_error, source,
new IllegalStateException());
}
try {
server.stop();
logger.info(server.getState());
server = null;
return LicensingResults.createOK(JettyMessages.JettyServerLauncher_ok_stop, source);
return LicensingResults.createOK(JettyMessages.JettyServerLauncher_server_stop_success, source);
} catch (Exception e) {
logger.warn(e.getMessage());
return LicensingResults.createError(JettyMessages.JettyServerLauncher_e_stop, source, e);
String msg = NLS.bind(JettyMessages.JettyServerLauncher_server_stop_error, e.getMessage());
logger.warn(msg);
return LicensingResults.createError(msg, source, e);
}
}

Original file line number Diff line number Diff line change
@@ -16,12 +16,13 @@

public class JettyMessages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.passage.lbc.internal.jetty.i18n.JettyMessages"; //$NON-NLS-1$
public static String JettyServerLauncher_e_start;
public static String JettyServerLauncher_e_start_exists;
public static String JettyServerLauncher_e_stop;
public static String JettyServerLauncher_e_stop_not_started;
public static String JettyServerLauncher_ok_start;
public static String JettyServerLauncher_ok_stop;
public static String JettyServerLauncher_server_start_error;
public static String JettyServerLauncher_server_running_error;
public static String JettyServerLauncher_server_not_started_error;
public static String JettyServerLauncher_server_stop_error;

public static String JettyServerLauncher_server_start_success;
public static String JettyServerLauncher_server_stop_success;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, JettyMessages.class);
Original file line number Diff line number Diff line change
@@ -11,9 +11,10 @@
# ArSysOp - initial API and implementation
###############################################################################

JettyServerLauncher_e_start=Jetty start: Error
JettyServerLauncher_e_start_exists=Jetty start: already exists
JettyServerLauncher_e_stop=Jetty stop: Error
JettyServerLauncher_e_stop_not_started=Jetty stop: not started
JettyServerLauncher_ok_start=Jetty start: OK
JettyServerLauncher_ok_stop=Jetty stop: OK
JettyServerLauncher_server_start_error=Launch Jetty Server with error: "{0}".
JettyServerLauncher_server_running_error=The error of an attempt to launch another one instance of Jetty Server, cause the server already running.
JettyServerLauncher_server_stop_error=Stops Jetty Server with error: {0}
JettyServerLauncher_server_not_started_error=Jetty Server was not started.

JettyServerLauncher_server_start_success=Jetty Server successfully started
JettyServerLauncher_server_stop_success=Jetty Server stopped successfully
35 changes: 35 additions & 0 deletions features/org.eclipse.passage.lbc.target.feature/feature.xml
Original file line number Diff line number Diff line change
@@ -73,4 +73,39 @@
version="0.0.0"
unpack="false"/>

<plugin
id="org.apache.httpcomponents.httpclient"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

<plugin
id="org.apache.httpcomponents.httpcore"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

<plugin
id="org.apache.commons.codec"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

<plugin
id="org.apache.commons.logging"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

<plugin
id="org.slf4j.api"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

</feature>
Original file line number Diff line number Diff line change
@@ -26,6 +26,9 @@
<vm>
</vm>

<plugins>
</plugins>

<features>
<feature id="org.eclipse.equinox.server.core"/>
<feature id="org.eclipse.equinox.server.jetty"/>
@@ -36,13 +39,11 @@
<feature id="org.eclipse.ecf.filetransfer.ssl.feature"/>
<feature id="org.eclipse.ecf.core.feature"/>
<feature id="org.eclipse.ecf.filetransfer.feature"/>
<feature id="org.eclipse.ecf.filetransfer.httpclient45.feature" installMode="root"/>
<feature id="org.eclipse.passage.lic.net.feature" installMode="root"/>
<feature id="org.eclipse.passage.lic.equinox.feature" installMode="root"/>
<feature id="org.eclipse.passage.lic.oshi.feature" installMode="root"/>
<feature id="org.eclipse.passage.lbc.target.feature"/>
<feature id="org.eclipse.passage.lbc.execute.feature"/>
</features>
</features>

<configurations>
<plugin id="org.apache.felix.scr" autoStart="true" startLevel="2" />

0 comments on commit 990fe5f

Please sign in to comment.