User Tools

Site Tools


sdk_example

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Last revision Both sides next revision
sdk_example [2015/08/10 17:31]
dloo
sdk_example [2015/08/10 17:36]
dloo
Line 4: Line 4:
  
 <​code>​ <​code>​
-    ​import com.perspectium.api.Message;​ +import com.perspectium.api.Message;​ 
-    import com.perspectium.logging.PerspectiumLogger;​ +import com.perspectium.logging.PerspectiumLogger;​ 
-    import com.perspectium.replicator.ASharer;​ +import com.perspectium.replicator.ASharer;​ 
-    import com.perspectium.replicator.AgentConfig;​+import com.perspectium.replicator.AgentConfig;​
  
-    ​public class EchoSharer extends ASharer {+public class EchoSharer extends ASharer { 
 +    final static PerspectiumLogger Log = PerspectiumLogger.create(EchoSharer.class);​ 
 + 
 +    private static final String DEFAULT_ECHO_TEXT = "Hi there - this is an echoed message "; 
 +    private static final String ECHO_MESSAGE = "​echo_message";​ 
 +    private static final String ECHO_ITERATIONS = "​echo_iterations";​
   
- final static PerspectiumLogger Log PerspectiumLogger.create(EchoSharer.class);+    private Message fMessage; 
 +    private String fEchoText;​ 
 +    private int fEchoIterations ​1;
   
- private static final String DEFAULT_ECHO_TEXT = "Hi there - this is an echoed message "; +    ​public void processMessages() { 
-  +        try { 
- private static final String ECHO_MESSAGE = "​echo_message";​ +            for (int iteration = 1; iteration <= fEchoIterations;​ iteration++) { 
- private static final String ECHO_ITERATIONS = "​echo_iterations";​ +                String text = fEchoText + " " + String.valueOf(iteration);​ 
-  +                Log.info("​publishing text: " + text);
- private Message fMessage; +
- private String fEchoText;​ +
-  +
- private int fEchoIterations = 1; +
-  +
- public void processMessages() { +
-  +
- try { +
- for (int iteration = 1; iteration <= fEchoIterations;​ iteration++) { +
- String text = fEchoText + " " + String.valueOf(iteration);​ +
- Log.info("​publishing text: " + text);+
   
- fMessage = new Message.Builder() +                ​fMessage = new Message.Builder() 
-  .topic(AgentConfig.getTopic(fTaskName)) +                        .topic(AgentConfig.getTopic(fTaskName)) 
-  .type(AgentConfig.getType(fTaskName)) +                        .type(AgentConfig.getType(fTaskName)) 
-  .key(AgentConfig.getKey(fTaskName)) +                        .key(AgentConfig.getKey(fTaskName)) 
-  .name(AgentConfig.getName(fTaskName)) +                        .name(AgentConfig.getName(fTaskName)) 
-  .value(text) +                        .value(text) 
-  .build(); +                        .build(); 
-  + 
- publish(fMessage);​ +                publish(fMessage);​ 
- +            
-  + 
- Log.info(String.format("​task:​ %s echoed %s message(s) to the queue: %s", ​ fTaskName, fEchoIterations,​ fQueueName));​+            Log.info(String.format("​task:​ %s echoed %s message(s) to the queue: %s", ​ fTaskName, fEchoIterations,​ fQueueName));​
   
- } catch (Exception e) { +        ​} catch (Exception e) { 
- Log.error("​Error:"​ + e.getMessage());​ +            Log.error("​Error:"​ + e.getMessage());​ 
- e.printStackTrace();​ +            e.printStackTrace();​ 
- }  + }  
- }+    }
  
- @Override +    ​@Override 
- public void initialize(final String taskName) { +    public void initialize(final String taskName) { 
- super.initialize(taskName);​+        super.initialize(taskName);​
   
- fEchoText = AgentConfig.getStringValue(fTaskName,​ ECHO_MESSAGE);​+        ​fEchoText = AgentConfig.getStringValue(fTaskName,​ ECHO_MESSAGE);​
   
- if (fEchoText == null) +        ​if (fEchoText == null) 
- fEchoText = DEFAULT_ECHO_TEXT;​+            fEchoText = DEFAULT_ECHO_TEXT;​
   
- if (AgentConfig.taskHasElement(fTaskName,​ ECHO_ITERATIONS)) +        ​if (AgentConfig.taskHasElement(fTaskName,​ ECHO_ITERATIONS)) 
- fEchoIterations = AgentConfig.getIntValue(fTaskName,​ ECHO_ITERATIONS);​+            fEchoIterations = AgentConfig.getIntValue(fTaskName,​ ECHO_ITERATIONS);​
   
- +    ​
-   ​}+}
 </​code>​ </​code>​
        
sdk_example.txt · Last modified: 2015/08/10 17:39 by dloo