View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.example.geomail.components;
8   
9   import org.mule.api.MuleEventContext;
10  import org.mule.api.lifecycle.Callable;
11  
12  import java.util.ArrayList;
13  import java.util.List;
14  import java.util.Random;
15  
16  /**
17   * TODO
18   */
19  public class DataGenerator implements Callable
20  {
21      private Random generator = new Random();
22      private int batchSize = 10;
23      
24      public Object onCall(MuleEventContext eventContext) throws Exception
25      {
26          eventContext.getMessage().setOutboundProperty("from.email.address", "testdatagenerator@geomail.com");
27  
28          // Create multiple IPs for each run since many addresses will not be valid
29          List<String> ipAddresses = new ArrayList<String>(batchSize);
30          for (int i = 0; i < batchSize; i++)
31          {
32              String address = new StringBuffer().append(generator.nextInt(255)).append(".")
33                  .append(generator.nextInt(255)).append(".").append(generator.nextInt(255)).
34                  append(".").append(generator.nextInt(255)).toString();
35              ipAddresses.add(address);
36          }
37  
38          return ipAddresses;
39      }
40  
41      public int getBatchSize()
42      {
43          return batchSize;
44      }
45  
46      public void setBatchSize(int batchSize)
47      {
48          this.batchSize = batchSize;
49      }
50  }