Search in sources :

Example 1 with SourceEnvironment

use of me.retrodaredevil.solarthing.actions.environment.SourceEnvironment in project solarthing by wildmountainfarms.

the class ExecutingCommandFeedbackActionNode method createAction.

@Override
public Action createAction(ActionEnvironment actionEnvironment) {
    SourceEnvironment sourceEnvironment = actionEnvironment.getInjectEnvironment().get(SourceEnvironment.class);
    EventReceiverEnvironment eventReceiverEnvironment = actionEnvironment.getInjectEnvironment().get(EventReceiverEnvironment.class);
    OpenSource source = sourceEnvironment.getSource();
    PacketListReceiverHandler packetListReceiverHandler = eventReceiverEnvironment.getEventPacketListReceiverHandler();
    List<Packet> packets = Arrays.asList(new ImmutableExecutionFeedbackPacket(message, category, new OpenSourceExecutionReason(source)));
    return Actions.createRunOnce(() -> {
        LOGGER.debug("Going to upload an execution feedback packet.");
        Instant now = Instant.now();
        packetListReceiverHandler.uploadSimple(now, packets);
    });
}
Also used : Packet(me.retrodaredevil.solarthing.packets.Packet) ImmutableExecutionFeedbackPacket(me.retrodaredevil.solarthing.type.event.feedback.ImmutableExecutionFeedbackPacket) SourceEnvironment(me.retrodaredevil.solarthing.actions.environment.SourceEnvironment) EventReceiverEnvironment(me.retrodaredevil.solarthing.actions.environment.EventReceiverEnvironment) OpenSource(me.retrodaredevil.solarthing.type.open.OpenSource) ImmutableExecutionFeedbackPacket(me.retrodaredevil.solarthing.type.event.feedback.ImmutableExecutionFeedbackPacket) Instant(java.time.Instant) PacketListReceiverHandler(me.retrodaredevil.solarthing.program.PacketListReceiverHandler) OpenSourceExecutionReason(me.retrodaredevil.solarthing.reason.OpenSourceExecutionReason)

Example 2 with SourceEnvironment

use of me.retrodaredevil.solarthing.actions.environment.SourceEnvironment in project solarthing by wildmountainfarms.

the class MateCommandActionNode method createAction.

@Override
public Action createAction(ActionEnvironment actionEnvironment) {
    MateCommandEnvironment mateCommandEnvironment = actionEnvironment.getInjectEnvironment().get(MateCommandEnvironment.class);
    SourceEnvironment sourceEnvironment = actionEnvironment.getInjectEnvironment().get(SourceEnvironment.class);
    Queue<? super SourcedCommand<MateCommand>> queue = mateCommandEnvironment.getQueue();
    OpenSource source = sourceEnvironment.getSource();
    return Actions.createRunOnce(() -> queue.add(new SourcedCommand<>(source, mateCommand)));
}
Also used : SourceEnvironment(me.retrodaredevil.solarthing.actions.environment.SourceEnvironment) MateCommandEnvironment(me.retrodaredevil.solarthing.actions.environment.MateCommandEnvironment) MateCommand(me.retrodaredevil.solarthing.solar.outback.command.MateCommand) OpenSource(me.retrodaredevil.solarthing.type.open.OpenSource) SourcedCommand(me.retrodaredevil.solarthing.commands.command.SourcedCommand)

Example 3 with SourceEnvironment

use of me.retrodaredevil.solarthing.actions.environment.SourceEnvironment in project solarthing by wildmountainfarms.

the class PacketHandlerInit method initHandlers.

public static <T extends PacketHandlingOption & CommandOption> Result initHandlers(T options, Supplier<? extends EnvironmentUpdater> environmentUpdaterSupplier, Collection<? extends PacketHandler> additionalPacketHandlers) throws IOException {
    List<DatabaseConfig> databaseConfigs = ConfigUtil.getDatabaseConfigs(options);
    PacketHandlerBundle packetHandlerBundle = PacketHandlerInit.getPacketHandlerBundle(databaseConfigs, SolarThingConstants.STATUS_DATABASE, SolarThingConstants.EVENT_DATABASE, options.getSourceId(), options.getFragmentId());
    List<PacketHandler> statusPacketHandlers = new ArrayList<>();
    final Runnable updateCommandActions;
    if (options.hasCommands()) {
        LOGGER.info(SolarThingConstants.SUMMARY_MARKER, "Command are enabled!");
        // this is used to determine the state of the system when a command is requested
        LatestPacketHandler latestPacketHandler = new LatestPacketHandler();
        statusPacketHandlers.add(latestPacketHandler);
        Map<String, ActionNode> actionNodeMap = ActionUtil.getActionNodeMap(CONFIG_MAPPER, options);
        ActionNodeDataReceiver commandReceiver = new ActionNodeDataReceiver(actionNodeMap, (source, injectEnvironmentBuilder) -> {
            injectEnvironmentBuilder.add(new NanoTimeProviderEnvironment(NanoTimeProvider.SYSTEM_NANO_TIME)).add(new TimeZoneEnvironment(options.getZoneId())).add(new LatestPacketGroupEnvironment(latestPacketHandler::getLatestPacketCollection)).add(new SourceEnvironment(source)).add(new EventReceiverEnvironment(PacketListReceiverHandlerBundle.createEventPacketListReceiverHandler(SolarMain.getSourceAndFragmentUpdater(options), options.getZoneId(), packetHandlerBundle)));
            EnvironmentUpdater environmentUpdater = environmentUpdaterSupplier.get();
            if (environmentUpdater == null) {
                throw new NullPointerException("The EnvironmentUpdater supplier gave a null value! (Fatal)");
            }
            environmentUpdater.updateInjectEnvironment(source, injectEnvironmentBuilder);
        });
        PacketGroupReceiver mainPacketGroupReceiver = new PacketGroupReceiverMultiplexer(Arrays.asList(commandReceiver, new RequestHeartbeatReceiver(PacketListReceiverHandlerBundle.createEventPacketListReceiverHandler(SolarMain.getSourceAndFragmentUpdater(options), options.getZoneId(), packetHandlerBundle))));
        statusPacketHandlers.add((packetCollection) -> commandReceiver.getActionUpdater().update());
        List<PacketHandler> commandPacketHandlers = CommandUtil.getCommandRequesterHandlerList(databaseConfigs, mainPacketGroupReceiver, options);
        statusPacketHandlers.add(new PacketHandlerMultiplexer(commandPacketHandlers));
        updateCommandActions = () -> commandReceiver.getActionUpdater().update();
    } else {
        LOGGER.info(SolarThingConstants.SUMMARY_MARKER, "Commands are disabled");
        updateCommandActions = () -> {
        };
    }
    statusPacketHandlers.addAll(additionalPacketHandlers);
    statusPacketHandlers.addAll(packetHandlerBundle.getStatusPacketHandlers());
    PacketListReceiverHandlerBundle bundle = PacketListReceiverHandlerBundle.createFrom(options, packetHandlerBundle, statusPacketHandlers);
    return new Result(bundle, updateCommandActions);
}
Also used : TimeZoneEnvironment(me.retrodaredevil.solarthing.actions.environment.TimeZoneEnvironment) EventReceiverEnvironment(me.retrodaredevil.solarthing.actions.environment.EventReceiverEnvironment) NanoTimeProviderEnvironment(me.retrodaredevil.action.node.environment.NanoTimeProviderEnvironment) LatestPacketGroupEnvironment(me.retrodaredevil.solarthing.actions.environment.LatestPacketGroupEnvironment) PacketGroupReceiver(me.retrodaredevil.solarthing.PacketGroupReceiver) ArrayList(java.util.ArrayList) ActionNode(me.retrodaredevil.action.node.ActionNode) RequestHeartbeatReceiver(me.retrodaredevil.solarthing.program.receiver.RequestHeartbeatReceiver) PacketGroupReceiverMultiplexer(me.retrodaredevil.solarthing.PacketGroupReceiverMultiplexer) EnvironmentUpdater(me.retrodaredevil.solarthing.actions.command.EnvironmentUpdater) SourceEnvironment(me.retrodaredevil.solarthing.actions.environment.SourceEnvironment) FileWritePacketHandler(me.retrodaredevil.solarthing.packets.handling.implementations.FileWritePacketHandler) PostPacketHandler(me.retrodaredevil.solarthing.packets.handling.implementations.PostPacketHandler) JacksonStringPacketHandler(me.retrodaredevil.solarthing.packets.handling.implementations.JacksonStringPacketHandler) ActionNodeDataReceiver(me.retrodaredevil.solarthing.program.receiver.ActionNodeDataReceiver)

Aggregations

SourceEnvironment (me.retrodaredevil.solarthing.actions.environment.SourceEnvironment)3 EventReceiverEnvironment (me.retrodaredevil.solarthing.actions.environment.EventReceiverEnvironment)2 OpenSource (me.retrodaredevil.solarthing.type.open.OpenSource)2 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 ActionNode (me.retrodaredevil.action.node.ActionNode)1 NanoTimeProviderEnvironment (me.retrodaredevil.action.node.environment.NanoTimeProviderEnvironment)1 PacketGroupReceiver (me.retrodaredevil.solarthing.PacketGroupReceiver)1 PacketGroupReceiverMultiplexer (me.retrodaredevil.solarthing.PacketGroupReceiverMultiplexer)1 EnvironmentUpdater (me.retrodaredevil.solarthing.actions.command.EnvironmentUpdater)1 LatestPacketGroupEnvironment (me.retrodaredevil.solarthing.actions.environment.LatestPacketGroupEnvironment)1 MateCommandEnvironment (me.retrodaredevil.solarthing.actions.environment.MateCommandEnvironment)1 TimeZoneEnvironment (me.retrodaredevil.solarthing.actions.environment.TimeZoneEnvironment)1 SourcedCommand (me.retrodaredevil.solarthing.commands.command.SourcedCommand)1 Packet (me.retrodaredevil.solarthing.packets.Packet)1 FileWritePacketHandler (me.retrodaredevil.solarthing.packets.handling.implementations.FileWritePacketHandler)1 JacksonStringPacketHandler (me.retrodaredevil.solarthing.packets.handling.implementations.JacksonStringPacketHandler)1 PostPacketHandler (me.retrodaredevil.solarthing.packets.handling.implementations.PostPacketHandler)1 PacketListReceiverHandler (me.retrodaredevil.solarthing.program.PacketListReceiverHandler)1 ActionNodeDataReceiver (me.retrodaredevil.solarthing.program.receiver.ActionNodeDataReceiver)1