View Javadoc

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