well, indeed.Here is the complete asynchronous method :

@Stateless
  | 36  @Name("importRunAction")
  | 37  public class ImportRunAction implements ImportRunActionInterface {
  | 38  
  | 39          @In
  | 40          EntityManager entityManager;
  | 41  
  | 42          public ImportRunAction() {
  | 43          }
  | 44  
  | 45          @Override
  | 46          public void run(Import importRule, User user) {
  | 47  
  | 48                  int bookCount = 0;
  | 49                  boolean success = true;
  | 50                  File passthroughData = null;
  | 51                  Datasource datasource = importRule.getDataSource();
  | 52  
  | 53                  List<Object> passthroughMetaData = null;
  | 54                  List<MicroStepAction> microActions = new 
ArrayList<MicroStepAction>();
  | 55  
  | 56                  Collection<DataType> previousDataType;
  | 57                  previousDataType = new ArrayList<DataType>();
  | 58                  previousDataType.add(DataType.NONE);
  | 59  
  | 60                  Event importRunEvent = Tools.getNewEvent();
  | 61                  importRunEvent.setUser(user);
  | 62                  importRunEvent.setIsParent(true);
  | 63                  importRunEvent.setObjectType(IMPORT);
  | 64                  importRunEvent.setName(datasource.getName());
  | 65  
  | 66                  importRule.setStartDate(new 
Date(System.currentTimeMillis()));
  | 67  
  | 68                  /*
  | 69                   * Asynchronous and ongoing task progress reporting
  | 70                   */
  | 71                  AsynchronousImportController aip = 
(AsynchronousImportController) Component
  | 72                                  
.getInstance("asynchronousImportController");
  | 73                  Progress progress = aip.getProgress(importRule);
  | 74  
  | 75                  try {
  | 76                          for (MicroStep m : importRule.getMicroSteps()) {
  | 77                                  if (!m.isEnabled()) {
  | 78                                          continue;
  | 79                                  }
  | 80                                  if 
(!m.acceptInputDatas(previousDataType)) {
  | 81                                          
FacesMessages.instance().addFromResourceBundle(
  | 82                                                          
"lrb.error.import.incorrectPreviousData");
  | 83                                          aip.remove(importRule);
  | 84                                          throw new Exception(
  | 85                                                          m.getName()
  | 86                                                                          
+ " "
  | 87                                                                          
+ Tools
  | 88                                                                          
                .getTranslation("lrb.error.import.incorrectPreviousData"));
  | 89                                  }
  | 90                                  MicroStepAction msa = (MicroStepAction) 
Class.forName(
  | 91                                                  
"com.lrb.dataImport.microStepActions."
  | 92                                                                  + 
m.getClass().getSimpleName() + "Action")
  | 93                                                  .newInstance();
  | 94                                  msa.setProgress(progress);
  | 95                                  microActions.add(msa);
  | 96                                  msa.setMicroStep(m);
  | 97                                  msa.setInputData(passthroughData);
  | 98                                  
msa.setInputMetaData(passthroughMetaData);
  | 99  
  | 100                                         /* Add all the parameters */
  | 101                                         msa.addParameter("user", user);
  | 102                                         msa.addParameter("datasource", 
datasource);
  | 103                                         msa.addParameter("table", 
importRule.getDataSource()
  | 104                                                         
.getTableName());
  | 105         
  | 106                                         /* Actually run the 
microStepAction */
  | 107                                         success = success && msa.run();
  | 108         
  | 109                                         msa.getEvent().setName(
  | 110                                                         
datasource.getName() + ":" + msa.getEvent().getName());
  | 111                                         
importRunEvent.addChild(msa.getEvent());
  | 112         
  | 113                                         if (success) {
  | 114                                                 passthroughData = 
msa.getOutputData();
  | 115                                                 passthroughMetaData = 
msa.getOutputMetadata();
  | 116                                                 previousDataType = 
m.getOutputDataType();
  | 117         
  | 118                                                 // extract the number 
of rows
  | 119                                                 Object parameter = 
msa.getParameter("rowCount");
  | 120                                                 if (parameter != null 
&& parameter instanceof Integer) {
  | 121                                                         bookCount = 
(Integer) parameter;
  | 122                                                         if (bookCount > 
0) {
  | 123                                                                 
datasource.setBookCount(bookCount);
  | 124                                                         }
  | 125                                                 }
  | 126                                         } else {
  | 127                                                 
FacesMessages.instance().addFromResourceBundle("lrb.error.import.failed");
  | 128                                                 
importRunEvent.setMessage("Failure");
  | 129                                                 importRunEvent.end();
  | 130                                                 
entityManager.persist(importRunEvent);
  | 131                                                 for (MicroStepAction 
action : microActions) {
  | 132                                                         
action.cleanUp();
  | 133                                                 }
  | 134                                                 aip.remove(importRule);
  | 135                                                 throw new 
Exception(importRunEvent.getMessage());
  | 136                                         }
  | 137         
  | 138                                         
importRunEvent.setMessage("Success");
  | 139                                         importRunEvent.end();
  | 140                                         
entityManager.persist(importRunEvent);
  | 141                                 }
  | 142         
  | 143                         } catch (Exception e) {
  | 144                                 
FacesMessages.instance().add(e.getMessage());
  | 145                                 for (MicroStepAction msa : 
microActions) {
  | 146                                         msa.cleanUp();
  | 147                                 }
  | 148                                 e.printStackTrace();
  | 149                                 aip.remove(importRule);
  | 150                         }
  | 151         
  | 152                         for (MicroStepAction msa : microActions) {
  | 153                                 msa.cleanUp();
  | 154                         }
  | 155                         aip.remove(importRule);
  | 156         
  | 157                         datasource.setBookCount(bookCount);
  | 158         
  | 159                         // TODO : find a way to make this work
  | 160                         // entityManager.merge(datasource);
  | 161                 }
  | 162         }

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4098597#4098597

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4098597
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to