Skip to content

Commit

Permalink
#346 Async: implement simple and important JSON parameters for commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Polevoy committed Jun 6, 2017
1 parent 73f67a7 commit 2f25d2e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions javalite-async/src/main/java/org/javalite/async/Command.java
Expand Up @@ -18,14 +18,18 @@
package org.javalite.async;

import com.thoughtworks.xstream.XStream;
import org.javalite.common.JsonHelper;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

import static org.javalite.common.Collections.map;

/**
* Super class of all commands. Only the method {@link #execute()} is to be provided by subclasses to
* do real application work.
Expand All @@ -36,6 +40,8 @@ public abstract class Command {

private String jmsMessageId;

private Map params = map("class", getClass().getSimpleName());

private static final XStream X_STREAM = new XStream(new CDATAXppDriver());

/**
Expand Down Expand Up @@ -106,4 +112,23 @@ public String getJMSMessageID() {
public void setJMSMessageID(String jmsMessageId) {
this.jmsMessageId = jmsMessageId;
}

/**
* Sets parameters and their values to reflect by the {@link #toJson()} method.
*
* @param params important parameters of this command - tings you want to see in a log file.
*/
public void setJsonParams(Map params){
this.params = params;
this.params.put("class", getClass().getSimpleName());
}

/**
* Used by writing returned value to the log.
*
* @return JSON representation of this command.
*/
public String toJson(){
return JsonHelper.toJsonString(params);
}
}

0 comments on commit 2f25d2e

Please sign in to comment.