Skip to content

Commit

Permalink
[Community wps-remote] WPS Remote: Logging - propagate messages to th…
Browse files Browse the repository at this point in the history
…e listeners
  • Loading branch information
Alessio Fabiani committed Nov 8, 2018
1 parent 9c4d473 commit 5b55ad6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.logging.Logger;
import org.geotools.process.Process;
import org.geotools.process.ProcessException;
import org.geotools.util.SimpleInternationalString;
import org.geotools.util.logging.Logging;
import org.opengis.feature.type.Name;
import org.opengis.util.ProgressListener;
Expand Down Expand Up @@ -183,7 +184,7 @@ public void setOutputs(Map<String, Object> outputs) {

@Override
public void progress(final String pId, final Double progress) {
if (pId.equals(pid)) {
if (pId != null && pId.equals(pid)) {
listener.progress(progress.floatValue());
}

Expand All @@ -194,7 +195,7 @@ public void progress(final String pId, final Double progress) {

@Override
public void complete(String pId, Object outputs) {
if (pId.equals(pid)) {
if (pId != null && pId.equals(pid)) {
listener.complete();

try {
Expand Down Expand Up @@ -240,4 +241,11 @@ public void exceptionOccurred(final String pId, Exception cause, Map<String, Obj
}
doneSignal.countDown();
}

@Override
public void setTask(String pId, String logMessage) {
if (pId != null && pId.equals(pid)) {
listener.setTask(new SimpleInternationalString(logMessage));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,13 @@ public interface RemoteProcessClientListener {
* @param metadata
*/
public void exceptionOccurred(final String pId, Exception cause, Map<String, Object> metadata);

/**
* Expose a log message to the {@link RemoteProcess} progress listener associated to the remote
* service with the unique @param pId
*
* @param pId
* @param logMessage
*/
public void setTask(final String pId, final String logMessage);
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public void handleSignal(

// NOTIFY LISTENERS
for (RemoteProcessClientListener listener : xmppClient.getRemoteClientListeners()) {
listener.setTask(pID, cause.getLocalizedMessage());
listener.exceptionOccurred(pID, cause, metadata);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.geoserver.wps.remote.RemoteProcessClientListener;
import org.geotools.util.logging.Logging;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
Expand Down Expand Up @@ -47,9 +48,14 @@ public void handleSignal(
LOGGER.fine(
"Could not correctly parse the Log level; using the default one 'INFO'.");
}
LOGGER.log(
logLevel,
"[" + pID + "]" + URLDecoder.decode(signalArgs.get("message"), "UTF-8"));
String logMessage =
"[" + pID + "]" + URLDecoder.decode(signalArgs.get("message"), "UTF-8");
LOGGER.log(logLevel, logMessage);

// NOTIFY LISTENERS
for (RemoteProcessClientListener listener : xmppClient.getRemoteClientListeners()) {
listener.setTask(pID, logMessage);
}
} catch (Exception e) {
LOGGER.log(
Level.SEVERE,
Expand Down

0 comments on commit 5b55ad6

Please sign in to comment.