Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License"). You may not
   * use this file except in compliance with the License. A copy of the License is
   * located at
   * 
   * http://aws.amazon.com/apache2.0
   * 
  * or in the "license" file accompanying this file. This file is distributed on
  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  * express or implied. See the License for the specific language governing
  * permissions and limitations under the License.
  */
 package com.amazonaws.services.simpleworkflow.flow.worker;
 
 
 
 
 public class GenericActivityWorker extends GenericWorker {
 
     private static final Log log = LogFactory.getLog(GenericActivityWorker.class);
 
     private static final String POLL_THREAD_NAME_PREFIX = "SWF Activity Poll ";
 
     private static final String ACTIVITY_THREAD_NAME_PREFIX = "SWF Activity ";
 
 
     private int taskExecutorThreadPoolSize = 100;
 
     public GenericActivityWorker(AmazonSimpleWorkflow serviceString domainString taskListToPoll) {
         super(servicedomaintaskListToPoll);
         if (service == null) {
             throw new IllegalArgumentException("service");
         }
     }
 
     public GenericActivityWorker() {
         super();
     }
 
         return ;
     }
 
     public void setActivityImplementationFactory(ActivityImplementationFactory activityImplementationFactory) {
         this. = activityImplementationFactory;
     }
 
     public int getTaskExecutorThreadPoolSize() {
         return ;
     }
 
     public void setTaskExecutorThreadPoolSize(int taskExecutorThreadPoolSize) {
         if (taskExecutorThreadPoolSize < 1) {
             throw new IllegalArgumentException("0 or negative taskExecutorThreadPoolSize");
         }
         checkStarted();
         this. = taskExecutorThreadPoolSize;
     }
 
     protected Semaphore createPollSemaphore() {
         return new Semaphore();
     }
 
     @Override
     public String toString() {
         return this.getClass().getSimpleName() + " [super=" + super.toString() + ", taskExecutorThreadPoolSize="
                 +  + "]";
     }
 
     @Override
     protected String getPollThreadNamePrefix() {
         return  + getTaskListToPoll() + " ";
     }
 
     @Override
     protected TaskPoller createPoller() {
         ThreadPoolExecutor tasksExecutor = new ThreadPoolExecutor(1, , 1, .,
                 new SynchronousQueue<Runnable>());
         tasksExecutor.setThreadFactory(new ExecutorThreadFactory( + " " + getTaskListToPoll() + " "));
         tasksExecutor.setRejectedExecutionHandler(new BlockCallerPolicy());
        return new ActivityTaskPoller(getTaskListToPoll(), tasksExecutor);
    }
    @Override
    public void registerTypesToPoll() {
    }
    public static void registerActivityTypes(AmazonSimpleWorkflow serviceString domainString defaultTaskList,
            ActivityImplementationFactory activityImplementationFactory) {
        for (ActivityType activityType : activityImplementationFactory.getActivityTypesToRegister()) {
            try {
                ActivityImplementation implementation = activityImplementationFactory.getActivityImplementation(activityType);
                if (implementation == null) {
                    throw new IllegalStateException("No implementation found for type needed registration: " + activityType);
                }
                ActivityTypeRegistrationOptions registrationOptions = implementation.getRegistrationOptions();
                if (registrationOptions != null) {
                    registerActivityType(servicedomainactivityTyperegistrationOptionsdefaultTaskList);
                }
            }
            catch (TypeAlreadyExistsException ex) {
                if (.isTraceEnabled()) {
                    .trace("Activity version already registered: " + activityType.getName() + "_" + activityType.getVersion());
                }
            }
        }
    }
    public static void registerActivityType(AmazonSimpleWorkflow serviceString domainActivityType activityType,
            ActivityTypeRegistrationOptions registrationOptionsString taskListToPollthrows AmazonServiceException {
        RegisterActivityTypeRequest registerActivity = new RegisterActivityTypeRequest();
        registerActivity.setDomain(domain);
        String taskList = registrationOptions.getDefaultTaskList();
        if (taskList == null) {
            taskList = taskListToPoll;
        }
        else if (taskList.equals(.)) {
            taskList = null;
        }
        if (taskList != null && !taskList.isEmpty()) {
            registerActivity.setDefaultTaskList(new TaskList().withName(taskList));
        }
        registerActivity.setName(activityType.getName());
        registerActivity.setVersion(activityType.getVersion());
        registerActivity.setDefaultTaskStartToCloseTimeout(FlowHelpers.secondsToDuration(registrationOptions.getDefaultTaskStartToCloseTimeoutSeconds()));
        registerActivity.setDefaultTaskScheduleToCloseTimeout(FlowHelpers.secondsToDuration(registrationOptions.getDefaultTaskScheduleToCloseTimeoutSeconds()));
        registerActivity.setDefaultTaskHeartbeatTimeout(FlowHelpers.secondsToDuration(registrationOptions.getDefaultTaskHeartbeatTimeoutSeconds()));
        registerActivity.setDefaultTaskScheduleToStartTimeout(FlowHelpers.secondsToDuration(registrationOptions.getDefaultTaskScheduleToStartTimeoutSeconds()));
        registerActivity.setDefaultTaskPriority(FlowHelpers.taskPriorityToString(registrationOptions.getDefaultTaskPriority()));
        
        if (registrationOptions.getDescription() != null) {
            registerActivity.setDescription(registrationOptions.getDescription());
        }
        service.registerActivityType(registerActivity);
        if (.isInfoEnabled()) {
            .info("regisered activity type: " + activityType);
        }
    }
    @Override
    protected void checkRequredProperties() {
        checkRequiredProperty("activityImplementationFactory");
    }
New to GrepCode? Check out our FAQ X