package org.robbins.raspberry.pi.service;

import org.robbins.raspberry.pi.exceptions.RaspberryPiAppException;
import org.robbins.raspberry.pi.model.PiAction;
import org.robbins.raspberry.pi.model.RegisteredActions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class PiActionServiceDelegator {

    @Autowired
    private Map<String, PiActionService> actionServiceMap;

    public void invokeAction(final PiAction action) throws RaspberryPiAppException {
        PiActionService service = actionServiceMap.get(action.getName());
        service.invokeAction(action);
    }

    public RegisteredActions listRegisteredActions() {
        RegisteredActions registeredActions = new RegisteredActions();
        registeredActions.setActions(actionServiceMap.keySet());
        return registeredActions;
    }
}

@@ -272,16 +272,72 @@
 owired;%0A
+import org.springframework.scheduling.annotation.Async;%0A
 import o
@@ -524,16 +524,27 @@
 ceMap;%0A%0A
+    @Async%0A
     publ

add @Async to action service invoke