public void startActivityWorker() throws Exception { // start activity AmazonSimpleWorkflow swfClient = AmazonSWFUtils.createSWFClient(); String domain = ConfigHelper.getInstance().getDomain(); // create client instance activityWorker = new ActivityWorker(swfClient, domain, Constants.ACTIVTY_LIST_JPL); // register Activities activityWorker.addActivitiesImplementation( new JPLDatacenterImpl() { int indexX = 0; int indexY = 0; @Override public synchronized void showResult(CombineResult result) { ActivityExecutionContextProvider provider = new ActivityExecutionContextProviderImpl(); ActivityExecutionContext aec = provider.getActivityExecutionContext(); String workflowId = aec.getWorkflowExecution().getWorkflowId(); int w = 500; int h = 300; if (indexX == 5) { indexX = 0; indexY = indexY == 0 ? 1 : 0; } else { indexX++; } int x = indexX * w; int y = indexY * h; BufferedImage partImage = baseImage.getSubimage(x, y, w, h); JLabel resultLabel = new JLabel(new ImageIcon(partImage)); // JDialog resultDialog = new JDialog(frame,"RESULT:"+workflowId); JFrame resultDialog = new JFrame("RESULT:" + workflowId); resultDialog.setSize(w, h); Point parentLocation = frame.getLocation(); int resultX = parentLocation.x + frame.getWidth() / 2 - w / 2; int resultY = parentLocation.y + frame.getHeight() / 2 - y / 2; System.out.println(resultX + " " + resultY); resultDialog.setLocation(new Point(Math.max(0, resultX), Math.max(0, resultY))); resultDialog.add(resultLabel); resultDialog.setVisible(true); resultDialog.toFront(); } }); // start task pooling activityWorker.start(); }
/** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { AmazonSimpleWorkflow swfService = TcgaWorkflowConfigHelper.getSWFClient(); String domain = TcgaWorkflowConfigHelper.getStack(); final ActivityWorker worker = new ActivityWorker(swfService, domain, TcgaActivities.ACTIVITIES_TASK_LIST); // Create activity implementations TcgaActivities tcgaActivitiesImpl = new TcgaActivitiesImpl(); worker.addActivitiesImplementation(tcgaActivitiesImpl); worker.start(); System.out.println("Activity Worker Started for Task List: " + worker.getTaskListToPoll()); Runtime.getRuntime() .addShutdownHook( new Thread() { @Override public void run() { try { worker.shutdownAndAwaitTermination(10, TimeUnit.MINUTES); System.out.println("Activity Worker Exited."); } catch (InterruptedException e) { e.printStackTrace(); } } }); System.out.println("Please press any key to terminate service."); try { System.in.read(); } catch (IOException e) { e.printStackTrace(); } System.exit(0); }
public static void main(String[] args) throws Exception { ClientConfiguration config = new ClientConfiguration().withSocketTimeout(70 * 1000); String swfAccessId = System.getProperty("AWS_ACCESS_KEY_ID"); String swfSecretKey = System.getProperty("AWS_SECRET_KEY"); AWSCredentials awsCredentials = new BasicAWSCredentials(swfAccessId, swfSecretKey); AmazonSimpleWorkflow service = new AmazonSimpleWorkflowClient(awsCredentials, config); service.setEndpoint("https://swf.us-east-1.amazonaws.com"); String domain = "hoopla-sandbox"; String taskListToPoll = "BaconSWFTaskList"; ActivityWorker aw = new ActivityWorker(service, domain, taskListToPoll); aw.addActivitiesImplementation(new GreeterActivitiesImpl()); aw.start(); WorkflowWorker wfw = new WorkflowWorker(service, domain, taskListToPoll); wfw.addWorkflowImplementationType(GreeterWorkflowImpl.class); wfw.start(); }